Java Code Examples for com.intellij.openapi.fileEditor.FileEditor#getUserData()

The following examples show how to use com.intellij.openapi.fileEditor.FileEditor#getUserData() . 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: DetectedIndentOptionsNotificationProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void updateIndentNotification(@Nonnull PsiFile file, boolean enforce) {
  VirtualFile vFile = file.getVirtualFile();
  if (vFile == null) return;

  if (!ApplicationManager.getApplication().isHeadlessEnvironment()
      || ApplicationManager.getApplication().isUnitTestMode() && myShowNotificationInTest)
  {
    Project project = file.getProject();
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    if (fileEditorManager == null) return;
    FileEditor fileEditor = fileEditorManager.getSelectedEditor(vFile);
    if (fileEditor != null) {
      Boolean notifiedFlag = fileEditor.getUserData(NOTIFIED_FLAG);
      if (notifiedFlag == null || enforce) {
        fileEditor.putUserData(NOTIFIED_FLAG, Boolean.TRUE);
        EditorNotifications.getInstance(project).updateNotifications(vFile);
      }
    }
  }
}
 
Example 4
Source File: LineStatusTracker.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
protected void installNotification(@Nonnull String text) {
  final FileEditor[] editors = myFileEditorManager.getAllEditors(myVirtualFile);
  for (FileEditor editor : editors) {
    JPanel panel = editor.getUserData(PANEL_KEY);
    if (panel == null) {
      final JPanel newPanel = new EditorNotificationPanel().text(text);
      editor.putUserData(PANEL_KEY, newPanel);
      myFileEditorManager.addTopComponent(editor, newPanel);
    }
  }
}
 
Example 5
Source File: LineStatusTracker.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@RequiredUIAccess
protected void destroyNotification() {
  final FileEditor[] editors = myFileEditorManager.getEditors(myVirtualFile);
  for (FileEditor editor : editors) {
    final JPanel panel = editor.getUserData(PANEL_KEY);
    if (panel != null) {
      myFileEditorManager.removeTopComponent(editor, panel);
      editor.putUserData(PANEL_KEY, null);
    }
  }
}
 
Example 6
Source File: OutdatedVersionNotifier.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateAllEditors() {
  if (myCache.getCachedIncomingChanges() == null) {
    requestLoadIncomingChanges();
    return;
  }
  debug("Updating editors");
  final VirtualFile[] files = myFileEditorManager.get().getOpenFiles();
  for(VirtualFile file: files) {
    final Pair<CommittedChangeList,Change> pair = myCache.getIncomingChangeList(file);
    final FileEditor[] fileEditors = myFileEditorManager.get().getEditors(file);
    for(FileEditor editor: fileEditors) {
      final OutdatedRevisionPanel oldPanel = editor.getUserData(PANEL_KEY);
      if (pair != null) {
        if (oldPanel != null) {
          oldPanel.setChangeList(pair.first, pair.second);
        }
        else {
          initPanel(pair.first, pair.second, editor);
        }
      }
      else if (oldPanel != null) {
        myFileEditorManager.get().removeTopComponent(editor, oldPanel);
        editor.putUserData(PANEL_KEY, null);
      }
    }
  }
}
 
Example 7
Source File: FindUsagesManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static Usage findSiblingUsage(@Nonnull final UsageSearcher usageSearcher,
                                      @Nonnull FileSearchScope dir,
                                      final FileEditorLocation currentLocation,
                                      @Nonnull final AtomicBoolean usagesWereFound,
                                      @Nonnull FileEditor fileEditor) {
  if (fileEditor.getUserData(KEY_START_USAGE_AGAIN) != null) {
    dir = dir == FileSearchScope.AFTER_CARET ? FileSearchScope.FROM_START : FileSearchScope.FROM_END;
  }

  final FileSearchScope direction = dir;

  final AtomicReference<Usage> foundUsage = new AtomicReference<>();
  usageSearcher.generate(usage -> {
    usagesWereFound.set(true);
    if (direction == FileSearchScope.FROM_START) {
      foundUsage.compareAndSet(null, usage);
      return false;
    }
    if (direction == FileSearchScope.FROM_END) {
      foundUsage.set(usage);
    }
    else if (direction == FileSearchScope.AFTER_CARET) {
      if (Comparing.compare(usage.getLocation(), currentLocation) > 0) {
        foundUsage.set(usage);
        return false;
      }
    }
    else if (direction == FileSearchScope.BEFORE_CARET) {
      if (Comparing.compare(usage.getLocation(), currentLocation) >= 0) {
        return false;
      }
      while (true) {
        Usage found = foundUsage.get();
        if (found == null) {
          if (foundUsage.compareAndSet(null, usage)) break;
        }
        else {
          if (Comparing.compare(found.getLocation(), usage.getLocation()) < 0 && foundUsage.compareAndSet(found, usage)) break;
        }
      }
    }

    return true;
  });

  fileEditor.putUserData(KEY_START_USAGE_AGAIN, null);

  return foundUsage.get();
}