com.intellij.openapi.fileEditor.FileEditorManagerEvent Java Examples

The following examples show how to use com.intellij.openapi.fileEditor.FileEditorManagerEvent. 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: ToggleReadOnlyAttributePanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void install(@Nonnull StatusBar statusBar) {
  myStatusBar = statusBar;
  Project project = statusBar.getProject();
  if (project == null) {
    return;
  }

  project.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
      if (myStatusBar != null) {
        myStatusBar.updateWidget(ID());
      }
    }
  });
}
 
Example #2
Source File: ORFileEditorListener.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
    VirtualFile newFile = event.getNewFile();
    if (newFile != null) {
        FileType fileType = newFile.getFileType();
        if (FileHelper.isReason(fileType) || FileHelper.isOCaml(fileType)) {
            // On tab change, we redo the background compilation
            Document document = FileDocumentManager.getInstance().getDocument(newFile);
            InsightUpdateQueue insightUpdateQueue = document == null ? null : document.getUserData(INSIGHT_QUEUE);
            if (insightUpdateQueue != null) {
                insightUpdateQueue.queue(m_project, document);
            }
            // and refresh inferred types
            InferredTypesService.queryForSelectedTextEditor(m_project);
        }
    }
}
 
Example #3
Source File: CurrentFileTodosPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
CurrentFileTodosPanel(Project project, TodoPanelSettings settings, Content content) {
  super(project, settings, true, content);

  VirtualFile[] files = FileEditorManager.getInstance(project).getSelectedFiles();
  setFile(files.length == 0 ? null : PsiManager.getInstance(myProject).findFile(files[0]), true);
  // It's important to remove this listener. It prevents invocation of setFile method after the tree builder is disposed
  project.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent e) {
      VirtualFile file = e.getNewFile();
      final PsiFile psiFile = file != null && file.isValid() ? PsiManager.getInstance(myProject).findFile(file) : null;
      // This invokeLater is required. The problem is setFile does a commit to PSI, but setFile is
      // invoked inside PSI change event. It causes an Exception like "Changes to PSI are not allowed inside event processing"
      DumbService.getInstance(myProject).smartInvokeLater(() -> setFile(psiFile, false));
    }
  });
}
 
Example #4
Source File: AutoScrollFromSourceHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void install() {
  final MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
  connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
      final FileEditor editor = event.getNewEditor();
      if (editor != null && myComponent.isShowing() && isAutoScrollEnabled()) {
        myAlarm.cancelAllRequests();
        myAlarm.addRequest(new Runnable() {
          @Override
          public void run() {
            selectElementFromEditor(editor);
          }
        }, getAlarmDelay(), getModalityState());
      }
    }
  });
}
 
Example #5
Source File: LineEndingsManager.java    From editorconfig-jetbrains with MIT License 6 votes vote down vote up
private void updateStatusBar() {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            IdeFrame frame = WindowManager.getInstance().getIdeFrame(project);
            StatusBar statusBar = frame.getStatusBar();
            StatusBarWidget widget = statusBar != null ? statusBar.getWidget("LineSeparator") : null;

            if (widget instanceof LineSeparatorPanel) {
                FileEditorManagerEvent event = new FileEditorManagerEvent(FileEditorManager.getInstance(project),
                                                                          null, null, null, null);
                ((LineSeparatorPanel)widget).selectionChanged(event);
            }
        }
    });
}
 
Example #6
Source File: StatusBarUpdater.java    From consulo with Apache License 2.0 6 votes vote down vote up
public StatusBarUpdater(Project project) {
  myProject = project;

  project.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
      updateLater();
    }
  });

  project.getMessageBus().connect(this).subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListenerAdapter() {
    @Override
    public void daemonFinished() {
      updateLater();
    }
  });
}
 
Example #7
Source File: EditorTracker.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Inject
public EditorTracker(@Nonnull Project project, @Nonnull Provider<WindowManager> windowManagerProvider) {
  myProject = project;

  project.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
      JFrame frame = windowManagerProvider.get().getFrame(myProject);
      if (frame == null || frame.getFocusOwner() == null) {
        return;
      }

      setActiveWindow(TargetAWT.from(frame));
    }
  });
}
 
Example #8
Source File: DesktopEditorComposite.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void fireSelectedEditorChanged(final FileEditor oldSelectedEditor, final FileEditor newSelectedEditor) {
  if ((!EventQueue.isDispatchThread() || !myFileEditorManager.isInsideChange()) && !Comparing.equal(oldSelectedEditor, newSelectedEditor)) {
    myFileEditorManager.notifyPublisher(() -> {
      final FileEditorManagerEvent event = new FileEditorManagerEvent(myFileEditorManager, myFile, oldSelectedEditor, myFile, newSelectedEditor);
      final FileEditorManagerListener publisher = myFileEditorManager.getProject().getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER);
      publisher.selectionChanged(event);
    });
    final JComponent component = newSelectedEditor.getComponent();
    final EditorWindowHolder holder = UIUtil.getParentOfType(EditorWindowHolder.class, component);
    if (holder != null) {
      ((FileEditorManagerImpl)myFileEditorManager).addSelectionRecord(myFile, holder.getEditorWindow());
    }
  }
}
 
Example #9
Source File: AnnotationsPreloader.java    From consulo with Apache License 2.0 5 votes vote down vote up
public AnnotationsPreloader(final Project project) {
  myProject = project;
  myUpdateQueue = new MergingUpdateQueue("Annotations preloader queue", 1000, true, null, project, null, false);

  project.getMessageBus().connect(project).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
      if (!isEnabled()) return;
      VirtualFile file = event.getNewFile();
      if (file != null) {
        schedulePreloading(file);
      }
    }
  });
}
 
Example #10
Source File: BuildifierAutoFormatter.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void initComponent() {
  mMessageBusConnection = ApplicationManager.getApplication().getMessageBus().connect(this);
  mMessageBusConnection.subscribe(
      FileEditorManagerListener.FILE_EDITOR_MANAGER,
      new FileEditorManagerListener() {
        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent event) {
          Project project = event.getManager().getProject();
          if (!BuckProjectSettingsProvider.getInstance(project).isAutoFormatOnBlur()) {
            return;
          }
          FileEditor newFileEditor = event.getNewEditor();
          FileEditor oldFileEditor = event.getOldEditor();
          if (oldFileEditor == null || oldFileEditor.equals(newFileEditor)) {
            return; // still editing same file
          }
          VirtualFile virtualFile = oldFileEditor.getFile();
          Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
          if (document == null) {
            return; // couldn't find document
          }
          PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
          if (!BuckFileType.INSTANCE.equals(psiFile.getFileType())) {
            return; // file type isn't a Buck file
          }
          Runnable runnable = () -> BuildifierUtil.doReformat(project, virtualFile);
          LOGGER.info("Autoformatting " + virtualFile.getPath());
          CommandProcessor.getInstance()
              .executeCommand(
                  project,
                  runnable,
                  null,
                  null,
                  UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION,
                  document);
        }
      });
}
 
Example #11
Source File: BlameStatusWidget.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
  VirtualFile newFile = event.getNewFile();
  if (newFile != null) {
    log.debug("Selection changed: ", newFile);
    updateBlame(newFile);
  }
}
 
Example #12
Source File: GitStatusWidget.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
  VirtualFile file = event.getNewFile();
  if (file != null) {
    runUpdate(myProject, file);
  } else {
    runUpdate(myProject);
  }
}
 
Example #13
Source File: WidgetPerfTipsPanel.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public WidgetPerfTipsPanel(Disposable parentDisposable, @NotNull FlutterApp app) {
  setLayout(new VerticalLayout(5));

  add(new JSeparator());

  perfManager = FlutterWidgetPerfManager.getInstance(app.getProject());
  perfTips = new JPanel();
  perfTips.setLayout(new VerticalLayout(0));

  linkListener = (source, tip) -> handleTipSelection(tip);
  final Project project = app.getProject();
  final MessageBusConnection bus = project.getMessageBus().connect(project);
  final FileEditorManagerListener listener = new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@NotNull FileEditorManagerEvent event) {
      selectedEditorChanged();
    }
  };
  selectedEditorChanged();
  bus.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);

  // Computing performance tips is somewhat expensive so we don't want to
  // compute them too frequently. Performance tips are only computed when
  // new performance stats are available but performance stats are updated
  // at 60fps so to be conservative we delay computing perf tips.
  final Timer perfTipComputeDelayTimer = new Timer(PERF_TIP_COMPUTE_DELAY, this::onComputePerfTips);
  perfTipComputeDelayTimer.start();
  Disposer.register(parentDisposable, perfTipComputeDelayTimer::stop);
}
 
Example #14
Source File: WidgetPerfTipsPanel.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public WidgetPerfTipsPanel(Disposable parentDisposable, @NotNull FlutterApp app) {
  setLayout(new VerticalLayout(5));

  add(new JSeparator());

  perfManager = FlutterWidgetPerfManager.getInstance(app.getProject());
  perfTips = new JPanel();
  perfTips.setLayout(new VerticalLayout(0));

  linkListener = (source, tip) -> handleTipSelection(tip);
  final Project project = app.getProject();
  final MessageBusConnection bus = project.getMessageBus().connect(project);
  final FileEditorManagerListener listener = new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@NotNull FileEditorManagerEvent event) {
      selectedEditorChanged();
    }
  };
  selectedEditorChanged();
  bus.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);

  // Computing performance tips is somewhat expensive so we don't want to
  // compute them too frequently. Performance tips are only computed when
  // new performance stats are available but performance stats are updated
  // at 60fps so to be conservative we delay computing perf tips.
  final Timer perfTipComputeDelayTimer = new Timer(PERF_TIP_COMPUTE_DELAY, this::onComputePerfTips);
  perfTipComputeDelayTimer.start();
  Disposer.register(parentDisposable, perfTipComputeDelayTimer::stop);
}
 
Example #15
Source File: CtrlMouseHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  disposeHighlighter();
  cancelPreviousTooltip();
}
 
Example #16
Source File: TogglePopupHintsPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  updateStatus();
}
 
Example #17
Source File: DvcsStatusWidget.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  LOG.debug("selection changed");
  update();
}
 
Example #18
Source File: LightToolWindowManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  bindToDesigner(getDesigner(event.getNewEditor()));
}
 
Example #19
Source File: NavBarListener.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {}
 
Example #20
Source File: DesktopEditorComposite.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @param file    {@code file} for which composite is being constructed
 * @param editors {@code edittors} that should be placed into the composite
 * @throws IllegalArgumentException if {@code editors}
 *                                  is {@code null} or {@code providers} is {@code null} or {@code myEditor} arrays is empty
 */
DesktopEditorComposite(@Nonnull final VirtualFile file, @Nonnull final FileEditor[] editors, @Nonnull final FileEditorManagerEx fileEditorManager) {
  myFile = file;
  myEditors = editors;
  if (NullUtils.hasNull(editors)) throw new IllegalArgumentException("Must not pass null editors in " + Arrays.asList(editors));
  myFileEditorManager = fileEditorManager;
  myInitialFileTimeStamp = myFile.getTimeStamp();

  Disposer.register(fileEditorManager.getProject(), this);

  if (editors.length > 1) {
    myTabbedPaneWrapper = createTabbedPaneWrapper(editors);
    JComponent component = myTabbedPaneWrapper.getComponent();
    myComponent = new MyComponent(component, component);
  }
  else if (editors.length == 1) {
    myTabbedPaneWrapper = null;
    FileEditor editor = editors[0];
    myComponent = new MyComponent(createEditorComponent(editor), editor.getPreferredFocusedComponent());
  }
  else {
    throw new IllegalArgumentException("editors array cannot be empty");
  }

  mySelectedEditor = editors[0];
  myFocusWatcher = new FocusWatcher();
  myFocusWatcher.install(myComponent);

  myFileEditorManager.addFileEditorManagerListener(new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@Nonnull final FileEditorManagerEvent event) {
      final VirtualFile oldFile = event.getOldFile();
      final VirtualFile newFile = event.getNewFile();
      if (Comparing.equal(oldFile, newFile) && Comparing.equal(getFile(), newFile)) {
        Runnable runnable = () -> {
          final FileEditor oldEditor = event.getOldEditor();
          if (oldEditor != null) oldEditor.deselectNotify();
          final FileEditor newEditor = event.getNewEditor();
          if (newEditor != null) newEditor.selectNotify();
          ((FileEditorProviderManagerImpl)FileEditorProviderManager.getInstance()).providerSelected(DesktopEditorComposite.this);
          ((IdeDocumentHistoryImpl)IdeDocumentHistory.getInstance(myFileEditorManager.getProject())).onSelectionChanged();
        };
        if (ApplicationManager.getApplication().isDispatchThread()) {
          CommandProcessor.getInstance().executeCommand(myFileEditorManager.getProject(), runnable, "Switch Active Editor", null);
        }
        else {
          runnable.run(); // not invoked by user
        }
      }
    }
  }, this);
}
 
Example #21
Source File: PositionPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  updatePosition(getEditor());
}
 
Example #22
Source File: ColumnSelectionModePanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  updateStatus();
}
 
Example #23
Source File: HintManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  hideHints(0, false, true);
}
 
Example #24
Source File: SvnBranchWidget.java    From SVNToolBox with Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(FileEditorManagerEvent event) {
    runUpdate();
}
 
Example #25
Source File: SymfonyProfilerWidget.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
    update(event.getManager().getProject());
}
 
Example #26
Source File: AutoSyncHandler.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(FileEditorManagerEvent event) {
  processEvent(event.getOldFile());
}
 
Example #27
Source File: GTMStatusWidget.java    From gtm-jetbrains-plugin with MIT License 4 votes vote down vote up
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
    runUpdate();
}
 
Example #28
Source File: EditorStatusChangeActivityDispatcher.java    From saros with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Calls {@link LocalEditorHandler#activateEditor(VirtualFile)}.
 *
 * <p>Does nothing if the opened editor is not a text editor.
 *
 * @param event the event to react to
 * @see FileEditorManagerListener#selectionChanged(FileEditorManagerEvent)
 */
private void generateEditorActivatedActivity(@NotNull FileEditorManagerEvent event) {
  FileEditor newEditor = event.getNewEditor();

  if (newEditor == null || newEditor instanceof TextEditor) {
    localEditorHandler.activateEditor(event.getNewFile());
  }
}
 
Example #29
Source File: RoboVmFileEditorManagerListener.java    From robovm-idea with GNU General Public License v2.0 2 votes vote down vote up
@Override
public void selectionChanged(FileEditorManagerEvent event) {

}