1

We have an application in which some views only work when attached to certain perspectives. We want to remove those views from the Window -> Show View dialog so that users cannot add them to perspectives where they don't work.

Any ideas on how to do this either programmatically or declaratively?

I have tried using <visibleWhen />, but the views are still showing in the dialog:

  <view class="com.mycompany.ViewClass" 
        id="com.mycompany.ViewId" 
        name="View Name" 
        restorable="true">

        <visibleWhen>
            <with variable="activeWorkbenchWindow.activePerspective">
                <equals value="com.mycompany.MyPerspective"/>
            </with>
        </visibleWhen>
  </view>

I don't think there is any problem with the <visibleWhen /> clause, so I'm wondering if it can be used with a View?

4

2 回答 2

0

它应该被视为菜单贡献,使用<visibleWhen/>仅在满足特定条件时显示该选项。

有关更多信息,请参阅wiki 文章“菜单贡献”

于 2010-04-28T18:54:44.623 回答
0

不幸的是,Eclipse 似乎已经通过ViewContentProvider.removeIntroView为 Show Views 对话框调用内容提供者上的 private 来为 Introduction 视图执行此操作。解决此限制的一种方法是通过添加到org.eclipse.ui.activities扩展点来定义活动(请参阅activityPatternBinding如何将活动映射到 UI 贡献)。这样做不仅会从 Show Views 对话框中删除视图,还会阻止它们在透视图中显示。然后可以以编程方式显示视图。ApplicationWorkbenchAdvisor.preStartup由于我们的应用程序的限制,我还必须启用该方法中的活动:

    Set<String> activityIds = new HashSet<String>();
    activityIds.add("com.my.activity.id");
    IWorkbenchActivitySupport activitySupport = PlatformUI.getWorkbench().getActivitySupport();
    activitySupport.setEnabledActivityIds(activityIds);

在这种情况下,必须在显示对话框之前禁用活动,因此也必须修改 Show Views 菜单贡献以执行此操作。

希望下一版本的 Eclipse 中会添加一个扩展点,以便开发人员可以选择以声明方式从对话框中删除视图。

于 2010-04-29T02:34:25.717 回答