home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / toolkit.jar / content / global / bindings / multibar.xml < prev    next >
Extensible Markup Language  |  2005-07-29  |  36KB  |  914 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE bindings [
  4. <!ENTITY % multibarDTD SYSTEM "chrome://global/locale/multibar.dtd" >
  5. %multibarDTD;
  6. ]>
  7. <bindings id="multibarBindings" xmlns="http://www.mozilla.org/xbl"
  8.   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  9.   xmlns:xbl="http://www.mozilla.org/xbl">
  10.   <binding id="multibar">
  11.     <implementation>
  12.       <method name="debug">
  13.         <parameter name="aStr"/>
  14.         <body>
  15.         // dump ("MULTIBAR: " + aStr);
  16.         </body>
  17.       </method>
  18.       <constructor><![CDATA[
  19.  
  20.           this.debug("MULTIBAR : Constructor, localName : " + this.localName + "\n");
  21.           // Searching for the toolbox palette in the toolbar binding because
  22.           // toolbars are constructed first.
  23.           if (!this.toolbox || this.toolbox.localName != 'toolbox') {
  24.             if (this.parentNode && this.parentNode.localName == 'toolbox')
  25.                this.toolbox = this.parentNode;
  26.           } else {
  27.               return;
  28.           }
  29.  
  30.           if (!this.toolbox.palette) {
  31.             // Look to see if there is a toolbarpalette.
  32.             var node = this.toolbox.firstChild;
  33.             while (node) {
  34.               if (node.localName == "toolbarpalette")
  35.                 break;
  36.               node = node.nextSibling;
  37.             }
  38.  
  39.             if (!node)
  40.               return;
  41.  
  42.             // Hold on to the palette but remove it from the document.
  43.             this.toolbox.palette = node;
  44.             this.toolbox.removeChild(node);
  45.           }
  46.  
  47.  
  48.           this.debug("\nConstructor for a multibar : " + this + "\n\n");
  49.           // Build up our contents from the palette.
  50.           var mycurrentSet = this.getAttribute("currentset");
  51.           if (!mycurrentSet)
  52.             mycurrentSet = this.getAttribute("defaultset");
  53.           if (mycurrentSet) {
  54.             this.currentSet = mycurrentSet;
  55.            } else {
  56.             addNewTray("default");
  57.             addNewTray("second_tray");
  58.           }
  59.  
  60.           if (this.toolbox.toolbarset.getAttribute("showsearch") == this.id) {
  61.               var newItem;
  62.                var paletteItem = this.toolbox.palette.firstChild;
  63.             while (paletteItem) {
  64.                 if (paletteItem.id == 'search-container') {
  65.                   newItem = paletteItem.cloneNode(true);
  66.                     break;
  67.                 }
  68.                 paletteItem = paletteItem.nextSibling;
  69.             }
  70.             if (newItem)
  71.                 this.searchParent.appendChild(newItem);
  72.           }
  73.  
  74.          //  this.showTrayTitle = this.showTrayTitle;
  75.  
  76.           if (this.hasAttribute("currentIndex"))
  77.           {
  78.                this.showTray(this.getAttribute("currentIndex"));
  79.           } else {
  80.              this.showTray(0);
  81.           }
  82.  
  83.  
  84.          ]]></constructor>
  85.       <property name="searchParent"
  86.         onget="return document.getAnonymousElementByAttribute(this,'anonid','multibar-searchbar-parent');"/>
  87.       <property name="searchBar" onget="return this.searchParent.firstChild;"/>
  88.       <property name="mLabel"
  89.         onget="return document.getAnonymousElementByAttribute(this,'anonid','multibar-tray-label');"/>
  90.       <property name="mTrayDeck"
  91.         onget="return document.getAnonymousElementByAttribute(this,'anonid','multibar-deck');"/>
  92.       <property name="mTrays" onget="return this.childNodes;"/>
  93.       <property name="mTrayBox" onget="return this.boxObject;"/>
  94.       <property name="currentTrayIndex" onget="return parseInt(this.mTrayDeck.selectedIndex);"
  95.         onset="this.mTrayDeck.selectedIndex=val;"/>
  96.       <property name="currentTrayOrdinal"
  97.         onget="return this.mCurrentControlButton.getAttribute('ordinal');"/>
  98.       <property name="currentTray" onget="return this.mTrays[this.currentTrayIndex]"/>
  99.       <property name="mCurrentControlButton"
  100.         onget="return this.mControlContainer.childNodes[this.currentTrayIndex];"/>
  101.       <property name="mControlContainer"
  102.         onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'multibar-control').childNodes[1];"/>
  103.       <property name="toolbox"/>
  104.       <method name="get_persisted_prop">
  105.         <parameter name="propertyName"/>
  106.         <body><![CDATA[
  107.           var result;
  108.           if (this.hasAttribute('customindex')) {
  109.                 result = this.toolbox.toolbarset.getAttribute(propertyName + this.getAttribute('customindex'));
  110.             } else {
  111.                 result = this.getAttribute(propertyName);
  112.             }
  113.           if (result == 'true') return true;
  114.           if (result == 'false') return false;
  115.           return result;
  116.         ]]></body>
  117.       </method>
  118.       <method name="persist_prop">
  119.         <parameter name="propertyName"/>
  120.         <parameter name="val"/>
  121.         <body><![CDATA[
  122.             if (val == null)
  123.                 return;
  124.  
  125.           if (this.hasAttribute('customindex'))
  126.           {
  127.           this.toolbox.toolbarset.setAttribute(propertyName + this.getAttribute('customindex'), val.toString());
  128.           document.persist(this.toolbox.toolbarset.id, propertyName + this.getAttribute('customindex'));
  129.           } else {
  130.             this.debug('ACK! no customindex attribute.\n');
  131.             this.setAttribute(propertyName, val.toString());
  132.           }
  133.          return val;
  134.         ]]></body>
  135.       </method>
  136.       <property name="mMenuDropMarker"
  137.         onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'spawnPopup');"/>
  138.       <property name="currentSet">
  139.         <getter><![CDATA[
  140.  
  141.               // JMC - little hack to make sure everything has an ordinal
  142.             //    this.reorderTrays();
  143.  
  144.             var currentSet = "";
  145.  
  146.             for (var i =0 ; i < this.mTrays.length; i++)
  147.             {
  148.                 var node = this.getTrayByOrdinal(i);
  149.                 if (node)
  150.                 {
  151.                 if (currentSet)
  152.                   currentSet += ";";
  153.                 currentSet += node.getAttribute('toolbarname') + ":" + node.currentSet;
  154.               }
  155.             }
  156.  
  157.             return currentSet ? currentSet : "__empty";
  158.           ]]></getter>
  159.         <setter><![CDATA[
  160.  
  161.             // Remove all items before the first permanent child and after the last permanent child.
  162.  
  163.             this.debug("Setting current set for multibar\n\n");
  164.             this.setAttribute("currentset", val);
  165.  
  166.             var node = this.mTrays[0];
  167.             while (node) {
  168.                 this.removeChild(node);
  169.                 // remove the control button
  170.                 this.mControlContainer.removeChild(this.mControlContainer.childNodes[0]);
  171.                 node = this.mTrays[0];
  172.             }
  173.  
  174.             if (val == "__empty")
  175.               return;
  176.  
  177.             if (val) {
  178.               var itemIds = val.split(";");
  179.               for (var i = 0; i < itemIds.length; i++) {
  180.                 var infoSplit = itemIds[i].split(":");
  181.                 var multibarName = infoSplit.shift();
  182.  
  183.                 this.debug("Going to add a tray called " + multibarName + "\n\n");
  184.                 var multibarcontents = infoSplit.join(":");
  185.                 var thisTray = this.addNewTray(multibarName, true);
  186.                 this.debug('Attempted to add a new tray... do we have a tray? : ' + thisTray + '\n');
  187.                 if (thisTray)
  188.                 {
  189.                     thisTray.setAttribute("currentset",multibarcontents);
  190.                     if (thisTray.currentSet != multibarcontents)
  191.                     {
  192.                         thisTray.currentSet = multibarcontents;
  193.                     } else
  194.                     {
  195.                         this.debug("Not setting currentSet because it already matches.\n");
  196.                     }
  197.                 }
  198.                   else
  199.                   {
  200.                        this.debug("Attempting bad or duplicate tray name add.\n");
  201.                   }
  202.               }
  203.             }
  204.  
  205.             this.persist_prop('multibar', this.getAttribute('toolbarname') + ":" + val);
  206.           ]]></setter>
  207.       </property>
  208.       <method name="getTrayByName">
  209.         <parameter name="trayName"/>
  210.         <body><![CDATA[
  211.  
  212.          for (var i = 0; i < this.mTrays.length; i++) {
  213.             if (this.mTrays[i].getAttribute("toolbarname") == trayName)
  214.                         return this.mTrays[i];
  215.           }
  216.  
  217.         ]]></body>
  218.       </method>
  219.       <method name="getTrayByOrdinal">
  220.         <parameter name="trayOrdinal"/>
  221.         <body><![CDATA[
  222.  
  223.         for (var i =0; i < this.mTrays.length; i++)
  224.         {
  225.             if (this.mControlContainer.childNodes[i].getAttribute("ordinal") == trayOrdinal) {
  226.                 return this.getTrayByName(this.mControlContainer.childNodes[i].getAttribute("tooltiptext"));
  227.             }
  228.         }
  229.  
  230.         ]]></body>
  231.       </method>
  232.       <method name="propagateAttribute">
  233.         <parameter name="parent"/>
  234.         <parameter name="attributeName"/>
  235.         <parameter name="attributeValue"/>
  236.         <parameter name="depth"/>
  237.         <body><![CDATA[
  238.                 if(parent && depth > 0) {
  239.                     this.debug(parent.localName);
  240.                         if(parent.localName != "stack") {
  241.                             parent.setAttribute(attributeName, attributeValue);
  242.                             this.debug("-" + attributeName + " = " + parent.getAttribute(attributeName) + "(" + attributeValue + ")\n");
  243.                         }
  244.                         for(var thisChild = parent.firstChild; thisChild; thisChild = thisChild.nextSibling) {
  245.                             this.propagateAttribute(thisChild, attributeName, attributeValue, depth - 1);
  246.                         }
  247.                     }
  248.                 ]]></body>
  249.       </method>
  250.       <method name="showTray">
  251.         <parameter name="trayIndex"/>
  252.         <body><![CDATA[
  253.           this.debug("Trying to show tray numba : " + trayIndex + "\n");
  254.           if (this.mTrays.length <= trayIndex) return;
  255.           // save the old tray index
  256.           var oldTrayIndex = this.mTrayDeck.getAttribute('selectedIndex');
  257.           this.mTrayDeck.setAttribute('selectedIndex', trayIndex);
  258.  
  259.           var labelText = this.mTrays[trayIndex].getAttribute('toolbarname');
  260.           this.mLabel.setAttribute('value', labelText);
  261.  
  262.           //
  263.           // set attribute for selected control icon
  264.           //
  265.           if (oldTrayIndex != null) {
  266.             this.debug("The old tray was at index " + oldTrayIndex + "\n\n");
  267.             var oldTray = this.mControlContainer.childNodes[parseInt(oldTrayIndex)];
  268.             if (oldTray) {
  269.               this.debug("The old tray was an " + oldTray.localName + "\n\n");
  270.               this.debug("The old tray was called " + oldTray.getAttribute('toolbarname') + "\n\n");
  271.                              this.propagateAttribute(this.mTrays[parseInt(oldTrayIndex)], 'isActive', 'false', 5);
  272.               oldTray.setAttribute('selected', 'false');
  273.             }
  274.           }
  275.           this.mControlContainer.childNodes[this.currentTrayIndex].setAttribute('selected', 'true');
  276.           this.propagateAttribute(this.mTrays[this.currentTrayIndex], 'isActive', 'true', 5);
  277.  
  278.           // make sure the multibar label text isn't greyed out
  279.           this.mLabel.removeAttribute('rollover');
  280.  
  281.           // JMC: Persist this sucka
  282.           this.persist_prop('multibarselected', this.currentTrayIndex);
  283.  
  284.           this.setAttribute('currentIndex', this.currentTrayIndex);
  285.  
  286.         ]]></body>
  287.       </method>
  288.       <method name="showTrayByObj">
  289.         <parameter name="aTray"/>
  290.         <body><![CDATA[
  291.  
  292.                 for (var i = 0; i < this.mTrays.length; i++) {
  293.                     if (this.mTrays[i] == aTray) {
  294.                         this.showTray(i);
  295.                         return;
  296.                     }
  297.                 }
  298.  
  299.               ]]></body>
  300.       </method>
  301.       <method name="getIndexOfTray">
  302.         <parameter name="aTray"/>
  303.         <body><![CDATA[
  304.                 for (var i = 0; i < this.mTrays.length; i++) {
  305.                     if (this.mTrays[i] == aTray) {
  306.                         return i;
  307.                     }
  308.                 }
  309.                ]]></body>
  310.       </method>
  311.       <method name="isInvalidName">
  312.         <parameter name="aName"/>
  313.         <parameter name="aType"/>
  314.         <body><![CDATA[
  315.          var errorCode = null;
  316.            if (!aName) {
  317.                 errorCode = "empty";
  318.             } else if (aName.indexOf(",") > -1 || aName.indexOf("|") > -1 || aName.indexOf(":") > -1 ||
  319.                     aName.indexOf(";") > -1 || aName.indexOf(".")  > -1|| aName.indexOf("?") > -1) {
  320.                 errorCode = "invalid";
  321.             } else {
  322.                 for (var i =0; i < this.mTrays.length; i++) {
  323.                     if (this.mTrays[i].getAttribute("toolbarname") == aName) {
  324.                         // JMC/JVL - Don't show error if renaming same tray to same name
  325.                         if (this.mTrays[i] == this.currentTray && aType == "rename")
  326.                             errorCode = "rename";
  327.                         else
  328.                             errorCode = "duplicate";
  329.                     }
  330.                 }
  331.             }
  332.             return errorCode;
  333.  
  334.           ]]></body>
  335.       </method>
  336.       <method name="checkDelete">
  337.         <parameter name="aTrayIndex"/>
  338.         <body><![CDATA[
  339.             var msgTitle = "";
  340.             var msgText = "";
  341.             var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  342.                  .getService(Components.interfaces.nsIPromptService);
  343.                      msgTitle = "Confirm Delete Tray";
  344.                      msgText = "You are about to delete the tray " + this.mTrays[aTrayIndex].getAttribute('toolbarname')  +
  345.                      " permanently. Are you sure you wish to proceed?";
  346.  
  347.                return promptService.confirm(null, msgTitle, msgText);
  348.             ]]></body>
  349.       </method>
  350.       <method name="checkName">
  351.         <parameter name="aName"/>
  352.         <parameter name="aType"/>
  353.         <body><![CDATA[
  354.             var errorCode = null;
  355.             var msgTitle = "";
  356.             var msgText = "";
  357.             var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  358.                  .getService(Components.interfaces.nsIPromptService);
  359.             errorCode = this.isInvalidName(aName, aType);
  360.             if (errorCode) {
  361.                switch (errorCode) {
  362.                   case "empty":
  363.                   default:
  364.                      msgTitle = "Missing tray name";
  365.                      msgText = "Please enter a tray name.";
  366.                      break;
  367.  
  368.                   case "invalid":
  369.                      msgTitle = "Invalid tray name";
  370.                      msgText = "Tray names cannot contain these characters: ',', '&', '=', ':', ';', '?'.";
  371.                      break;
  372.  
  373.                   case "duplicate":
  374.                      msgTitle = "Duplicate tray name";
  375.                      msgText = "You cannot have two trays with the same name.";
  376.                      break;
  377.  
  378.                   case "rename":
  379.                      return false;
  380.                }
  381.                promptService.alert(null, msgTitle, msgText);
  382.                return false;
  383.             }
  384.             return true;
  385.             ]]></body>
  386.       </method>
  387.       <method name="addNewTray">
  388.         <parameter name="trayName"/>
  389.         <parameter name="bSuppressOrdinal"/>
  390.         <body><![CDATA[
  391.  
  392.           trayName = trayName.replace(/^\s+/, "").replace(/\s+$/, "");
  393.  
  394.                 if (this.mTrays.length > 9) {
  395.                     var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  396.                     .getService(Components.interfaces.nsIPromptService);
  397.                     var msgTitle = "Too many trays";
  398.                     var msgText = "You can have only 10 trays per multibar. \nTry creating a new multibar, \nor remove some of your existing trays.";
  399.                     promptService.alert(null, msgTitle, msgText);
  400.                     return false;
  401.  
  402.                 } else if (!this.checkName(trayName, 'add')) {
  403.                     this.debug('Bad tray name!!!\n');
  404.               return null;
  405.             }
  406.  
  407.           this.debug("\nAdding a tray named : " + trayName + "\n\n");
  408.           var trayId = trayName.replace(/\s/g,"_");
  409.             //*
  410.             //* add tray control button
  411.             //*
  412.             // create image elem
  413.             var newImage = document.createElement('image');
  414.             newImage.setAttribute('class', 'multibar-control-btn-icon');
  415.             // create label elem
  416.             var newLabel = document.createElement('label');
  417.             newLabel.setAttribute('class', 'multibar-control-btn-label');
  418.             // create stack elem and attach children
  419.             var newStack = document.createElement('stack');
  420.             newLabel.setAttribute('value', this.mControlContainer.childNodes.length + 1);
  421.             newStack.appendChild(newImage);
  422.             newStack.appendChild(newLabel);
  423.             // create toolbarbutton elem and attach stack
  424.  
  425.             var newButton = document.createElement('toolbarbutton');
  426.             newButton.setAttribute('trayIndex', this.mControlContainer.childNodes.length);
  427.             newButton.setAttribute('tooltiptext', trayName);
  428.             newButton.setAttribute('trayName', trayId);
  429.             newButton.setAttribute('onmouseover', "var mb=this; while (mb.localName!='multibar') mb=mb.parentNode; mb.changeLabel(this);");
  430.             newButton.setAttribute('onmouseout', "var mb=this; while (mb.localName!='multibar') mb=mb.parentNode; mb.changeLabel();");
  431.  
  432.             newButton.appendChild(newStack);
  433.  
  434.  
  435.             // append new tray control
  436.             this.mControlContainer.appendChild(newButton);
  437.  
  438.           //*
  439.           //* add tray
  440.           //*
  441.           // create multibar tray elem
  442.           var newTray = document.createElement('multibartray');
  443.           newTray.setAttribute('toolbarname', trayName);
  444.           newTray.setAttribute("customizable", "true");
  445.           suffix = (new Date()).getTime()+this.childNodes.length;
  446.           newTray.id = this.getAttribute("toolbarname").replace(/\s/g,"_") + "_" + trayId;
  447.  
  448.           // append the new tray
  449.           this.appendChild(newTray);
  450.           if (!bSuppressOrdinal)
  451.               this.assignOrdinal(newTray);
  452.  
  453.           this.reorderTrays();
  454.           this.persist_prop('multibar', this.getAttribute('toolbarname') + ":" + this.currentSet);
  455.           // select the newly added tray
  456.           if (!bSuppressOrdinal)
  457.               this.showTray(this.mControlContainer.childNodes.length-1);
  458.  
  459.           this.printControl();
  460.           this.debug('number of trays: ' + this.childNodes.length + '\n');
  461.           return newTray;
  462.         ]]></body>
  463.       </method>
  464.       <method name="changeLabel">
  465.         <parameter name="aButton"/>
  466.         <body><![CDATA[
  467.      var labelText;
  468.  
  469.          if (aButton && (aButton != this.mCurrentControlButton)) {
  470.              labelText = aButton.getAttribute('tooltiptext');
  471.              this.mLabel.setAttribute("rollover", "true");
  472.          } else {
  473.              labelText = this.currentTray.getAttribute('toolbarname');
  474.              this.mLabel.removeAttribute("rollover");
  475.          }
  476.          this.mLabel.setAttribute('value', labelText);
  477.      ]]></body>
  478.       </method>
  479.       <method name="insertItem">
  480.         <parameter name="aId"/>
  481.         <parameter name="aBeforeElt"/>
  482.         <parameter name="aWrapper"/>
  483.         <parameter name="aBeforePermanent"/>
  484.         <body><![CDATA[
  485.  
  486.             // Just insert this to the current tray
  487.             var newItem = this.mTrays[this.currentTrayIndex].insertItem(aId, aBeforeElt, aWrapper, aBeforePermanent);
  488.             this.setAttribute("currentset",this.currentSet);
  489.             return newItem;
  490.           ]]></body>
  491.       </method>
  492.       <method name="renameTray">
  493.         <parameter name="trayIndex"/>
  494.         <parameter name="trayName"/>
  495.         <body><![CDATA[
  496.         
  497.         // JMC - If this tray is showing the search widget, update the toolbarset to point to its' new toolbarname_
  498.         
  499.         var oldTrayId = this.mTrays[trayIndex].id;
  500.  
  501.           trayName = trayName.replace(/^\s+/, "").replace(/\s+$/, "");
  502.           trayId = trayName.replace(/\s/g,"_");
  503.  
  504.           if (!this.checkName(trayName, 'rename')) {
  505.             return false;
  506.           }
  507.           // change the tray name attribute
  508.           this.mTrays[trayIndex].setAttribute('toolbarname', trayName);
  509.           this.mTrays[trayIndex].id = trayId;
  510.  
  511.         if (this.toolbox.toolbarset.getAttribute('showsearch') == oldTrayId) {
  512.             this.toolbox.toolbarset.setAttribute('showsearch', trayId);
  513.             document.persist(this.toolbox.toolbarset.id, "showsearch");
  514.         }
  515.  
  516.           // change the control button tooltip
  517.           this.mControlContainer.childNodes[trayIndex].setAttribute('tooltiptext', trayName);
  518.           this.mControlContainer.childNodes[trayIndex].setAttribute('trayName', trayId);
  519.  
  520.           // change the control label if current tray
  521.           if(trayIndex == this.currentTrayIndex) {
  522.             this.mLabel.setAttribute('value', trayName);
  523.           }
  524.           this.setAttribute('currentset', this.currentSet);
  525.           this.reorderTrays();
  526.           this.persist_prop('multibar', this.getAttribute('toolbarname') + ":" + this.currentSet);
  527.           return true;
  528.  
  529.         ]]></body>
  530.       </method>
  531.       <method name="deleteTrayByObj">
  532.         <parameter name="trayObj"/>
  533.         <parameter name="aForce"/>
  534.         <body><![CDATA[
  535.  
  536.                this.deleteTray(this.getIndexOfTray(trayObj), aForce);
  537.  
  538.                 ]]></body>
  539.       </method>
  540.       <method name="deleteTray">
  541.         <parameter name="trayIndex"/>
  542.         <parameter name="aForce"/>
  543.         <body><![CDATA[
  544.  
  545.                if (!aForce && !this.checkDelete(trayIndex)) // Early exit prevents prompting
  546.                {
  547.                    return false;
  548.                }
  549.  
  550.             var oldOrdinal = this.mControlContainer.childNodes[trayIndex].getAttribute("ordinal");
  551.          var currentOrdinal = this.mControlContainer.childNodes[this.currentTrayIndex].getAttribute("ordinal");
  552.          this.debug("MULTIBAR: doing delete, old currentset is : " + this.currentSet + "\n\n");
  553.  
  554.          var orderSplit = this.currentSet.split(";");
  555.          orderSplit.splice(oldOrdinal,1);
  556.          this.debug("MULTIBAR: doing delete, new currentset is : " + orderSplit.join(";") + "\n\n");
  557.          this.setAttribute("currentset", orderSplit.join(";"));
  558.  
  559.           this.reorderTrays();
  560.  
  561.           // remove the tray from multibar
  562.           this.removeChild(this.mTrays[trayIndex]);
  563.  
  564.           // remove the control button
  565.           this.mControlContainer.removeChild(this.mControlContainer.childNodes[trayIndex]);
  566.  
  567.           // Reset the trayIndex attribute in case delete or add has changed them
  568.           for (var i=0; i < this.mTrays.length; i++)
  569.           {
  570.             this.mControlContainer.childNodes[i].setAttribute('trayIndex', i);
  571.           }
  572.  
  573.             // Get tray with ordinal one less than this one
  574.             if (oldOrdinal <= currentOrdinal)
  575.           this.showTrayByObj(this.getTrayByOrdinal((oldOrdinal > 0) ? (oldOrdinal - 1) : 0));
  576.          else
  577.           this.showTrayByObj(this.getTrayByOrdinal(currentOrdinal));
  578.  
  579.  
  580.           this.persist_prop('multibar', this.getAttribute('toolbarname') + ":" + this.currentSet);
  581.  
  582.           return true;
  583.         ]]></body>
  584.       </method>
  585.       <method name="showPopup">
  586.         <body><![CDATA[
  587.           this.debug('***** showPopup() *******\n');
  588.           var dropmarker = this.mMenuDropMarker;
  589.           var popup = document.getElementById('multibarMenu');
  590.  
  591.                     //
  592.                     // first delete all menuitems associated with trays
  593.                     //
  594.                     this.debug('**** number of trays: ' + this.mTrays.length + '\n');
  595.                     while(popup.firstChild.hasAttribute("trayOrdinal")) {
  596.                         popup.removeChild(popup.firstChild);
  597.                     }
  598.  
  599.                     //
  600.                     // add a menuitem for each tray
  601.                     //
  602.                     var traySeparatorItem = popup.firstChild;
  603.                     var menuitem;
  604.                     for(var j = 0; j < this.mTrays.length; j++) {
  605.                         menuitem = document.createElement("menuitem");
  606.                         menuitem.setAttribute("type", "checkbox");
  607.                         menuitem.setAttribute("label", this.mControlContainer.childNodes[this.ordinalToIndex(j)].getAttribute("trayName"));
  608.                         menuitem.setAttribute("trayOrdinal", j);
  609.                         if(this.ordinalToIndex(j) == this.currentTrayIndex) {
  610.                             menuitem.setAttribute("checked", "true");
  611.                         }
  612.                         popup.insertBefore(menuitem, traySeparatorItem);
  613.                     }
  614.           /*
  615.           // check/uncheck Show Tray Title menu item
  616.           var showTrayTitleMenuItem = document.getElementById('multibarShowTrayTitleMenuItem');
  617.           if(this.showTrayTitle)
  618.           {
  619.             showTrayTitleMenuItem.setAttribute('checked', 'true');
  620.           }
  621.           else
  622.           {
  623.             showTrayTitleMenuItem.removeAttribute('checked');
  624.           }
  625.           */
  626.  
  627.           popup.multibar = this;
  628.           this.debug("x: "+ dropmarker.boxObject.screenX + " y: " + dropmarker.boxObject.screenY + dropmarker.boxObject.height);
  629.           popup.showPopup(dropmarker,
  630.                           -1,
  631.                           -1,
  632.                           "popup", "bottomleft", "topleft");
  633.         ]]></body>
  634.       </method>
  635.       <method name="menuCommand">
  636.         <parameter name="event"/>
  637.         <body><![CDATA[
  638.             if(event.target.hasAttribute("trayOrdinal")) {
  639.                 this.showTray(this.ordinalToIndex(event.target.getAttribute("trayOrdinal")));
  640.           } else if(event.target.id == "multibarAddMenuItem") {
  641.             window.openDialog("chrome://global/content/addRenameTrayDialog.xul", "addRenameTrayDialog",
  642.                               "centerscreen,modal=yes", 'add', this);
  643.           } else if(event.target.id == "multibarRenameMenuItem") {
  644.             window.openDialog("chrome://global/content/addRenameTrayDialog.xul", "addRenameTrayDialog",
  645.                               "centerscreen,modal=yes", 'rename', this);
  646.           } else if(event.target.id == "multibarEditMenuItem") {
  647.             window.openDialog("chrome://global/content/editTrayDialog.xul", "editTrayDialog",
  648.                               "centerscreen,modal=yes", this);
  649.           } else if(event.target.id == "multibarShowTrayTitleMenuItem") {
  650.           this.debug("Toggling show title\n");
  651.             this.showTrayTitle = !this.showTrayTitle;
  652.           } else if(event.target.id == "multibarCustomizeMenuItem") {
  653.             BrowserCustomizeToolbar();
  654.           }
  655.         ]]></body>
  656.       </method>
  657.       <!-- debug -->
  658.       <method name="printControl">
  659.         <body><![CDATA[
  660.           if(!this.mControlContainer) {
  661.             this.debug('Can not find the control\n');
  662.             return;
  663.           }
  664.  
  665.           this.debug('number of controls: ' + this.mControlContainer.childNodes.length + '\n');
  666.         ]]></body>
  667.       </method>
  668.       <method name="reorderTrays">
  669.         <body><![CDATA[
  670.           this.debug("multibar: gonna reorder Trays\n\n");
  671.               var thisChild = this.firstChild;
  672.               while (thisChild) {
  673.                   if (thisChild.localName == 'multibartray') {
  674.                       thisChild.removeAttribute('ordinal');
  675.                   }
  676.                   thisChild = thisChild.nextSibling;
  677.               }
  678.  
  679.               var orderSplit = this.getAttribute("currentset").split(";");
  680.               var ordinalCount = 0;
  681.               for (var i = 0; i < orderSplit.length; i++) {
  682.                   var trayCSet = orderSplit[i];
  683.                   var trayName = trayCSet.split(":").shift();
  684.                   this.debug ("Trying to find the tray called : " + trayName + "\n\n");
  685.                    this.debug("multibar: Looking for button with trayName " + trayName + "\n\n");
  686.                   var thisButton = document.getAnonymousElementByAttribute(this, "tooltiptext", trayName);
  687.                   if (thisButton)
  688.                   {
  689.                     this.debug("multibar: Setting ordinal " + (ordinalCount) + "\n\n");
  690.                     thisButton.setAttribute('ordinal', ordinalCount);
  691.                     thisButton.childNodes[0].childNodes[1].setAttribute('value', ordinalCount+1);
  692.                     ordinalCount++;
  693.                   }
  694.               }
  695.           ]]></body>
  696.       </method>
  697.       <method name="assignOrdinal">
  698.         <parameter name="aTray"/>
  699.         <body><![CDATA[
  700.                 var barOrder = this.getAttribute("currentset");
  701.                 this.setAttribute("currentset", barOrder + ";"
  702.                 + aTray.getAttribute("toolbarname") + ":"
  703.                 + aTray.currentSet);
  704.  
  705.          ]]></body>
  706.       </method>
  707.       <method name="moveTrayUp">
  708.         <parameter name="aTray"/>
  709.         <body><![CDATA[
  710.           var orderSplit = this.currentSet.split(";");
  711.           var currentIndex;
  712.           var trayCSet;
  713.           for (var i=0; i < orderSplit.length; i++) {
  714.               trayCSet = orderSplit[i];
  715.               var trayName = trayCSet.split(":").shift();
  716.                if (trayName == aTray.getAttribute("toolbarname")) {
  717.                   currentIndex = i;
  718.                   break;
  719.                }
  720.           }
  721.  
  722.           if (currentIndex > 0) {
  723.               var previousTrayCSet = orderSplit[currentIndex - 1];
  724.               var previousTrayName = previousTrayCSet.split(":").shift();
  725.               orderSplit[currentIndex] = previousTrayCSet;
  726.               orderSplit[currentIndex - 1] = trayCSet;
  727.  
  728.               this.setAttribute("currentset", orderSplit.join(";"));
  729.               // this.parentNode.setAttribute("currentset", this.parentNode.getAttribute("currentSet"));
  730.                this.reorderTrays();
  731.             this.persist_prop('multibar', this.getAttribute('toolbarname') + ":" + this.currentSet);
  732.             this.persist_prop('multibarselected', this.currentTrayIndex);
  733.             this.persist_prop('currentIndex', this.currentTrayIndex);
  734.           }
  735.  
  736.           ]]></body>
  737.       </method>
  738.       <method name="moveTrayDown">
  739.         <parameter name="aTray"/>
  740.         <body><![CDATA[
  741.           var orderSplit = this.currentSet.split(";");
  742.           var currentIndex;
  743.           var trayCSet;
  744.           for (var i=0; i < orderSplit.length; i++) {
  745.               trayCSet = orderSplit[i];
  746.               var trayName = trayCSet.split(":").shift();
  747.                if (trayName == aTray.getAttribute("toolbarname")) {
  748.                   currentIndex = i;
  749.                   break;
  750.                }
  751.           }
  752.  
  753.           if (currentIndex < orderSplit.length - 1) {
  754.               var previousTrayCSet = orderSplit[currentIndex + 1];
  755.               var previousTrayName = previousTrayCSet.split(":").shift();
  756.               orderSplit[currentIndex] = previousTrayCSet;
  757.               orderSplit[currentIndex + 1] = trayCSet;
  758.  
  759.               this.setAttribute("currentset", orderSplit.join(";"));
  760.               // this.parentNode.setAttribute("currentset", this.parentNode.getAttribute("currentSet"));
  761.                this.reorderTrays();
  762.             this.persist_prop('multibar', this.getAttribute('toolbarname') + ":" + this.currentSet);
  763.             this.persist_prop('multibarselected', this.currentTrayIndex);
  764.             this.persist_prop('currentIndex', this.currentTrayIndex);
  765.           }
  766.  
  767.           ]]></body>
  768.       </method>
  769.       <method name="ordinalToIndex">
  770.         <parameter name="aOrdinal"/>
  771.         <body><![CDATA[
  772.               for(var i = 0; i < this.mTrays.length; i++) {
  773.                   if(aOrdinal == this.mControlContainer.childNodes[i].getAttribute('ordinal'))
  774.                       return i;
  775.               }
  776.               this.debug("**** ERROR - could not find ordinal!\n");
  777.           ]]></body>
  778.       </method>
  779.     </implementation>
  780.     <content>
  781.       <xul:hbox class="multibar toolbar-left-margin  toolbar-right-margin" flex="1">
  782.          
  783.         <xul:vbox class="multibar-main-control" align="stretch" pack="stretch">
  784.           <xul:button tooltiptext="&multibarDropDown.tooltiptext;" anonid="spawnPopup" class="multibar-top-button-target " align="stretch" pack="end" flex="1">
  785.           <xul:stack align="stretch" pack="stretch" flex="1">
  786.             <xul:vbox align="stretch" pack="stretch" flex="1">
  787.               <xul:hbox class="multibar-main-button"/>
  788.               <xul:hbox class="multibar-main-horiz-line" align="stretch" pack="stretch" flex="1"/>
  789.             </xul:vbox>
  790.             <xul:hbox class="multibar-label-and-drop" align="center" pack="end">
  791.               <xul:spacer flex="1"/>
  792.                 <xul:label anonid="multibar-tray-label" class="multibar-tray-label" crop="end" />
  793.               <xul:spacer flex="1"/>
  794.               <xul:image class="multibar-drop" context=""/>
  795.             </xul:hbox>
  796.           </xul:stack>
  797.           </xul:button>
  798.           <xul:hbox pack="end">
  799.             <xul:toolbarbutton tooltiptext="&multibarLeftButton.tooltiptext;" class="multibar-left-button" prevTray="true" context=""/>
  800.             <xul:toolbarbutton tooltiptext="&multibarRightButton.tooltiptext;" class="multibar-right-button" nextTray="true"  context=""/>
  801.           </xul:hbox>
  802.         </xul:vbox>
  803.        
  804.         
  805.         <xul:vbox style="display:none;" anonid="multibar-control" class="multibar-control"
  806.               align="center" pack="center">
  807.               <xul:hbox align="start" pack="center">
  808.                 <xul:label anonid="multibar-tray-label-old" class="multibar-tray-label-old"
  809.                   crop="end"/>
  810.               </xul:hbox>
  811.               <xul:hbox anonid="multibar-control-container" class="multibar-control-container"
  812.                 align="center" pack="center"/>
  813.             </xul:vbox>       
  814.         
  815.         <xul:vbox flex="1">
  816.           <xul:hbox class="multibartray-top-edge" align="stretch" pack="stretch"/>
  817.             <xul:hbox pack="stretch" flex="10">
  818.             <xul:hbox anonid="multibar-searchbar-parent"/>
  819.             <xul:deck anonid="multibar-deck" flex="10" class="multibar-deck" selectedIndex="0">
  820.               <children/>
  821.             </xul:deck>
  822.             </xul:hbox>
  823.         <xul:hbox class="multibartray-bottom-edge" align="stretch" pack="stretch"/>
  824.         </xul:vbox>
  825.         <xul:hbox>
  826.           <xul:vbox pack="stretch" align="stretch">
  827.             <xul:hbox class="multibar-ctl-right-top">
  828.               <xul:image/>
  829.             </xul:hbox>
  830.             <xul:hbox class="multibar-ctl-right-middle" flex="1"/>
  831.             <xul:hbox class="multibar-ctl-right-bottom">
  832.               <xul:image/>
  833.             </xul:hbox>
  834.           </xul:vbox>
  835.         </xul:hbox>
  836.       </xul:hbox>
  837.     </content>
  838.     <handlers>
  839.       <handler event="command"><![CDATA[
  840.  
  841.         if (event.originalTarget.hasAttribute('trayIndex')) {
  842.           this.debug('catch all command handler\n');
  843.           var idx = parseInt(event.originalTarget.getAttribute('trayIndex'));
  844.           this.showTray(idx);
  845.  
  846.           /*
  847.           if (idx >= this.mTrays.length-1) {
  848.             this.showTray(0);
  849.             this.showTrayTitle = false;
  850.           } else {
  851.             this.showTray(idx + 1);
  852.             this.showTrayTitle = true;
  853.           }
  854.           */
  855.         }
  856.  
  857.         if(event.originalTarget.hasAttribute('nextTray')) {
  858.               var newOrdinal;
  859.                     if(this.currentTrayOrdinal == this.mTrays.length - 1) {
  860.                         newOrdinal = 0;
  861.                     } else {
  862.                         newOrdinal = parseInt(this.currentTrayOrdinal) + 1;
  863.                     }
  864.                     showTrayByObj(this.getTrayByOrdinal(newOrdinal));
  865.         } else if(event.originalTarget.hasAttribute('prevTray')) {
  866.               var newOrdinal;
  867.                     if(this.currentTrayOrdinal == 0) {
  868.                         newOrdinal = this.mTrays.length - 1;
  869.                     } else {
  870.                         newOrdinal = parseInt(this.currentTrayOrdinal) - 1;
  871.                     }
  872.                     showTrayByObj(this.getTrayByOrdinal(newOrdinal));
  873.         }
  874.       ]]></handler>
  875.       <handler event="click" button="0"><![CDATA[
  876.         // if(event.originalTarget.parentNode == this.mMenuDropMarker) {
  877.         if(event.originalTarget == this.mMenuDropMarker) {
  878.           this.showPopup();
  879.         }
  880.         event.preventBubble();
  881.       ]]></handler>
  882.       <handler event="click" button="2"><![CDATA[
  883.         // MERC (rpaul) prevent multibar dropmarker menu and toolbar
  884.         // contect menu from simultaneously appearing
  885.         // if(event.originalTarget.parentNode == this.mMenuDropMarker) {
  886.         if(event.originalTarget == this.mMenuDropMarker) {
  887.           return;
  888.         }
  889.         event.preventBubble();
  890.       ]]></handler>
  891.     </handlers>
  892.   </binding>
  893.   <binding id="multibartray" extends="chrome://global/content/bindings/toolbar.xml#toolbar-overflow">
  894.     <content>
  895.       <xul:hbox flex="1" class="multibartray-left-margin">
  896.           <xul:hbox flex="1" align="center" class="toolbar-inner-container ">
  897.             <children/>
  898.           </xul:hbox>
  899.         <xul:toolbarbutton anonid="overflow-button" type="menu" class="toolbar-overflow-button"
  900.           hidden="true">
  901.           <xul:menupopup anonid="overflow-menu" class="toolbar-overflow-menu"/>
  902.         </xul:toolbarbutton>
  903.       </xul:hbox>
  904.     </content>
  905.     <implementation>
  906.       <property name="mode" onget="return this.parentNode.getAttribute('mode');"/>
  907.       <property name="iconsize" onget="return this.parentNode.getAttribute('iconsize');"/>
  908.       <constructor><![CDATA[
  909.           this.debug("MULTIBARTRAY : Constructor, localName : " + this.localName + "\n");
  910.           ]]></constructor>
  911.     </implementation>
  912.   </binding>
  913. </bindings>
  914.