com.intellij.openapi.wm.ex.ToolWindowManagerListener Java Examples

The following examples show how to use com.intellij.openapi.wm.ex.ToolWindowManagerListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestResultsPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected TestResultsPanel(@Nonnull JComponent console, AnAction[] consoleActions, TestConsoleProperties properties,
                           @Nonnull String splitterProportionProperty, float splitterDefaultProportion) {
  super(new BorderLayout(0,1));
  myConsole = console;
  myConsoleActions = consoleActions;
  myProperties = properties;
  mySplitterProportionProperty = splitterProportionProperty;
  mySplitterDefaultProportion = splitterDefaultProportion;
  myStatisticsSplitterProportionProperty = mySplitterProportionProperty + "_Statistics";
  final ToolWindowManagerListener listener = new ToolWindowManagerListener() {
    @Override
    public void stateChanged() {
      final boolean splitVertically = splitVertically();
      myStatusLine.setPreferredSize(splitVertically);
      mySplitter.setOrientation(splitVertically);
      revalidate();
      repaint();
    }
  };
  ToolWindowManagerEx.getInstanceEx(properties.getProject()).addToolWindowManagerListener(listener, this);
}
 
Example #2
Source File: IMWindowFactory.java    From SmartIM4IntelliJ with Apache License 2.0 5 votes vote down vote up
@Override public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
    instance = this;
    this.project = project;
    toolWindow.setToHideOnEmptyContent(true);
    createContents(project, toolWindow);
    ToolWindowManager manager = ToolWindowManager.getInstance(project);
    if (manager instanceof ToolWindowManagerEx) {
        ToolWindowManagerEx managerEx = ((ToolWindowManagerEx)manager);
        managerEx.addToolWindowManagerListener(new ToolWindowManagerListener() {
            @Override public void toolWindowRegistered(@NotNull String id) {
            }

            @Override public void stateChanged() {
                ToolWindow window =
                    ToolWindowManager.getInstance(project).getToolWindow(IMWindowFactory.TOOL_WINDOW_ID);
                if (window != null) {
                    boolean visible = window.isVisible();
                    if (visible && toolWindow.getContentManager().getContentCount() == 0) {
                        createContents(project, window);
                    }
                }
            }
        });
    }

    //        Disposer.register(project, new Disposable() {
    //            @Override
    //            public void dispose() {
    //                if (panel != null && panel.isEnabled()) {
    //                    panel.setEnabled(false);
    //                    panel = null;
    //                }
    //            }
    //        });
}
 
Example #3
Source File: ToolWindowManagerBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected ToolWindowManagerBase(Project project, Provider<WindowManager> windowManager) {
  myProject = project;
  myWindowManager = windowManager;

  myCommandProcessor = createCommandProcessor();
  myInternalDecoratorListener = createInternalDecoratorListener();

  MessageBusConnection busConnection = project.getMessageBus().connect(this);
  busConnection.subscribe(ToolWindowManagerListener.TOPIC, myDispatcher.getMulticaster());
}
 
Example #4
Source File: FreelineTerminal.java    From freeline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void initTerminal(final ToolWindow toolWindow) {
    toolWindow.setToHideOnEmptyContent(true);
    LocalTerminalDirectRunner terminalRunner = LocalTerminalDirectRunner.createTerminalRunner(myProject);
    toolWindow.setStripeTitle("Freeline");
    Content content = createTerminalInContentPanel(terminalRunner, toolWindow);
    toolWindow.getContentManager().addContent(content);
    toolWindow.setShowStripeButton(true);
    toolWindow.setTitle("Console");
    ((ToolWindowManagerEx) ToolWindowManager.getInstance(this.myProject)).addToolWindowManagerListener(new ToolWindowManagerListener() {
        @Override
        public void toolWindowRegistered(@NotNull String s) {

        }

        @Override
        public void stateChanged() {
            ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(FreelineToolWindowFactory.TOOL_WINDOW_ID);
            if (window != null) {
                boolean visible = window.isVisible();
                if (visible && toolWindow.getContentManager().getContentCount() == 0) {
                    initTerminal(window);
                }
            }
        }
    });
    toolWindow.show(null);
    JBTabbedTerminalWidget terminalWidget = getTerminalWidget(toolWindow);
    if (terminalWidget != null && terminalWidget.getCurrentSession() != null) {
        Terminal terminal = terminalWidget.getCurrentSession().getTerminal();
        if (terminal != null) {
            terminal.setCursorVisible(false);
        }
    }
}
 
Example #5
Source File: ReactNativeConsole.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
     * Init and show this console pane.
     * @param toolWindow
     */
    public void init(final ToolWindow toolWindow) {
        toolWindow.setToHideOnEmptyContent(true);
        toolWindow.setStripeTitle("RN Console");
        toolWindow.setIcon(PluginIcons.React);
        Content content = createConsoleTabContent(toolWindow, true, "Welcome", null);
//        toolWindow.getContentManager().addContent(content);
//        toolWindow.getContentManager().addContent(new ContentImpl(new JButton("Test"), "Build2", false));

        // ======= test a terminal create ======
//        LocalTerminalDirectRunner terminalRunner = LocalTerminalDirectRunner.createTerminalRunner(myProject);
//        Content testTerminalContent = createTerminalInContentPanel(terminalRunner, toolWindow);
//        toolWindow.getContentManager().addContent(testTerminalContent);

//        SimpleTerminal term  = new SimpleTerminal();
//        term.sendString("ls\n");
//        toolWindow.getContentManager().addContent(new ContentImpl(term.getComponent(), "terminal", false));
        toolWindow.setShowStripeButton(true);// if set to false, then sometimes the window will be hidden from the dock area for ever 2017-05-26
//        toolWindow.setTitle(" - ");
        // TODO Change to Eventbus
        ((ToolWindowManagerEx) ToolWindowManager.getInstance(this.myProject)).addToolWindowManagerListener(new ToolWindowManagerListener() {
            @Override
            public void toolWindowRegistered(@NotNull String s) {
            }

            @Override
            public void stateChanged() {
                ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(RNToolWindowFactory.TOOL_WINDOW_ID);
                if (window != null) {
                    boolean visible = window.isVisible();
                    if (visible && toolWindow.getContentManager().getContentCount() == 0) {
                        init(window);
                    }
                }
            }
        });
        toolWindow.show(null);
    }
 
Example #6
Source File: RoutesView.java    From railways with MIT License 4 votes vote down vote up
/**
 * Initializes tool window.
 *
 * @param toolWindow Tool window to initialize.
 */
synchronized void initToolWindow(final ToolWindow toolWindow) {
    myToolWindow = toolWindow;
    myContentManager = toolWindow.getContentManager();

    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        toolWindow.setContentUiType(ToolWindowContentUiType.getInstance("combo"), null);
        toolWindow.getComponent().putClientProperty(ToolWindowContentUi.HIDE_ID_LABEL, "true");
    }

    // Add all modules that are already added till this moment.
    Module[] modules = ModuleManager.getInstance(myProject).getModules();
    for (Module m : modules)
        addModulePane(m);

    // Add listener to update mainPanel when a module is selected from
    // tool window header.
    myContentManager.addContentManagerListener(new ContentManagerAdapter() {
        @Override
        public void selectionChanged(@NotNull ContentManagerEvent event) {
            // When user selects a module from tool window combo,
            // selectionChanges is called twice:
            // 1. With 'remove' operation -  for previously selected item,
            // 2. With 'add' operation - for newly selected item.
            if (event.getOperation() == ContentManagerEvent.ContentOperation.add) {
                viewSelectionChanged();
                refreshRouteActionsStatus();
            }
        }
    });


    // Open tab that was active in previous IDE session
    Content savedContent = myContentManager.getContent(myState.selectedTabId);
    if (savedContent != null)
        myContentManager.setSelectedContent(savedContent);

    mainPanel.getRouteFilter().setMountedRoutesVisible(!myState.hideMountedRoutes);

    myConnection.subscribe(ToolWindowManagerListener.TOPIC, new ToolWindowManagerListener() {

        /**
         * This method is called when ToolWindow changes its state, i.e.
         * expanded/collapsed, docked to another panel, etc.
         */
        @Override
        public void stateChanged() {
            // We have to check if our tool window is still registered, as
            // otherwise it will raise an exception when project is closed.
            if (ToolWindowManagerEx.getInstanceEx(myProject).getToolWindow("Routes") == null)
                return;

            updateToolWindowOrientation(toolWindow);

            if (toolWindow.isVisible())
                if (currentPane != null && currentPane.isRoutesInvalidated())
                    currentPane.updateRoutes();

            refreshRouteActionsStatus();
        }
    });

    updateToolWindowOrientation(toolWindow);
}
 
Example #7
Source File: ToolWindowHeadlessManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void addToolWindowManagerListener(@Nonnull ToolWindowManagerListener listener, @Nonnull Disposable parentDisposable) {
}
 
Example #8
Source File: ToolWindowHeadlessManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void removeToolWindowManagerListener(@Nonnull ToolWindowManagerListener listener) {
}
 
Example #9
Source File: ToolWindowManagerBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void fireToolWindowRegistered(final String id) {
  myProject.getMessageBus().syncPublisher(ToolWindowManagerListener.TOPIC).toolWindowRegistered(id);
}
 
Example #10
Source File: ToolWindowManagerBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void fireStateChanged() {
  myProject.getMessageBus().syncPublisher(ToolWindowManagerListener.TOPIC).stateChanged();
}
 
Example #11
Source File: ToolWindowManagerBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void addToolWindowManagerListener(@Nonnull ToolWindowManagerListener l) {
  myDispatcher.addListener(l);
}
 
Example #12
Source File: ToolWindowManagerBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void addToolWindowManagerListener(@Nonnull ToolWindowManagerListener l, @Nonnull Disposable parentDisposable) {
  myProject.getMessageBus().connect(parentDisposable).subscribe(ToolWindowManagerListener.TOPIC, l);
}
 
Example #13
Source File: ToolWindowManagerBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void removeToolWindowManagerListener(@Nonnull ToolWindowManagerListener l) {
  myDispatcher.removeListener(l);
}
 
Example #14
Source File: EditorTabbedContainer.java    From consulo with Apache License 2.0 4 votes vote down vote up
EditorTabbedContainer(final DesktopEditorWindow window, Project project) {
  myWindow = window;
  myProject = project;
  final ActionManager actionManager = ActionManager.getInstance();
  myTabs = new JBEditorTabs(project, actionManager, IdeFocusManager.getInstance(project), this);
  myTabs.setBorder(new MyShadowBorder(myTabs));
  myTabs.setTransferHandler(new MyTransferHandler());
  myTabs.setDataProvider(new MyDataProvider())
          .setPopupGroup(() -> (ActionGroup)CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_EDITOR_TAB_POPUP),
                         ActionPlaces.EDITOR_TAB_POPUP, false).addTabMouseListener(new TabMouseListener()).getPresentation().setTabDraggingEnabled(true)
          .setUiDecorator(() -> new UiDecorator.UiDecoration(null, new Insets(TabsUtil.TAB_VERTICAL_PADDING, 8, TabsUtil.TAB_VERTICAL_PADDING, 8)))
          .setTabLabelActionsMouseDeadzone(TimedDeadzone.NULL).setGhostsAlwaysVisible(true).setTabLabelActionsAutoHide(false)
          .setActiveTabFillIn(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()).setPaintFocus(false).getJBTabs()
          .addListener(new TabsListener.Adapter() {
            @Override
            public void selectionChanged(final TabInfo oldSelection, final TabInfo newSelection) {
              final FileEditorManager editorManager = FileEditorManager.getInstance(myProject);
              final FileEditor oldEditor = oldSelection != null ? editorManager.getSelectedEditor((VirtualFile)oldSelection.getObject()) : null;
              if (oldEditor != null) {
                oldEditor.deselectNotify();
              }

              VirtualFile newFile = (VirtualFile)newSelection.getObject();
              final FileEditor newEditor = editorManager.getSelectedEditor(newFile);
              if (newEditor != null) {
                newEditor.selectNotify();
              }

              if (GeneralSettings.getInstance().isSyncOnFrameActivation()) {
                VfsUtil.markDirtyAndRefresh(true, false, false, newFile);
              }
            }
          }).setSelectionChangeHandler((info, requestFocus, doChangeSelection) -> {
    final ActionCallback result = new ActionCallback();
    CommandProcessor.getInstance().executeCommand(myProject, () -> {
      ((IdeDocumentHistoryImpl)IdeDocumentHistory.getInstance(myProject)).onSelectionChanged();
      result.notify(doChangeSelection.run());
    }, "EditorChange", null);
    return result;
  }).getPresentation().setRequestFocusOnLastFocusedComponent(true);
  myTabs.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      if (myTabs.findInfo(e) != null || isFloating()) return;
      if (!e.isPopupTrigger() && SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
        final ActionManager mgr = ActionManager.getInstance();
        mgr.tryToExecute(mgr.getAction("HideAllWindows"), e, null, ActionPlaces.UNKNOWN, true);
      }
    }
  });

  setTabPlacement(UISettings.getInstance().EDITOR_TAB_PLACEMENT);

  updateTabBorder();

  ((ToolWindowManagerEx)ToolWindowManager.getInstance(myProject)).addToolWindowManagerListener(new ToolWindowManagerListener() {
    @Override
    public void stateChanged() {
      updateTabBorder();
    }

    @Override
    public void toolWindowRegistered(@Nonnull final String id) {
      updateTabBorder();
    }
  });

  project.getMessageBus().connect().subscribe(UISettingsListener.TOPIC, uiSettings -> updateTabBorder());

  Disposer.register(project, this);
}
 
Example #15
Source File: SpeedSearchBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void manageSearchPopup(@Nullable SearchPopup searchPopup) {
  Project project = null;
  if (ApplicationManager.getApplication() != null && !ApplicationManager.getApplication().isDisposed()) {
    project = DataManager.getInstance().getDataContext(myComponent).getData(CommonDataKeys.PROJECT);
  }
  if (project != null && project.isDefault()) {
    project = null;
  }
  if (mySearchPopup != null) {
    if (myPopupLayeredPane != null) {
      myPopupLayeredPane.remove(mySearchPopup);
      myPopupLayeredPane.validate();
      myPopupLayeredPane.repaint();
      myPopupLayeredPane = null;
    }

    if (myListenerDisposable != null) {
      Disposer.dispose(myListenerDisposable);
      myListenerDisposable = null;
    }
  }
  else if (searchPopup != null) {
    FeatureUsageTracker.getInstance().triggerFeatureUsed("ui.tree.speedsearch");
  }

  mySearchPopup = myComponent.isShowing() ? searchPopup : null;

  fireStateChanged();

  //select here!


  if (mySearchPopup == null || !myComponent.isDisplayable()) return;

  if (project != null) {
    myListenerDisposable = Disposable.newDisposable();
    project.getMessageBus().connect(myListenerDisposable).subscribe(ToolWindowManagerListener.TOPIC, myWindowManagerListener);
  }
  JRootPane rootPane = myComponent.getRootPane();
  myPopupLayeredPane = rootPane == null ? null : rootPane.getLayeredPane();
  if (myPopupLayeredPane == null) {
    LOG.error(this + " in " + myComponent);
    return;
  }
  myPopupLayeredPane.add(mySearchPopup, JLayeredPane.POPUP_LAYER);
  moveSearchPopup();

  mySearchPopup.refreshSelection();
}
 
Example #16
Source File: ProjectViewImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Inject
public ProjectViewImpl(@Nonnull Project project, FileEditorManager fileEditorManager, ToolWindowManager toolWindowManager, @Nonnull ProjectViewSharedSettings projectViewSharedSettings) {
  myProject = project;
  myProjectViewSharedSettings = projectViewSharedSettings;

  constructUi();

  myFileEditorManager = fileEditorManager;

  myConnection = project.getMessageBus().connect();
  myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
    @Override
    public void rootsChanged(ModuleRootEvent event) {
      refresh();
    }
  });

  myAutoScrollFromSourceHandler = new MyAutoScrollFromSourceHandler();

  myDataProvider = new MyPanel();
  myDataProvider.add(myPanel, BorderLayout.CENTER);
  myCopyPasteDelegator = new CopyPasteDelegator(myProject, myPanel) {
    @Override
    @Nonnull
    protected PsiElement[] getSelectedElements() {
      final AbstractProjectViewPane viewPane = getCurrentProjectViewPane();
      return viewPane == null ? PsiElement.EMPTY_ARRAY : viewPane.getSelectedPSIElements();
    }
  };
  myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() {
    @Override
    protected boolean isAutoScrollMode() {
      return isAutoscrollToSource(myCurrentViewId);
    }

    @Override
    protected void setAutoScrollMode(boolean state) {
      setAutoscrollToSource(state, myCurrentViewId);
    }
  };
  ((ToolWindowManagerEx)toolWindowManager).addToolWindowManagerListener(new ToolWindowManagerListener() {
    private boolean toolWindowVisible;

    @Override
    public void stateChanged() {
      ToolWindow window = toolWindowManager.getToolWindow(ToolWindowId.PROJECT_VIEW);
      if (window == null) return;
      if (window.isVisible() && !toolWindowVisible) {
        String id = getCurrentViewId();
        if (isAutoscrollToSource(id)) {
          AbstractProjectViewPane currentProjectViewPane = getCurrentProjectViewPane();

          if (currentProjectViewPane != null) {
            myAutoScrollToSourceHandler.onMouseClicked(currentProjectViewPane.getTree());
          }
        }
        if (isAutoscrollFromSource(id)) {
          myAutoScrollFromSourceHandler.setAutoScrollEnabled(true);
        }
      }
      toolWindowVisible = window.isVisible();
    }
  });
}
 
Example #17
Source File: ToolWindowHeadlessManagerImpl.java    From consulo with Apache License 2.0 2 votes vote down vote up
@Override
public void addToolWindowManagerListener(@Nonnull ToolWindowManagerListener listener) {

}