Search in sources :

Example 16 with IdeFocusManager

use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.

the class DiffPanelImpl method setDiffRequest.

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();
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) Editor(com.intellij.openapi.editor.Editor)

Example 17 with IdeFocusManager

use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.

the class JBTable method editCellAt.

@Override
public boolean editCellAt(final int row, final int column, final EventObject e) {
    if (cellEditor != null && !cellEditor.stopCellEditing()) {
        return false;
    }
    if (row < 0 || row >= getRowCount() || column < 0 || column >= getColumnCount()) {
        return false;
    }
    if (!isCellEditable(row, column)) {
        return false;
    }
    if (e instanceof KeyEvent) {
        // do not start editing in autoStartsEdit mode on Ctrl-Z and other non-typed events
        if (!UIUtil.isReallyTypedEvent((KeyEvent) e) || ((KeyEvent) e).getKeyChar() == KeyEvent.CHAR_UNDEFINED)
            return false;
        SpeedSearchSupply supply = SpeedSearchSupply.getSupply(this);
        if (supply != null && supply.isPopupActive()) {
            return false;
        }
    }
    final TableCellEditor editor = getCellEditor(row, column);
    if (editor != null && editor.isCellEditable(e)) {
        editorComp = prepareEditor(editor, row, column);
        //((JComponent)editorComp).setBorder(null);
        if (editorComp == null) {
            removeEditor();
            return false;
        }
        editorComp.setBounds(getCellRect(row, column, false));
        add(editorComp);
        editorComp.validate();
        if (surrendersFocusOnKeyStroke()) {
            // this replaces focus request in JTable.processKeyBinding
            final IdeFocusManager focusManager = IdeFocusManager.findInstanceByComponent(this);
            focusManager.setTypeaheadEnabled(false);
            focusManager.requestFocus(editorComp, true).doWhenProcessed(() -> focusManager.setTypeaheadEnabled(true));
        }
        setCellEditor(editor);
        setEditingRow(row);
        setEditingColumn(column);
        editor.addCellEditorListener(this);
        return true;
    }
    return false;
}
Also used : KeyEvent(java.awt.event.KeyEvent) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager)

Example 18 with IdeFocusManager

use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.

the class ToolbarUpdater method updateActions.

private void updateActions(boolean now, final boolean transparentOnly, final boolean forced) {
    final Runnable updateRunnable = new MyUpdateRunnable(this, transparentOnly, forced);
    final Application app = ApplicationManager.getApplication();
    if (now || app.isUnitTestMode()) {
        updateRunnable.run();
    } else {
        final IdeFocusManager fm = IdeFocusManager.getInstance(null);
        if (!app.isHeadlessEnvironment()) {
            if (app.isDispatchThread() && myComponent.isShowing()) {
                fm.doWhenFocusSettlesDown(updateRunnable);
            } else {
                UiNotifyConnector.doWhenFirstShown(myComponent, () -> fm.doWhenFocusSettlesDown(updateRunnable));
            }
        }
    }
}
Also used : IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) Application(com.intellij.openapi.application.Application)

Example 19 with IdeFocusManager

use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.

the class FocusTracesAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final IdeFocusManager manager = IdeFocusManager.getGlobalInstance();
    if (!(manager instanceof FocusManagerImpl))
        return;
    final FocusManagerImpl focusManager = (FocusManagerImpl) manager;
    myActive = !myActive;
    if (myActive) {
        myFocusTracker = new AWTEventListener() {

            @Override
            public void eventDispatched(AWTEvent event) {
                if (event instanceof FocusEvent && event.getID() == FocusEvent.FOCUS_GAINED) {
                    focusManager.recordFocusRequest(((FocusEvent) event).getComponent(), false);
                }
            }
        };
        Toolkit.getDefaultToolkit().addAWTEventListener(myFocusTracker, AWTEvent.FOCUS_EVENT_MASK);
    }
    if (!myActive) {
        final List<FocusRequestInfo> requests = focusManager.getRequests();
        new FocusTracesDialog(project, new ArrayList<>(requests)).show();
        Toolkit.getDefaultToolkit().removeAWTEventListener(myFocusTracker);
        myFocusTracker = null;
        requests.clear();
    }
}
Also used : FocusManagerImpl(com.intellij.openapi.wm.impl.FocusManagerImpl) Project(com.intellij.openapi.project.Project) AWTEventListener(java.awt.event.AWTEventListener) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) ArrayList(java.util.ArrayList) FocusEvent(java.awt.event.FocusEvent) FocusRequestInfo(com.intellij.openapi.wm.impl.FocusRequestInfo)

Example 20 with IdeFocusManager

use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.

the class IdeEventQueue method storeLastFocusedComponent.

private static void storeLastFocusedComponent(@NotNull WindowEvent we) {
    final Window eventWindow = we.getWindow();
    if (we.getID() == WindowEvent.WINDOW_DEACTIVATED || we.getID() == WindowEvent.WINDOW_LOST_FOCUS) {
        Component frame = UIUtil.findUltimateParent(eventWindow);
        Component focusOwnerInDeactivatedWindow = eventWindow.getMostRecentFocusOwner();
        IdeFrame[] allProjectFrames = WindowManager.getInstance().getAllProjectFrames();
        if (focusOwnerInDeactivatedWindow != null) {
            for (IdeFrame ideFrame : allProjectFrames) {
                JFrame aFrame = WindowManager.getInstance().getFrame(ideFrame.getProject());
                if (aFrame.equals(frame)) {
                    IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance();
                    if (focusManager instanceof FocusManagerImpl) {
                        ((FocusManagerImpl) focusManager).setLastFocusedAtDeactivation(ideFrame, focusOwnerInDeactivatedWindow);
                    }
                }
            }
        }
    }
}
Also used : FocusManagerImpl(com.intellij.openapi.wm.impl.FocusManagerImpl) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Aggregations

IdeFocusManager (com.intellij.openapi.wm.IdeFocusManager)27 Project (com.intellij.openapi.project.Project)6 IdeFrame (com.intellij.openapi.wm.IdeFrame)5 NotNull (org.jetbrains.annotations.NotNull)4 FocusManagerImpl (com.intellij.openapi.wm.impl.FocusManagerImpl)3 DataManager (com.intellij.ide.DataManager)2 Disposable (com.intellij.openapi.Disposable)2 PersistentStateComponent (com.intellij.openapi.components.PersistentStateComponent)2 AsyncResult (com.intellij.openapi.util.AsyncResult)2 Nullable (org.jetbrains.annotations.Nullable)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Patches (com.intellij.Patches)1 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 PsiElement2UsageTargetAdapter (com.intellij.find.findUsages.PsiElement2UsageTargetAdapter)1 AllIcons (com.intellij.icons.AllIcons)1 IdeBundle (com.intellij.ide.IdeBundle)1 CopyReferenceAction (com.intellij.ide.actions.CopyReferenceAction)1 GotoFileAction (com.intellij.ide.actions.GotoFileAction)1 DarculaTextBorder (com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder)1 DarculaTextFieldUI (com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI)1