예제 #1
0
 public void actionPerformed(ActionEvent e) {
   KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
   Container container = kfm.getCurrentFocusCycleRoot();
   FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
   if (null == policy) policy = kfm.getDefaultFocusTraversalPolicy();
   Component next =
       moveDown
           ? policy.getComponentAfter(container, PaletteGroupHeader.this)
           : policy.getComponentBefore(container, PaletteGroupHeader.this);
   if (null != next && next instanceof PaletteComponentList) {
     final PaletteComponentList list = (PaletteComponentList) next;
     if (list.getModel().getSize() != 0) {
       list.takeFocusFrom(PaletteGroupHeader.this, list == myComponentList ? 0 : -1);
       return;
     } else {
       next =
           moveDown
               ? policy.getComponentAfter(container, next)
               : policy.getComponentBefore(container, next);
     }
   }
   if (null != next && next instanceof PaletteGroupHeader) {
     next.requestFocus();
   }
 }
  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);
    WolfTheProblemSolver.getInstance(project).addProblemListener(listener);
    ActionManager.getInstance().addAnActionListener(listener);

    final MessageBusConnection connection = project.getMessageBus().connect();
    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);
      }
    }
  }
예제 #3
0
 @Nullable
 private static Editor getEditorFromFocus() {
   final Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
   if (c instanceof EditorComponentImpl) {
     return ((EditorComponentImpl) c).getEditor();
   }
   return null;
 }
  @Nullable
  private Editor validateCurrentEditor() {
    Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (focusOwner instanceof JComponent) {
      final JComponent jComponent = (JComponent) focusOwner;
      if (jComponent.getClientProperty("AuxEditorComponent") != null)
        return null; // Hack for EditorSearchComponent
    }

    return myEditor;
  }
 static void unsubscribeFrom(NavBarPanel panel) {
   final NavBarListener listener = (NavBarListener) panel.getClientProperty(LISTENER);
   panel.putClientProperty(LISTENER, null);
   if (listener != null) {
     final Project project = panel.getProject();
     KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(listener);
     FileStatusManager.getInstance(project).removeFileStatusListener(listener);
     PsiManager.getInstance(project).removePsiTreeChangeListener(listener);
     WolfTheProblemSolver.getInstance(project).removeProblemListener(listener);
     ActionManager.getInstance().removeAnActionListener(listener);
     final MessageBusConnection connection = (MessageBusConnection) panel.getClientProperty(BUS);
     panel.putClientProperty(BUS, null);
     if (connection != null) {
       connection.disconnect();
     }
   }
 }
예제 #6
0
    private void disposeFocusTrackbackIfNoChildWindowFocused(
        @Nullable IdeFocusManager focusManager) {
      if (myFocusTrackback == null) return;

      final DialogWrapper wrapper = myDialogWrapper.get();
      if (wrapper == null || !wrapper.isShowing()) {
        myFocusTrackback.dispose();
        return;
      }

      if (focusManager != null) {
        final Component c = focusManager.getFocusedDescendantFor(wrapper.getContentPane());
        if (c == null) {
          myFocusTrackback.dispose();
        }
      } else {
        final Component owner =
            KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        if (owner == null || !SwingUtilities.isDescendingFrom(owner, wrapper.getContentPane())) {
          myFocusTrackback.dispose();
        }
      }
    }
예제 #7
0
    @Override
    public void update(AnActionEvent e) {
      Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
      e.getPresentation().setEnabled(false);
      if (focusOwner instanceof JComponent
          && SpeedSearchBase.hasActiveSpeedSearch((JComponent) focusOwner)) {
        return;
      }

      if (StackingPopupDispatcher.getInstance().isPopupFocused()) return;

      if (focusOwner instanceof JTree) {
        JTree tree = (JTree) focusOwner;
        if (!tree.isEditing()) {
          e.getPresentation().setEnabled(true);
        }
      } else if (focusOwner instanceof JTable) {
        JTable table = (JTable) focusOwner;
        if (!table.isEditing()) {
          e.getPresentation().setEnabled(true);
        }
      }
    }
  /**
   * @return <code>true</code> if and only if the passed event is already dispatched by the <code>
   *     IdeKeyEventDispatcher</code> and there is no need for any other processing of the event.
   */
  public boolean dispatchKeyEvent(final KeyEvent e) {
    if (myDisposed) return false;

    if (e.isConsumed()) {
      return false;
    }

    // http://www.jetbrains.net/jira/browse/IDEADEV-12372
    if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
      if (e.getID() == KeyEvent.KEY_PRESSED) {
        myLeftCtrlPressed = e.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT;
      } else if (e.getID() == KeyEvent.KEY_RELEASED) {
        myLeftCtrlPressed = false;
      }
    } else if (e.getKeyCode() == KeyEvent.VK_ALT) {
      if (e.getID() == KeyEvent.KEY_PRESSED) {
        myRightAltPressed = e.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT;
      } else if (e.getID() == KeyEvent.KEY_RELEASED) {
        myRightAltPressed = false;
      }
    }

    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focusOwner = focusManager.getFocusOwner();

    // shortcuts should not work in shortcut setup fields
    if (focusOwner instanceof ShortcutTextField) {
      return false;
    }
    if (focusOwner instanceof JTextComponent && ((JTextComponent) focusOwner).isEditable()) {
      if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED && e.getKeyChar() != KeyEvent.VK_ESCAPE) {
        MacUIUtil.hideCursor();
      }
    }

    MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager();
    MenuElement[] selectedPath = menuSelectionManager.getSelectedPath();
    if (selectedPath.length > 0) {
      if (!(selectedPath[0] instanceof ComboPopup)) {
        // The following couple of lines of code is a PATCH!!!
        // It is needed to ignore ENTER KEY_TYPED events which sometimes can reach editor when an
        // action
        // is invoked from main menu via Enter key.
        setState(KeyState.STATE_PROCESSED);
        setPressedWasProcessed(true);
        return false;
      }
    }

    // Keymap shortcuts (i.e. not local shortcuts) should work only in:
    // - main frame
    // - floating focusedWindow
    // - when there's an editor in contexts
    Window focusedWindow = focusManager.getFocusedWindow();
    boolean isModalContext = focusedWindow != null && isModalContext(focusedWindow);

    final DataManager dataManager = DataManager.getInstance();
    if (dataManager == null) return false;

    DataContext dataContext = dataManager.getDataContext();

    myContext.setDataContext(dataContext);
    myContext.setFocusOwner(focusOwner);
    myContext.setModalContext(isModalContext);
    myContext.setInputEvent(e);

    try {
      if (getState() == KeyState.STATE_INIT) {
        return inInitState();
      } else if (getState() == KeyState.STATE_PROCESSED) {
        return inProcessedState();
      } else if (getState() == KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE) {
        return inWaitForSecondStrokeState();
      } else if (getState() == KeyState.STATE_SECOND_STROKE_IN_PROGRESS) {
        return inSecondStrokeInProgressState();
      } else if (getState() == KeyState.STATE_KEY_GESTURE_PROCESSOR) {
        return myKeyGestureProcessor.process();
      } else {
        throw new IllegalStateException("state = " + getState());
      }
    } finally {
      myContext.clear();
    }
  }