home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / komunikace / kmeleon / K-Meleon1.1.3en-US.exe / chrome / embed.jar / kmprefs / content / pref-webfind.xul < prev    next >
Extensible Markup Language  |  2007-04-23  |  16KB  |  437 lines

  1. <?xml version="1.0"?>
  2. <?xml-stylesheet type="text/css" href="chrome://global/skin/"?>
  3. <!DOCTYPE page SYSTEM "chrome://kmprefs/locale/pref-webfind.dtd">
  4. <page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 
  5. id="prefWebfind" onunload="Search.exit()">
  6.  
  7. <stringbundle id="pref_bundle" src="chrome://kmprefs/locale/pref.properties"/>
  8. <stringbundle id="xml_bundle" src="chrome://kmprefs/locale/kmprefs/xml.properties"/>
  9.  
  10. <script type="application/x-javascript" src="chrome://kmprefs/content/pref.js"/>
  11. <script type="application/x-javascript" src="chrome://kmprefs/content/kmprefs/xml.js"/>
  12. <script type="application/x-javascript" src="chrome://kmprefs/content/kplugins/jsbridge.js"/>
  13. <script type="application/x-javascript">
  14. <![CDATA[
  15. var menu;
  16.  
  17. CFGtoXML.init("search");
  18.  
  19. var Engines = new XML("file:///"+getFile(getFolder("KUserSettings"),"search.xml").path);
  20.  
  21. var JSB = new JSBridge();
  22.  
  23. function init(e) {
  24.     menu = document.createElement("menupopup");
  25.     for(var j=0,engines=Engines.data.getElementsByTagName("engine"),item;j<engines.length;j++) {
  26.         item = document.createElement("menuitem");
  27.         item.setAttribute("value",engines[j].getAttribute("url"));
  28.         item.setAttribute("label",engines[j].getAttribute("caption"));
  29.         menu.appendChild(item);
  30.     }
  31.     URLBar.init();
  32.     if(kPlugin.load("macros") && kMacrosModule.load("search")) {
  33.         if(JSB.load) {
  34.             document.getElementById("JSBridgeOff").style.display = "none";
  35.             document.getElementById("JSBridgeOn").style.display = "block";
  36.         }
  37.     } else {
  38.         var elem = document.getElementsByTagName("tab");
  39.         elem[1].parentNode.removeChild(elem[1]);
  40.         elem[1].parentNode.removeChild(elem[1]);
  41.         elem = document.getElementsByTagName("tabpanel");
  42.         elem[1].parentNode.removeChild(elem[1]);
  43.         elem[1].parentNode.removeChild(elem[1]);
  44.     }
  45. }
  46.  
  47. var URLBar = {
  48.  
  49. init: function() {
  50.     for(var j=0,box=document.getElementsByTagName("checkbox");j<box.length;j++) initCheckbox(box[j].id);
  51.     document.getElementById("browser.urlbar.autoFill").disabled = !document.getElementById("browser.urlbar.autocomplete.enabled").checked;
  52.  
  53.     try {
  54.         for(var box=document.getElementsByTagName("textbox"),j=box.length-1;j>-1;j--)
  55.             initTextbox(box[j].id,false);
  56.     } catch(e) {}
  57.     if(!kPlugin.load("macros") || !kMacrosModule.load("domcomplete")) {
  58.         var elem = document.getElementById("domComplete");
  59.         elem.parentNode.removeChild(elem);
  60.     }
  61.  
  62.     this.initKeyword();
  63.     this.initKeywordMenu();
  64. },
  65. initKeyword: function() {
  66.     var val = document.getElementById("keyword.enabled").checked;
  67.  
  68.     document.getElementById("browser.fixup.alternate.enabled").disabled = val;
  69.     document.getElementById("browser.fixup.alternate.prefix").disabled = val;
  70.     document.getElementById("browser.fixup.alternate.suffix").disabled = val;
  71. },
  72. initKeywordMenu: function() {
  73.     var elem = document.getElementById("keyword.URL");
  74.  
  75.     if(elem.hasChildNodes()) elem.removeChild(elem.firstChild);
  76.     elem.appendChild(menu.cloneNode(true));
  77.     initMenulist("keyword.URL","",false);
  78. }
  79.  
  80. };
  81.  
  82. var Search = {
  83.  
  84. _base: "kmeleon.plugins.macros.search.",
  85. _dflt: "kmeleon.general.searchEngine",
  86. _elem: ["engine","meta"],
  87. _menu: ["_Search_Engines_Configurable","_Search_Engines_Metasearch"],
  88. _cmnd: ["Search_Engine","Search_Metasearch"],
  89. _labl: ["","&Metasearch"],
  90.  
  91. done: [false,false],
  92. init: function(n) {
  93.     if(!this.done[n]) {
  94.         var j = 0;
  95.         var prefID = this._base + this._elem[n] + j + ".url";
  96.  
  97.         var box = document.getElementById(this._elem[n]),
  98.             val = getPrefValue(prefID);
  99.  
  100.         pref.setIntPref(this._base+this._elem[n]+".max",0);
  101.         while(box.hasChildNodes()) box.removeChild(box.firstChild);
  102.         while(val != null) {
  103.             if(val) {
  104.                 this._addMenu(n,prefID);
  105.                 initMenulist(prefID,"",false);
  106.             }
  107.             j++;
  108.             prefID = this._base + this._elem[n] + j + ".url";
  109.             val = getPrefValue(prefID);
  110.         }
  111.         this.done[n] = true;
  112.     }
  113. },
  114. exit: function() {
  115.     for(var j=0;j<this._elem.length;j++) restoreDefault(this._base+this._elem[j]+".max");
  116.     Engines.save(getFile(getFolder("KUserSettings"),"search.xml"),["caption","url"]);
  117. },
  118. add: function(n) {
  119.     this._addMenu(n,this._base+this._elem[n]+document.getElementById(this._elem[n]).getElementsByTagName("menulist").length+".url");
  120. },
  121. _addMenu: function(n,elemID) {
  122.     var elem = document.createElement("menulist"),
  123.         prnt = document.getElementById(this._elem[n]);
  124.  
  125.     elem.id = elemID;
  126.     elem.setAttribute("flex",1); // omitting this slows rendering!
  127.     elem.setAttribute("oncommand","Search.setEngine("+n+",this)");
  128.     elem.appendChild(menu.cloneNode(true));
  129.     prnt.appendChild(elem);
  130.  
  131.     prnt.lastChild.firstChild.insertBefore(document.createElement("menuseparator"),prnt.lastChild.firstChild.firstChild);
  132.     elem = document.createElement("menuitem");
  133.     elem.setAttribute("value","");
  134.     elem.setAttribute("label",document.getElementById("pref_bundle").getString("remove_entry"));
  135.     prnt.lastChild.firstChild.insertBefore(elem,prnt.lastChild.firstChild.firstChild);
  136.     prnt.lastChild.selectedIndex = 0;
  137.  
  138.     pref.setIntPref(this._base+this._elem[n]+".max",pref.getIntPref(this._base+this._elem[n]+".max")+1);
  139.  
  140. },
  141. setEngine: function(n,elem) {
  142.     var val = elem.value,
  143.         lbl = (val) ? elem.selectedItem.label : "";
  144.  
  145.     if(!n) {
  146.         this._delMenu();
  147.         this._setDefault(elem,val,lbl);
  148.         setCharPref(elem.id.substr(0,elem.id.lastIndexOf("."))+".name",lbl);
  149.     }
  150.     setCharPref(elem.id,val);
  151.     if(!val) {
  152.         this._sanitize(this._elem[n]);
  153.         this.done[n] = false;
  154.         this.init(n);
  155.     }
  156.     this._setMenu(n);
  157. },
  158. _setDefault: function(elem,value,label) {
  159.     if(getPrefValue(elem.id)==getPrefValue(this._dflt))
  160.         if(value) {
  161.             setCharPref(this._dflt,value);
  162.             setCharPref(this._dflt+"Name",label);
  163.         } else    pref.setBoolPref(this._base+"locked",false)
  164. },
  165. _delMenu: function() {
  166.     for(var j=0;j<pref.getIntPref(this._base+this._elem[0]+".max");j++)
  167.         JSB.setmenu(this._menu[0],"macro","",this._cmnd[0]+"("+j+")","");
  168. },
  169. _setMenu: function(n) {
  170.     var max = pref.getIntPref(this._base+this._elem[n]+".max");
  171.  
  172.     if(n)
  173.         JSB.setmenu(this._menu[n],"macro",this._labl[n],(max)?this._cmnd[n]:"","");
  174.     else for(var j=0;j<max;j++)
  175.         JSB.setmenu(this._menu[n],"macro",getPrefValue(this._base+this._elem[0]+j+".name"),this._cmnd[n]+"("+j+")","");
  176. //    JSB.rebuildmenu(this._menu[n]);
  177. },
  178. _sanitize: function(prefPart) {
  179.     var max = pref.getIntPref(this._base+prefPart+".max");
  180.  
  181.     for(var j=0;j<max;j++)
  182.         if(getPrefValue(this._base+prefPart+j+".url")=="") {
  183.             for(var i=j+1;i<max;i++) {
  184.                 setCharPref(this._base+prefPart+(i-1)+".url",getPrefValue(this._base+prefPart+i+".url"));
  185.                 if(prefPart=="engine") setCharPref(this._base+prefPart+(i-1)+".name",getPrefValue(this._base+prefPart+i+".name"));
  186.             }
  187.             setCharPref(this._base+prefPart+(max-1)+".url","");
  188.             if(prefPart=="engine") setCharPref(this._base+prefPart+(max-1)+".name","");
  189.         }
  190.     for(var j=0,url;j<max;j++) {
  191.         url = this._base+prefPart+j+".url";
  192.         if(getPrefValue(url)) continue;
  193.         restoreDefault(url);
  194.         if(getPrefValue(url)==null) {
  195.             if(prefPart=="engine") restoreDefault(this._base+prefPart+j+".name");
  196.         } else
  197.             setCharPref(url,"");
  198.     }
  199. }
  200.  
  201. };
  202.  
  203. var Database = {
  204.  
  205. _add: false,
  206. _ndx: false,
  207. _cap: null,
  208. _url: null,
  209.  
  210. done: false,
  211. tree: null,
  212. init: function() {
  213.     if(!this.done) {
  214.         this.done = true;
  215.         this.tree = document.getElementById("database");
  216.         while(this.tree.hasChildNodes()) this.tree.removeChild(this.tree.firstChild);
  217.         for(var j=0,engines=Engines.data.getElementsByTagName("engine"),titem,tcell;j<engines.length;j++) {
  218.             titem = document.createElement("treeitem");
  219.             titem.appendChild(document.createElement("treerow"));
  220.             tcell = document.createElement("treecell");
  221.             tcell.setAttribute("label",engines[j].getAttribute("caption"));
  222.             titem.firstChild.appendChild(tcell);
  223.             tcell = document.createElement("treecell");
  224.             tcell.setAttribute("label",engines[j].getAttribute("url"));
  225.             titem.firstChild.appendChild(tcell);
  226.             this.tree.appendChild(titem);
  227.         }
  228.     }
  229. },
  230. del: function() {
  231.     this._ndx = this.tree.parentNode.currentIndex;
  232.     if(this._ndx>-1) {
  233.         this.tree.removeChild(this.tree.childNodes[this._ndx]);
  234.         if(Engines.del("engine",this._ndx)) this._refresh();
  235.     }
  236. },
  237. add: function() {
  238.     this._ndx = -1;
  239.     this._add = true;
  240.     this._cap = null;
  241.     this._url = null;
  242.     window.openDialog("chrome://kmprefs/content/kmprefs/dlg-webfind.xul","engnAdd" ,"chrome,modal=yes,resizable=no",this);
  243. },
  244. edit: function() {
  245.     this._ndx = this.tree.parentNode.currentIndex;
  246.     this._add = false;
  247.     this._cap = this.tree.childNodes[this._ndx].firstChild.firstChild.getAttribute("label");
  248.     this._url = this.tree.childNodes[this._ndx].firstChild.firstChild.nextSibling.getAttribute("label");
  249.     window.openDialog("chrome://kmprefs/content/kmprefs/dlg-webfind.xul","engnEdit","chrome,modal=yes,resizable=no",this);
  250. },
  251. select: function() {
  252.     var ndx = this.tree.parentNode.currentIndex;
  253.     document.getElementById("edit").setAttribute("disabled",(ndx==-1));
  254.     document.getElementById("delete").setAttribute("disabled",(ndx==-1));
  255. },
  256. set: function(caption,url) {
  257.     if((this._cap != caption) || (this._url != url)) {
  258.         Engines.set("engine",this._ndx,["caption","url"],[caption,url],0);
  259.         this._refresh();
  260.         this.done = false;
  261.         this.init();
  262.     }
  263. },
  264. _refresh: function() {
  265.     init(false);
  266.     for(var j=0;j<Search.done.length;j++) Search.done[j] = false;
  267. }
  268.  
  269. };
  270. ]]>
  271. </script>
  272.  
  273. <keyset>
  274.   <key id="addKey" keycode="VK_INSERT" oncommand="Database.add()"/>
  275.   <key id="delKey" keycode="VK_DELETE" oncommand="Database.del()"/>
  276. </keyset>
  277.  
  278. <vbox flex="1" style="overflow:auto">
  279.   <dialogheader title="&webfind.header;"/>
  280.   <separator class="thin"/>
  281.   <tabcontrol flex="1">
  282.     <tabbox flex="1">
  283.       <tabs>
  284.         <tab label="&webfind.urlbar;"/>
  285.         <tab label="&webfind.websearch;" oncommand="Search.init(0)"/>
  286.         <tab label="&webfind.metasearch;" oncommand="Search.init(1)"/>
  287.         <tab label="&webfind.database;" oncommand="Database.init()"/>
  288.       </tabs>
  289.       <tabpanels flex="1">
  290.         <tabpanel flex="1" orient="vertical" style="overflow:auto">
  291. <!-- URL Bar -->
  292. <groupbox>
  293.   <caption label="&autocomplete.label;"/>
  294.   <checkbox oncommand="toggleCheckbox(this.id);this.nextSibling.disabled=!this.checked" id="browser.urlbar.autocomplete.enabled" label="&autocomplete.enable;"/>
  295.   <checkbox oncommand="toggleCheckbox(this.id)" id="browser.urlbar.autoFill" label="&autofill.enable;" style="margin-left:2em"/>
  296. </groupbox>
  297. <groupbox id="domComplete">
  298.   <caption label="&domCompletion.label;"/>
  299.   <separator class="thin"/>
  300.   <grid>
  301.     <columns>
  302.       <column style="padding-right:1em"/>
  303.       <column flex="1"/>
  304.       <column flex="1"/>
  305.     </columns>
  306.     <rows>
  307.       <row align="center">
  308.         <label value="&whenPressing;"/>
  309.         <label value="&domCompletion.prefix;"/>
  310.         <label value="&domCompletion.suffix;"/>
  311.       </row>
  312.       <row>
  313.         <separator class="thin"/>
  314.       </row>
  315.       <row align="center">
  316.         <label value="&domCompletion.key0;"/>
  317.         <textbox id="kmeleon.plugins.macros.domComplete0.prefix" flex="1" class="uri-element" oninput="setCharPref(this.id,this.value)"/>
  318.         <textbox id="kmeleon.plugins.macros.domComplete0.suffix" flex="1" class="uri-element" oninput="setCharPref(this.id,this.value)"/>
  319.       </row>
  320.       <row align="center">
  321.         <label value="&domCompletion.key1;"/>
  322.         <textbox id="kmeleon.plugins.macros.domComplete1.prefix" flex="1" class="uri-element" oninput="setCharPref(this.id,this.value)"/>
  323.         <textbox id="kmeleon.plugins.macros.domComplete1.suffix" flex="1" class="uri-element" oninput="setCharPref(this.id,this.value)"/>
  324.       </row>
  325.       <row align="center">
  326.         <label value="&domCompletion.key2;"/>
  327.         <textbox id="kmeleon.plugins.macros.domComplete2.prefix" flex="1" class="uri-element" oninput="setCharPref(this.id,this.value)"/>
  328.         <textbox id="kmeleon.plugins.macros.domComplete2.suffix" flex="1" class="uri-element" oninput="setCharPref(this.id,this.value)"/>
  329.       </row>
  330.     </rows>
  331.   </grid>
  332.   <separator class="thin"/>
  333.   <description>¯osNote;</description>
  334. </groupbox>
  335. <groupbox>
  336.   <caption label="&fixupAlt.label;"/>
  337.   <checkbox oncommand="toggleCheckbox(this.id)" id="browser.fixup.alternate.enabled" label="&fixupAlt.enable;"/>
  338.   <separator class="thin"/>
  339.   <grid>
  340.     <columns>
  341.       <column style="padding-right:1em"/>
  342.       <column flex="1"/>
  343.       <column flex="1"/>
  344.     </columns>
  345.     <rows>
  346.       <row align="center">
  347.         <label value="&domCompletion.key2;" style="visibility:hidden"/>
  348.         <label value="&domCompletion.prefix;"/>
  349.         <label value="&domCompletion.suffix;"/>
  350.       </row>
  351.       <row>
  352.         <separator class="thin"/>
  353.       </row>
  354.       <row align="center">
  355.         <label value="&domCompletion.key2;" style="visibility:hidden"/>
  356.         <textbox id="browser.fixup.alternate.prefix" flex="1" class="uri-element" oninput="setCharPref(this.id,this.value)"/>
  357.         <textbox id="browser.fixup.alternate.suffix" flex="1" class="uri-element" oninput="setCharPref(this.id,this.value)"/>
  358.       </row>
  359.     </rows>
  360.   </grid>
  361.   <separator class="thin"/>
  362. </groupbox>
  363. <groupbox>
  364.   <caption label="&keyword.label;"/>
  365.   <checkbox oncommand="toggleCheckbox(this.id);URLBar.initKeyword()" id="keyword.enabled" label="&keyword.enable;"/>
  366.   <vbox id="keyword">
  367.     <separator class="thin"/>
  368.     <hbox align="center">
  369.       <label value="&domCompletion.key2;" style="visibility:hidden;padding-right:1em"/>
  370.       <label value="&keyword.engine;"/>
  371.       <menulist id="keyword.URL" oncommand="setCharPref(this.id,this.value)" flex="1"/>
  372.     </hbox>
  373.   </vbox>
  374. </groupbox>
  375. <!-- URL Bar -->
  376.     </tabpanel>
  377.         <tabpanel flex="1" orient="vertical">
  378. <!-- Web Search -->
  379. <separator class="thin"/>
  380. <description>&websearch.descr;</description>
  381. <separator class="thin"/>
  382. <vbox id="engine" flex="1" style="overflow:auto"/>
  383. <vbox flex="1000"/>
  384. <separator class="thin"/>
  385. <hbox>
  386.   <button label="&webfind.addEntry;" oncommand="Search.add(0);"/>
  387.   <hbox flex="1"/>
  388. </hbox>
  389. <separator class="thin"/>
  390. <description id="JSBridgeOn" style="display:none">¯osNote;</description>
  391. <description id="JSBridgeOff">&websearch.note;</description>
  392. <!-- Web Search -->
  393.     </tabpanel>
  394.         <tabpanel flex="1" orient="vertical">
  395. <!-- Metasearch -->
  396. <separator class="thin"/>
  397. <description>&meta.descr;</description>
  398. <separator class="thin"/>
  399. <vbox id="meta" flex="1" style="overflow:auto"/>
  400. <vbox flex="1000"/>
  401. <separator class="thin"/>
  402. <hbox>
  403.   <button label="&webfind.addEntry;" oncommand="Search.add(1);"/>
  404.   <hbox flex="1"/>
  405. </hbox>
  406. <separator class="thin"/>
  407. <description>¯osNote;</description>
  408. <!-- Metasearch -->
  409.     </tabpanel>
  410.         <tabpanel flex="1" orient="vertical" style="overflow:auto">
  411. <!-- Database -->
  412. <separator class="thin"/>
  413. <description>&database.descr;</description>
  414. <separator class="thin"/>
  415. <tree flex="1" seltype="single" hidecolumnpicker="true" onselect="Database.select()">
  416.   <treecols>
  417.     <treecol label="&database.caption;" flex="1"/>
  418.     <splitter class="tree-splitter"/>
  419.     <treecol label="&database.url;" flex="2"/>
  420.   </treecols>
  421.   <treechildren id="database"/>
  422. </tree>
  423. <separator class="thin"/>
  424. <hbox>
  425.   <button label="&add;" oncommand="Database.add()" key="addKey"/>
  426.   <button id="edit" label="&edit;" oncommand="Database.edit()" disabled="true"/>
  427.   <button id="delete" label="&delete;" oncommand="Database.del()" key="delKey" disabled="true"/>
  428.   <hbox flex="1"/>
  429. </hbox>
  430. <!-- Database -->
  431.     </tabpanel>
  432.       </tabpanels>
  433.     </tabbox>
  434.   </tabcontrol>
  435. </vbox>
  436.  
  437. </page>