Clickable text in editor?

Answered

How can I create a text in editor that is clickable (and opens a pane in Preferences?)

 

0
4 comments

Could you please describe "text in editor" in more detail or share screenshot?

Settings can be opened programatically via com.intellij.openapi.options.ShowSettingsUtil

0
Avatar
Permanently deleted user

OK, let me clarify this. I have a plugin which has a preview window for displaying results of certain processing (mostly in plain text or JSON format). 

In a pseudo-code it looks like this:

PsiFile f = PsiFileFactory.getInstance(getProject()).createFileFromText(language, previewOutput);
Editor editor = EditorFactory.getInstance().createEditor(f.getViewProvider().getDocument(), getProject(), language.getAssociatedFileType(), true);

And the results are displayed as follows:

editor.getDocument().setText(previewOutput);

However, if a certain setting in a plugin is not configured, I want to display an error message, something like: "The XYZ setting is not configured, please configure it at Tools -> MyPlugin" - and the portion of the text "please configure it at Tools -> MyPlugin" should be clickable (and probably displayed in a different color) so that when user clicks on it, the settings panel opens. I did figure the ShowSettingsUtil part, and it works, but how do I make that error text or the portion of it clickable and invoke an action that opens the settings panel?

0

You could add a component displaying this status + links/actions via com.intellij.openapi.editor.Editor#setHeaderComponent, check com.intellij.ui.EditorNotificationPanel as convenient base class for such header.

0
Avatar
Permanently deleted user

Perfect, it worked for me! Thank you very much!

 

0

Please sign in to leave a comment.