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

0
7 comments

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.

0
Avatar
Permanently deleted user

Thank you Dmitry.

 

To get the history list of opened files I can do 

EditorHistoryManager.getInstance(project).getFiles()

But to save this list I don't know how. Every time I start the IntelliJ the list is empty. Do I need to do something to persist?

Thanks once again
0

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)?

0
Avatar
Permanently deleted user

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

0

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.

0
Avatar
Permanently deleted user

I don't see no loadState. I also did not find EditorHistoryManager.loadState (my IDE version is 15)

0

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.

0

Please sign in to leave a comment.