コード例 #1
0
  public void dispose() {
    final EditorFactory editorFactory = EditorFactory.getInstance();
    editorFactory.releaseEditor(myConsoleEditor);
    editorFactory.releaseEditor(myHistoryViewer);

    final FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
    final boolean isOpen = editorManager.isFileOpen(myVirtualFile);
    if (isOpen) {
      editorManager.closeFile(myVirtualFile);
    }
  }
コード例 #2
0
  private void installEditorFactoryListener() {
    final FileEditorManagerAdapter fileEditorListener =
        new FileEditorManagerAdapter() {
          @Override
          public void fileOpened(FileEditorManager source, VirtualFile file) {
            if (!Comparing.equal(file, myVirtualFile) || myConsoleEditor == null) return;
            Editor selectedTextEditor = source.getSelectedTextEditor();
            for (FileEditor fileEditor : source.getAllEditors(file)) {
              if (!(fileEditor instanceof TextEditor)) continue;
              final EditorEx editor = (EditorEx) ((TextEditor) fileEditor).getEditor();
              editor.addFocusListener(myFocusListener);
              if (selectedTextEditor == editor) { // already focused
                myCurrentEditor = editor;
              }
              EmptyAction.registerActionShortcuts(
                  editor.getComponent(), myConsoleEditor.getComponent());
              editor
                  .getCaretModel()
                  .addCaretListener(
                      new CaretListener() {
                        public void caretPositionChanged(CaretEvent e) {
                          queueUiUpdate(false);
                        }
                      });
            }
            queueUiUpdate(false);
          }

          @Override
          public void fileClosed(FileEditorManager source, VirtualFile file) {
            if (!Comparing.equal(file, myVirtualFile)) return;
            if (myUiUpdateRunnable != null
                && !Boolean.TRUE.equals(
                    file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN))) {
              if (myCurrentEditor != null && myCurrentEditor.isDisposed()) myCurrentEditor = null;
              ApplicationManager.getApplication().runReadAction(myUiUpdateRunnable);
            }
          }
        };
    myProject
        .getMessageBus()
        .connect(this)
        .subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, fileEditorListener);
    FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
    if (editorManager.isFileOpen(myVirtualFile)) {
      fileEditorListener.fileOpened(editorManager, myVirtualFile);
    }
  }