I like to use the navigation history provided by Eclipse in my RCP Application. Unfortunately this feature isn't well documented. In fact I only found this Wiki entry: http://wiki.eclipse.org/FAQ_How_do_I_hook_my_editor_to_the_Back_and_Forward_buttons%3F
It mentions that every editor can be marked in the navigation history, without having to specify a location. This is exactly what I want.
Regardless of whether the specific editor has any support for navigation history, markLocation will work. If the editor doesn’t implement INavigationLocationProvider, a history entry will be added, allowing the user to jump back to that editor but without returning to any particular location.
I added the following lines of code to my application in order to add a navigation entry each time a new Editor is opened.
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = page.openEditor( input, MyEditor.ID );
page.getNavigationHistory().markLocation( editor );
My problem is that the code doesn't work. The toolbar icons for the commands org.eclipse.ui.navigate.backwardHistory
and org.eclipse.ui.navigate.forwardHistory
stay grayed out.
I have found the solution. In order to use the Navigation History in your Eclipse RCP application you have to add the following lines of code to your ApplicationActionBarAdvisor
.
/**
* Fills the cool bar with the main toolbars for the window.
* <p>
* The default implementation does nothing. Subclasses may override.
* </p>
*
* @param coolBar
* the cool bar manager
*/
protected void fillCoolBar( ICoolBarManager coolBar ) {
IToolBarManager navigation = new ToolBarManager( SWT.FLAT );
IAction backward = getAction( IWorkbenchCommandConstants.NAVIGATE_BACKWARD_HISTORY );
IAction forward = getAction( IWorkbenchCommandConstants.NAVIGATE_FORWARD_HISTORY );
navigation.add( backward );
navigation.add( forward );
coolBar.add( navigation );
}
/**
* Instantiates the actions used in the fill methods. Use
* {@link #register(IAction)} to register the action with the key binding
* service and add it to the list of actions to be disposed when the window
* is closed.
*
* @param window
* the window containing the action bars
*/
protected void makeActions( IWorkbenchWindow window ) {
IAction backward = ActionFactory.BACKWARD_HISTORY.create( window );
backward.setId( IWorkbenchCommandConstants.NAVIGATE_BACKWARD_HISTORY );
IAction forward = ActionFactory.FORWARD_HISTORY.create( window );
forward.setId( IWorkbenchCommandConstants.NAVIGATE_FORWARD_HISTORY );
register( backward );
register( forward );
}
You have to implement the INavigationLocationProvider interface in your editor.
You can see how the Eclipse group implemented the interface in their AbstractTextEditor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With