Where to register statusbar?

Question: I want to use add something to the IntelliJ status bar (a word counter for the current open editor). But where do I register the status bar? Is there a startup for the plugin, so the statusbar is loaded only once? Or do I need to load/unload it every time the correct editor gets the focus? Does this mean I need to unload it at some point??

Thanks,

Erik

5 comments
Comment actions Permalink

See com.intellij.openapi.wm.impl.status.EditorBasedWidget. You could install your widget in ProjectComponent.

0
Comment actions Permalink

Hi Yann, thanks for the answer. I'm not sure what a ProjectComponent is, and how that works, and actually, the same for the EditorBasedWidget...Actually, I'm not even sure what an EditorBasedWidget is, how do I activate it, how do I deactive it, etc?

The goal I'm trying to reach is to implement a simple wordcounter for specific editors, in this case, the AsciiDoc editor, and when the editor opens, add a new entry to the statusbar which will show the number of words. Well, that part is working, but right now I have a bug which will register the statusbar for each open editor, which is wrong, and it never removes the status bar, so when I open a Java editor, I still see the wordcount, which is not what I want.

So, my guess was that I would have to register the StatusBar on focus (I don't yet know where to do it in the code)
Then, update the text in the StatusBar (that part is done)
Then, when the editor doesn't have the focus anymore, remove the StatusBar (also no idea yet where to do that).

So, it would be most appreciated if you could give me some pointer on where to do this. I'm not really familiar yet with IntelliJ Plugin Dev, and I'm having some troubles (and a lot of frustration) finding my way around.

Thanks! Erik

0
Comment actions Permalink

EditorBasedWidget implements com.intellij.openapi.fileEditor.FileEditorManagerListener for exactly that reason, just override fileOpened/Closed to add/remove your widget according to the filetype.

0
Comment actions Permalink

Hi Yann,

Thanks for the reply. I'm slowly getting there, but still not completely, because of having the status bar shown/hidden on fileOpen/fileClose, I want to have the status bar changed whenever I switch editor. For example, I only want the statusbar to show a wordcounter when I select the asciidoc file, and when I select another file, I want to hide it (I haven't closed the file yet, I'm just switching tabs.)

Thanks for the help so far!

Erik

0
Comment actions Permalink

Override the selectionChanged() method in EditorBasedWidget and hide your component if the new selection isn't your file.

0

Please sign in to leave a comment.