home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / toolkit.jar / content / global / consoleBindings.xml < prev    next >
Encoding:
Extensible Markup Language  |  2001-08-04  |  15.4 KB  |  442 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE window SYSTEM "chrome://global/locale/console.dtd">
  4.  
  5. <bindings id="consoleBindings"
  6.           xmlns="http://www.mozilla.org/xbl"
  7.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  8.  
  9.   <binding id="console-box" extends="xul:box">
  10.     <content>  
  11.       <xul:stringbundle src="chrome://global/locale/console.properties" role="string-bundle"/>
  12.       <xul:box class="console-box-internal" flex="1">
  13.         <xul:vbox class="console-rows" flex="1" role="console-rows"/>
  14.       </xul:box>
  15.     </content>
  16.   
  17.     <implementation>
  18.     
  19.       <property name="count">
  20.         <getter>return this.mCount</getter>
  21.       </property>
  22.     
  23.       <property name="mode">
  24.         <getter>return this.mMode;</getter>
  25.         <setter><![CDATA[
  26.           this.mMode = val ? val : "All";
  27.           this.setAttribute("mode", this.mMode);
  28.         ]]></setter>
  29.       </property>
  30.     
  31.       <property name="sortOrder">
  32.         <getter>return this.mSort</getter>
  33.         <setter><![CDATA[
  34.           if (this.mSort != val) {
  35.             this.mSort = val == -1 ? -1 : 1;
  36.             this.setAttribute("sortOrder", this.mSort);
  37.             this.reverseRows();
  38.           }
  39.         ]]></setter>
  40.       </property>
  41.     
  42.       <property name="selectedItem">
  43.         <getter>return this.mSelectedItem</getter>
  44.         <setter><![CDATA[
  45.           if (this.mSelectedItem)
  46.             this.mSelectedItem.removeAttribute("selected");
  47.           
  48.           this.mSelectedItem = val;
  49.           val.setAttribute("selected", "true");
  50.         ]]></setter>
  51.       </property>
  52.     
  53.       <method name="init">
  54.         <body><![CDATA[
  55.           this.mCount = 0;
  56.           
  57.           this.mConsoleListener = {
  58.             console: this, 
  59.             observe : function(aObject) { this.console.appendItem(aObject); }
  60.           };
  61.           
  62.           this.mConsoleRowBox = this.getAnonElByAttr("role", "console-rows");
  63.           this.mStrBundle = this.getAnonElByAttr("role", "string-bundle");
  64.           
  65.           try {
  66.             var isupports = Components.classes['@mozilla.org/consoleservice;1'].getService();
  67.             this.mCService = isupports.QueryInterface(Components.interfaces.nsIConsoleService);
  68.             this.mCService.registerListener(this.mConsoleListener);
  69.           } catch (ex) {
  70.             appendItem(
  71.               "Unable to display errors - couldn't get Console Service component. " +
  72.               "(Missing @mozilla.org/consoleservice;1)");
  73.             return;
  74.           }          
  75.                     
  76.           // initialize properties from attributes
  77.           this.mSort = this.getAttribute("sortOrder") == -1 ? -1 : 1;
  78.           
  79.           if (this.hasAttribute("mode"))
  80.             this.mMode = this.getAttribute("mode");
  81.           else
  82.             this.mMode = "All";
  83.  
  84.           this.appendInitialItems();
  85.         ]]></body>
  86.       </method>
  87.     
  88.       <method name="destroy">
  89.         <body><![CDATA[
  90.           this.mCService.unregisterListener(this.mConsoleListener);
  91.         ]]></body>
  92.       </method>
  93.     
  94.       <method name="appendInitialItems">
  95.         <body><![CDATA[
  96.           var out = {}; // Throwaway references to support 'out' parameters.
  97.           this.mCService.getMessageArray(out, {});
  98.           var messages = out.value;
  99.       
  100.           // In case getMessageArray returns 0-length array as null
  101.           if (!messages)
  102.             messages = [];
  103.       
  104.           var i;
  105.           var cleared = 0;
  106.         
  107.           // Checks if console ever been cleared
  108.           for (i = messages.length-1; i >=0 ; --i) { 
  109.             if (messages[i].message == "__CLEAR__") {
  110.               cleared = i + 1;
  111.               break;
  112.             }
  113.           }
  114.         
  115.           // Populates tree with error messages after latest "clear"
  116.           for (i = cleared; i < messages.length; ++i)
  117.             this.appendItem(messages[i]);
  118.         ]]></body>
  119.       </method>
  120.  
  121.       <method name="appendItem">
  122.         <parameter name="aObject"/>
  123.         <body><![CDATA[
  124.           if (aObject.message == "__CLEAR__") return;
  125.  
  126.           try {
  127.             // Try to QI it to a script error to get more info
  128.             var scriptError = aObject.QueryInterface(Components.interfaces.nsIScriptError);
  129.             this.appendError(scriptError);
  130.           } catch (ex) {
  131.             try {
  132.               // Try to QI it to a console message
  133.               var msg = aObject.QueryInterface(Components.interfaces.nsIConsoleMessage);
  134.               this.appendMessage(msg.message);
  135.             } catch (ex2) {
  136.               // Give up and append the object itself as a string
  137.               this.appendMessage(aObject);
  138.             }
  139.           }
  140.         ]]></body>
  141.       </method>
  142.  
  143.       <method name="appendError">
  144.         <parameter name="aObject"/>
  145.         <body><![CDATA[
  146.           var row = this.createConsoleRow();
  147.           var nsIScriptError = Components.interfaces.nsIScriptError;
  148.           
  149.           // Is this error actually just a non-fatal warning?
  150.           var warning = aObject.flags & nsIScriptError.warningFlag != 0;
  151.   
  152.           var typetext = warning ? "typeWarning" : "typeError";
  153.           row.setAttribute("typetext", this.mStrBundle.getString(typetext));
  154.           row.setAttribute("type", warning ? "warning" : "error");
  155.           row.setAttribute("msg", aObject.message);
  156.           if (aObject.lineNumber || aObject.sourceName) {
  157.             row.setAttribute("url", aObject.sourceName);
  158.             row.setAttribute("line", aObject.lineNumber);
  159.           } else {
  160.             row.setAttribute("hideSource", "true");
  161.           }
  162.           if (aObject.sourceLine) {
  163.             row.setAttribute("code", aObject.sourceLine.replace("\n", "", "g"));
  164.             if (aObject.columnNumber) {
  165.               row.setAttribute("col", aObject.columnNumber);
  166.               row.setAttribute("errorDots", this.repeatChar(" ", aObject.columnNumber));
  167.               row.setAttribute("errorCaret", " ");
  168.             } else {
  169.               row.setAttribute("hideCaret", "true");
  170.             }
  171.           } else {
  172.             row.setAttribute("hideCode", "true");
  173.           }
  174.           this.appendConsoleRow(row);
  175.         ]]></body>
  176.       </method>
  177.             
  178.       <method name="appendMessage">
  179.         <parameter name="aMessage"/>
  180.         <parameter name="aType"/>
  181.         <body><![CDATA[
  182.           var row = this.createConsoleRow();
  183.           row.setAttribute("type", aType ? aType : "message");
  184.           row.setAttribute("msg", aMessage);
  185.           this.appendConsoleRow(row);
  186.         ]]></body>
  187.       </method>
  188.       
  189.       <method name="clear">
  190.         <body><![CDATA[
  191.           this.mCService.logStringMessage("__CLEAR__");
  192.           this.mCount = 0;
  193.           
  194.           var newRows = this.createConsoleRowBox();
  195.           this.mConsoleRowBox.parentNode.replaceChild(newRows, this.mConsoleRowBox);
  196.           this.mConsoleRowBox = newRows;
  197.         ]]></body>
  198.       </method>
  199.             
  200.       <method name="copySelectedItem">
  201.         <body><![CDATA[
  202.           if (this.mSelectedItem)
  203.             this.copyString(this.mSelectedItem.toString());
  204.         ]]></body>
  205.       </method>
  206.  
  207.       <method name="createConsoleRowBox">
  208.         <body><![CDATA[
  209.           var box = document.createElement("box");
  210.           box.setAttribute("class", "console-rows");
  211.           box.setAttribute("orient", "vertical");
  212.           box.setAttribute("flex", "1");
  213.           return box;
  214.         ]]></body>
  215.       </method>
  216.                   
  217.       <method name="createConsoleRow">
  218.         <body><![CDATA[
  219.           var row = document.createElement("box");
  220.           row.setAttribute("class", "console-row");
  221.           row._IsConsoleRow = true;
  222.           row._ConsoleBox = this;
  223.           return row;
  224.         ]]></body>
  225.       </method>
  226.             
  227.       <method name="appendConsoleRow">
  228.         <parameter name="aRow"/>
  229.         <body><![CDATA[
  230.           if (this.mSort == 1) {
  231.             this.mConsoleRowBox.appendChild(aRow);
  232.           } else if (this.mSort == -1) {
  233.             if (this.mConsoleRowBox.childNodes.length == 0)
  234.               this.mConsoleRowBox.appendChild(aRow);
  235.             else
  236.               this.mConsoleRowBox.insertBefore(aRow, this.mConsoleRowBox.firstChild);
  237.           }
  238.                     
  239.           ++this.mCount;
  240.           if (this.mCount > 250) this.deleteFirst();
  241.         ]]></body>
  242.       </method>
  243.             
  244.       <method name="deleteFirst">
  245.         <body><![CDATA[
  246.           var node = this.mConsoleRowBox.firstChild;
  247.           this.mConsoleRowBox.removeChild(node);
  248.           --this.mCount;
  249.         ]]></body>
  250.       </method>
  251.             
  252.       <method name="reverseRows">
  253.         <body><![CDATA[
  254.           var box = this.mConsoleRowBox;
  255.           var row;
  256.           for (var i = 0; i < box.childNodes.length; ++i) {
  257.             row = box.firstChild;
  258.             box.removeChild(row);
  259.             if (i == 0)
  260.               box.appendChild(row);
  261.             else
  262.               box.insertBefore(row, box.childNodes[box.childNodes.length - i]);
  263.           }
  264.         ]]></body>
  265.       </method>
  266.       
  267.       <!-- UTILITY FUNCTIONS -->
  268.       
  269.       <!-- We need this method only because document.getAnonymousElementByAttribute 
  270.           is crashing (as of 2/26/2001) -->
  271.       <method name="getAnonElByAttr">
  272.         <parameter name="aAttr"/>
  273.         <parameter name="aVal"/>
  274.         <body><![CDATA[
  275.           var kids = document.getAnonymousNodes(this);
  276.           for (var i = 0; i < kids.length; ++i) {
  277.             if (kids[i].getAttribute(aAttr) == aVal)
  278.               return kids[i];
  279.             var kids2 = kids[i].getElementsByAttribute(aAttr, aVal);
  280.             if (kids2.length > 0)
  281.               return kids2[0];
  282.           }
  283.           return null;
  284.         ]]></body>
  285.       </method>
  286.  
  287.       <method name="repeatChar">
  288.         <parameter name="aChar"/>
  289.         <parameter name="aCol"/>
  290.         <body><![CDATA[
  291.           var str = "";
  292.           if (aCol)
  293.             for (var i = 1; i < aCol; ++i)
  294.               str += aChar;
  295.           
  296.           return str;
  297.         ]]></body>
  298.       </method>
  299.           
  300.       <method name="copyString">
  301.         <parameter name="aString"/>
  302.         <body><![CDATA[
  303.           try {
  304.             const clipURI = "@mozilla.org/widget/clipboard;1";
  305.             const clipI = Components.interfaces.nsIClipboard;
  306.             var clipboard = Components.classes[clipURI].getService(clipI);
  307.           
  308.             const transURI = "@mozilla.org/widget/transferable;1";
  309.             var transferable = Components.classes[transURI].createInstance(Components.interfaces.nsITransferable);
  310.           
  311.             transferable.addDataFlavor("text/unicode");
  312.             
  313.             const strURI = "@mozilla.org/supports-wstring;1";
  314.             var wstring = Components.classes[strURI].createInstance(Components.interfaces.nsISupportsWString);
  315.             
  316.             wstring.data = aString;
  317.             transferable.setTransferData("text/unicode", wstring, aString.length * 2);
  318.             clipboard.setData(transferable, null, clipI.kGlobalClipboard);
  319.           } catch (ex) {
  320.             // Unable to copy anything, die quietly
  321.           }
  322.         ]]></body>
  323.       </method>
  324.  
  325.       <constructor> this.init(); </constructor>
  326.       <destructor> this.destroy(); </destructor>
  327.     </implementation>
  328.     
  329.     <handlers>
  330.       <handler event="mousedown"><![CDATA[
  331.         if (event.button == 0 || event.button == 2) {
  332.           var target = event.originalTarget;
  333.   
  334.           while (target && !("_IsConsoleRow" in target))
  335.             target = target.parentNode;
  336.  
  337.           if (target)
  338.             this.selectedItem = target;
  339.         }
  340.       ]]></handler>
  341.     </handlers>
  342.   </binding>
  343.  
  344.   <binding id="error" extends="xul:box">
  345.     <content>
  346.       <xul:box class="console-row-internal-box" flex="1">
  347.         <xul:box class="console-row-icon" align="center" inherits="selected">
  348.           <xul:image class="console-icon" inherits="src,type"/>
  349.         </xul:box>
  350.         <xul:vbox class="console-row-content" inherits="selected" flex="1">
  351.           <xul:box class="console-row-msg" align="start">
  352.             <xul:text class="label" inherits="value=typetext"/>
  353.             <xul:html class="console-error-msg" inherits="value=msg" flex="1"/>
  354.           </xul:box>
  355.           <xul:box class="console-row-file" inherits="hidden=hideSource">
  356.             <xul:text class="label" value="&errFile.label;"/>
  357.             <xul:box class="console-error-source" inherits="url"/>
  358.             <spring flex="1"/>
  359.             <xul:text class="label" value="&errLine.label;"/>
  360.             <xul:text class="label" inherits="value=line" flex="1"/>
  361.           </xul:box>
  362.           <xul:vbox class="console-row-code" inherits="selected,hidden=hideCode">
  363.             <xul:text class="monospace console-code" inherits="value=code"/>
  364.             <xul:box inherits="hidden=hideCaret">
  365.               <xul:text class="monospace console-dots" inherits="value=errorDots"/>
  366.               <xul:text class="monospace console-caret" inherits="value=errorCaret"/>
  367.               <xul:spring flex="1"/>
  368.             </xul:box>
  369.           </xul:vbox>
  370.         </xul:vbox>
  371.       </xul:box>
  372.     </content>
  373.  
  374.     <implementation>
  375.       
  376.       <method name="toString">
  377.         <body><![CDATA[
  378.           var msg = this.getAttribute("typetext") + " " + this.getAttribute("msg");
  379.           
  380.           var strBundle = this._ConsoleBox.mStrBundle;
  381.           
  382.           if (this.hasAttribute("line") && this.hasAttribute("url")) {
  383.             msg += "\n" + strBundle.getFormattedString("errFile", 
  384.                                         [this.getAttribute("url")]) + "\n";
  385.             if (this.hasAttribute("col")) {
  386.               msg += strBundle.getFormattedString("errLineCol",
  387.                          [this.getAttribute("line"), this.getAttribute("col")]);
  388.             } else
  389.               msg += strBundle.getFormattedString("errLine", [this.getAttribute("line")]);
  390.           }
  391.           
  392.           if (this.hasAttribute("code"))
  393.             msg += "\n" + strBundle.getString("errCode") + "\n" + this.getAttribute("code");
  394.           
  395.           return msg;
  396.         ]]></body>
  397.       </method>
  398.       
  399.     </implementation>
  400.     
  401.   </binding>
  402.   
  403.   <binding id="message" extends="xul:box">
  404.     <content>
  405.       <xul:box class="console-internal-box" flex="1">
  406.         <xul:box class="console-row-icon" align="center">
  407.           <xul:image class="console-icon" inherits="src,type"/>
  408.         </xul:box>
  409.         <xul:vbox class="console-row-content" inherits="selected" flex="1">
  410.           <xul:vbox class="console-row-msg" flex="1">
  411.             <xul:html class="console-msg-text" inherits="value=msg" flex="1"/>
  412.           </xul:vbox>
  413.         </xul:vbox>
  414.       </xul:box>
  415.     </content>
  416.  
  417.     <implementation>
  418.       <method name="toString">
  419.         <body><![CDATA[
  420.           return this.getAttribute("msg");
  421.         ]]></body>
  422.       </method>
  423.     </implementation>
  424.   </binding>
  425.  
  426.   <binding id="console-error-source" extends="xul:box">
  427.     <content>
  428.       <xul:text class="text-link" inherits="value=url" crop="right"/>
  429.     </content>
  430.  
  431.     <handlers>
  432.       <handler event="click"><![CDATA[
  433.           window.openDialog(
  434.             "chrome://navigator/content/viewSource.xul", "_blank", 
  435.             "scrollbars,resizable,chrome,dialog=no", this.getAttribute("url"));
  436.       ]]></handler>
  437.     </handlers>
  438.   </binding>
  439.  
  440. </bindings>
  441.  
  442.