Java Code Examples for com.intellij.openapi.wm.IdeFocusManager#getFocusOwner()

The following examples show how to use com.intellij.openapi.wm.IdeFocusManager#getFocusOwner() . 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: DesktopEditorAnalyzeStatusPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private AnAction createAction(@Nonnull String id, @Nonnull Image icon) {
  AnAction delegate = ActionManager.getInstance().getAction(id);
  AnAction result = new DumbAwareAction(delegate.getTemplatePresentation().getText(), null, icon) {
    @RequiredUIAccess
    @Override
    public void actionPerformed(@Nonnull AnActionEvent e) {
      IdeFocusManager focusManager = IdeFocusManager.getInstance(myEditor.getProject());

      AnActionEvent delegateEvent = AnActionEvent.createFromAnAction(delegate, e.getInputEvent(), ActionPlaces.EDITOR_INSPECTIONS_TOOLBAR, myEditor.getDataContext());

      if (focusManager.getFocusOwner() != myEditor.getContentComponent()) {
        focusManager.requestFocus(myEditor.getContentComponent(), true).doWhenDone(() -> {
          delegate.actionPerformed(delegateEvent);
        });
      }
      else {
        delegate.actionPerformed(delegateEvent);
      }
    }
  };

  result.copyShortcutFrom(delegate);
  return result;
}
 
Example 2
Source File: FileEditorManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private EditorsSplitters getActiveSplittersSync() {
  assertDispatchThread();

  final IdeFocusManager fm = IdeFocusManager.getInstance(myProject);
  Component focusOwner = fm.getFocusOwner();
  if (focusOwner == null) {
    focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
  }
  if (focusOwner == null) {
    focusOwner = fm.getLastFocusedFor(fm.getLastFocusedFrame());
  }

  DockContainer container = myDockManager.getContainerFor(focusOwner);
  if (container == null) {
    focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    container = myDockManager.getContainerFor(focusOwner);
  }

  if (container instanceof DockableEditorTabbedContainer) {
    return ((DockableEditorTabbedContainer)container).getSplitters();
  }
  return getMainSplitters();
}
 
Example 3
Source File: QueryPanel.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
public void requestFocusOnEditor() {// Code from requestFocus of EditorImpl
    final IdeFocusManager focusManager = IdeFocusManager.getInstance(this.project);
    JComponent editorContentComponent = getCurrentOperatorPanel().getRequestFocusComponent();
    if (focusManager.getFocusOwner() != editorContentComponent) {
        focusManager.requestFocus(editorContentComponent, true);
    }
}
 
Example 4
Source File: DesktopEditorImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void requestFocus() {
  final IdeFocusManager focusManager = IdeFocusManager.getInstance(myProject);
  if (focusManager.getFocusOwner() != myEditorComponent) { //IDEA-64501
    focusManager.requestFocus(myEditorComponent, true);
  }
}