Plug into the back and forward navigation mechanism

Answered

I am building a plugin with my own FileEditor for a file type wich is not a TextFileEditor. Still I would like to plug into the back and forward navigation mechanism so I can push places onto the history stack and get callbacks when the user uses the back button.

Is this even possible? And if yes, how?

4 comments
Comment actions Permalink

Hi Sven,

I don't see any way of integrating with the IdeDocumentHistory for non-text editors. Its logic for retrieving caret position supports only TextEditors.

0
Comment actions Permalink

Thanks. Could you nonetheless give me an idea of how this works? Maybe I could create a "virtual text editor" since I have something like a caret position.

Otherwise I would just create my own history stack just for my plugin.

0
Comment actions Permalink
  1. IdeDocumentHistoryImpl listens to CommandListener actions which are triggered by e.g. editors or other actions like go to line, etc. For example, when you click the mouse button in the default text editor, the EditorImpl class executes CommandProcessor.executeCommand() method with the proper arguments and the event is handled in IdeDocumentHistoryImpl. See EditorImpl.MyMouseAdapter.mousePressed() for the details.
  2. IdeDocumentHistoryImpl.onCommandStarted() is called and the current place information is saved.
  3. If the command caller invoked IdeDocumentHistoryImpl.includeCurrentCommandAsNavigation() method, then position is saved in the history and will be available when invoking back/forward actions. Please note, that it is done e.g. for mouse clicks, navigating via go to line action, etc., and is not done for e.g. key press commands, so positions visited by using the keyboard are not stored and are not available via back/forward actions.

I suggest setting breakpoints in public methods of the IdeDocumentHistoryImpl class and inspecting what is done in specific contexts.

1
Comment actions Permalink

Thanks for the explanation. I will see what I can do with it.

0

Please sign in to leave a comment.