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

The following examples show how to use com.intellij.openapi.wm.IdeFocusManager#getInstance() . 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: RunnerLayoutUiImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public RunnerLayoutUiImpl(@Nonnull Project project,
                          @Nonnull Disposable parent,
                          @Nonnull String runnerId,
                          @Nonnull String runnerTitle,
                          @Nonnull String sessionName) {
  myLayout = RunnerLayoutSettings.getInstance().getLayout(runnerId);
  consulo.disposer.Disposer.register(parent, this);

  myContentUI = new RunnerContentUi(project, this, ActionManager.getInstance(), IdeFocusManager.getInstance(project), myLayout,
                                    runnerTitle + " - " + sessionName);
  consulo.disposer.Disposer.register(this, myContentUI);

  myViewsContentManager = getContentFactory().createContentManager(myContentUI.getContentUI(), true, project);
  myViewsContentManager.addDataProvider(this);
  consulo.disposer.Disposer.register(this, myViewsContentManager);
}
 
Example 2
Source File: FileEditorManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public ActionCallback notifyPublisher(@Nonnull final Runnable runnable) {
  final IdeFocusManager focusManager = IdeFocusManager.getInstance(myProject);
  final AsyncResult<Void> done = new AsyncResult<>();
  return myBusyObject.execute(new ActiveRunnable() {
    @Nonnull
    @Override
    public AsyncResult<Void> run() {
      focusManager.doWhenFocusSettlesDown(new ExpirableRunnable.ForProject(myProject) {
        @Override
        public void run() {
          runnable.run();
          done.setDone();
        }
      });
      return done;
    }
  });
}
 
Example 3
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 4
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 5
Source File: FileEditorManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private AsyncResult<EditorsSplitters> getActiveSplittersAsync() {
  final AsyncResult<EditorsSplitters> result = new AsyncResult<>();
  final IdeFocusManager fm = IdeFocusManager.getInstance(myProject);
  fm.doWhenFocusSettlesDown(() -> {
    if (myProject.isDisposed()) {
      result.setRejected();
      return;
    }
    Component focusOwner = fm.getFocusOwner();
    DockContainer container = myDockManager.getContainerFor(focusOwner);
    if (container instanceof DockableEditorTabbedContainer) {
      result.setDone(((DockableEditorTabbedContainer)container).getSplitters());
    }
    else {
      result.setDone(getMainSplitters());
    }
  });
  return result;
}
 
Example 6
Source File: NavBarListener.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void keyPressed(final KeyEvent e) {
  if (!(e.isAltDown() || e.isMetaDown() || e.isControlDown() || myPanel.isNodePopupActive())) {
    if (!Character.isLetter(e.getKeyChar())) {
      return;
    }

    final IdeFocusManager focusManager = IdeFocusManager.getInstance(myPanel.getProject());
    final AsyncResult<Void> firstCharTyped = new AsyncResult<>();
    focusManager.typeAheadUntil(firstCharTyped);
    myPanel.moveDown();
    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        try {
          final Robot robot = new Robot();
          final boolean shiftOn = e.isShiftDown();
          final int code = e.getKeyCode();
          if (shiftOn) {
            robot.keyPress(KeyEvent.VK_SHIFT);
          }
          robot.keyPress(code);
          robot.keyRelease(code);

          //don't release Shift
          firstCharTyped.setDone();
        }
        catch (AWTException ignored) {
        }
      }
    });
  }
}
 
Example 7
Source File: AbstractPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
private IdeFocusManager getFocusManager() {
  if (myProject != null) {
    return IdeFocusManager.getInstance(myProject);
  }
  if (myOwner != null) {
    return IdeFocusManager.findInstanceByComponent(myOwner);
  }
  return IdeFocusManager.findInstance();
}
 
Example 8
Source File: JBTabsPaneImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public JBTabsPaneImpl(@Nullable Project project, int tabPlacement, @Nonnull Disposable parent) {
  myTabs = new JBEditorTabs(project, ActionManager.getInstance(), project == null ? null : IdeFocusManager.getInstance(project), parent) {
    @Override
    public boolean isAlphabeticalMode() {
      return false;
    }

    @Override
    public boolean supportsCompression() {
      return false;
    }
  };
  myTabs.setFirstTabOffset(10);

  myTabs.addListener(new TabsListener.Adapter() {
    @Override
    public void selectionChanged(TabInfo oldSelection, TabInfo newSelection) {
      fireChanged(new ChangeEvent(myTabs));
    }
  }).getPresentation()
          .setPaintBorder(1, 1, 1, 1)
          .setTabSidePaintBorder(2)
          .setPaintFocus(UIUtil.isUnderBuildInLaF())
          .setAlwaysPaintSelectedTab(UIUtil.isUnderBuildInLaF())
          .setGhostsAlwaysVisible(true);

  setTabPlacement(tabPlacement);
}
 
Example 9
Source File: DialogWrapperPeerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public IdeFocusManager getFocusManager() {
  Project project = getProject();
  if (project != null && !project.isDisposed()) {
    return IdeFocusManager.getInstance(project);
  }
  else {
    return IdeFocusManager.findInstance();
  }
}
 
Example 10
Source File: DirDiffPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void focusTable() {
  final Project project = myModel.getProject();
  final IdeFocusManager focusManager = project == null || project.isDefault() ?
                                       IdeFocusManager.getGlobalInstance() :
                                       IdeFocusManager.getInstance(project);
  focusManager.requestFocus(myTable, true);
}
 
Example 11
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 12
Source File: ContentManagerBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected IdeFocusManager getFocusManager() {
  return IdeFocusManager.getInstance(myProject);
}
 
Example 13
Source File: JBTabsImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Deprecated
@DeprecationInfo("Use JBEditorTabs or TabbedPaneWrapper")
@SuppressWarnings("deprecation")
private JBTabsImpl(@Nonnull Project project, @Nonnull Disposable parent) {
  this(project, ActionManager.getInstance(), IdeFocusManager.getInstance(project), parent);
}
 
Example 14
Source File: DiffPanelImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void setDiffRequest(DiffRequest data) {
  myDiffRequest = data;
  if (data.getHints().contains(DiffTool.HINT_DO_NOT_IGNORE_WHITESPACES)) {
    setComparisonPolicy(ComparisonPolicy.DEFAULT, false);
  }
  myDataProvider.putData(myDiffRequest.getGenericData());

  DiffContent content1 = data.getContents()[0];
  DiffContent content2 = data.getContents()[1];

  setContents(content1, content2);
  setTitles(data);

  setWindowTitle(myOwnerWindow, data.getWindowTitle());
  myPanel.setToolbarActions(createToolbar());
  data.customizeToolbar(myPanel.resetToolbar());
  myPanel.registerToolbarActions();
  initEditorSettings(getEditor1());
  initEditorSettings(getEditor2());

  final JComponent oldBottomComponent = myPanel.getBottomComponent();
  if (oldBottomComponent instanceof Disposable) {
    Disposer.dispose((Disposable)oldBottomComponent);
  }
  final JComponent newBottomComponent = data.getBottomComponent();
  myPanel.setBottomComponent(newBottomComponent);


  if (myIsRequestFocus) {
    IdeFocusManager fm = IdeFocusManager.getInstance(myProject);
    boolean isEditor1Focused = getEditor1() != null && fm.getFocusedDescendantFor(getEditor1().getComponent()) != null;

    boolean isEditor2Focused = myData.getContent2() != null && getEditor2() != null && fm.getFocusedDescendantFor(getEditor2().getComponent()) != null;

    if (isEditor1Focused || isEditor2Focused) {
      Editor e = isEditor2Focused ? getEditor2() : getEditor1();
      if (e != null) {
        fm.requestFocus(e.getContentComponent(), true);
      }
    }

    myPanel.requestScrollEditors();
  }
}
 
Example 15
Source File: ProgressWindow.java    From consulo with Apache License 2.0 4 votes vote down vote up
IdeFocusManager getFocusManager() {
  return IdeFocusManager.getInstance(myProject);
}
 
Example 16
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);
  }
}
 
Example 17
Source File: ApiDebuggerTabsIml.java    From ApiDebugger with Apache License 2.0 4 votes vote down vote up
public ApiDebuggerTabsIml(Project project, Disposable parent) {
    mTabs = new JBEditorTabs(project, ActionManager.getInstance(), IdeFocusManager.getInstance(project), parent);
    mTabs.addListener(createListener());
    mTabs.setTabDraggingEnabled(true);
}
 
Example 18
Source File: Switcher.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void closeTabOrToolWindow() {
  final JBList selectedList = getSelectedList();
  final int[] selected = selectedList.getSelectedIndices();
  Arrays.sort(selected);
  int selectedIndex = 0;
  for (int i = selected.length - 1; i >= 0; i--) {
    selectedIndex = selected[i];
    Object value = selectedList.getModel().getElementAt(selectedIndex);
    if (value instanceof FileInfo) {
      final FileInfo info = (FileInfo)value;
      final VirtualFile virtualFile = info.first;
      final FileEditorManagerImpl editorManager = (FileEditorManagerImpl)FileEditorManager.getInstance(project);
      final JList jList = getSelectedList();
      final EditorWindow wnd = findAppropriateWindow(info);
      if (wnd == null) {
        editorManager.closeFile(virtualFile, false, false);
      }
      else {
        editorManager.closeFile(virtualFile, wnd, false);
      }

      final IdeFocusManager focusManager = IdeFocusManager.getInstance(project);
      myAlarm.cancelAllRequests();
      myAlarm.addRequest(() -> {
        JComponent focusTarget = selectedList;
        if (selectedList.getModel().getSize() == 0) {
          focusTarget = selectedList == files ? toolWindows : files;
        }
        focusManager.requestFocus(focusTarget, true);
      }, 300);
      if (jList.getModel().getSize() == 1) {
        removeElementAt(jList, selectedIndex);
        this.remove(jList);
        final Dimension size = toolWindows.getSize();
        myPopup.setSize(new Dimension(size.width, myPopup.getSize().height));
      }
      else {
        removeElementAt(jList, selectedIndex);
        jList.setSize(jList.getPreferredSize());
      }
      if (isPinnedMode()) {
        EditorHistoryManager.getInstance(project).removeFile(virtualFile);
      }
    }
    else if (value instanceof ToolWindow) {
      final ToolWindow toolWindow = (ToolWindow)value;
      if (twManager instanceof ToolWindowManagerEx) {
        ToolWindowManagerEx manager = (ToolWindowManagerEx)twManager;
        manager.hideToolWindow(toolWindow.getId(), false, false);
      }
      else {
        toolWindow.hide(null);
      }
    }
  }
  pack();
  myPopup.getContent().revalidate();
  myPopup.getContent().repaint();
  if (getSelectedList().getModel().getSize() > selectedIndex) {
    getSelectedList().setSelectedIndex(selectedIndex);
    getSelectedList().ensureIndexIsVisible(selectedIndex);
  }
}
 
Example 19
Source File: FlutterView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void addInspectorViewContent(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow) {
  final ContentManager contentManager = toolWindow.getContentManager();
  final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(true);
  final JBRunnerTabs runnerTabs = new JBRunnerTabs(myProject, ActionManager.getInstance(), IdeFocusManager.getInstance(myProject), this);
  runnerTabs.setSelectionChangeHandler(this::onTabSelectionChange);
  final JPanel tabContainer = new JPanel(new BorderLayout());

  final String tabName;
  final FlutterDevice device = app.device();
  if (device == null) {
    tabName = app.getProject().getName();
  }
  else {
    final List<FlutterDevice> existingDevices = new ArrayList<>();
    for (FlutterApp otherApp : perAppViewState.keySet()) {
      existingDevices.add(otherApp.device());
    }
    tabName = device.getUniqueName(existingDevices);
  }

  final Content content = contentManager.getFactory().createContent(null, tabName, false);
  tabContainer.add(runnerTabs.getComponent(), BorderLayout.CENTER);
  content.setComponent(tabContainer);
  content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
  content.setIcon(FlutterIcons.Phone);
  contentManager.addContent(content);

  if (emptyContent != null) {
    contentManager.removeContent(emptyContent, true);
    emptyContent = null;
  }

  contentManager.setSelectedContent(content);

  final PerAppState state = getOrCreateStateForApp(app);
  assert (state.content == null);
  state.content = content;

  final DefaultActionGroup toolbarGroup = createToolbar(toolWindow, app, inspectorService);
  toolWindowPanel.setToolbar(ActionManager.getInstance().createActionToolbar("FlutterViewToolbar", toolbarGroup, true).getComponent());

  toolbarGroup.add(new OverflowAction(getOrCreateStateForApp(app), this, app));

  final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("InspectorToolbar", toolbarGroup, true);
  final JComponent toolbarComponent = toolbar.getComponent();
  toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
  tabContainer.add(toolbarComponent, BorderLayout.NORTH);

  final boolean debugConnectionAvailable = app.getLaunchMode().supportsDebugConnection();
  final boolean hasInspectorService = inspectorService != null;

  // If the inspector is available (non-release mode), then show it.
  if (debugConnectionAvailable) {
    if (hasInspectorService) {
      final boolean detailsSummaryViewSupported = inspectorService.isDetailsSummaryViewSupported();
      addInspectorPanel(WIDGET_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.widget, app, inspectorService, toolWindow,
                        toolbarGroup, true, detailsSummaryViewSupported);
      addInspectorPanel(RENDER_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.renderObject, app, inspectorService,
                        toolWindow, toolbarGroup, false, false);
    }
    else {
      // If in profile mode, add disabled tabs for the inspector.
      addDisabledTab(WIDGET_TAB_LABEL, runnerTabs, toolbarGroup);
      addDisabledTab(RENDER_TAB_LABEL, runnerTabs, toolbarGroup);
    }
  }
  else {
    // Add a message about the inspector not being available in release mode.
    final JBLabel label = new JBLabel("Inspector not available in release mode", SwingConstants.CENTER);
    label.setForeground(UIUtil.getLabelDisabledForeground());
    tabContainer.add(label, BorderLayout.CENTER);
  }
}
 
Example 20
Source File: FlutterView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void addInspectorViewContent(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow) {
  final ContentManager contentManager = toolWindow.getContentManager();
  final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(true);
  final JBRunnerTabs runnerTabs = new JBRunnerTabs(myProject, ActionManager.getInstance(), IdeFocusManager.getInstance(myProject), this);
  runnerTabs.setSelectionChangeHandler(this::onTabSelectionChange);
  final JPanel tabContainer = new JPanel(new BorderLayout());

  final String tabName;
  final FlutterDevice device = app.device();
  if (device == null) {
    tabName = app.getProject().getName();
  }
  else {
    final List<FlutterDevice> existingDevices = new ArrayList<>();
    for (FlutterApp otherApp : perAppViewState.keySet()) {
      existingDevices.add(otherApp.device());
    }
    tabName = device.getUniqueName(existingDevices);
  }

  final Content content = contentManager.getFactory().createContent(null, tabName, false);
  tabContainer.add(runnerTabs.getComponent(), BorderLayout.CENTER);
  content.setComponent(tabContainer);
  content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
  content.setIcon(FlutterIcons.Phone);
  contentManager.addContent(content);

  if (emptyContent != null) {
    contentManager.removeContent(emptyContent, true);
    emptyContent = null;
  }

  contentManager.setSelectedContent(content);

  final PerAppState state = getOrCreateStateForApp(app);
  assert (state.content == null);
  state.content = content;

  final DefaultActionGroup toolbarGroup = createToolbar(toolWindow, app, inspectorService);
  toolWindowPanel.setToolbar(ActionManager.getInstance().createActionToolbar("FlutterViewToolbar", toolbarGroup, true).getComponent());

  toolbarGroup.add(new OverflowAction(getOrCreateStateForApp(app), this, app));

  final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("InspectorToolbar", toolbarGroup, true);
  final JComponent toolbarComponent = toolbar.getComponent();
  toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
  tabContainer.add(toolbarComponent, BorderLayout.NORTH);

  final boolean debugConnectionAvailable = app.getLaunchMode().supportsDebugConnection();
  final boolean hasInspectorService = inspectorService != null;

  // If the inspector is available (non-release mode), then show it.
  if (debugConnectionAvailable) {
    if (hasInspectorService) {
      final boolean detailsSummaryViewSupported = inspectorService.isDetailsSummaryViewSupported();
      addInspectorPanel(WIDGET_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.widget, app, inspectorService, toolWindow,
                        toolbarGroup, true, detailsSummaryViewSupported);
      addInspectorPanel(RENDER_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.renderObject, app, inspectorService,
                        toolWindow, toolbarGroup, false, false);
    }
    else {
      // If in profile mode, add disabled tabs for the inspector.
      addDisabledTab(WIDGET_TAB_LABEL, runnerTabs, toolbarGroup);
      addDisabledTab(RENDER_TAB_LABEL, runnerTabs, toolbarGroup);
    }
  }
  else {
    // Add a message about the inspector not being available in release mode.
    final JBLabel label = new JBLabel("Inspector not available in release mode", SwingConstants.CENTER);
    label.setForeground(UIUtil.getLabelDisabledForeground());
    tabContainer.add(label, BorderLayout.CENTER);
  }
}