XUL:如何在 statusbarpanel 内创建嵌套的 menupopup (使用 statusbarpanel-menu-iconic)

发布于 2024-09-14 07:51:03 字数 2344 浏览 7 评论 0原文

在 XUL 中,您可以使用 标签创建状态栏面板图标,类似于 Firebug 和 Greasemonkey 使用的图标。如果你设置了正确的类,你可以在里面扔一个 ,然后当用户点击图标时有一个弹出菜单,就像这样......

<statusbarpanel class="statusbarpanel-menu-iconic"
        src="chrome://YourExtension/content/icon.png">
    <menupopup>
        <menuitem label="whatever" oncommand="doSomething();">
        <menuitem label="whatever else" oncommand="doSomethingElse();">
    </menupopup>
</statusbarpanel>

现在,与其他弹出-up 菜单,您可以使用 menu 标签嵌套一系列菜单:

<statusbarpanel class="statusbarpanel-menu-iconic"
        src="chrome://YourExtension/content/icon.png">
    <menu value="Old">
        <menupopup>
            <menuitem label="whatever" oncommand="doSomething();">
            <menuitem label="whatever else" oncommand="doSomethingElse();">
        </menupopup>
    </menu>
    <menu value="New>
        <menupopup>
            <menuitem label="yet another" oncommand="doYetAnotherSomething();">
        </menupopup>
    </menu>
</statusbarpanel>

但上面的代码实际上不起作用,因为 不允许

child(好吧,它会允许它,但不会产生所需的效果)。

所以,我想知道的是......有什么方法可以制作一个带有多层菜单项的状态栏面板图标触发菜单?

* 编辑 * 由于我无法将其发布在答案的评论中(并获得语法着色等),这就是最终对我有用的内容(感谢 Sathish!):

<statusbarpanel class="statusbarpanel-menu-iconic"
        src="chrome://YourExtension/content/icon.png" popup="stausBarPanelMenu">
</statusbarpanel>
<popup id="statusBarPanelMenu" position="start_before">
    <menu value="Old">
        <menupopup>
            <menuitem label="whatever" oncommand="doSomething();">
            <menuitem label="whatever else" oncommand="doSomethingElse();">
        </menupopup>
    </menu>
    <menu value="New>
        <menupopup>
            <menuitem label="yet another" oncommand="doYetAnotherSomething();">
        </menupopup>
    </menu>
</popop>

哦,作为任何可能读到此内容的 XUL 开发人员的旁注:您确实应该消除“状态栏面板内的菜单弹出”样式的弹出窗口。回答这个问题的样式同样易于学习/使用,功能更加强大,并且它依赖于可与其他 XUL 元素一起使用的相同弹出机制。这整个“状态栏面板内的菜单弹出”这只是一个令人困惑的、不需要的异常现象。

In XUL you can use create a status bar panel icon, similar to the ones used by Firebug and Greasemonkey, with the <statusbarpanel> tag. If you set the right class, you can throw a <menupop> inside, and then have a pop-up menu when the user clicks on the icon, like so ...

<statusbarpanel class="statusbarpanel-menu-iconic"
        src="chrome://YourExtension/content/icon.png">
    <menupopup>
        <menuitem label="whatever" oncommand="doSomething();">
        <menuitem label="whatever else" oncommand="doSomethingElse();">
    </menupopup>
</statusbarpanel>

Now, with other pop-up menus, you can nest a series of menus using the menu tag:

<statusbarpanel class="statusbarpanel-menu-iconic"
        src="chrome://YourExtension/content/icon.png">
    <menu value="Old">
        <menupopup>
            <menuitem label="whatever" oncommand="doSomething();">
            <menuitem label="whatever else" oncommand="doSomethingElse();">
        </menupopup>
    </menu>
    <menu value="New>
        <menupopup>
            <menuitem label="yet another" oncommand="doYetAnotherSomething();">
        </menupopup>
    </menu>
</statusbarpanel>

but the above code doesn't actually work, because <statusbarpanel> won't allow a <menu> child (well, it will allow it, but not create the desired effect).

So, what I was wondering was ... is there any way I can make a status bar panel icon-triggered menu with multiple layers of menu items?

* EDIT *
Since I can't post this in the comment to the answer (and get syntax coloring and such), here's what finally worked for me (thanks Sathish!):

<statusbarpanel class="statusbarpanel-menu-iconic"
        src="chrome://YourExtension/content/icon.png" popup="stausBarPanelMenu">
</statusbarpanel>
<popup id="statusBarPanelMenu" position="start_before">
    <menu value="Old">
        <menupopup>
            <menuitem label="whatever" oncommand="doSomething();">
            <menuitem label="whatever else" oncommand="doSomethingElse();">
        </menupopup>
    </menu>
    <menu value="New>
        <menupopup>
            <menuitem label="yet another" oncommand="doYetAnotherSomething();">
        </menupopup>
    </menu>
</popop>

Oh, and as a side note to any XUL devs who might read this: you should really eliminate the "menupopup inside a statusbarpanel" style of pop-up. The style that answered this question is just as easy to learn/use, significantly more powerful, and it relies on the same popup mechanisms that can be used with the other XUL elements. This whole "menupopup inside a statusbarpanel" this is just a confusing, un-needed, anomaly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始于初秋 2024-09-21 07:51:03

试试这个:

  1. 创建一个弹出元素,如下所示:
    <弹出...>
    <菜单...>

    <菜单项...>


  2. popup元素的id分配给oncontextmenu属性或动态显示使用 statusbarpanel 元素的 onclick 事件。

Try this:

  1. create a popup element like this:
    <popup ... >
    <menu ... >
    <menupopup ... >
    <menuitem ... >
    </menupopup ... >
    </menu>
    </popup>

  2. assign the id of popup element to the oncontextmenu attribute or show it dynamically using onclick event of the statusbarpanel element.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文