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

The following examples show how to use com.intellij.openapi.fileEditor.FileEditor#putUserData() . 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 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 2
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 3
Source File: FindUsagesManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void startFindUsages(@Nonnull FindUsagesOptions findUsagesOptions, @Nonnull FindUsagesHandler handler, PsiFile scopeFile, FileEditor editor) {
  boolean singleFile = scopeFile != null;

  clearFindingNextUsageInFile();
  LOG.assertTrue(handler.getPsiElement().isValid());
  PsiElement[] primaryElements = handler.getPrimaryElements();
  checkNotNull(primaryElements, handler, "getPrimaryElements()");
  PsiElement[] secondaryElements = handler.getSecondaryElements();
  checkNotNull(secondaryElements, handler, "getSecondaryElements()");
  if (singleFile) {
    editor.putUserData(KEY_START_USAGE_AGAIN, null);
    findUsagesInEditor(primaryElements, secondaryElements, handler, scopeFile, FileSearchScope.FROM_START, findUsagesOptions.clone(), editor);
  }
  else {
    boolean skipResultsWithOneUsage = FindSettings.getInstance().isSkipResultsWithOneUsage();
    findUsages(primaryElements, secondaryElements, handler, findUsagesOptions, skipResultsWithOneUsage);
  }
}
 
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: OutdatedVersionNotifier.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void initPanel(final CommittedChangeList list, final Change c, final FileEditor editor) {
  if (!isIncomingChangesSupported(list)) {
    return;
  }
  final OutdatedRevisionPanel component = new OutdatedRevisionPanel(list, c);
  editor.putUserData(PANEL_KEY, component);
  myFileEditorManager.get().addTopComponent(editor, component);
}
 
Example 8
Source File: FindUsagesManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void findUsagesInEditor(@Nonnull final PsiElement[] primaryElements,
                                @Nonnull final PsiElement[] secondaryElements,
                                @Nonnull FindUsagesHandler handler,
                                @Nonnull PsiFile scopeFile,
                                @Nonnull FileSearchScope direction,
                                @Nonnull final FindUsagesOptions findUsagesOptions,
                                @Nonnull FileEditor fileEditor) {
  initLastSearchElement(findUsagesOptions, primaryElements, secondaryElements);

  clearStatusBar();

  final FileEditorLocation currentLocation = fileEditor.getCurrentLocation();

  PsiElement2UsageTargetAdapter[] primaryTargets = PsiElement2UsageTargetAdapter.convert(primaryElements);
  PsiElement2UsageTargetAdapter[] secondaryTargets = PsiElement2UsageTargetAdapter.convert(primaryElements);
  final UsageSearcher usageSearcher = createUsageSearcher(primaryTargets, secondaryTargets, handler, findUsagesOptions, scopeFile);
  AtomicBoolean usagesWereFound = new AtomicBoolean();

  Usage fUsage = findSiblingUsage(usageSearcher, direction, currentLocation, usagesWereFound, fileEditor);

  if (fUsage != null) {
    fUsage.navigate(true);
    fUsage.selectInEditor();
  }
  else if (!usagesWereFound.get()) {
    String message = getNoUsagesFoundMessage(primaryElements[0]) + " in " + scopeFile.getName();
    showHintOrStatusBarMessage(message, fileEditor);
  }
  else {
    fileEditor.putUserData(KEY_START_USAGE_AGAIN, VALUE_START_USAGE_AGAIN);
    showHintOrStatusBarMessage(getSearchAgainMessage(primaryElements[0], direction), fileEditor);
  }
}
 
Example 9
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();
}