【问题标题】:Eclipse RCP: save a perspective programmaticallyEclipse RCP:以编程方式保存透视图
【发布时间】:2014-12-10 06:14:56
【问题描述】:

我需要稍微定制一下我的 RCP 应用程序和透视图的使用。特别是,我想提供一个自定义菜单项,让用户保存当前透视图,但 WITHOUT 显示内置对话框:

所以我不想使用默认的eclipse方式注册“保存透视”Action并放入菜单。即,我不想这样做:

@Override
protected void makeActions(IWorkbenchWindow window)
{
    // ...
    register(ActionFactory.SAVE_PERSPECTIVE.create(window));
    // ...
}

@Override
protected void fillMenuBar(IMenuManager menuBar)
{
    // ...
    windowMenu.add(getAction(ActionFactory.SAVE_PERSPECTIVE.getId()));
    // ...
}

那么,如果我写了一个自定义的 Action,我需要在那里做些什么来保存当前的视角?

【问题讨论】:

    标签: java eclipse eclipse-rcp perspective


    【解决方案1】:

    这很简单。在自定义动作中,我执行以下操作来保存透视图:

    IWorkbenchPage page = window.getActivePage();
    IPerspectiveRegistry perspectiveRegistry = window.getWorkbench()
            .getPerspectiveRegistry();
    IPerspectiveDescriptor personalPerspectiveDescriptor = perspectiveRegistry
            .findPerspectiveWithId(perspectiveId);
    
    if (page != null && personalPerspectiveDescriptor != null) {
        // ... other stuff like different confirm dialogs
        page.savePerspectiveAs(personalPerspectiveDescriptor);
    }
    

    可以在此处找到如何使用透视图让用户自定义布局而不显示太多内置透视图功能的一个很好的示例:

    http://www.subshell.com/en/subshell/blog/article-Eclipse-RCP-Change-Your-Perspective100.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-19
      • 1970-01-01
      • 2011-01-13
      • 2013-03-02
      • 2012-08-22
      • 2012-04-13
      • 1970-01-01
      相关资源
      最近更新 更多