简体   繁体   English

如何使用firefox插件SDK创建选项弹出对话框?

[英]How do I create an options popup dialog using firefox addon sdk?

So I decided recently to create a firefox extension I have been thinking about, but do not have any prior experience with it. 因此,我最近决定创建一个我一直在考虑的firefox扩展 ,但是没有任何经验。 I read on the official tutorials and figured that the addons sdk seemed to fit me well, but I seem to have hit a hitch using it. 我阅读了官方教程后发现, SDK插件似乎很适合我,但使用它似乎很顺利。

What I want to do is create an options popup dialog , similar to the one you see if you press alt-tools-options . 我要做的是创建一个选项弹出对话框 ,类似于您按alt-tools-options时看到的对话框 That is, a border with title and close button on the upper part, and a bigger area inside the window where I can define an "intuitive" (default elements with the skin the user is used to) GUI. 也就是说,在顶部带有标题和关闭按钮的边框,在窗口内较大的区域,我可以在其中定义“直观”(用户习惯使用皮肤的默认元素)GUI。 The tabs at the top (general, privacy security etc.) is nothing I really need, though would not hurt either. 顶部的选项卡(常规,隐私安全性等)不是我真正需要的,尽管也不会造成伤害。

So the issue is that from my searches, when you use addon sdk, you are not supposed to use XUL which has those elements, but instead you seem to be supposed to create something custom using HTML in a panel . 所以问题是从我的搜索来看,当您使用addon sdk时,不应该使用具有这些元素的XUL,而应该在面板中使用HTML创建自定义内容。 I don't think its possible to create the top-bar akin to the real options-menu when using that, although if I am wrong I would not mind being corrected. 我认为使用这种方法无法创建类似于真实选项菜单的顶栏,尽管如果我错了,我不介意予以纠正。

I had a similar issue before, where I wanted a drop-down menu from the toolbar similar to the default ones, which I solved thanks to: How to add a dropdown menu to a firefox addon sdk powered addon toolbar button? 之前我遇到过类似的问题,我希望从工具栏中获得一个与默认菜单类似的下拉菜单,由于以下原因,我得以解决: 如何将下拉菜单添加到由Firefox附加组件,sdk驱动的附加工具栏按钮? . Might be worth noting that that the button opening the options dialog is one of the menuitems created as described there. 可能值得注意的是,打开选项对话框的按钮是其中所描述的菜单项之一。 I was considering that it could probably be possible (aka I am not sure) to use something akin to this, but sadly I do not know how I would create a "separate" (drag-able) popup that I could use this on. 我当时正在考虑使用类似的东西可能(又是我不确定),但是可悲的是,我不知道如何创建一个“单独的”(可拖动的)弹出窗口来使用。

If possible, I would prefer there to exist a solution, but if someone knows that it is indeed impossible, please do post that so and I can give up without regrets and just make some sort of custom HTML panel instead :) 如果可能的话,我希望有一个解决方案,但是如果有人知道这确实是不可能的,请发布这样的内容,这样我就可以毫不遗憾地放弃,而只是制作某种自定义HTML面板:)

tldr: Is there a way to create a popup dialog similar (in style) to the options window you can open using alt-tools-options in firefox when developing using addon sdk? tldr:有没有一种方法可以创建一个弹出对话框,其样式类似于在使用addon sdk开发时可以使用Firefox中的alt-tools-options打开的选项窗口?

Essentially, you aren't supposed to, at least not with the SDK. 本质上,您不应该使用,至少不要使用SDK。

But then again, it is still possible, but you need to do a lot of stuff yourself: 但是,仍然有可能,但是您需要自己做很多事情:

  1. You need to register a chrome: package for your add-on, as the resource: URIs the SDK uses internally do not work correctly for XUL windows. 您需要为加载项注册chrome:软件包,因为SDK内部使用的resource: URI在XUL窗口中无法正常工作。 Create a Chrome Registration ( chrome.manifest file). 创建一个Chrome注册文件( chrome.manifest文件)。 The SDK supports this since Firefox 24 IIRC. 自Firefox 24 IIRC起,SDK就支持此功能。
  2. Create the XUL file. 创建XUL文件。 For preferences/options windows, there is already the <prefwindow> binding. 对于首选项/选项窗口,已经有<prefwindow>绑定。 Look at other extensions and or the Firefox Options dialog (which is a huge thing with multiple overlays, so better look at other extensions). 再看其他的扩展和或Firefox的选项对话框 (这是与多个叠加,所以最好看看其他扩展一个巨大的东西)。 Place the XUL file in chrome/content/<somefile>.xul . 将XUL文件放在chrome/content/<somefile>.xul This will then correspond to chrome://<registered_package_from_1>/content/<somefile>.xul . 然后,这将对应于chrome://<registered_package_from_1>/content/<somefile>.xul
  3. Implement something that will actually display the window. 实现一些将实际显示窗口的内容。 Normally non-SDK add-ons would just put em:optionsURL into their install.rdf , to have the Add-On Manager automatically create a Preferences button that will open the specified URL, but in the SDK this is generated from package.json and there is no way to put optionsURL in package.json if I'm not mistaken. 通常,非SDK附加组件只会将em:optionsURL放入其install.rdf ,以使附加组件管理器自动创建将打开指定URL的“首选项”按钮,但是在SDK中,它是由package.json和如果我没有记错的话,没有办法将optionsURL放在package.json But you could do other things, like using a simple-prefs type: control button to have a button in your about:addons page, or add it to some browser menu (which would require yet another heap of XUL-modifying, require("chrome") code.). 但是您可以做其他事情,例如使用simple-prefs type: control按钮在about:addons页面中添加按钮,或将其添加到某些浏览器菜单中(这将需要对XUL进行另一堆修改, require("chrome")代码。)。 To actually open the dialog, you could use window/utils.openDialog . 要实际打开对话框,可以使用window/utils.openDialog
  4. Don't forget to close any open windows again when your add-on gets unloaded. 卸载加载项时,不要忘记再次关闭任何打开的窗口。

As you can see, not a simple task... If you're just after preferences in general, consider using simple-prefs . 如您所见,这不是一个简单的任务...如果您通常只喜欢首选项,请考虑使用simple-prefs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM