com.intellij.ide.ui.UISettingsListener Java Examples

The following examples show how to use com.intellij.ide.ui.UISettingsListener. 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: IdeMenuBar.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void addNotify() {
  super.addNotify();

  updateMenuActions();

  // Add updater for menus
  myActionManager.addTimerListener(1000, new WeakTimerListener(myTimerListener));
  UISettingsListener UISettingsListener = new UISettingsListener() {
    @Override
    public void uiSettingsChanged(final UISettings source) {
      updateMnemonicsVisibility();
      myPresentationFactory.reset();
    }
  };
  UISettings.getInstance().addUISettingsListener(UISettingsListener, myDisposable);
  Disposer.register(ApplicationManager.getApplication(), myDisposable);
  IdeEventQueue.getInstance().addDispatcher(this, myDisposable);
}
 
Example #2
Source File: EditorHistoryManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Inject
EditorHistoryManager(@Nonnull Project project) {
  myProject = project;

  MessageBusConnection connection = project.getMessageBus().connect();

  connection.subscribe(UISettingsListener.TOPIC, new UISettingsListener() {
    @Override
    public void uiSettingsChanged(UISettings uiSettings) {
      trimToSize();
    }
  });

  connection.subscribe(FileEditorManagerListener.Before.FILE_EDITOR_MANAGER, new FileEditorManagerListener.Before.Adapter() {
    @Override
    public void beforeFileClosed(@Nonnull FileEditorManager source, @Nonnull VirtualFile file) {
      updateHistoryEntry(file, false);
    }
  });
  connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new MyEditorManagerListener());
}
 
Example #3
Source File: BreadcrumbsInitializingActivity.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void runActivity(@Nonnull Project project) {
  if (project.isDefault() || ApplicationManager.getApplication().isUnitTestMode() || project.isDisposed()) {
    return;
  }

  MessageBusConnection connection = project.getMessageBus().connect();
  connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new MyFileEditorManagerListener());
  connection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() {
    @Override
    public void fileTypesChanged(@Nonnull FileTypeEvent event) {
      reinitBreadcrumbsInAllEditors(project);
    }
  });

  VirtualFileManager.getInstance().addVirtualFileListener(new MyVirtualFileListener(project), project);
  connection.subscribe(UISettingsListener.TOPIC, uiSettings -> reinitBreadcrumbsInAllEditors(project));

  UIUtil.invokeLaterIfNeeded(() -> reinitBreadcrumbsInAllEditors(project));
}
 
Example #4
Source File: StructureViewComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void setupTree() {
  myTree.setCellRenderer(new NodeRenderer());
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
  myTree.setShowsRootHandles(true);
  registerPsiListener(myProject, this, this::queueUpdate);
  myProject.getMessageBus().connect(this).subscribe(UISettingsListener.TOPIC, o -> rebuild());

  if (showScrollToFromSourceActions()) {
    myAutoScrollToSourceHandler.install(myTree);
    myAutoScrollFromSourceHandler.install();
  }

  TreeUtil.installActions(getTree());

  new TreeSpeedSearch(getTree(), treePath -> {
    Object userObject = TreeUtil.getLastUserObject(treePath);
    return userObject != null ? FileStructurePopup.getSpeedSearchText(userObject) : null;
  });

  addTreeKeyListener();
  addTreeMouseListeners();
  restoreState();
}
 
Example #5
Source File: GitStatusWidget.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
private void connect() {
  myConnection.subscribe(PerRepoInfoCache.CACHE_CHANGE, new PerRepoStatusCacheListener() {
    @Override
    public void stateChanged(@NotNull RepoInfo info, @NotNull GitRepository repository) {
      if (isActive()) {
        onCacheChange(myProject, info, repository);
      }
    }
  });
  myConnection.subscribe(AppConfigNotifier.CONFIG_TOPIC, new AppConfigNotifier() {
    @Override
    public void configChanged(@NotNull GitToolBoxConfig2 previous, @NotNull GitToolBoxConfig2 current) {
      updateVisibleFromConfig();
      if (current.getShowStatusWidget()) {
        runUpdateLater(myProject);
      }
      if (current.getShowStatusWidget() != previous.getShowStatusWidget()) {
        repaintStatusBar();
      }
    }
  });
  myConnection.subscribe(UISettingsListener.TOPIC, uiSettings -> {
    if (isActive()) {
      repaintStatusBar();
    }
  });
  myConnection.subscribe(ChangesTrackerService.CHANGES_TRACKER_TOPIC, () -> {
    if (isActive()) {
      runUpdateLater(myProject);
    }
  });
}
 
Example #6
Source File: IdeNotificationArea.java    From consulo with Apache License 2.0 5 votes vote down vote up
public IdeNotificationArea() {
  myLabel = Label.create();

  new ClickListener() {
    @Override
    public boolean onClick(@Nonnull MouseEvent e, int clickCount) {
      EventLog.toggleLog(getProject(), null);
      return true;
    }
  }.installOn(TargetAWT.to(myLabel));

  MessageBusConnection connection = Application.get().getMessageBus().connect(this);
  connection.subscribe(UISettingsListener.TOPIC, source -> updateStatus());
  connection.subscribe(LogModel.LOG_MODEL_CHANGED, () -> Application.get().invokeLater(IdeNotificationArea.this::updateStatus));
}
 
Example #7
Source File: GTMStatusWidget.java    From gtm-jetbrains-plugin with MIT License 4 votes vote down vote up
@Override
public void install(@NotNull StatusBar statusBar) {
    super.install(statusBar);
    myConnection.subscribe(UISettingsListener.TOPIC, uiSettings -> runUpdateLater());
}
 
Example #8
Source File: OuterIgnoreWrapper.java    From idea-gitignore with MIT License 4 votes vote down vote up
/** Constructor. */
@SuppressWarnings("unchecked")
public OuterIgnoreWrapper(@NotNull final Project project, @NotNull final IgnoreLanguage language,
                          @NotNull final List<VirtualFile> outerFiles) {
    this.outerFiles = outerFiles;
    settings = IgnoreSettings.getInstance();

    panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 5, 10));

    northPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 5));

    JBLabel label = new JBLabel(
            IgnoreBundle.message("outer.label"),
            UIUtil.ComponentStyle.REGULAR,
            UIUtil.FontColor.BRIGHTER
    );
    label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
    northPanel.add(label);

    tabbedPanel = new TabbedPaneWrapper(project);
    messageBus = project.getMessageBus().connect();
    messageBus.subscribe(UISettingsListener.TOPIC, uiSettings -> updateTabbedPanelPolicy());
    updateTabbedPanelPolicy();

    linkLabel = new LinkLabel(
            outerFiles.get(0).getPath(),
            null,
            (aSource, aLinkData) -> Utils.openFile(project, outerFiles.get(tabbedPanel.getSelectedIndex()))
    );
    final VirtualFile userHomeDir = VfsUtil.getUserHomeDir();

    for (final VirtualFile outerFile : outerFiles) {
        Document document = FileDocumentManager.getInstance().getDocument(outerFile);
        Editor outerEditor = document != null ? Utils.createPreviewEditor(document, null, true) : null;

        if (outerEditor != null) {
            final JScrollPane scrollPanel = ScrollPaneFactory.createScrollPane(outerEditor.getComponent());
            scrollPanel.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
            scrollPanel.setPreferredSize(new Dimension(0, settings.getOuterIgnoreWrapperHeight()));

            String path = outerFile.getPath();
            if (userHomeDir != null) {
                path = path.replace(userHomeDir.getPath(), "~");
            }

            Icon icon = ((language instanceof GitLanguage) || (language instanceof GitExcludeLanguage))
                    ? AllIcons.Vcs.Ignore_file : language.getIcon();

            tabbedPanel.addTab(path, icon, scrollPanel, outerFile.getCanonicalPath());
            outerEditors.add(outerEditor);
        }
    }

    northPanel.addMouseListener(this);
    northPanel.addMouseMotionListener(this);
    tabbedPanel.addChangeListener(this);

    panel.add(northPanel, BorderLayout.NORTH);
    panel.add(tabbedPanel.getComponent(), BorderLayout.CENTER);
    panel.add(linkLabel, BorderLayout.SOUTH);
}
 
Example #9
Source File: ToolWindowsWidget.java    From consulo with Apache License 2.0 4 votes vote down vote up
ToolWindowsWidget(@Nonnull Disposable parent) {
  setBorder(JBUI.Borders.empty());
  new BaseButtonBehavior(this, TimedDeadzone.NULL) {
    @Override
    protected void execute(MouseEvent e) {
      performAction();
    }
  }.setActionTrigger(MouseEvent.MOUSE_PRESSED);

  IdeEventQueue.getInstance().addDispatcher(e -> {
    if (e instanceof MouseEvent) {
      MouseEvent mouseEvent = (MouseEvent)e;
      if (mouseEvent.getComponent() == null || !SwingUtilities.isDescendingFrom(mouseEvent.getComponent(), SwingUtilities.getWindowAncestor(this))) {
        return false;
      }

      if (e.getID() == MouseEvent.MOUSE_MOVED && isShowing()) {
        Point p = mouseEvent.getLocationOnScreen();
        Point screen = this.getLocationOnScreen();
        if (new Rectangle(screen.x - 4, screen.y - 2, getWidth() + 4, getHeight() + 4).contains(p)) {
          mouseEntered();
          wasExited = false;
        }
        else {
          if (!wasExited) {
            wasExited = mouseExited(p);
          }
        }
      }
      else if (e.getID() == MouseEvent.MOUSE_EXITED) {
        //mouse exits WND
        mouseExited(mouseEvent.getLocationOnScreen());
      }
    }
    return false;
  }, parent);

  ApplicationManager.getApplication().getMessageBus().connect(this).subscribe(UISettingsListener.TOPIC, this);
  KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner", this);
  myAlarm = new Alarm(parent);
}
 
Example #10
Source File: DesktopEditorsSplitters.java    From consulo with Apache License 2.0 4 votes vote down vote up
public DesktopEditorsSplitters(FileEditorManagerImpl manager, DockManager dockManager, boolean createOwnDockableContainer) {
  myComponent = new IdePanePanel(new BorderLayout()) {
    @Override
    protected void paintComponent(Graphics g) {
      if (showEmptyText()) {
        Graphics2D gg = IdeBackgroundUtil.withFrameBackground(g, this);
        super.paintComponent(gg);
        g.setColor(UIUtil.isUnderDarcula() ? UIUtil.getBorderColor() : new Color(0, 0, 0, 50));
        g.drawLine(0, 0, getWidth(), 0);
      }
    }
  };
  myComponent.setFocusTraversalPolicy(new MyFocusTraversalPolicy());
  myComponent.setTransferHandler(new MyTransferHandler());
  DataManager.registerDataProvider(myComponent, dataId -> {
    if (dataId == KEY) {
      return this;
    }
    return null;
  });

  AWTComponentProviderUtil.putMark(myComponent, this);

  myManager = manager;
  myFocusWatcher = new MyFocusWatcher();

  clear();

  if (createOwnDockableContainer) {
    DockableEditorTabbedContainer dockable = new DockableEditorTabbedContainer(myManager.getProject(), this, false);
    Disposer.register(manager.getProject(), dockable);
    dockManager.register(dockable);
  }
  KeymapManagerListener keymapListener = keymap -> {
    myComponent.invalidate();
    myComponent.repaint();
  };
  KeymapManager.getInstance().addKeymapManagerListener(keymapListener, this);

  Application.get().getMessageBus().connect(this).subscribe(UISettingsListener.TOPIC, source -> {
    if (!myManager.getProject().isOpen()) {
      return;
    }

    for (VirtualFile file : getOpenFiles()) {
      updateFileBackgroundColor(file);
      updateFileIcon(file);
      updateFileColor(file);
    }
  });
}
 
Example #11
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 #12
Source File: FileEditorManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void projectOpened(@Nonnull MessageBusConnection connection) {
  //myFocusWatcher.install(myWindows.getComponent ());
  getMainSplitters().startListeningFocus();

  final FileStatusManager fileStatusManager = FileStatusManager.getInstance(myProject);
  if (fileStatusManager != null) {
    /*
      Updates tabs colors
     */
    final MyFileStatusListener myFileStatusListener = new MyFileStatusListener();
    fileStatusManager.addFileStatusListener(myFileStatusListener, myProject);
  }
  connection.subscribe(FileTypeManager.TOPIC, new MyFileTypeListener());
  connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyRootsListener());

  /*
    Updates tabs names
   */
  final MyVirtualFileListener myVirtualFileListener = new MyVirtualFileListener();
  VirtualFileManager.getInstance().addVirtualFileListener(myVirtualFileListener, myProject);
  /*
    Extends/cuts number of opened tabs. Also updates location of tabs.
   */
  connection.subscribe(UISettingsListener.TOPIC, new MyUISettingsListener());

  StartupManager.getInstance(myProject).registerPostStartupActivity((DumbAwareRunnable)() -> {
    if (myProject.isDisposed()) return;
    setTabsMode(UISettings.getInstance().getEditorTabPlacement() != UISettings.TABS_NONE);

    ToolWindowManager.getInstance(myProject).invokeLater(() -> {
      if (!myProject.isDisposed()) {
        CommandProcessor.getInstance().executeCommand(myProject, () -> {
          ApplicationManager.getApplication().invokeLater(() -> {
            long currentTime = System.nanoTime();
            Long startTime = myProject.getUserData(ProjectImpl.CREATION_TIME);
            if (startTime != null) {
              LOG.info("Project opening took " + (currentTime - startTime) / 1000000 + " ms");
              PluginManagerCore.dumpPluginClassStatistics(LOG);
            }
          }, myProject.getDisposed());
          // group 1
        }, "", null);
      }
    });
  });
}
 
Example #13
Source File: DockManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private DockWindow(String id, Project project, DockContainer container, boolean dialog) {
  super(project, null, dialog);
  myId = id;
  myContainer = container;
  setProject(project);

  if (!(container instanceof DockContainer.Dialog)) {
    setStatusBar(WindowManager.getInstance().getStatusBar(project).createChild());
  }

  myUiContainer = new NonOpaquePanel(new BorderLayout());

  NonOpaquePanel center = new NonOpaquePanel(new BorderLayout(0, 2));
  if (UIUtil.isUnderAquaLookAndFeel()) {
    center.setOpaque(true);
    center.setBackground(JBTabsImpl.MAC_AQUA_BG_COLOR);
  }

  center.add(myNorthPanel, BorderLayout.NORTH);

  myDockContentUiContainer = new NonOpaquePanel(new BorderLayout());
  myDockContentUiContainer.add(myContainer.getContainerComponent(), BorderLayout.CENTER);
  center.add(myDockContentUiContainer, BorderLayout.CENTER);

  myUiContainer.add(center, BorderLayout.CENTER);
  if (myStatusBar != null) {
    myUiContainer.add(myStatusBar.getComponent(), BorderLayout.SOUTH);
  }

  setComponent(myUiContainer);
  addDisposable(container);

  IdeEventQueue.getInstance().addPostprocessor(this, this);

  myContainer.addListener(new DockContainer.Listener.Adapter() {
    @Override
    public void contentRemoved(Object key) {
      getReady().doWhenDone(() -> {
        if (myContainer.isEmpty()) {
          close();
        }
      });
    }
  }, this);

  UISettings.getInstance().addUISettingsListener(new UISettingsListener() {
    @Override
    public void uiSettingsChanged(UISettings source) {
      updateNorthPanel();
    }
  }, this);

  updateNorthPanel();
}
 
Example #14
Source File: DesktopToolWindowPanelImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
  try {
    final ToolWindowAnchor anchor = myInfo.getAnchor();
    class MySplitter extends Splitter implements UISettingsListener {
      @Override
      public void uiSettingsChanged(UISettings uiSettings) {
        if (anchor == ToolWindowAnchor.LEFT) {
          setOrientation(!uiSettings.getLeftHorizontalSplit());
        }
        else if (anchor == ToolWindowAnchor.RIGHT) {
          setOrientation(!uiSettings.getRightHorizontalSplit());
        }
      }
    }
    Splitter splitter = new MySplitter();
    splitter.setOrientation(anchor.isSplitVertically());
    if (!anchor.isHorizontal()) {
      splitter.setAllowSwitchOrientationByMouseClick(true);
      splitter.addPropertyChangeListener(evt -> {
        if (!Splitter.PROP_ORIENTATION.equals(evt.getPropertyName())) return;
        boolean isSplitterHorizontalNow = !splitter.isVertical();
        UISettings settings = UISettings.getInstance();
        if (anchor == ToolWindowAnchor.LEFT) {
          if (settings.getLeftHorizontalSplit() != isSplitterHorizontalNow) {
            settings.setLeftHorizontalSplit(isSplitterHorizontalNow);
            settings.fireUISettingsChanged();
          }
        }
        if (anchor == ToolWindowAnchor.RIGHT) {
          if (settings.getRightHorizontalSplit() != isSplitterHorizontalNow) {
            settings.setRightHorizontalSplit(isSplitterHorizontalNow);
            settings.fireUISettingsChanged();
          }
        }
      });
    }
    JComponent c = getComponentAt(anchor);
    float newWeight;
    if (c instanceof DesktopInternalDecorator) {
      DesktopInternalDecorator oldComponent = (DesktopInternalDecorator)c;
      if (myInfo.isSplit()) {
        splitter.setFirstComponent(oldComponent);
        splitter.setSecondComponent(myNewComponent);
        float proportion = getPreferredSplitProportion(oldComponent.getWindowInfo().getId(), WindowInfoImpl
                .normalizeWeigh(oldComponent.getWindowInfo().getSideWeight() / (oldComponent.getWindowInfo().getSideWeight() + myInfo.getSideWeight())));
        splitter.setProportion(proportion);
        if (!anchor.isHorizontal() && !anchor.isSplitVertically()) {
          newWeight = WindowInfoImpl.normalizeWeigh(oldComponent.getWindowInfo().getWeight() + myInfo.getWeight());
        }
        else {
          newWeight = WindowInfoImpl.normalizeWeigh(oldComponent.getWindowInfo().getWeight());
        }
      }
      else {
        splitter.setFirstComponent(myNewComponent);
        splitter.setSecondComponent(oldComponent);
        splitter.setProportion(WindowInfoImpl.normalizeWeigh(myInfo.getSideWeight()));
        if (!anchor.isHorizontal() && !anchor.isSplitVertically()) {
          newWeight = WindowInfoImpl.normalizeWeigh(oldComponent.getWindowInfo().getWeight() + myInfo.getWeight());
        }
        else {
          newWeight = WindowInfoImpl.normalizeWeigh(myInfo.getWeight());
        }
      }
    }
    else {
      newWeight = WindowInfoImpl.normalizeWeigh(myInfo.getWeight());
    }
    setComponent(splitter, anchor, newWeight);

    if (!myDirtyMode) {
      myLayeredPane.validate();
      myLayeredPane.repaint();
    }
  }
  finally {
    finish();
  }
}
 
Example #15
Source File: NavBarRootPaneExtension.java    From consulo with Apache License 2.0 3 votes vote down vote up
@Inject
public NavBarRootPaneExtension(Project project) {
  myProject = project;

  myProject.getMessageBus().connect().subscribe(UISettingsListener.TOPIC, uiSettings -> toggleRunPanel(!uiSettings.getShowMainToolbar() && uiSettings.getShowNavigationBar() && !uiSettings.getPresentationMode()));

  myNavToolbarGroupExist = runToolbarExists();

  Disposer.register(myProject, this);
}