home *** CD-ROM | disk | FTP | other *** search
/ PC Advisor 2005 August / PCADVD_121.iso / internet / nsb-setup.exe / chrome / browser.jar / content / browser / sitecontrols / bindings.xml next >
Encoding:
Extensible Markup Language  |  2005-04-29  |  13.6 KB  |  398 lines

  1. <?xml version="1.0"?>  
  2.  
  3. <!DOCTYPE window [
  4.   <!ENTITY % sitecontrolsDTD SYSTEM "chrome://browser/locale/sitecontrols.dtd" >
  5.   %sitecontrolsDTD;
  6. ]>
  7.  
  8. <bindings id="siteControlsBindings" 
  9.           xmlns="http://www.mozilla.org/xbl" 
  10.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 
  11.           xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  12.           xmlns:xbl="http://www.mozilla.org/xbl">
  13.  
  14.   <binding id="sitecontrols-tree">
  15.     <implementation>
  16.       <constructor><![CDATA[
  17.         this.debug('CONSTRUCTOR');
  18.         // This function only reads in the sitecontrols from disk if they have not already been read.
  19.         sitecontrols.initServices();
  20.  
  21.         // Load column settings from persisted attribute
  22.         var colinfostr = this.getAttribute("colinfo");
  23.         var colinfo = colinfostr.split(" ");
  24.         for (var i = 0; i < colinfo.length; ++i) {
  25.           if (colinfo[i] == "") continue;
  26.  
  27.           var querymarker = colinfo[i].indexOf("?");
  28.           var anonid = colinfo[i].substring(4, querymarker);
  29.           var col = document.getAnonymousElementByAttribute(this, "id", anonid);
  30.  
  31.           if (!anonid || !col) break;
  32.  
  33.           var attrstring = colinfo[i].substr(querymarker + 1);
  34.  
  35.           var attrpairs = attrstring.split("&");
  36.           for (var j = 0; j < attrpairs.length; ++j) {
  37.             var pair = attrpairs[j].split("=");
  38.             col.setAttribute(pair[0], pair[1]);
  39.           }
  40.         }
  41.       ]]></constructor>
  42.  
  43.  
  44.       <property name="db">
  45.         <getter><![CDATA[
  46.           return this.tree.database;
  47.         ]]></getter>
  48.       </property>
  49.  
  50.  
  51.       <field name="sorted">false</field>
  52.  
  53.  
  54.       <method name="refreshSort">
  55.         <body>
  56.         <![CDATA[
  57.           //return;
  58.           this.debug('refreshSort()');
  59.           
  60.           // This ensures that we don't sort twice in the tree that is clicked on 
  61.           // as a result of 1) the click and 2) the pref listener. 
  62.           if (!this.sorted) {
  63.             try {
  64.               var sortColumn = 'siteName';
  65.               var sortDirection = 'ascending';
  66.           
  67.               // Walk the columns, when we find a column with a sort resource that matches the supplied
  68.               // data, stop and make sure it's sort active. 
  69.               var treecols = document.getAnonymousElementByAttribute(this, "anonid", "treecols");
  70.               var child = treecols.firstChild;
  71.               while (child) {
  72.                 if (child.localName != "splitter") {
  73.                   if (child.getAttribute("id") == sortColumn) {
  74.                     child.setAttribute("sortActive", "true");
  75.                     child.setAttribute("sortDirection", sortDirection);
  76.                     this.treeBuilder.sort(child, false);
  77.                     break;
  78.                   }
  79.                 }          
  80.                 child = child.nextSibling;
  81.               }
  82.             }
  83.             catch (e) {
  84.               dump("error in refresh sort:"+e)
  85.             }
  86.           }
  87.           this.sorted = false;
  88.         ]]>
  89.         </body>
  90.       </method>
  91.  
  92.  
  93.       <property name="columns">
  94.         <getter>
  95.         <![CDATA[
  96.           var cols = [];
  97.           var treecols = document.getAnonymousElementByAttribute(this, "anonid", "treecols");
  98.           var child = treecols.firstChild;
  99.           while (child) {
  100.             if (child.localName != "splitter") {
  101.               var obj = {
  102.                 label: child.getAttribute("label"),
  103.                 accesskey: child.getAttribute("accesskey"),
  104.                 resource: child.getAttribute("sort"),
  105.                 sortActive: child.getAttribute("sortActive") == "true",
  106.                 hidden: child.getAttribute("hidden")
  107.               }
  108.               cols.push(obj);
  109.             }
  110.             child = child.nextSibling;
  111.           }
  112.           return cols;
  113.         ]]>
  114.         </getter>
  115.       </property>
  116.  
  117.  
  118.       <property name="tree">
  119.         <getter><![CDATA[
  120.           return document.getAnonymousElementByAttribute(this, "anonid", "sitecontrols-tree");
  121.         ]]></getter>
  122.       </property>
  123.  
  124.  
  125.       <property name="treeChildren">
  126.         <getter><![CDATA[
  127.           return document.getAnonymousElementByAttribute(this, "anonid", "sitecontrols-treechildren");
  128.         ]]></getter>
  129.       </property>
  130.  
  131.  
  132.       <property name="treeBoxObject">
  133.         <getter><![CDATA[
  134.           return this.tree.boxObject.QueryInterface(Components.interfaces.nsITreeBoxObject);
  135.         ]]></getter>
  136.       </property>
  137.  
  138.  
  139.       <property name="treeBuilder">
  140.         <getter><![CDATA[
  141.           return this.tree.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder);
  142.         ]]></getter>
  143.       </property>
  144.  
  145.  
  146.       <property name="type">
  147.         <getter><![CDATA[
  148.           if (!this._type) {
  149.             var type = this.getAttribute("type");
  150.             if (!type)
  151.               type = "multi-column";
  152.             this._type = type;
  153.           }
  154.           return this._type;
  155.         ]]></getter>
  156.       </property>
  157.  
  158.  
  159.       <property name="currentIndex">
  160.         <getter><![CDATA[
  161.           return this.treeBoxObject.selection.currentIndex;
  162.         ]]></getter>
  163.       </property>
  164.  
  165.  
  166.       <property name="currentResource">
  167.         <getter><![CDATA[
  168.           return this.treeBuilder.getResourceAtIndex(this.currentIndex);
  169.         ]]></getter>
  170.       </property>
  171.  
  172.  
  173.       <method name="getRowResource">
  174.         <parameter name="aRow"/>
  175.         <body><![CDATA[
  176.           this.debug('getRowResource(...)');
  177.           if (aRow != -1)
  178.             return this.treeBuilder.getResourceAtIndex(aRow);
  179.           else
  180.             return this.getRootResource();
  181.         ]]></body>
  182.       </method>
  183.  
  184.  
  185.       <method name="getParentResource">
  186.         <parameter name="aRow"/>
  187.         <body><![CDATA[
  188.           this.debug('getParentResource(...)');
  189.           if (aRow != -1) {
  190.             var parentIndex = this.treeBoxObject.view.getParentIndex(aRow);
  191.             return this.getRowResource(parentIndex);
  192.           }
  193.           return this.getRootResource(); // assume its parent is the root
  194.         ]]></body>
  195.       </method>
  196.  
  197.  
  198.       <method name="getRootResource">
  199.         <body><![CDATA[
  200.           this.debug('getRootResource()');
  201.           var tree = document.getAnonymousElementByAttribute(this, "anonid", "sitecontrols-tree");
  202.           return RDF.GetResource(tree.ref);
  203.         ]]></body>
  204.       </method>
  205.  
  206.  
  207.       <method name="focus">
  208.         <body>
  209.           this.debug('focus()');
  210.           this.tree.focus();
  211.         </body>
  212.       </method>
  213.  
  214.  
  215.       <method name="removeItemConfirm">
  216.         <body><![CDATA[
  217.           this.debug('removeItemConfirm()');
  218.  
  219.           // Bail if nothing is selected
  220.           var siteRes = this.tree.view.getResourceAtIndex(this.tree.currentIndex);
  221.           if (!siteRes) return;
  222.  
  223.           // Bail if it's one of the "Default"s or "Local Files" site
  224.           var titleProp = sitecontrols.RDF.GetResource(sitecontrols.SC_NS+'title');
  225.           var titleRes = sitecontrols.SCDS.GetTarget(siteRes, titleProp, true);
  226.           var titleLit = titleRes.QueryInterface(Components.interfaces.nsIRDFLiteral);
  227.           if (titleLit.Value == 'Local Files' ||
  228.               titleLit.Value == 'Verified Default' ||
  229.               titleLit.Value == 'Not Verified Default' ||
  230.               titleLit.Value == 'Warning Default') return;
  231.  
  232.           // Prompt for confirmation
  233.           const IPS = Components.interfaces.nsIPromptService;
  234.           var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  235.                              .getService(IPS);
  236.           var promptMessage = 'Remove this site from your list of controlled sites?';
  237.           var checkEveryTime = { value: null };
  238.           // xxxTODO: i18n
  239.           var rv = ps.confirmEx(window, 'Remove Site', promptMessage, 
  240.                                 (IPS.BUTTON_TITLE_YES * IPS.BUTTON_POS_0) + 
  241.                                 (IPS.BUTTON_TITLE_NO * IPS.BUTTON_POS_1),
  242.                                 null, null, null, null, checkEveryTime);
  243.           if (rv == 0) {
  244.             this.debug('removing...');
  245.             sitecontrols.SCSVC.removeControlledSite(titleLit.Value);
  246.             this.refreshList();
  247.             this.debug('...finished removing :)');
  248.           }
  249.         ]]></body>
  250.       </method>
  251.  
  252.  
  253.       <method name="debug">
  254.         <parameter name="msg"/>
  255.         <body><![CDATA[
  256.           dump('sitecontrols-tree: '+msg+'\n');
  257.         ]]></body>
  258.       </method>
  259.  
  260.  
  261.       <method name="refreshList">
  262.       <parameter name="aInput"/>
  263.         <body><![CDATA[
  264.           this.debug('refreshList('+aInput+')');
  265.  
  266.           // Clear out the existing datasources
  267.           datasources = this.tree.database.GetDataSources();
  268.           while (datasources.hasMoreElements())
  269.             this.tree.database.RemoveDataSource(datasources.getNext());
  270.  
  271.           var ds = new SiteControlsFilterDataSource;
  272.           if (aInput) ds.SetFilter(aInput);
  273.           this.tree.database.AddDataSource(ds);
  274.           this.tree.builder.rebuild();
  275.         ]]></body>
  276.       </method>
  277.  
  278.     </implementation>
  279.   </binding>
  280.  
  281.  
  282.   <binding id="sitecontrols-tree-basic"
  283.            extends="chrome://browser/content/sitecontrols/bindings.xml#sitecontrols-tree">
  284.     <xbl:resources>
  285.       <xbl:stylesheet src="chrome://browser/skin/pref/sitecontrols-tree.css"/>
  286.     </xbl:resources>
  287.     <xbl:content xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  288.                  xmlns:xbl="http://www.mozilla.org/xbl"
  289.                  contextmenu="_child">
  290.       <!-- context menu -->
  291.       <menupopup>
  292.         <menuitem anonid="removeSite"
  293.                   label="Remove site"
  294.                   oncommand="this.parentNode.parentNode.removeItemConfirm();"/>
  295.       </menupopup>
  296.       <vbox flex="1">
  297.         <tree anonid="sitecontrols-tree" flex="1" class="plain"
  298.               datasources="rdf:null" ref="SiteControls:Root"
  299.               sortResource="http://home.netscape.com/SC-rdf#title"
  300.               hidecolumnpicker="true" seltype="single" flags="dont-build-content"
  301.               onselect="this.treeBoxObject.view.selectionChanged();">
  302.           <template container="?uri" member="?site">
  303.             <rule>
  304.               <conditions>
  305.                 <content uri="?uri"/>
  306.                 <member container="?uri" child="?site"/>
  307.                 <triple subject="?site"
  308.                         predicate="http://home.netscape.com/SC-rdf#title"
  309.                         object="?title"/>
  310.                 <triple subject="?site"
  311.                         predicate="http://home.netscape.com/SC-rdf#securityLevel"
  312.                         object="Low"/>
  313.               </conditions>
  314.               <action>
  315.                 <treechildren anonid="sitecontrols-treechildren">
  316.                   <treeitem uri="?site" value="?title">
  317.                     <treerow>
  318.                       <treecell class="site" label="?title" properties="Low"/>
  319.                     </treerow>
  320.                   </treeitem>
  321.                 </treechildren>
  322.               </action>
  323.             </rule>
  324.             <rule>
  325.               <conditions>
  326.                 <content uri="?uri"/>
  327.                 <member container="?uri" child="?site"/>
  328.                 <triple subject="?site"
  329.                         predicate="http://home.netscape.com/SC-rdf#title"
  330.                         object="?title"/>
  331.                 <triple subject="?site"
  332.                         predicate="http://home.netscape.com/SC-rdf#securityLevel"
  333.                         object="Medium"/>
  334.               </conditions>
  335.               <action>
  336.                 <treechildren anonid="sitecontrols-treechildren">
  337.                   <treeitem uri="?site" value="?title">
  338.                     <treerow>
  339.                       <treecell class="site" label="?title" properties="Medium"/>
  340.                     </treerow>
  341.                   </treeitem>
  342.                 </treechildren>
  343.               </action>
  344.             </rule>
  345.             <rule>
  346.               <conditions>
  347.                 <content uri="?uri"/>
  348.                 <member container="?uri" child="?site"/>
  349.                 <triple subject="?site"
  350.                         predicate="http://home.netscape.com/SC-rdf#title"
  351.                         object="?title"/>
  352.                 <triple subject="?site"
  353.                         predicate="http://home.netscape.com/SC-rdf#securityLevel"
  354.                         object="High"/>
  355.               </conditions>
  356.               <action>
  357.                 <treechildren anonid="sitecontrols-treechildren">
  358.                   <treeitem uri="?site" value="?title">
  359.                     <treerow>
  360.                       <treecell class="site" label="?title" properties="High"/>
  361.                     </treerow>
  362.                   </treeitem>
  363.                 </treechildren>
  364.               </action>
  365.             </rule>
  366.             <rule>
  367.               <conditions>
  368.                 <content uri="?uri"/>
  369.                 <member container="?uri" child="?site"/>
  370.                 <triple subject="?site"
  371.                         predicate="http://home.netscape.com/SC-rdf#title"
  372.                         object="?title"/>
  373.               </conditions>
  374.               <action>
  375.                 <treechildren anonid="sitecontrols-treechildren">
  376.                   <treeitem uri="?site" value="?title">
  377.                     <treerow>
  378.                       <treecell class="site" label="?title" properties="Custom"/>
  379.                     </treerow>
  380.                   </treeitem>
  381.                 </treechildren>
  382.               </action>
  383.             </rule>
  384.           </template>
  385.           <treecols anonid="treecols">
  386.             <treecol id="siteName" sortActive="true" sortDirection="ascending"
  387.                      hideheader="true" flex="2"
  388.                      sort="?title"/>
  389.           </treecols>
  390.         </tree>
  391.       </vbox>
  392.     </xbl:content>
  393.     <implementation>
  394.       <field name="clickCount">2</field>
  395.     </implementation>
  396.   </binding>
  397.  
  398. </bindings>