如何在rcp应用程序的工具栏中显示撤消和重做操作

时间:2019-03-25 16:34:21

标签: java eclipse swt rcp

我正在使用一个带有工具栏的rcp应用程序来快速访问某些操作,包括撤消和重做。我的问题是,这两个特定操作没有显示在工具栏中。我已将原因定位到应用程序启动时生成的workbench.xmi文件。具有属性persistedState的标签key="persp.hiddenItems"persp.hideToolbarSC:org.eclipse.ui.edit.undo,persp.hideToolbarSC:org.eclipse.ui.edit.redo属性中包含value="..."。如果我从workbench.xmi中删除了这些条目,则撤消和重做操作将按原样显示在工具栏中。

我的问题是:我该怎么做才能使org.eclipse.ui.edit.undoorg.eclipse.ui.edit.redo不再以该属性开头?

我最初使用eclipse neon时没有这个问题,但是当更新到Eclipse 2018-12时,这开始发生。

编辑:

我最终通过将撤消和重做操作的ID更改为其他内容来使其正常工作。我必须在动作的构造函数中使用setId(...)setActionDefinedId(...)设置ID,然后必须在{{1}中plugin.xml<extension point="org.eclipse.ui.commands">下定义命令。 }标签。

与实际解决方案相比,此解决方案更像是一种解决方法,但对我有用。

2 个答案:

答案 0 :(得分:2)

这是由hiddenToolBarItem扩展点的org.eclipse.ui.perspectiveExtensions元素设置的。

org.eclipse.ui.ide插件使用它来禁用以下工具栏项:

  <extension
         point="org.eclipse.ui.perspectiveExtensions">
      <perspectiveExtension targetID="*">
         <!--
              disable "print" button which is defined by org.eclipse.ui.actions.ActionFactory.PRINT
              and contributed by org.eclipse.ui.internal.ide.WorkbenchActionBuilder
         -->
         <hiddenToolBarItem id="print" />
         <!--
              disable "undo" button which is defined by org.eclipse.ui.actions.ActionFactory.UNDO
              and contributed by org.eclipse.ui.internal.ide.WorkbenchActionBuilder
         -->
         <hiddenToolBarItem id="org.eclipse.ui.edit.undo" />
         <!--
              disable "redo" button which is defined by org.eclipse.ui.actions.ActionFactory.REDO
              and contributed by org.eclipse.ui.internal.ide.WorkbenchActionBuilder
         -->
         <hiddenToolBarItem id="org.eclipse.ui.edit.redo" />
      </perspectiveExtension>
   </extension>

除了放弃插件外,我看不到其他清除方法。

答案 1 :(得分:0)

我遇到了同样的问题。升级到2019年月食后,撤消/重做消失了。

覆盖org.eclipse.ui.ide全局透视图设置中的硬编码的一种方法是直接修改透视图状态。例如。在ApplicationWorkbenchWindowAdvisor.postWindowOpen()

        WorkbenchPage page = (WorkbenchPage) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            String str = page.getCurrentPerspective().getPersistedState().get(ModeledPageLayout.HIDDEN_ITEMS_KEY);
            str=str.replace("persp.hideToolbarSC:org.eclipse.ui.edit.undo,", "");
            str=str.replace("persp.hideToolbarSC:org.eclipse.ui.edit.redo,", "");
            page.getCurrentPerspective().getPersistedState().put(ModeledPageLayout.HIDDEN_ITEMS_KEY,str);