Exemplo n.º 1
0
 private void fileChanged(VirtualFile newFile) {
   FileEditor fileEditor =
       newFile == null
           ? null
           : FileEditorManager.getInstance(getProject()).getSelectedEditor(newFile);
   Editor editor = fileEditor instanceof TextEditor ? ((TextEditor) fileEditor).getEditor() : null;
   myEditor = new WeakReference<Editor>(editor);
   update();
 }
 private static void updateModifiedProperty(@NotNull VirtualFile file) {
   for (Project project : ProjectManager.getInstance().getOpenProjects()) {
     FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
     for (FileEditor editor : fileEditorManager.getAllEditors(file)) {
       if (editor instanceof TextEditorImpl) {
         ((TextEditorImpl) editor).updateModifiedProperty();
       }
     }
   }
 }
 @Override
 public void propertyChanged(@NotNull VirtualFilePropertyEvent event) {
   if (VirtualFile.PROP_NAME.equals(event.getPropertyName())) {
     FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
     VirtualFile file = event.getFile();
     if (fileEditorManager.isFileOpen(file)) {
       reinitBreadcrumbsComponent(fileEditorManager, file);
     }
   }
 }
  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);
    }
  }
 public void calcData(DataKey key, DataSink sink) {
   if (OpenFileDescriptor.NAVIGATE_IN_EDITOR == key) {
     sink.put(OpenFileDescriptor.NAVIGATE_IN_EDITOR, myConsoleEditor);
     return;
   } else if (getProject().isInitialized()) {
     FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
     final Object o =
         ((FileEditorManagerImpl) editorManager)
             .getData(key.getName(), myConsoleEditor, myVirtualFile);
     sink.put(key, o);
   }
 }
  @Override
  @Nullable
  public FileEditorLocation getLocation() {
    VirtualFile virtualFile = getFile();
    if (virtualFile == null) return null;
    FileEditor editor = FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile);
    if (!(editor instanceof TextEditor)) return null;

    Segment segment = getUsageInfo().getSegment();
    if (segment == null) return null;
    return new TextEditorLocation(segment.getStartOffset(), (TextEditor) editor);
  }
  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);
    }
  }
 private void reinitBreadcrumbsInAllEditors() {
   FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
   for (VirtualFile virtualFile : fileEditorManager.getOpenFiles()) {
     reinitBreadcrumbsComponent(fileEditorManager, virtualFile);
   }
 }
 public Editor openTextEditor(boolean focus) {
   return FileEditorManager.getInstance(getProject()).openTextEditor(getDescriptor(), focus);
 }