2014-12-05 48 views
1

我正在为客户端开发Firefox附加组件。Firefox Addon SDK:带有多个复选框的提示

当用户卸载附加组件时,我需要向用户显示一个提示,其中包含三个复选框。这些复选框将作为用户恢复其以前的浏览器设置的选项。

我已经成功地创建了一个提示上uninstall/disable,使用nsIPromptService接口的confirmCheck方法:

let value = {value: true}; 

let confirm = promptService.confirmCheck(
    null, 
    "Uninstall My Extension", 
    "You are uninstalling My Extension. You can chose these options to restore your settings to previous state.", 
    "Remove My Extension as the default search engine, homepage, new tab landing page, and restore to my previous settings", 
    value 
); 

唯一的问题是,它仅包含一个复选框,我需要3米不同的人,对“搜索引擎”,“主页”和“新标签网址”。

我通过附加SDK使用chrome代码,并且不熟悉XUL。

我应该怎么办?我真的需要学习XUL来创建一个简单的提示吗?

+0

您可以执行三个不同的按钮:https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIPromptService?redirectlocale=en-US&redirectslug=nsIPromptService#confirmEx_example。但是对于三个复选框,您必须使用XUL或HTML创建自己的提示。 – Noitidart 2014-12-05 08:09:34

+0

@Noitidart不同的按钮不适合我。有没有HTML提示的教程?我不知道那个HTML可以用于提示而不是XUL。 – 2014-12-05 08:12:00

+0

你绝对可以。用“Services.ww.openWindow”打开一个新窗口,使其成为模式并加载HTML页面。或者使用xul元素叠加当前窗口,例如堆栈,卡组或其他重叠,附加一个iframe并在其中加载一个html页面。从此回购安装此插件:https://github.com/Noitidart/adhelp/tree/patch-1使用[GitHub扩展安装程序](https://addons.mozilla.org/en-US/firefox/addon/github -extension-installer /)安装完成后,重新启动浏览器,按alt进入菜单栏,查看“AdHelp”菜单项,从中选择“图片”菜单,覆盖当前选项卡。 – Noitidart 2014-12-05 08:24:58

回答

2

好的,回答我自己的问题,正如我想到的那样。我发现最简单的方法(比较)是使用XUL:

这是我prompt.xul:

<?xml version="1.0"?> 
<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?> 
<dialog id="myDialog" 
     title="My Extension" 
     xmlns:html="http://www.w3.org/1999/xhtml" 
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 
     onload="init();" 
     buttons="accept" 
     buttonlabelaccept="OK" 
     ondialogaccept="return doContinue();"> 

    <script type="application/x-javascript"> 
     function init() { 

     } 

     function doContinue() { 
      window.arguments[0].CHECK_1 = document.querySelector('#check_1').checked; 
      window.arguments[0].CHECK_2 = document.querySelector('#check_2').checked; 
      window.arguments[0].CHECK_3 = document.querySelector('#check_3').checked; 
      return true; 
     } 
    </script> 

    <html:div style="width: 410px;"> 
     <html:div> 
      <html:p>You have selected to uninstall My Extension</html:p> 
     </html:div> 
     <html:blockquote id="checkboxes_container"> 
      <html:div id="remove_search_container"> 
       <html:input type="checkbox" id="check_1" value="true" checked="true"/> 
       <html:label for="check_1">Label 1</html:label> 
      </html:div> 
      <html:div id="remove_homepage_container"> 
       <html:input type="checkbox" id="check_2" value="true" checked="true"/> 
       <html:label for="check_2">Label 2</html:label> 
      </html:div> 
      <html:div id="remove_newtab_container"> 
       <html:input type="checkbox" id="check_3" value="true" checked="true"/> 
       <html:label for="check_3">Label 3</html:label> 
      </html:div> 
     </html:blockquote> 
    </html:div> 
</dialog> 

加入镀铬包chrome.manifest后,这个文件应该是访问:

chrome://YOUR_PACKAGE_NAME/content/PATH_TO_dialog.xul 

我使用铬代码加载提示,在main.js

let Window = Cc["@mozilla.org/embedcomp/window-watcher;1"] 
      .getService(Ci.nsIWindowWatcher); 

let arg = { 

    CHECK_1: false, 

    CHECK_2: false, 

    CHECK_3: false 

}; 

let window = Window.activeWindow.openDialog("chrome://YOUR_PACKAGE_NAME/content/PATH_TO_dialog.xul", "myWindow", "chrome,modal,centerscreen", arg); 

用户关闭提示后,arg对象将包含提示的复选框值。例如,如果用户囊括了所有的复选框,则arg对象将是:

{ 

    CHECK_1 : true, 

    CHECK_2 : true, 

    CHECK_3 : true 

} 

这为我做。祝你今天愉快!

+0

太棒了!感谢分享!! :) – Noitidart 2014-12-06 21:56:32