New Editor Tab Action for plugin
Hi,
So me and my team are trying to make this plugin that tracks documents changes. What we want to happen is that every time a file is opened in an editor tab, we want a window to pop up that asks do you want to start the logging activity? But we're having difficulty in finding what kind of listener object we need to use? What's the action that happens when a document is opened? And should this be implemented in an application component or project component?
Thanks.
Please sign in to leave a comment.
First, you can use EditorTrackerListener and `com.intellij.codeInsight.daemon.impl.EditorTracker` to listen for events.
But, probably, creating a window is too much of a distraction.
For example, you can register `com.intellij.ui.EditorNotifications.Provider` to create a notification panel on top of Editor when it is opened.
>And should this be implemented in an application component or project component?
This choice depends on what you are trying to achieve. Most likely, you're interested in a project component.
Thanks a lot, it works for the most part. Right now, I'm creating a dialog box that asks the user if they want to initiate the log recording. If the file that's going to be logged is already in existence, it works fine, but every time I create a new file and a new tab is created, it hits an error when I press any buttons that's a part of the dialog box(even the X button), "AWT events are not allowed inside write action: java.awt.event.InvocationEvent". I think even switching to notifications won't help. Any suggestions?
You need to wrap your code into `ApplicationManager.getApplication().invokeLater(Runnable)`.
See https://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/general_threading_rules.html
IIRC, switching to notifications should help as well (and will prevent focus stealing by dialog).
Ex: // inside listener