Simple plugin idea, looking for some OpenApi pointers
I'd like to implement something like Highlight Usages, but on a wider context and scope.
When I invoke my new "Extended Highlight Usages", the usages are not only shown in current editor, but also in all other editors, and new editors that are opened after that.
The highlighting should not disappear after the regular "Esc" invoking, like it does for Ctrl-Shift-F7.
I'm not sure about the UI, most likely I'll provide an intention to add/remove the target of some reference from the current "Extended Highlight Usages" set.
I'd like the set of current active highlightings to survive a project reopen etc.
Any API pointers to get started?
请先登录再写评论。
Hello Taras,
Well, this should be pretty straightforward. Use Editor.getMarkupModel()
for highlighting and EditorFactory.addEditorFactoryListener() to receive
notifications about editor creation in order to add highlighting to newly
opened editors.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Here is some code that can highlight PsiElements in the current editor like Hightlight Usages in File does (in the proper colors and working Find Next and Find Previous).
elementCollection) { if (elementCollection.isEmpty()) { return; } final Application application = ApplicationManager.getApplication(); application.invokeLater(new Runnable() { public void run() { final PsiElement[] elements = elementCollection.toArray( new PsiElement[elementCollection.size()]); final Project project = elements[0].getProject(); final FileEditorManager editorManager = FileEditorManager.getInstance(project); final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance(); final Editor editor = editorManager.getSelectedTextEditor(); if (editor == null) { return; } final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme(); final TextAttributes textattributes = globalScheme.getAttributes( EditorColors.SEARCH_RESULT_ATTRIBUTES); final HighlightManager highlightManager = HighlightManager.getInstance(project); highlightManager.addOccurrenceHighlights( editor, elements, textattributes, true, null); final WindowManager windowManager = WindowManager.getInstance(); final StatusBar statusBar = windowManager.getStatusBar(project); statusBar.setInfo(InspectionGadgetsBundle.message( "press.escape.to.remove.highlighting.message")); final FindManager findmanager = FindManager.getInstance(project); FindModel findmodel = findmanager.getFindNextModel(); if(findmodel == null) { findmodel = findmanager.getFindInFileModel(); } findmodel.setSearchHighlighters(true); findmanager.setFindWasPerformed(); findmanager.setFindNextModel(findmodel); } }); } ]]>Thank you both, will give it a try tonight.