listener for ide actions

I am creating first plugin for idea.
Can I create listener for ide actions like "on open file", "on close file", "commit in git" and etc

My be link to documentation or examples?

thank you

0
1 comment
Official comment

Hi,

As for listening for "on open file" and "on close file" event, it can be archived with this code:

MessageBus messageBus = project.getMessageBus();
// or
// MessageBus messageBus = ApplicationManager.getApplication().getMessageBus();
MessageBusConnection connection = messageBus.connect();
connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
@Override
public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {

}

@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {

}
});
// when it's no longer needed, call 'connection.disconnect()'

To listen for "commit in git", you may use `com.intellij.openapi.vcs.checkin.CheckinHandlerFactory` extension point:

Register it in plugin.xml

<checkinHandlerFactory implementation="package.YourCheckinHandlerFactory"/>

Then you need to obtain information about checked in files in com.intellij.openapi.vcs.checkin.CheckinHandler#checkinSuccessful (see javadoc):

public void checkinSuccessful() {
panel.getFiles()
}

See another example: com.intellij.tools.ExternalToolsCheckinHandlerFactory.

As for documentation or examples, please refer to IntelliJ IDEA source code https://github.com/JetBrains/intellij-community and http://www.jetbrains.org/intellij/sdk/docs

Please sign in to leave a comment.