Save history of each open files
Hi,
I'm developing a plugin for IntelliJ to among other things, save history of all opened files the user opens.
My main difficulties are:
How can I capture each of this event? And Where and how can I can save this history?
Thanks
Please sign in to leave a comment.
EditorHistoryManager already does this (it is used, in particular, for 'Recent Files' functionality) - it listens to events from FileEditorManager (see FileEditorManagerListener), and it implements PersistentStateComponent, so the state is remembered across restarts. You can either reuse it, or implement something similar in your plugin.
Thank you Dmitry.
To get the history list of opened files I can do
Could you please clarify what list is empty after IDE restart? The one returned by EditorHistoryManager.getFiles()? If the latter, have you opened any editors in corresponding IDE (probably the one you try to debug)?
If I open 3 editors, before closing the EditorHistoryManager.getFiles() returned these 3 files. Then I restarted the IDE (in debug) and tried again EditorHistoryManager.getFiles() and return empty!
I also tried to open the editors and then close them, the EditorHistoryManager.getFiles() returned these 3 files, but after restart returned empty
Can you check whether EditorHistoryManager.loadState (and a lambda inside it) is invoked on IDEA opening (by putting breakpoints there)? It can be that you're trying to get information from EditorHistoryManager before its state is restored.
I don't see no loadState. I also did not find EditorHistoryManager.loadState (my IDE version is 15)
The class indeed was changed somewhat in past years. Try setting breakpoint to EditorHistoryManager.addEntry instead, that method seems to be existing for a long time.
EditorHistoryManager initialization is performed using StartupManager.runWhenProjectIsInitialized. You might need to use similar call to delay initialization of your component accordingly.