gpt4 book ai didi

java - 在 Eclipse RCP 中使用导航历史记录

转载 作者:搜寻专家 更新时间:2023-10-31 20:14:42 24 4
gpt4 key购买 nike

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

它提到可以在导航历史记录中标记每个编辑器,而不必指定位置。这正是我想要的。

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.

我在我的应用程序中添加了以下代码行,以便在每次打开新编辑器时添加一个导航条目。

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = page.openEditor( input, MyEditor.ID );
page.getNavigationHistory().markLocation( editor );

我的问题是代码不起作用。命令 org.eclipse.ui.navigate.backwardHistoryorg.eclipse.ui.navigate.forwardHistory 的工具栏图标保持灰色。

最佳答案

我找到了解决方案。为了在您的 Eclipse RCP 应用程序中使用 Navigation History,您必须将以下代码行添加到您的 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 );
}

关于java - 在 Eclipse RCP 中使用导航历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10417009/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com