Java Code Examples for com.intellij.openapi.fileEditor.FileEditorManager#getEditors()

The following examples show how to use com.intellij.openapi.fileEditor.FileEditorManager#getEditors() . 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: DaemonCodeAnalyzerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void cleanFileLevelHighlights(@Nonnull Project project, final int group, PsiFile psiFile) {
  if (psiFile == null) return;
  FileViewProvider provider = psiFile.getViewProvider();
  VirtualFile vFile = provider.getVirtualFile();
  final FileEditorManager manager = FileEditorManager.getInstance(project);
  for (FileEditor fileEditor : manager.getEditors(vFile)) {
    final List<HighlightInfo> infos = fileEditor.getUserData(FILE_LEVEL_HIGHLIGHTS);
    if (infos == null) continue;
    List<HighlightInfo> infosToRemove = new ArrayList<>();
    for (HighlightInfo info : infos) {
      if (info.getGroup() == group) {
        manager.removeTopComponent(fileEditor, info.fileLevelComponent);
        infosToRemove.add(info);
      }
    }
    infos.removeAll(infosToRemove);
  }
}
 
Example 2
Source File: DaemonCodeAnalyzerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void addFileLevelHighlight(@Nonnull final Project project, final int group, @Nonnull final HighlightInfo info, @Nonnull final PsiFile psiFile) {
  VirtualFile vFile = psiFile.getViewProvider().getVirtualFile();
  final FileEditorManager manager = FileEditorManager.getInstance(project);
  for (FileEditor fileEditor : manager.getEditors(vFile)) {
    if (fileEditor instanceof TextEditor) {
      FileLevelIntentionComponent component = new FileLevelIntentionComponent(info.getDescription(), info.getSeverity(), info.getGutterIconRenderer(), info.quickFixActionRanges, project, psiFile,
                                                                              ((TextEditor)fileEditor).getEditor(), info.getToolTip());
      manager.addTopComponent(fileEditor, component);
      List<HighlightInfo> fileLevelInfos = fileEditor.getUserData(FILE_LEVEL_HIGHLIGHTS);
      if (fileLevelInfos == null) {
        fileLevelInfos = new ArrayList<>();
        fileEditor.putUserData(FILE_LEVEL_HIGHLIGHTS, fileLevelInfos);
      }
      info.fileLevelComponent = component;
      info.setGroup(group);
      fileLevelInfos.add(info);
    }
  }
}
 
Example 3
Source File: OutdatedVersionNotifier.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void fileOpened(@Nonnull FileEditorManager source, @Nonnull VirtualFile file) {
  if (myCache.getCachedIncomingChanges() == null) {
    requestLoadIncomingChanges();
  }
  else {
    final Pair<CommittedChangeList, Change> pair = myCache.getIncomingChangeList(file);
    if (pair != null) {
      final FileEditor[] fileEditors = source.getEditors(file);
      for(FileEditor editor: fileEditors) {
        initPanel(pair.first, pair.second, editor);
      }
    }
  }
}
 
Example 4
Source File: NavigationUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean activatePsiElementIfOpen(@Nonnull PsiElement elt, boolean searchForOpen, boolean requestFocus) {
  if (!elt.isValid()) return false;
  elt = elt.getNavigationElement();
  final PsiFile file = elt.getContainingFile();
  if (file == null || !file.isValid()) return false;

  VirtualFile vFile = file.getVirtualFile();
  if (vFile == null) return false;

  if (!EditorHistoryManager.getInstance(elt.getProject()).hasBeenOpen(vFile)) return false;

  final FileEditorManager fem = FileEditorManager.getInstance(elt.getProject());
  if (!fem.isFileOpen(vFile)) {
    fem.openFile(vFile, requestFocus, searchForOpen);
  }

  final TextRange range = elt.getTextRange();
  if (range == null) return false;

  final FileEditor[] editors = fem.getEditors(vFile);
  for (FileEditor editor : editors) {
    if (editor instanceof TextEditor) {
      final Editor text = ((TextEditor)editor).getEditor();
      final int offset = text.getCaretModel().getOffset();

      if (range.containsOffset(offset)) {
        // select the file
        fem.openFile(vFile, requestFocus, searchForOpen);
        return true;
      }
    }
  }

  return false;
}
 
Example 5
Source File: RunIdeConsoleAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void configureConsole(@Nonnull VirtualFile file, @Nonnull FileEditorManager source) {
  MyRunAction runAction = new MyRunAction();
  for (FileEditor fileEditor : source.getEditors(file)) {
    if (!(fileEditor instanceof TextEditor)) continue;
    Editor editor = ((TextEditor)fileEditor).getEditor();
    runAction.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, editor.getComponent());
  }
}