fileOpen comes *after* selectionChanged?

Howdy folks, I'm getting some confusing behavior in the order of operations between opening a file and selectionChanged events. My interpretation looking at the forum posts is that selectionChanged is for when the user selects a different editor tab. That is the behavior I see. I recently decided to split opening file and when it is selected, but what I'm seeing is that the file open event comes after selectionChanged (but only for the first file that was left open last time IDE was running). You can see in my log here with the bold elements that it seems to select grammar B.g4 before it has been opened. The behavior seems strange to me.

2014-04-21 21:25:46,789 [  20288]   INFO -  ANTLR ANTLRv4PluginController - selectionChanged none -> B.g4 testplugin

2014-04-21 21:25:46,790 [  20289]   INFO -  ANTLR ANTLRv4PluginController - loadGrammars open B.g4 testplugin

2014-04-21 21:25:46,889 [  20388]   INFO -  ANTLR ANTLRv4PluginController - loadGrammars BLexer, BParser

2014-04-21 21:25:46,889 [  20388]   INFO -             ANTLR PreviewPanel - switchToGrammar B.g4 testplugin

2014-04-21 21:25:46,889 [  20388]   INFO -             ANTLR PreviewPanel - createEditor: create new editor for B.g4 testplugin

2014-04-21 21:26:18,231 [  51730]   INFO -  ANTLR ANTLRv4PluginController - fileOpenedEvent B.g4 testplugin

2014-04-21 21:26:30,415 [  63914]   INFO -  ANTLR ANTLRv4PluginController - fileOpenedEvent Catalog.g4 testplugin

2014-04-21 21:26:35,823 [  69322]   INFO -  ANTLR ANTLRv4PluginController - fileOpenedEvent F.g4 testplugin

2014-04-21 21:26:39,567 [  73066]   INFO -  ANTLR ANTLRv4PluginController - fileOpenedEvent T.g4 testplugin

2014-04-21 21:26:40,943 [  74442]   INFO -  ANTLR ANTLRv4PluginController - fileOpenedEvent X.g testplugin

2014-04-21 21:26:42,562 [  76061]   INFO - tor.impl.FileEditorManagerImpl - Project opening took 71828 ms

2014-04-21 21:26:42,893 [  76392]   INFO - ANTLR ANTLRv4ExternalAnnotator - collectionInformation file://Catalog.g4

...

My listener just delegates all behavior to some methods in my plug-in but here is how I set it up in case it is wrong:

// Listen for editor window changes

MessageBusConnection msgBus = project.getMessageBus().connect(project);

msgBus.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER,

     new FileEditorManagerAdapter() {

             @Override

             public void selectionChanged(FileEditorManagerEvent event) {

                     currentEditorFileChangedEvent(event.getOldFile(), event.getNewFile());

             }   

             @Override

             public void fileOpened(FileEditorManager source, VirtualFile file) {

                     fileOpenedEvent(file);

             }   

             @Override

             public void fileClosed(FileEditorManager source, VirtualFile file) {

                     editorFileClosedEvent(file);

             }   

     }   

);                   


Can somebody explain the intended sequence if any for these listener methods? The javadoc shows "TODO[vova] write javadoc"  Hopefully I'm doing something stupid and it's easy to fix. This behavior occurs in 129.1359 jdk 6 and 135.690 jdk 7.

[Could this be related to why I don't always see fileClosed events when I quit the IDE?]

Thanks!
Ter

1 comment

Well, I'm not sure what the intended sequence is, but I spent the time to read through the code and I see the following sequence in FileEditorManagerImpl.openFileImpl4():

getProject().getMessageBus().syncPublisher(FileEditorManagerListener.Before.FILE_EDITOR_MANAGER).beforeFileOpened(this, file);
window.getOwner().setCurrentWindow(window, focusEditor);

[...].fileOpened(FileEditorManagerImpl.this, file);


so it looks like before file opened, selection changed, file opened. I guess this makes sense. the file opened his notifying us after the fact that the selection changed event had to open the file and display it. I think the before file opened event is the one I want.

from looking at the code, before file opened does *not* it triggered if someone simply switches tabs, which is what I want. When the selection changed event occurs, the code makes it look like everything is been set up.

Hopefully this is correct and that it helps someone :) I will add this to my set of notes that I host on plug-in development.

Ter

0

Please sign in to leave a comment.