Java Code Examples for com.intellij.codeInsight.highlighting.HighlightManager#removeSegmentHighlighter()

The following examples show how to use com.intellij.codeInsight.highlighting.HighlightManager#removeSegmentHighlighter() . 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: InplaceRefactoring.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void finish(boolean success) {
  if (!ourRenamersStack.isEmpty() && ourRenamersStack.peek() == this) {
    ourRenamersStack.pop();
  }
  if (myHighlighters != null) {
    if (!myProject.isDisposed()) {
      final HighlightManager highlightManager = HighlightManager.getInstance(myProject);
      for (RangeHighlighter highlighter : myHighlighters) {
        highlightManager.removeSegmentHighlighter(myEditor, highlighter);
      }
    }

    myHighlighters = null;
    myEditor.putUserData(INPLACE_RENAMER, null);
  }
  if (myBalloon != null) {
    if (!isRestart()) {
      myBalloon.hide();
    }
  }
}
 
Example 2
Source File: FlowInPlaceRenamer.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
private void finish() {
    ourRenamersStack.pop();
    if (this.myHighlighters != null) {
        Project project = this.myEditor.getProject();
        if (project != null && !project.isDisposed()) {
            HighlightManager highlightManager = HighlightManager.getInstance(project);
            Iterator var3 = this.myHighlighters.iterator();

            while (var3.hasNext()) {
                RangeHighlighter highlighter = (RangeHighlighter) var3.next();
                highlightManager.removeSegmentHighlighter(this.myEditor, highlighter);
            }
        }
    }
}
 
Example 3
Source File: BreadcrumbsWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void itemHovered(Crumb crumb, @SuppressWarnings("unused") InputEvent event) {
  if (!Registry.is("editor.breadcrumbs.highlight.on.hover")) {
    return;
  }

  HighlightManager hm = HighlightManager.getInstance(myProject);
  if (myHighlighed != null) {
    for (RangeHighlighter highlighter : myHighlighed) {
      hm.removeSegmentHighlighter(myEditor, highlighter);
    }
    myHighlighed = null;
  }
  if (crumb instanceof NavigatableCrumb) {
    final TextRange range = ((NavigatableCrumb)crumb).getHighlightRange();
    if (range == null) return;
    final TextAttributes attributes = new TextAttributes();
    final CrumbPresentation p = PsiCrumb.getPresentation(crumb);
    Color color = p == null ? null : p.getBackgroundColor(false, false, false);
    if (color == null) color = BreadcrumbsComponent.ButtonSettings.getBackgroundColor(false, false, false, false);
    if (color == null) color = UIUtil.getLabelBackground();
    final Color background = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.CARET_ROW_COLOR);
    attributes.setBackgroundColor(makeTransparent(color, background != null ? background : Gray._200, 0.3));
    myHighlighed = new ArrayList<>(1);
    int flags = HighlightManager.HIDE_BY_ESCAPE | HighlightManager.HIDE_BY_TEXT_CHANGE | HighlightManager.HIDE_BY_ANY_KEY;
    hm.addOccurrenceHighlight(myEditor, range.getStartOffset(), range.getEndOffset(), attributes, flags, myHighlighed, null);
  }
}
 
Example 4
Source File: InplaceChangeSignature.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void detach() {
  myEditor.getDocument().removeDocumentListener(this);
  HighlightManager highlightManager = HighlightManager.getInstance(myProject);
  for (RangeHighlighter highlighter : myHighlighters) {
    highlightManager.removeSegmentHighlighter(myEditor, highlighter);
  }
  myHighlighters.clear();
  myBalloon.hide();
  myDetector = null;
  FinishMarkAction.finish(myProject, myEditor, myMarkAction);
  myEditor.putUserData(INPLACE_CHANGE_SIGNATURE, null);
}
 
Example 5
Source File: ExtractMethodHelper.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Notifies user about found duplicates and then highlights each of them in the editor and asks user how to proceed.
 *
 * @param callElement generated expression or statement that contains invocation of the new method
 * @param editor      instance of editor where refactoring is performed
 * @param replacer    strategy of substituting each duplicate occurence with the replacement fragment
 * @param duplicates  discovered duplicates of extracted code fragment
 * @see #collectDuplicates(SimpleDuplicatesFinder, List, PsiElement)
 */
public static void replaceDuplicates(@Nonnull PsiElement callElement,
                                     @Nonnull Editor editor,
                                     @Nonnull Consumer<Pair<SimpleMatch, PsiElement>> replacer,
                                     @Nonnull List<SimpleMatch> duplicates) {
  if (!duplicates.isEmpty()) {
    final String message = RefactoringBundle
            .message("0.has.detected.1.code.fragments.in.this.file.that.can.be.replaced.with.a.call.to.extracted.method",
                     ApplicationNamesInfo.getInstance().getProductName(), duplicates.size());
    final boolean isUnittest = ApplicationManager.getApplication().isUnitTestMode();
    final Project project = callElement.getProject();
    final int exitCode = !isUnittest ? Messages.showYesNoDialog(project, message,
                                                                RefactoringBundle.message("refactoring.extract.method.dialog.title"),
                                                                Messages.getInformationIcon()) :
                         Messages.YES;
    if (exitCode == Messages.YES) {
      boolean replaceAll = false;
      final Map<SimpleMatch, RangeHighlighter> highlighterMap = new HashMap<>();
      for (SimpleMatch match : duplicates) {
        if (!match.getStartElement().isValid() || !match.getEndElement().isValid()) continue;
        final Pair<SimpleMatch, PsiElement> replacement = Pair.create(match, callElement);
        if (!replaceAll) {
          highlightInEditor(project, match, editor, highlighterMap);

          int promptResult = FindManager.PromptResult.ALL;
          //noinspection ConstantConditions
          if (!isUnittest) {
            ReplacePromptDialog promptDialog =
                    new ReplacePromptDialog(false, RefactoringBundle.message("replace.fragment"), project);
            promptDialog.show();
            promptResult = promptDialog.getExitCode();
          }
          if (promptResult == FindManager.PromptResult.SKIP) {
            final HighlightManager highlightManager = HighlightManager.getInstance(project);
            final RangeHighlighter highlighter = highlighterMap.get(match);
            if (highlighter != null) highlightManager.removeSegmentHighlighter(editor, highlighter);
            continue;
          }
          if (promptResult == FindManager.PromptResult.CANCEL) break;

          if (promptResult == FindManager.PromptResult.OK) {
            replaceDuplicate(project, replacer, replacement);
          }
          else if (promptResult == FindManager.PromptResult.ALL) {
            replaceDuplicate(project, replacer, replacement);
            replaceAll = true;
          }
        }
        else {
          replaceDuplicate(project, replacer, replacement);
        }
      }
    }
  }
}