在Eclipse RCP中使用导航历史记录 [英] Use Navigation History in Eclipse RCP

查看:256
本文介绍了在Eclipse RCP中使用导航历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢使用Eclipse在我的RCP应用程序中提供的导航历史。不幸的是,这个功能没有很好的记录其实我只是找到这个维基条目: http://wiki.eclipse.org/FAQ_How_do_I_hook_my_editor_to_the_Back_and_Forward_buttons%3F

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.


无论特定编辑器是否支持导航历史,markLocation都可以正常工作。如果编辑器不实现INavigationLocationProvider,则会添加历史记录条目,允许用户跳回该编辑器,但不返回任何特定位置。

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

我的问题是代码不起作用。命令 org.eclipse.ui.navigate.backwardHistory org.eclipse.ui.navigate.forwardHistory

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.

推荐答案

我找到了解决方案。为了在Eclipse RCP应用程序中使用导航历史记录,您必须在 ApplicationActionBarAdvisor 中添加以下代码行。

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 );
}

这篇关于在Eclipse RCP中使用导航历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆