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

The following examples show how to use com.intellij.openapi.fileEditor.FileEditorManager#isFileOpen() . 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: DocImpl.java    From floobits-intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void applyHighlight(HighlightContext highlight) {
    final FileEditorManager manager = FileEditorManager.getInstance(context.project);
    final VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);

    if ((highlight.force || highlight.following) && virtualFile != null && virtualFile.isValid()) {
        boolean spam = false;
        if (!manager.isFileOpen(virtualFile) || !Arrays.asList(manager.getSelectedFiles()).contains(virtualFile)) {
            spam = true;
        }
        if (spam && highlight.username.length() > 0 && highlight.force) {
            context.statusMessage(String.format("%s has summoned you!", highlight.username));
        }
        manager.openFile(virtualFile, false, true);
    }

    highlight.textLength = document.getTextLength();
    if (highlight.textLength == 0) {
        return;
    }
    synchronized (context) {
        try {
            context.setListener(false);
            highlight.force = highlight.force || highlight.following;
            highlight.context = context;
            applyHighlight_(highlight);
        } catch (Throwable e) {
            Flog.error(e);
        } finally {
            context.setListener(true);
        }
    }
}
 
Example 2
Source File: SrcFileAnnotator.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void hideCoverageData() {
  if (myEditor == null) return;
  final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
  final List<RangeHighlighter> highlighters = myEditor.getUserData(COVERAGE_HIGHLIGHTERS);
  if (highlighters != null) {
    for (final RangeHighlighter highlighter : highlighters) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          highlighter.dispose();
        }
      });
    }
    myEditor.putUserData(COVERAGE_HIGHLIGHTERS, null);
  }
  
  final Map<FileEditor, EditorNotificationPanel> map = myFile.getCopyableUserData(NOTIFICATION_PANELS);
  if (map != null) {
    final VirtualFile vFile = myFile.getVirtualFile();
    LOG.assertTrue(vFile != null);
    boolean freeAll = !fileEditorManager.isFileOpen(vFile);
    myFile.putCopyableUserData(NOTIFICATION_PANELS, null);
    for (FileEditor fileEditor : map.keySet()) {
      if (!freeAll && !isCurrentEditor(fileEditor)) {
        continue;
      }
      fileEditorManager.removeTopComponent(fileEditor, map.get(fileEditor));
    }
  }

  final DocumentListener documentListener = myEditor.getUserData(COVERAGE_DOCUMENT_LISTENER);
  if (documentListener != null) {
    myDocument.removeDocumentListener(documentListener);
    myEditor.putUserData(COVERAGE_DOCUMENT_LISTENER, null);
  }
}
 
Example 3
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 4
Source File: LanguageConsoleImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void closeFile() {
  if (getProject().isOpen()) {
    FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
    if (editorManager.isFileOpen(getVirtualFile())) {
      editorManager.closeFile(getVirtualFile());
    }
  }
}
 
Example 5
Source File: BreadcrumbsInitializingActivity.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChanged(@Nonnull VirtualFilePropertyEvent event) {
  if (VirtualFile.PROP_NAME.equals(event.getPropertyName()) && !myProject.isDisposed()) {
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    VirtualFile file = event.getFile();
    if (fileEditorManager.isFileOpen(file)) {
      reinitBreadcrumbsComponent(fileEditorManager, file);
    }
  }
}