private IdeFocusManager getFocusManager() {
   if (myProject != null) {
     return IdeFocusManager.getInstance(myProject);
   } else if (myOwner != null) {
     return IdeFocusManager.findInstanceByComponent(myOwner);
   } else {
     return IdeFocusManager.findInstance();
   }
 }
  public boolean isFocused() {
    IdeFocusManager fm = IdeFocusManager.getInstance(myProject);
    Component component = fm.getFocusedDescendantFor(myToolWindow.getComponent());
    if (component != null) return true;

    Component owner = fm.getLastFocusedFor(WindowManager.getInstance().getIdeFrame(myProject));

    return owner != null && SwingUtilities.isDescendingFrom(owner, myToolWindow.getComponent());
  }
Ejemplo n.º 3
0
 @Override
 public IdeFocusManager getFocusManager() {
   Project project = getProject();
   if (project != null && !project.isDisposed()) {
     return IdeFocusManager.getInstance(project);
   } else {
     return IdeFocusManager.findInstance();
   }
 }
Ejemplo n.º 4
0
  @Override
  public ActionCallback show() {
    LOG.assertTrue(
        EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only");
    if (myTypeAheadCallback != null) {
      IdeFocusManager.getInstance(myProject).typeAheadUntil(myTypeAheadCallback);
    }
    LOG.assertTrue(
        EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only");
    final ActionCallback result = new ActionCallback();

    final AnCancelAction anCancelAction = new AnCancelAction();
    final JRootPane rootPane = getRootPane();
    anCancelAction.registerCustomShortcutSet(
        new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)), rootPane);
    myDisposeActions.add(
        new Runnable() {
          @Override
          public void run() {
            anCancelAction.unregisterCustomShortcutSet(rootPane);
          }
        });

    if (!myCanBeParent && myWindowManager != null) {
      myWindowManager.doNotSuggestAsParent(myDialog.getWindow());
    }

    final CommandProcessorEx commandProcessor =
        ApplicationManager.getApplication() != null
            ? (CommandProcessorEx) CommandProcessor.getInstance()
            : null;
    final boolean appStarted = commandProcessor != null;

    if (myDialog.isModal() && !isProgressDialog()) {
      if (appStarted) {
        commandProcessor.enterModal();
        LaterInvocator.enterModal(myDialog);
      }
    }

    if (appStarted) {
      hidePopupsIfNeeded();
    }

    try {
      myDialog.show();
    } finally {
      if (myDialog.isModal() && !isProgressDialog()) {
        if (appStarted) {
          commandProcessor.leaveModal();
          LaterInvocator.leaveModal(myDialog);
        }
      }

      myDialog.getFocusManager().doWhenFocusSettlesDown(result.createSetDoneRunnable());
    }

    return result;
  }
Ejemplo n.º 5
0
 @Override
 @SuppressWarnings("deprecation")
 public void hide() {
   super.hide();
   if (myFocusTrackback != null
       && !(myFocusTrackback.isSheduledForRestore()
           || myFocusTrackback.isWillBeSheduledForRestore())) {
     myFocusTrackback.setWillBeSheduledForRestore();
     IdeFocusManager mgr = getFocusManager();
     Runnable r =
         new Runnable() {
           @Override
           public void run() {
             if (myFocusTrackback != null) myFocusTrackback.restoreFocus();
             myFocusTrackback = null;
           }
         };
     mgr.doWhenFocusSettlesDown(r);
   }
 }
  public static void navigateToFailedPlaceholder(
      @NotNull final StudyState studyState,
      @NotNull final Task task,
      @NotNull final VirtualFile taskDir,
      @NotNull final Project project) {
    TaskFile selectedTaskFile = studyState.getTaskFile();
    Editor editor = studyState.getEditor();
    TaskFile taskFileToNavigate = selectedTaskFile;
    VirtualFile fileToNavigate = studyState.getVirtualFile();
    final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
    if (!taskManager.hasFailedAnswerPlaceholders(selectedTaskFile)) {
      for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
        String name = entry.getKey();
        TaskFile taskFile = entry.getValue();
        if (taskManager.hasFailedAnswerPlaceholders(taskFile)) {
          taskFileToNavigate = taskFile;
          VirtualFile virtualFile = taskDir.findChild(name);
          if (virtualFile == null) {
            continue;
          }
          FileEditor fileEditor =
              FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
          if (fileEditor instanceof StudyEditor) {
            StudyEditor studyEditor = (StudyEditor) fileEditor;
            editor = studyEditor.getEditor();
          }
          fileToNavigate = virtualFile;
          break;
        }
      }
    }
    if (fileToNavigate != null) {
      FileEditorManager.getInstance(project).openFile(fileToNavigate, true);
    }
    final Editor editorToNavigate = editor;
    ApplicationManager.getApplication()
        .invokeLater(
            () ->
                IdeFocusManager.getInstance(project)
                    .requestFocus(editorToNavigate.getContentComponent(), true));

    StudyNavigator.navigateToFirstFailedAnswerPlaceholder(editor, taskFileToNavigate);
  }
Ejemplo n.º 7
0
  public static void focusProjectWindow(final Project p, boolean executeIfAppInactive) {
    FocusCommand cmd =
        new FocusCommand() {
          @NotNull
          @Override
          public ActionCallback run() {
            JFrame f = WindowManager.getInstance().getFrame(p);
            if (f != null) {
              f.toFront();
              // f.requestFocus();
            }
            return ActionCallback.DONE;
          }
        };

    if (executeIfAppInactive) {
      AppIcon.getInstance().requestFocus((IdeFrame) WindowManager.getInstance().getFrame(p));
      cmd.run();
    } else {
      IdeFocusManager.getInstance(p).requestFocus(cmd, true);
    }
  }
Ejemplo n.º 8
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();
        }
      }
    }
  public void dispose() {
    if (myDisposed) {
      return;
    }
    myDisposed = true;

    Disposer.dispose(this, false);

    assert ApplicationManager.getApplication().isDispatchThread();

    if (myPopup != null) {
      cancel(myDisposeEvent);
    }

    if (myContent != null) {
      myContent.removeAll();
      myContent.removeKeyListener(mySearchKeyListener);
    }
    myContent = null;
    myPreferredFocusedComponent = null;
    myComponent = null;
    myFocusTrackback = null;
    myCallBack = null;
    myListeners = null;

    if (myMouseOutCanceller != null) {
      final Toolkit toolkit = Toolkit.getDefaultToolkit();
      // it may happen, but have no idea how
      // http://www.jetbrains.net/jira/browse/IDEADEV-21265
      if (toolkit != null) {
        toolkit.removeAWTEventListener(myMouseOutCanceller);
      }
    }
    myMouseOutCanceller = null;

    if (myFocusWatcher != null) {
      myFocusWatcher.dispose();
      myFocusWatcher = null;
    }

    resetWindow();

    if (myFinalRunnable != null) {
      final ActionCallback typeaheadDone = new ActionCallback();
      Runnable runFinal =
          new Runnable() {
            @Override
            public void run() {
              SwingUtilities.invokeLater(
                  new Runnable() {
                    @Override
                    public void run() {
                      typeaheadDone.setDone();
                    }
                  });
              myFinalRunnable.run();
              myFinalRunnable = null;
            }
          };

      IdeFocusManager.getInstance(myProject).typeAheadUntil(typeaheadDone);
      getFocusManager().doWhenFocusSettlesDown(runFinal);
    }
  }
  EditorTabbedContainer(final EditorWindow window, Project project, final int tabPlacement) {
    myWindow = window;
    myProject = project;
    final ActionManager actionManager = ActionManager.getInstance();
    myTabs = new JBEditorTabs(project, actionManager, IdeFocusManager.getInstance(project), this);
    myTabs
        .setDataProvider(new MyDataProvider())
        .setPopupGroup(
            new Getter<ActionGroup>() {
              public ActionGroup get() {
                return (ActionGroup)
                    CustomActionsSchema.getInstance()
                        .getCorrectedAction(IdeActions.GROUP_EDITOR_TAB_POPUP);
              }
            },
            ActionPlaces.EDITOR_TAB_POPUP,
            false)
        .setNavigationActionsEnabled(false)
        .addTabMouseListener(new TabMouseListener())
        .getPresentation()
        .setTabDraggingEnabled(true)
        .setUiDecorator(
            new UiDecorator() {
              @NotNull
              public UiDecoration getDecoration() {
                return new UiDecoration(
                    null,
                    new Insets(
                        TabsUtil.TAB_VERTICAL_PADDING, 10, TabsUtil.TAB_VERTICAL_PADDING, 10));
              }
            })
        .setTabLabelActionsMouseDeadzone(TimedDeadzone.NULL)
        .setGhostsAlwaysVisible(true)
        .setTabLabelActionsAutoHide(false)
        .setActiveTabFillIn(
            EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground())
        .setPaintFocus(false)
        .getJBTabs()
        .addListener(
            new TabsListener.Adapter() {
              public void selectionChanged(final TabInfo oldSelection, final TabInfo newSelection) {
                final FileEditorManager editorManager = FileEditorManager.getInstance(myProject);
                final FileEditor oldEditor =
                    oldSelection != null
                        ? editorManager.getSelectedEditor((VirtualFile) oldSelection.getObject())
                        : null;
                if (oldEditor != null) {
                  oldEditor.deselectNotify();
                }

                final FileEditor newEditor =
                    editorManager.getSelectedEditor((VirtualFile) newSelection.getObject());
                if (newEditor != null) {
                  newEditor.selectNotify();
                }
              }
            })
        .setAdditionalSwitchProviderWhenOriginal(new MySwitchProvider())
        .setSelectionChangeHandler(
            new JBTabs.SelectionChangeHandler() {
              @Override
              public ActionCallback execute(
                  TabInfo info, boolean requestFocus, final ActiveRunnable doChangeSelection) {
                final ActionCallback result = new ActionCallback();
                CommandProcessor.getInstance()
                    .executeCommand(
                        myProject,
                        new Runnable() {
                          @Override
                          public void run() {
                            ((IdeDocumentHistoryImpl) IdeDocumentHistory.getInstance(myProject))
                                .onSelectionChanged();
                            result.notify(doChangeSelection.run());
                          }
                        },
                        "EditorChange",
                        null);
                return result;
              }
            })
        .getPresentation()
        .setRequestFocusOnLastFocusedComponent(true);

    setTabPlacement(UISettings.getInstance().EDITOR_TAB_PLACEMENT);

    updateTabBorder();

    ((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject))
        .addToolWindowManagerListener(
            new ToolWindowManagerAdapter() {
              public void stateChanged() {
                updateTabBorder();
              }

              public void toolWindowRegistered(@NotNull final String id) {
                updateTabBorder();
              }
            });

    UISettings.getInstance()
        .addUISettingsListener(
            new UISettingsListener() {
              public void uiSettingsChanged(UISettings source) {
                updateTabBorder();
              }
            },
            this);

    Disposer.register(project, this);
  }
 public void requestFocus(boolean forced) {
   if (myTabs != null) {
     IdeFocusManager.getInstance(myProject).requestFocus(myTabs.getComponent(), forced);
   }
 }