所有视图的动态弹出菜单 [英] Dynamic popup menu for all views

查看:262
本文介绍了所有视图的动态弹出菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为所有视图提供动态弹出菜单。我可以创建一个动态弹出菜单的贡献,但我必须设置URI并注册它为某些视图。现在我正在尝试动态注册菜单,当用户选择另一个视图时:

I need to provide a dynamic popup menu for all views. I can create a dynamic popup menu contributibution, but I must set the URI and register it for certain view. Now I'm trying to register the menu dynamically, when the user selects another view:

public class GlobalSelectionListener implements ISelectionListener {
    HashSet<IWorkbenchPart> extended = new HashSet<IWorkbenchPart>();

    @Override
    public void selectionChanged(IWorkbenchPart part, ISelection selection) {
        if (!extended.contains(part)) {
            IWorkbenchPartSite wps = part.getSite();
            if (wps == null)
                return;
            //creates popup menu for this part
            MenuManager mgr = new MenuManager();
            mgr.add(new DynamicMenu()); //DynamicMenu extends ContributionItem
            wps.registerContextMenu("identifier." + mgr.hashCode(), mgr, wps.getSelectionProvider());
            extended.add(part);
            System.out.println(part + " menu extended");
        }
    }
}

但这不行。弹出菜单中没有任何一个菜单项。我不知道是否有可能这样做。是否有任何方法动态添加任意视图的弹出菜单?看来, registerContextMenu()方法会执行其他操作。

But this does not work. No one menu item appears in popup menu. I don't know, whether is it ever possible to do it this way. Is there any method to add popup menu for arbitrary view dynamically? It seems, that the registerContextMenu() method does something else.

推荐答案

问题没有解决,但有一个解决方法。可以在 plugin.xml 文件中注册所需视图和编辑器的弹出菜单。通常使用插件的数量有限。如果你写一个插件,你知道你需要什么插件。使用间谍插件(ALT + SHIFT + F1)查看活动菜单贡献标识符,并注册您对所需视图和编辑器的弹出式菜单的贡献。

The problem was not solved, nevertheless there is a workaround. It is possible to register the pop-up menu in plugin.xml file for all views and editors needed. Usualy the number of plugin usecases is limited. If you're writting a plugin, you know what you need the plugin for. Use the Spy plug-in (ALT+SHIFT+F1) to see the active menu contribution identifiers and register your contribution to the pop-up menu of all views and editors you need.

这篇关于所有视图的动态弹出菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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