如何通过工具栏按钮 XUL 打开 Firefox AddOn 的首选项窗格?

发布于 2024-12-27 21:06:23 字数 496 浏览 1 评论 0原文

我的 FireFox AddOn 的首选项窗格是 XUL 文档(XML 用户界面语言)。该文件名为 options.xul。

在 browser.xul 中,我创建了一个带有选项按钮的工具栏。单击“选项”按钮时,应该会显示由 options.xul 定义的首选项窗格。但我不知道如何从 oncommand 调用首选项窗格。

调用 Javascript 函数非常简单。但是如何调用插件的首选项窗格呢?下面是一个调用 JavaScript 函数的命令,但是如何调用 Preferene 窗格呢?

如果有人可以请在 browser.xul 中发布对以下内容的更改:

    <menupopup>
    <menuitem label="Options" tooltiptext="Options" oncommand="example.LoadURL('http://www.google.com/')" />
    </menupopup>

The Preference Pane for my FireFox AddOn is an XUL document (XML User Interface Language). The file is called options.xul.

In browser.xul, I have created a toolbar with a button for Options. When the Options button is clicked, it should bring up the Preference Pane defined by the options.xul. But I do not know how to call the Preference Pane from oncommand.

Calling a Javascript function is straight forward. But how does one call the AddOn's Preference Pane? Below is an oncommand calling a javascript function but how does one call the Preferene Pane?

If someone could please post the alteration to the following in browser.xul:

    <menupopup>
    <menuitem label="Options" tooltiptext="Options" oncommand="example.LoadURL('http://www.google.com/')" />
    </menupopup>

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

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

发布评论

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

评论(2

离不开的别离 2025-01-03 21:06:23

您无法打开这样的窗格。首选项窗格是首选项窗口的一部分。您的 option.xul 应该至少看起来像这样

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<prefwindow xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    <prefpane id="myOptions" label="My Options">
        <preferences>
            <preference id="pref-option1" name="myapp.myoption1" type="bool"/>
            <preference id="pref-option2" name="myapp.myoption2" type="int"/>
        </preferences>
        <checkbox label="Option Checkbox" preference="pref-option1"/>
        <textbox label="Duration:" preference="pref-option2"/>
    </prefpane>
</prefwindow>

在 browser.xul 中,您的 oncommand 可以使用以下命令打开首选项窗口:

oncommand = "window.openDialog('chrome://whatever_location/option.xul',' My Option Dialog','chrome,toolbar');"

(或者您想要执行 openDialog 的 javascript 中的任何方法)

其他信息 上找到

有关 prefwindows 和窗格的信息可以在https://developer.mozilla.org/en/XUL/prefwindow

https://developer.mozilla.org/en/XUL/prefpane

You can not open a pane as such. A preference pane is a part of a preference window. Your option.xul should look at least something like this

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<prefwindow xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    <prefpane id="myOptions" label="My Options">
        <preferences>
            <preference id="pref-option1" name="myapp.myoption1" type="bool"/>
            <preference id="pref-option2" name="myapp.myoption2" type="int"/>
        </preferences>
        <checkbox label="Option Checkbox" preference="pref-option1"/>
        <textbox label="Duration:" preference="pref-option2"/>
    </prefpane>
</prefwindow>

In the browser.xul your oncommand could open the preference window using :

oncommand = "window.openDialog('chrome://whatever_location/option.xul',' My Option Dialog','chrome,toolbar');"

(or whatever method in your javascript that you would like to do the openDialog)

Additional information about prefwindows and panes can be found on

https://developer.mozilla.org/en/XUL/prefwindow or

https://developer.mozilla.org/en/XUL/prefpane

心房的律动 2025-01-03 21:06:23

我认为“首选项窗格”实际上是指附加组件的选项对话框窗口,而不仅仅是

中的单个 。我还假设您有一个 options.xul,它功能齐全,可以使用附加选项卡中的普通选项按钮用作选项对话框。

我发现打开选项对话框需要与上面显示的 tazyDevel 有所不同的选项,这样它看起来就像是从附加组件选项卡打开的一样。我不确定这是否是 2012 年到 2014 年(当我编写下面的代码时)的差异,或者是否只是实现差异。如果我没记错的话,当我写这篇文章时,我检查了 Firefox 如何启动选项对话框窗口并复制那里正在使用的选项。

我使用以下代码从附加组件主对话框窗口中的按钮打开我的附加组件之一的选项对话框(除了通过附加组件选项卡可用之外):

XUL(打开附加组件的按钮)选项对话框):

<button label="Options" id="optionsButtonId"
        onclick="myExtension.optionsButton();"
        tooltiptext="Open the options window."
        hidden="false" />

JavaScript:

/**
 * The Options button.
 */
optionsButton : function() {
     window.openDialog('chrome://myExtension/content/options.xul', '',
                       'chrome,titlebar,toolbar,centerscreen,modal');
},

根据代码的组织方式,您可能需要手动应用一些首选项和/或使用首选项观察器将更改传播到需要了解它们的内容。

myExtension 是您用来调用扩展程序的任何内容的占位符。假定包含函数的单个对象变量,就像您用来标识 chrome.manifest 文件中的内容的 myExtension 一样。

I assume that by "Preference Pane" you actually mean the Option Dialog window for your add-on, not just a single <prefpane> within the <prefwindow>. I also assume that you have an options.xul which is fully functional for use as a options dialog using the normal option button from the add-on tab.

I found that somewhat different options than tazyDevel shows above were needed to have the options dialog open so that it appears as if it was opened from the add-ons tab. I am not sure if this is a difference from 2012 to 2014 (when I wrote the code below), or if it is just an implementation difference. If I recall correctly, when I wrote this, I checked to see how Firefox was launching the options dialog windows and copied the options that were being used there.

I use the following code to open the options dialog for one of my add-ons from a button in the add-on's main dialog window (in addition to having it available through the add-ons tab):

XUL (the button that opens the options dialog):

<button label="Options" id="optionsButtonId"
        onclick="myExtension.optionsButton();"
        tooltiptext="Open the options window."
        hidden="false" />

JavaScript:

/**
 * The Options button.
 */
optionsButton : function() {
     window.openDialog('chrome://myExtension/content/options.xul', '',
                       'chrome,titlebar,toolbar,centerscreen,modal');
},

Depending on how your code is organized, you may need to manually apply some preferences and/or have preference observer(s) which propagate the changes to what needs to know about them.

myExtension is a placeholder for whatever you are using to call your extension. A single object variable containing functions is assumed, as is myExtension being what you use to identify your content in your chrome.manifest file.

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