use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class RemoveUnusedVariableFix method showSideEffectsWarning.
public static RemoveUnusedVariableUtil.RemoveMode showSideEffectsWarning(List<PsiElement> sideEffects, PsiVariable variable, Editor editor, boolean canCopeWithSideEffects, @NonNls String beforeText, @NonNls String afterText) {
if (sideEffects.isEmpty())
return RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL;
if (ApplicationManager.getApplication().isUnitTestMode()) {
return canCopeWithSideEffects ? RemoveUnusedVariableUtil.RemoveMode.MAKE_STATEMENT : RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL;
}
Project project = editor.getProject();
HighlightManager highlightManager = HighlightManager.getInstance(project);
PsiElement[] elements = PsiUtilCore.toPsiElementArray(sideEffects);
EditorColorsManager manager = EditorColorsManager.getInstance();
TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
highlightManager.addOccurrenceHighlights(editor, elements, attributes, true, null);
SideEffectWarningDialog dialog = new SideEffectWarningDialog(project, false, variable, beforeText, afterText, canCopeWithSideEffects);
dialog.show();
int code = dialog.getExitCode();
return RemoveUnusedVariableUtil.RemoveMode.values()[code];
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class HighlightUsagesHandler method highlightOtherOccurrences.
public static void highlightOtherOccurrences(final List<PsiElement> otherOccurrences, Editor editor, boolean clearHighlights) {
EditorColorsManager manager = EditorColorsManager.getInstance();
TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
PsiElement[] elements = PsiUtilCore.toPsiElementArray(otherOccurrences);
doHighlightElements(editor, elements, attributes, clearHighlights);
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class HighlightUsagesHandlerBase method performHighlighting.
protected void performHighlighting() {
boolean clearHighlights = HighlightUsagesHandler.isClearHighlights(myEditor);
EditorColorsManager manager = EditorColorsManager.getInstance();
TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
TextAttributes writeAttributes = manager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
HighlightUsagesHandler.highlightRanges(HighlightManager.getInstance(myEditor.getProject()), myEditor, attributes, clearHighlights, myReadUsages);
HighlightUsagesHandler.highlightRanges(HighlightManager.getInstance(myEditor.getProject()), myEditor, writeAttributes, clearHighlights, myWriteUsages);
if (!clearHighlights) {
WindowManager.getInstance().getStatusBar(myEditor.getProject()).setInfo(myStatusText);
// enable f3 navigation
HighlightHandlerBase.setupFindModel(myEditor.getProject());
}
if (myHintText != null) {
HintManager.getInstance().showInformationHint(myEditor, myHintText);
}
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class FindUtil method doSearch.
@Nullable
private static FindResult doSearch(@NotNull Project project, @NotNull final Editor editor, int offset, boolean toWarn, @NotNull FindModel model, boolean adjustEditor) {
FindManager findManager = FindManager.getInstance(project);
Document document = editor.getDocument();
final FindResult result = findManager.findString(document.getCharsSequence(), offset, model, getVirtualFile(editor));
boolean isFound = result.isStringFound();
final SelectionModel selection = editor.getSelectionModel();
if (isFound && !model.isGlobal()) {
if (!selectionMayContainRange(selection, result)) {
isFound = false;
} else if (!selectionStrictlyContainsRange(selection, result)) {
final int[] starts = selection.getBlockSelectionStarts();
for (int newOffset : starts) {
if (newOffset > result.getStartOffset()) {
return doSearch(project, editor, newOffset, toWarn, model, adjustEditor);
}
}
}
}
if (!isFound) {
if (toWarn) {
processNotFound(editor, model.getStringToFind(), model, project);
}
return null;
}
if (adjustEditor) {
final CaretModel caretModel = editor.getCaretModel();
final ScrollingModel scrollingModel = editor.getScrollingModel();
int oldCaretOffset = caretModel.getOffset();
boolean forward = oldCaretOffset < result.getStartOffset();
final ScrollType scrollType = forward ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP;
if (model.isGlobal()) {
int targetCaretPosition = result.getEndOffset();
if (selection.getSelectionEnd() - selection.getSelectionStart() == result.getLength()) {
// keeping caret's position relative to selection
// use case: FindNext is used after SelectNextOccurrence action
targetCaretPosition = caretModel.getOffset() - selection.getSelectionStart() + result.getStartOffset();
}
if (caretModel.getCaretAt(editor.offsetToVisualPosition(targetCaretPosition)) != null) {
// use case: FindNext is used after SelectNextOccurrence action
return result;
}
caretModel.moveToOffset(targetCaretPosition);
selection.removeSelection();
scrollingModel.scrollToCaret(scrollType);
scrollingModel.runActionOnScrollingFinished(() -> {
scrollingModel.scrollTo(editor.offsetToLogicalPosition(result.getStartOffset()), scrollType);
scrollingModel.scrollTo(editor.offsetToLogicalPosition(result.getEndOffset()), scrollType);
});
} else {
moveCaretAndDontChangeSelection(editor, result.getStartOffset(), scrollType);
moveCaretAndDontChangeSelection(editor, result.getEndOffset(), scrollType);
}
IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
EditorColorsManager manager = EditorColorsManager.getInstance();
TextAttributes selectionAttributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
if (!model.isGlobal()) {
final RangeHighlighterEx segmentHighlighter = (RangeHighlighterEx) editor.getMarkupModel().addRangeHighlighter(result.getStartOffset(), result.getEndOffset(), HighlighterLayer.SELECTION + 1, selectionAttributes, HighlighterTargetArea.EXACT_RANGE);
MyListener listener = new MyListener(editor, segmentHighlighter);
caretModel.addCaretListener(listener);
} else {
selection.setSelection(result.getStartOffset(), result.getEndOffset());
}
}
return result;
}
use of com.intellij.openapi.editor.colors.EditorColorsManager in project intellij-community by JetBrains.
the class InplaceRefactoring method highlightTemplateVariables.
private void highlightTemplateVariables(Template template, Editor topLevelEditor) {
//add highlights
if (myHighlighters != null) {
// can be null if finish is called during testing
Map<TextRange, TextAttributes> rangesToHighlight = new HashMap<>();
final TemplateState templateState = TemplateManagerImpl.getTemplateState(topLevelEditor);
if (templateState != null) {
EditorColorsManager colorsManager = EditorColorsManager.getInstance();
for (int i = 0; i < templateState.getSegmentsCount(); i++) {
final TextRange segmentOffset = templateState.getSegmentRange(i);
final String name = template.getSegmentName(i);
TextAttributes attributes = null;
if (name.equals(PRIMARY_VARIABLE_NAME)) {
attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
} else if (name.equals(OTHER_VARIABLE_NAME)) {
attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
}
if (attributes == null)
continue;
rangesToHighlight.put(segmentOffset, attributes);
}
}
addHighlights(rangesToHighlight, topLevelEditor, myHighlighters, HighlightManager.getInstance(myProject));
}
}
Aggregations