com.intellij.openapi.actionSystem.ex.AnActionListener Java Examples

The following examples show how to use com.intellij.openapi.actionSystem.ex.AnActionListener. 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: ActionTracer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public JComponent getComponent() {
  if (myComponent == null) {
    myText = new JTextArea();
    final JBScrollPane log = new JBScrollPane(myText);
    final AnAction clear = new AnAction("Clear", "Clear log", AllIcons.General.Reset) {
      @Override
      public void actionPerformed(AnActionEvent e) {
        myText.setText(null);
      }
    };
    myComponent = new JPanel(new BorderLayout());
    final DefaultActionGroup group = new DefaultActionGroup();
    group.add(clear);
    myComponent.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent(), BorderLayout.NORTH);
    myComponent.add(log);

    myListenerDisposable = Disposable.newDisposable();
    Application.get().getMessageBus().connect(myListenerDisposable).subscribe(AnActionListener.TOPIC, this);
  }

  return myComponent;
}
 
Example #2
Source File: ActionTracker.java    From consulo with Apache License 2.0 6 votes vote down vote up
ActionTracker(Editor editor, Disposable parentDisposable) {
  myEditor = editor;
  myProject = editor.getProject();
  ActionManager.getInstance().addAnActionListener(new AnActionListener.Adapter() {
    @Override
    public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
      myActionsHappened = true;
    }
  }, parentDisposable);
  myEditor.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    public void documentChanged(DocumentEvent e) {
      if (!myIgnoreDocumentChanges) {
        myActionsHappened = true;
      }
    }
  }, parentDisposable);
}
 
Example #3
Source File: IgnoredViewDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void addCustomActions(@Nonnull DefaultActionGroup group, @Nonnull ActionToolbar actionToolbar) {
  ActionManager actionManager = ActionManager.getInstance();
  AnAction deleteAction = EmptyAction.registerWithShortcutSet("ChangesView.DeleteUnversioned.From.Dialog", CommonShortcuts.getDelete(), myView);
  actionManager.addAnActionListener(new AnActionListener.Adapter() {
    @Override
    public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
      if (action.equals(deleteAction)) {
        refreshView();
        refreshChanges(myProject, getBrowserBase(myView));
      }
    }
  }, myDisposable);
  group.add(deleteAction);
  myView.setMenuActions(new DefaultActionGroup(deleteAction));
}
 
Example #4
Source File: MultipleChangeListBrowser.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void setupRebuildListForActions() {
  ActionManager actionManager = ActionManager.getInstance();
  final AnAction moveAction = actionManager.getAction(IdeActions.MOVE_TO_ANOTHER_CHANGE_LIST);
  final AnAction deleteAction = actionManager.getAction("ChangesView.DeleteUnversioned.From.Dialog");

  actionManager.addAnActionListener(new AnActionListener.Adapter() {
    @Override
    public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
      if (moveAction.equals(action) || myMoveActionWithCustomShortcut != null && myMoveActionWithCustomShortcut.equals(action)) {
        rebuildList();
      }
      else if (deleteAction.equals(action)) {
        UnversionedViewDialog.refreshChanges(myProject, MultipleChangeListBrowser.this);
      }
    }
  }, this);
}
 
Example #5
Source File: ActionManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void fireBeforeActionPerformed(@Nonnull AnAction action, @Nonnull DataContext dataContext, @Nonnull AnActionEvent event) {
  myPrevPerformedActionId = myLastPreformedActionId;
  myLastPreformedActionId = getId(action);
  if (myLastPreformedActionId == null && action instanceof ActionIdProvider) {
    myLastPreformedActionId = ((ActionIdProvider)action).getId();
  }
  //noinspection AssignmentToStaticFieldFromInstanceMethod
  LastActionTracker.ourLastActionId = myLastPreformedActionId;
  final PsiFile file = dataContext.getData(CommonDataKeys.PSI_FILE);
  final Language language = file != null ? file.getLanguage() : null;
  //ActionsCollector.getInstance().record(CommonDataKeys.PROJECT.getData(dataContext), action, event, language);
  for (AnActionListener listener : myActionListeners) {
    listener.beforeActionPerformed(action, dataContext, event);
  }
  publisher().beforeActionPerformed(action, dataContext, event);
}
 
Example #6
Source File: IdeTooltipManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
public IdeTooltipManager() {
  myIsEnabled = Registry.get("ide.tooltip.callout");
  myHelpTooltip = Registry.get("ide.helptooltip.enabled");

  RegistryValueListener.Adapter listener = new RegistryValueListener.Adapter() {
    @Override
    public void afterValueChanged(@Nonnull RegistryValue value) {
      processEnabled();
    }
  };
  Application application = ApplicationManager.getApplication();
  myIsEnabled.addListener(listener, application);
  myHelpTooltip.addListener(listener, application);

  Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);

  application.getMessageBus().connect(application).subscribe(AnActionListener.TOPIC, new AnActionListener() {
    @Override
    public void beforeActionPerformed(@Nonnull AnAction action, @Nonnull DataContext dataContext, @Nonnull AnActionEvent event) {
      hideCurrent(null, action, event);
    }
  });

  processEnabled();
}
 
Example #7
Source File: NavBarListener.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void subscribeTo(NavBarPanel panel) {
  if (panel.getClientProperty(LISTENER) != null) {
    unsubscribeFrom(panel);
  }

  final NavBarListener listener = new NavBarListener(panel);
  final Project project = panel.getProject();
  panel.putClientProperty(LISTENER, listener);
  KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(listener);
  FileStatusManager.getInstance(project).addFileStatusListener(listener);
  PsiManager.getInstance(project).addPsiTreeChangeListener(listener);

  final MessageBusConnection connection = project.getMessageBus().connect();
  connection.subscribe(AnActionListener.TOPIC, listener);
  connection.subscribe(ProblemListener.TOPIC, listener);
  connection.subscribe(ProjectTopics.PROJECT_ROOTS, listener);
  connection.subscribe(NavBarModelListener.NAV_BAR, listener);
  connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);
  panel.putClientProperty(BUS, connection);
  panel.addKeyListener(listener);

  if (panel.isInFloatingMode()) {
    final Window window = SwingUtilities.windowForComponent(panel);
    if (window != null) {
      window.addWindowFocusListener(listener);
    }
  }
}
 
Example #8
Source File: DocumentationComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void registerSizeTracker() {
  AbstractPopup hint = myHint;
  if (hint == null || mySizeTrackerRegistered) return;
  mySizeTrackerRegistered = true;
  hint.addResizeListener(this::onManualResizing, this);
  ApplicationManager.getApplication().getMessageBus().connect(this).subscribe(AnActionListener.TOPIC, new AnActionListener() {
    @Override
    public void afterActionPerformed(@Nonnull AnAction action, @Nonnull DataContext dataContext, @Nonnull AnActionEvent event) {
      if (action instanceof WindowAction) onManualResizing();
    }
  });
}
 
Example #9
Source File: UnversionedViewDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void refreshViewAfterActionPerformed(@Nonnull final List<AnAction> actions) {
  ActionManager.getInstance().addAnActionListener(new AnActionListener.Adapter() {
    @Override
    public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
      if (actions.contains(action)) {
        refreshView();
        if (myDeleteActionWithCustomShortcut.equals(action)) {
          // We can not utilize passed "dataContext" here as it results in
          // "cannot share data context between Swing events" assertion.
          refreshChanges(myProject, getBrowserBase(myView));
        }
      }
    }
  }, myDisposable);
}
 
Example #10
Source File: ActionManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void fireAfterActionPerformed(@Nonnull AnAction action, @Nonnull DataContext dataContext, @Nonnull AnActionEvent event) {
  myPrevPerformedActionId = myLastPreformedActionId;
  myLastPreformedActionId = getId(action);
  //noinspection AssignmentToStaticFieldFromInstanceMethod
  LastActionTracker.ourLastActionId = myLastPreformedActionId;
  for (AnActionListener listener : myActionListeners) {
    try {
      listener.afterActionPerformed(action, dataContext, event);
    }
    catch (AbstractMethodError ignored) {
    }
  }
  publisher().afterActionPerformed(action, dataContext, event);
}
 
Example #11
Source File: ActionManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void fireBeforeEditorTyping(char c, @Nonnull DataContext dataContext) {
  myLastTimeEditorWasTypedIn = System.currentTimeMillis();
  for (AnActionListener listener : myActionListeners) {
    listener.beforeEditorTyping(c, dataContext);
  }
  publisher().beforeEditorTyping(c, dataContext);
}
 
Example #12
Source File: ActionMacroManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public ActionMacroManager(Application application, ActionManager actionManager) {
  myActionManager = actionManager;
  application.getMessageBus().connect(this).subscribe(AnActionListener.TOPIC, new AnActionListener() {
    @Override
    public void beforeActionPerformed(AnAction action, DataContext dataContext, final AnActionEvent event) {
      String id = myActionManager.getId(action);
      if (id == null) return;
      //noinspection HardCodedStringLiteral
      if ("StartStopMacroRecording".equals(id)) {
        myLastActionInputEvent.add(event.getInputEvent());
      }
      else if (myIsRecording) {
        myRecordingMacro.appendAction(id);
        String shortcut = null;
        if (event.getInputEvent() instanceof KeyEvent) {
          shortcut = KeymapUtil.getKeystrokeText(KeyStroke.getKeyStrokeForEvent((KeyEvent)event.getInputEvent()));
        }
        notifyUser(id + (shortcut != null ? " (" + shortcut + ")" : ""), false);
        myLastActionInputEvent.add(event.getInputEvent());
      }
    }
  });

  myKeyProcessor = new MyKeyPostpocessor();

  Platform.runIfDesktopPlatform(() -> IdeEventQueue.getInstance().addPostprocessor(myKeyProcessor, null));
}
 
Example #13
Source File: EditorLastActionTrackerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
EditorLastActionTrackerImpl(Application application, ActionManager actionManager, EditorFactory editorFactory) {
  myActionManager = actionManager;
  application.getMessageBus().connect(this).subscribe(AnActionListener.TOPIC, this);
  myEditorEventMulticaster = editorFactory.getEventMulticaster();
  myEditorEventMulticaster.addEditorMouseListener(this);
}
 
Example #14
Source File: ActionToolbarImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
PopupToolbar(@Nonnull String place, @Nonnull ActionGroup actionGroup, final boolean horizontal, @Nonnull JComponent parent) {
  super(place, actionGroup, horizontal, false, true);
  ApplicationManager.getApplication().getMessageBus().connect(this).subscribe(AnActionListener.TOPIC, this);
  myParent = parent;
  setBorder(myParent.getBorder());
}
 
Example #15
Source File: KeyPromoter.java    From IntelliJ-Key-Promoter-X with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public KeyPromoter() {
  Topics.subscribe(AnActionListener.TOPIC, this, this);
  long eventMask = AWTEvent.MOUSE_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK | AWTEvent.WINDOW_STATE_EVENT_MASK;
  Toolkit.getDefaultToolkit().addAWTEventListener(this, eventMask);
}
 
Example #16
Source File: ActionManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void removeAnActionListener(AnActionListener listener) {
  myActionListeners.remove(listener);
}
 
Example #17
Source File: ActionManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void addAnActionListener(AnActionListener listener) {
  myActionListeners.add(listener);
}
 
Example #18
Source File: ActionManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static AnActionListener publisher() {
  return ApplicationManager.getApplication().getMessageBus().syncPublisher(AnActionListener.TOPIC);
}
 
Example #19
Source File: HintManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public HintManagerImpl() {
  myEditorManagerListener = new MyEditorManagerListener();

  myCaretMoveListener = new CaretListener() {
    @Override
    public void caretPositionChanged(@Nonnull CaretEvent e) {
      hideHints(HIDE_BY_ANY_KEY | HIDE_BY_CARET_MOVE, false, false);
    }
  };

  mySelectionListener = new SelectionListener() {
    @Override
    public void selectionChanged(@Nonnull SelectionEvent e) {
      hideHints(HIDE_BY_CARET_MOVE, false, false);
    }
  };

  final MyProjectManagerListener projectManagerListener = new MyProjectManagerListener();
  for (Project project : ProjectManager.getInstance().getOpenProjects()) {
    projectManagerListener.projectOpened(project);
  }

  MessageBusConnection busConnection = ApplicationManager.getApplication().getMessageBus().connect();
  busConnection.subscribe(ProjectManager.TOPIC, projectManagerListener);
  busConnection.subscribe(AnActionListener.TOPIC, new MyAnActionListener());

  myEditorMouseListener = new EditorMouseListener() {
    @Override
    public void mousePressed(@Nonnull EditorMouseEvent event) {
      hideAllHints();
    }
  };

  myVisibleAreaListener = e -> {
    updateScrollableHints(e);
    if (e.getOldRectangle() == null || e.getOldRectangle().x != e.getNewRectangle().x || e.getOldRectangle().y != e.getNewRectangle().y) {
      hideHints(HIDE_BY_SCROLLING, false, false);
    }
  };

  myEditorDocumentListener = new DocumentListener() {
    @Override
    public void documentChanged(@Nonnull DocumentEvent event) {
      LOG.assertTrue(SwingUtilities.isEventDispatchThread());
      if (event.getOldLength() == 0 && event.getNewLength() == 0) return;
      HintInfo[] infos = getHintsStackArray();
      for (HintInfo info : infos) {
        if (BitUtil.isSet(info.flags, HIDE_BY_TEXT_CHANGE)) {
          if (info.hint.isVisible()) {
            info.hint.hide();
          }
          myHintsStack.remove(info);
        }
      }

      if (myHintsStack.isEmpty()) {
        updateLastEditor(null);
      }
    }
  };
}
 
Example #20
Source File: ActionManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated Use {@link AnActionListener#TOPIC}
 */
public void addAnActionListener(AnActionListener listener, Disposable parentDisposable) {
  Application.get().getMessageBus().connect(parentDisposable).subscribe(AnActionListener.TOPIC, listener);
}
 
Example #21
Source File: ActionManager.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * @deprecated Use {@link AnActionListener#TOPIC}
 */
public abstract void removeAnActionListener(AnActionListener listener);
 
Example #22
Source File: ActionManager.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * @deprecated Use {@link AnActionListener#TOPIC}
 */
public abstract void addAnActionListener(AnActionListener listener);