I read a solution would be to implement SettingsSavingComponent, but in that save() method i don't know if i cand obtain the Project. I saw a good solution for me is to implement AnActionListener (and do my logic in beforeActionPerformed method), but i don't know how to'catch' the save action using it.
I want every time documentes are saved to test if myEditor.isModified and depending of that make some changes to some files. I manged to catch the SaveAllAction implementig AnActionListener.(and get the Project from dataContext) Project project = PlatformDataKeys.PROJECT.getData(dataContext); FileEditor[] openedEditors = FileEditorManager.getInstance(project).getAllEditors();
But 'save' can also be made at frame deactivation, and i'm not catching this. How can this be done? (if i use SettingsSavingComponent, i'm notified every time a save is made, but i dont know the project (if i have multiple projects opened)) (is there a way to get the list of opened Projects?)
You can implement FileDocumentManagerListener and listen to save events using project/application.getMessageBus().connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, listener)
Thank you Peter, I managed to do it implementing ProjectComponent and SettingsSavingComponent, and also implementing the constructor: public MyComponent(Project project) { this.project = project; } And then i was able to get my needed project in the save() method
I read a solution would be to implement SettingsSavingComponent, but in that save() method i don't know if i cand obtain the Project.
I saw a good solution for me is to implement AnActionListener (and do my logic in beforeActionPerformed method), but i don't know how to'catch' the save action using it.
What exactly do you want to intercept/trigger on this action?
I want every time documentes are saved to test if myEditor.isModified and depending of that make some changes to some files.
I manged to catch the SaveAllAction implementig AnActionListener.(and get the Project from dataContext)
Project project = PlatformDataKeys.PROJECT.getData(dataContext);
FileEditor[] openedEditors = FileEditorManager.getInstance(project).getAllEditors();
But 'save' can also be made at frame deactivation, and i'm not catching this. How can this be done?
(if i use SettingsSavingComponent, i'm notified every time a save is made, but i dont know the project (if i have multiple projects opened))
(is there a way to get the list of opened Projects?)
You can implement FileDocumentManagerListener and listen to save events using
project/application.getMessageBus().connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, listener)
Thank you Peter, I managed to do it implementing ProjectComponent and SettingsSavingComponent, and also implementing the constructor:
public MyComponent(Project project) {
this.project = project;
}
And then i was able to get my needed project in the save() method