com.intellij.openapi.wm.IdeFocusManager Java Examples
The following examples show how to use
com.intellij.openapi.wm.IdeFocusManager.
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: TableModelEditor.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public JComponent createComponent() { return toolbarDecorator.addExtraAction( new ToolbarDecorator.ElementActionButton(IdeBundle.message("button.copy"), PlatformIcons.COPY_ICON) { @Override public void actionPerformed(@Nonnull AnActionEvent e) { TableUtil.stopEditing(table); List<T> selectedItems = table.getSelectedObjects(); if (selectedItems.isEmpty()) { return; } for (T item : selectedItems) { model.addRow(itemEditor.clone(item, false)); } IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(table); TableUtil.updateScroller(table); } } ).createPanel(); }
Example #2
Source File: FileEditorManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
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: FileEditorManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@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 #4
Source File: DesktopEditorWindow.java From consulo with Apache License 2.0 | 6 votes |
TComp(@Nonnull DesktopEditorWindow window, @Nonnull DesktopEditorWithProviderComposite editor) { super(new BorderLayout()); myEditor = editor; myWindow = window; add(editor.getComponent(), BorderLayout.CENTER); addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { ApplicationManager.getApplication().invokeLater(() -> { if (!hasFocus()) return; final JComponent focus = myEditor.getSelectedEditorWithProvider().getFileEditor().getPreferredFocusedComponent(); if (focus != null && !focus.hasFocus()) { IdeFocusManager.getGlobalInstance().requestFocus(focus, true); } }); } }); }
Example #5
Source File: TabbedPaneWrapper.java From consulo with Apache License 2.0 | 6 votes |
public final synchronized void removeTabAt(final int index) { assertIsDispatchThread(); final boolean hadFocus = IJSwingUtilities.hasFocus2(myTabbedPaneHolder); final TabWrapper wrapper = getWrapperAt(index); try { myTabbedPane.removeTabAt(index); if (myTabbedPane.getTabCount() == 0) { // to clear BasicTabbedPaneUI.visibleComponent field myTabbedPane.revalidate(); } if (hadFocus) { IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(myTabbedPaneHolder); } } finally { wrapper.dispose(); } }
Example #6
Source File: CommanderPanel.java From consulo with Apache License 2.0 | 6 votes |
public final void setActive(final boolean active) { myActive = active; if (active) { myTitlePanel.setBackground(DARK_BLUE); myTitlePanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED, DARK_BLUE_BRIGHTER, DARK_BLUE_DARKER)); myParentTitle.setForeground(Color.white); } else { final Color color = UIUtil.getPanelBackground(); LOG.assertTrue(color != null); myTitlePanel.setBackground(color); myTitlePanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, color.brighter(), color.darker())); myParentTitle.setForeground(JBColor.foreground()); } final int[] selectedIndices = myList.getSelectedIndices(); if (selectedIndices.length == 0 && myList.getModel().getSize() > 0) { myList.setSelectedIndex(0); if (!myList.hasFocus()) { IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(myList); } } else if (myList.getModel().getSize() > 0) { // need this to generate SelectionChanged events so that listeners, added by Commander, will be notified myList.setSelectedIndices(selectedIndices); } }
Example #7
Source File: DesktopEditorErrorPanel.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess private void doMouseClicked(MouseEvent e) { if (mySmallIconVisible && e.getY() < getIconPanelSize()) { showTrafficLightTooltip(e); return; } IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> { IdeFocusManager.getGlobalInstance().requestFocus(myEditor.getContentComponent(), true); }); int lineCount = myEditor.getDocument().getLineCount() + myEditor.getSettings().getAdditionalLinesCount(); if (lineCount == 0) { return; } if (e.getX() > 0 && e.getX() <= getWidth()) { myMarkupModel.doClick(e); } }
Example #8
Source File: BegTableUI.java From consulo with Apache License 2.0 | 6 votes |
public void actionPerformed(ActionEvent e) { JTable table = (JTable)e.getSource(); if (!table.hasFocus()) { CellEditor cellEditor = table.getCellEditor(); if (cellEditor != null && !cellEditor.stopCellEditing()) { return; } IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(table); return; } ListSelectionModel rsm = table.getSelectionModel(); int anchorRow = rsm.getAnchorSelectionIndex(); ListSelectionModel csm = table.getColumnModel().getSelectionModel(); int anchorColumn = csm.getAnchorSelectionIndex(); table.editCellAt(anchorRow, anchorColumn); Component editorComp = table.getEditorComponent(); if (editorComp != null) { editorComp.addKeyListener(myAdapter); IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(editorComp); } }
Example #9
Source File: NavBarPanel.java From consulo with Apache License 2.0 | 6 votes |
public NavBarPanel(@Nonnull Project project, boolean docked) { super(new FlowLayout(FlowLayout.LEFT, 0, 0)); myProject = project; myModel = createModel(); myIdeView = new NavBarIdeView(this); myPresentation = new NavBarPresentation(myProject); myUpdateQueue = new NavBarUpdateQueue(this); installPopupHandler(this, -1); setOpaque(false); if (!docked && UIUtil.isUnderDarcula()) { setBorder(new LineBorder(Gray._120, 1)); } myUpdateQueue.queueModelUpdateFromFocus(); myUpdateQueue.queueRebuildUi(); if (!docked) { final ActionCallback typeAheadDone = new ActionCallback(); IdeFocusManager.getInstance(project).typeAheadUntil(typeAheadDone, "NavBarPanel"); myUpdateQueue.queueTypeAheadDone(typeAheadDone); } Disposer.register(project, this); AccessibleContextUtil.setName(this, "Navigation Bar"); }
Example #10
Source File: DesktopEditorAnalyzeStatusPanel.java From consulo with Apache License 2.0 | 6 votes |
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 #11
Source File: LogConfigurationPanel.java From consulo with Apache License 2.0 | 6 votes |
public LogFileCellEditor(LogFileOptions options) { myLogFileOptions = options; myComponent = new CellEditorComponentWithBrowseButton<JTextField>(new TextFieldWithBrowseButton(), this); getChildComponent().setEditable(false); getChildComponent().setBorder(null); myComponent.getComponentWithButton().getButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showEditorDialog(myLogFileOptions); JTextField textField = getChildComponent(); textField.setText(myLogFileOptions.getName()); IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(textField); myModel.fireTableDataChanged(); } }); }
Example #12
Source File: EnableDisableAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(ActionEvent e) { if (getTable().isEditing()) return; int[] rows = getTable().getSelectedRows(); if (rows.length > 0) { boolean valueToBeSet = false; for (final int row : rows) { if (!isRowChecked(row)) { valueToBeSet = true; break; } } applyValue(rows, valueToBeSet); // myMyTableModel.fireTableRowsUpdated(rows[0], rows[rows.length - 1]); } IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(getTable()); }
Example #13
Source File: FileEditorManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@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 #14
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 5 votes |
private void navigateAndHint(@NotNull Usage usage, @Nullable final String hint, @NotNull final FindUsagesHandler handler, @NotNull final RelativePoint popupPosition, final int maxUsages, @NotNull final FindUsagesOptions options) { usage.navigate(true); if (hint == null) return; final Editor newEditor = getEditorFor(usage); if (newEditor == null) return; final Project project = handler.getProject(); //opening editor is performing in invokeLater IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(new Runnable() { @Override public void run() { newEditor.getScrollingModel().runActionOnScrollingFinished(new Runnable() { @Override public void run() { // after new editor created, some editor resizing events are still bubbling. To prevent hiding hint, invokeLater this IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(new Runnable() { @Override public void run() { if (newEditor.getComponent().isShowing()) { showHint(hint, newEditor, popupPosition, handler, maxUsages, options); } } }); } }); } }); }
Example #15
Source File: ScopeTreeViewPanel.java From consulo with Apache License 2.0 | 5 votes |
public void selectNode(final PsiElement element, final PsiFileSystemItem file, final boolean requestFocus) { final Runnable runnable = new Runnable() { @Override public void run() { myUpdateQueue.queue(new Update("Select") { @Override public void run() { if (myProject.isDisposed()) return; PackageDependenciesNode node = myBuilder.findNode(file, element); if (node != null && node.getPsiElement() != element) { final TreePath path = new TreePath(node.getPath()); if (myTree.isCollapsed(path)) { myTree.expandPath(path); myTree.makeVisible(path); } } node = myBuilder.findNode(file, element); if (node != null) { TreeUtil.selectPath(myTree, new TreePath(node.getPath())); if (requestFocus) { IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(myTree); } } } }); } }; doWhenDone(runnable); }
Example #16
Source File: TreeUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static ActionCallback selectInTree(Project project, @Nullable DefaultMutableTreeNode node, boolean requestFocus, @Nonnull JTree tree, boolean center) { if (node == null) return ActionCallback.DONE; final TreePath treePath = new TreePath(node.getPath()); tree.expandPath(treePath); if (requestFocus) { ActionCallback result = new ActionCallback(2); IdeFocusManager.getInstance(project).requestFocus(tree, true).notifyWhenDone(result); selectPath(tree, treePath, center).notifyWhenDone(result); return result; } return selectPath(tree, treePath, center); }
Example #17
Source File: BaseButtonBehavior.java From consulo with Apache License 2.0 | 5 votes |
public void mousePressed(MouseEvent e) { Component owner = IdeFocusManager.getInstance(null).getFocusOwner(); myWasPressedOnFocusTransfer = owner == null; if (passIfNeeded(e, !myWasPressedOnFocusTransfer)) return; setPressedByMouse(true); if (myActionTrigger == MouseEvent.MOUSE_PRESSED) { execute(e); } else { repaintComponent(); } }
Example #18
Source File: TextEditorWithPreview.java From consulo with Apache License 2.0 | 5 votes |
private void invalidateLayout() { adjustEditorsVisibility(); myToolbarWrapper.refresh(); myComponent.repaint(); final JComponent focusComponent = getPreferredFocusedComponent(); if (focusComponent != null) { IdeFocusManager.findInstanceByComponent(focusComponent).requestFocus(focusComponent, true); } }
Example #19
Source File: FocusManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
private FurtherRequestor(@Nonnull IdeFocusManager manager, @Nonnull Expirable expirable) { myManager = manager; myExpirable = expirable; if (Registry.is("ide.debugMode")) { myAllocation = new Exception(); } }
Example #20
Source File: ProjectManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
private void openProjectRequireBackgroundTask(Project project, UIAccess uiAccess) { myApplication.getMessageBus().syncPublisher(TOPIC).projectOpened(project, uiAccess); final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(project); startupManager.runStartupActivities(uiAccess); startupManager.runPostStartupActivitiesFromExtensions(uiAccess); if (!project.isDisposed()) { startupManager.runPostStartupActivities(uiAccess); Application application = Application.get(); if (!application.isHeadlessEnvironment() && !application.isUnitTestMode()) { final TrackingPathMacroSubstitutor macroSubstitutor = ((ProjectEx)project).getStateStore().getStateStorageManager().getMacroSubstitutor(); if (macroSubstitutor != null) { StorageUtil.notifyUnknownMacros(macroSubstitutor, project, null); } } if (application.isActive()) { consulo.ui.Window projectFrame = WindowManager.getInstance().getWindow(project); if (projectFrame != null) { uiAccess.giveAndWaitIfNeed(() -> IdeFocusManager.getInstance(project).requestFocus(projectFrame, true)); } } application.invokeLater(() -> { if (!project.isDisposedOrDisposeInProgress()) { startupManager.scheduleBackgroundPostStartupActivities(uiAccess); } }, ModalityState.NON_MODAL, o -> project.isDisposedOrDisposeInProgress()); } }
Example #21
Source File: DesktopEditorComposite.java From consulo with Apache License 2.0 | 5 votes |
@Override public void requestFocus() { if (myFocusComponent != null) { IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> { IdeFocusManager.getGlobalInstance().requestFocus(myFocusComponent, true); }); } }
Example #22
Source File: GotoActionBase.java From consulo with Apache License 2.0 | 5 votes |
protected static Pair<String, Integer> getInitialText(boolean useEditorSelection, AnActionEvent e) { final String predefined = e.getData(PlatformDataKeys.PREDEFINED_TEXT); if (!StringUtil.isEmpty(predefined)) { return Pair.create(predefined, 0); } if (useEditorSelection) { final Editor editor = e.getData(CommonDataKeys.EDITOR); if (editor != null) { final String selectedText = editor.getSelectionModel().getSelectedText(); if (selectedText != null && !selectedText.contains("\n")) { return Pair.create(selectedText, 0); } } } final String query = e.getData(SpeedSearchSupply.SPEED_SEARCH_CURRENT_QUERY); if (!StringUtil.isEmpty(query)) { return Pair.create(query, 0); } final Component focusOwner = IdeFocusManager.getInstance(getEventProject(e)).getFocusOwner(); if (focusOwner instanceof JComponent) { final SpeedSearchSupply supply = SpeedSearchSupply.getSupply((JComponent)focusOwner); if (supply != null) { return Pair.create(supply.getEnteredPrefix(), 0); } } if (myInAction != null) { final Pair<String, Integer> lastString = ourLastStrings.get(myInAction); if (lastString != null) { return lastString; } } return Pair.create("", 0); }
Example #23
Source File: PsiViewerDialog.java From consulo with Apache License 2.0 | 5 votes |
private void focusRefs() { IdeFocusManager.getInstance(myProject).requestFocus(myRefs, true); if (myRefs.getModel().getSize() > 0) { if (myRefs.getSelectedIndex() == -1) { myRefs.setSelectedIndex(0); } } }
Example #24
Source File: NavBarPanel.java From consulo with Apache License 2.0 | 5 votes |
public void requestSelectedItemFocus() { int index = myModel.getSelectedIndex(); if (index >= 0 && index < myModel.size() && allowNavItemsFocus()) { IdeFocusManager.getInstance(myProject).requestFocus(getItem(index), true); } else { IdeFocusManager.getInstance(myProject).requestFocus(this, true); } }
Example #25
Source File: DialogButtonGroup.java From consulo with Apache License 2.0 | 5 votes |
private void upPressed() { Component[] components = getComponents(); for (int i = 0; i < components.length; i++) { if (components[i].hasFocus()) { if (i == 0) { IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(components[components.length - 1]); return; } IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(components[i - 1]); return; } } }
Example #26
Source File: DesktopWrappedLayoutImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void requestFocus() { if (getTargetComponent() == this) { IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(super::requestFocus); return; } IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(getTargetComponent()); }
Example #27
Source File: RadioUpDownListener.java From consulo with Apache License 2.0 | 5 votes |
private static boolean click(final JRadioButton button) { if (button.isEnabled() && button.isVisible()) { IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(button); button.doClick(); return true; } return false; }
Example #28
Source File: FlutterDescriptionProvider.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static Collection<ModuleGalleryEntry> getGalleryList(boolean isCreatingProject) { boolean projectHasFlutter = isCreatingProject; // True for projects, false for modules. boolean isAndroidProject = false; // True if the host project is an Android app. OptionalValueProperty<FlutterProjectModel> sharedModel = new OptionalValueProperty<>(); ArrayList<ModuleGalleryEntry> res = new ArrayList<>(); if (!isCreatingProject) { IdeFrame frame = IdeFocusManager.getGlobalInstance().getLastFocusedFrame(); Project project = frame == null ? null : frame.getProject(); if (project == null) return res; for (Module module : FlutterModuleUtils.getModules(project)) { if (FlutterModuleUtils.isFlutterModule(module)) { projectHasFlutter = true; break; } } isAndroidProject = AndroidUtils.isAndroidProject(project); } if (projectHasFlutter) { // Makes no sense to add some Flutter templates to Android projects. if (isCreatingProject) { res.add(new FlutterApplicationGalleryEntry(sharedModel)); } res.add(new FlutterPluginGalleryEntry(sharedModel)); res.add(new FlutterPackageGalleryEntry(sharedModel)); if (isCreatingProject) { res.add(new FlutterModuleGalleryEntry(sharedModel)); } else if (isAndroidProject) { res.add(new AddToAppModuleGalleryEntry(sharedModel)); res.add(new ImportFlutterModuleGalleryEntry(sharedModel)); } } else { // isCreatingProject == false res.add(new AddToAppModuleGalleryEntry(sharedModel)); res.add(new ImportFlutterModuleGalleryEntry(sharedModel)); } return res; }
Example #29
Source File: DiffPanelImpl.java From consulo with Apache License 2.0 | 5 votes |
public void focusOppositeSide() { if (myCurrentSide == myLeftSide) { IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(myRightSide.getEditor().getContentComponent()); } else { IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(myLeftSide.getEditor().getContentComponent()); } }
Example #30
Source File: DocumentationComponent.java From consulo with Apache License 2.0 | 5 votes |
@Override public void requestFocus() { // With a screen reader active, set the focus directly to the editor because // it makes it easier for users to read/navigate the documentation contents. IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> { if (ScreenReader.isActive()) { IdeFocusManager.getGlobalInstance().requestFocus(myEditorPane, true); } else { IdeFocusManager.getGlobalInstance().requestFocus(myScrollPane, true); } }); }