home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 December / PCWorld_2005-12_cd.bin / komunikace / netscape / nsb-install-8-0.exe / chrome / toolkit.jar / content / global / consoleBindings.xml < prev    next >
Extensible Markup Language  |  2005-09-26  |  14KB  |  386 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.           xmlns:xbl="http://www.mozilla.org/xbl">
  9.  
  10.   <binding id="console-box" extends="xul:box">
  11.     <content>  
  12.       <xul:stringbundle src="chrome://global/locale/console.properties" role="string-bundle"/>
  13.       <xul:vbox class="console-box-internal">
  14.         <xul:vbox class="console-rows" role="console-rows" xbl:inherits="dir=sortOrder"/>
  15.       </xul:vbox>
  16.     </content>
  17.   
  18.     <implementation>
  19.       <field name="limit" readonly="true">
  20.         250
  21.       </field>
  22.       <field name="_showChromeErrors">-1</field>
  23.       
  24.       <property name="showChromeErrors">
  25.         <getter><![CDATA[
  26.           if (this._showChromeErrors != -1)
  27.             return this._showChromeErrors;
  28.           var pref = Components.classes['@mozilla.org/preferences-service;1'].getService();
  29.           pref = pref.QueryInterface(Components.interfaces.nsIPrefBranch);
  30.  
  31.           try {
  32.             return this._showChromeErrors = pref.getBoolPref("javascript.options.showInConsole");
  33.           }
  34.           catch(ex) {
  35.             return this._showChromeErrors = false;
  36.           }
  37.         ]]></getter>
  38.       </property>          
  39.  
  40.       <property name="count" readonly="true">
  41.         <getter>return this.mCount</getter>
  42.       </property>
  43.     
  44.       <property name="mode">
  45.         <getter>return this.mMode;</getter>
  46.         <setter><![CDATA[
  47.           this.mMode = val || "All";
  48.           this.setAttribute("mode", this.mMode);
  49.           return val;
  50.         ]]></setter>
  51.       </property>
  52.     
  53.       <property name="sortOrder">
  54.         <getter>return this.getAttribute("sortOrder");</getter>
  55.         <setter>this.setAttribute("sortOrder", val); return val;</setter>
  56.       </property>
  57.       <field name="mSelectedItem">null</field>
  58.       <property name="selectedItem">
  59.         <getter>return this.mSelectedItem</getter>
  60.         <setter><![CDATA[
  61.           if (this.mSelectedItem)
  62.             this.mSelectedItem.removeAttribute("selected");
  63.           
  64.           this.mSelectedItem = val;
  65.           val.setAttribute("selected", "true");
  66.         ]]></setter>
  67.       </property>
  68.     
  69.       <method name="init">
  70.         <body><![CDATA[
  71.           this.mCount = 0;
  72.           
  73.           this.mConsoleListener = {
  74.             console: this, 
  75.             observe : function(aObject) { this.console.appendItem(aObject); }
  76.           };
  77.           
  78.           this.mConsoleRowBox = document.getAnonymousElementByAttribute(this, "role", "console-rows");
  79.           this.mStrBundle = document.getAnonymousElementByAttribute(this, "role", "string-bundle");
  80.           
  81.           try {
  82.             var isupports = Components.classes['@mozilla.org/consoleservice;1'].getService();
  83.             this.mCService = isupports.QueryInterface(Components.interfaces.nsIConsoleService);
  84.             this.mCService.registerListener(this.mConsoleListener);
  85.           } catch (ex) {
  86.             appendItem(
  87.               "Unable to display errors - couldn't get Console Service component. " +
  88.               "(Missing @mozilla.org/consoleservice;1)");
  89.             return;
  90.           }          
  91.                     
  92.           this.mMode = this.getAttribute("mode") || "All";
  93.  
  94.           this.appendInitialItems();
  95.         ]]></body>
  96.       </method>
  97.     
  98.       <method name="destroy">
  99.         <body><![CDATA[
  100.           this.mCService.unregisterListener(this.mConsoleListener);
  101.         ]]></body>
  102.       </method>
  103.     
  104.       <method name="appendInitialItems">
  105.         <body><![CDATA[
  106.           var out = {}; // Throwaway references to support 'out' parameters.
  107.           this.mCService.getMessageArray(out, {});
  108.           var messages = out.value;
  109.       
  110.           // In case getMessageArray returns 0-length array as null
  111.           if (!messages)
  112.             messages = [];
  113.       
  114.           var limit = messages.length - this.limit;
  115.           if (limit < 0) limit = 0;
  116.         
  117.           // Checks if console ever been cleared
  118.           for (var i = messages.length - 1; i >= limit; --i)
  119.             if (!messages[i].message)
  120.               break;
  121.         
  122.           // Populate with messages after latest "clear"
  123.           while (++i < messages.length)
  124.             this.appendItem(messages[i]);
  125.         ]]></body>
  126.       </method>
  127.  
  128.       <method name="appendItem">
  129.         <parameter name="aObject"/>
  130.         <body><![CDATA[
  131.           if (!aObject.message) return;
  132.  
  133.           try {
  134.             // Try to QI it to a script error to get more info
  135.             var scriptError = aObject.QueryInterface(Components.interfaces.nsIScriptError);
  136.             
  137.             // filter chrome urls
  138.             if (!this.showChromeErrors && scriptError.sourceName.substr(0, 9) == "chrome://")
  139.               return;
  140.  
  141.             this.appendError(scriptError);
  142.           } catch (ex) {
  143.             try {
  144.               // Try to QI it to a console message
  145.               var msg = aObject.QueryInterface(Components.interfaces.nsIConsoleMessage);
  146.               this.appendMessage(msg.message);
  147.             } catch (ex2) {
  148.               // Give up and append the object itself as a string
  149.               this.appendMessage(aObject);
  150.             }
  151.           }
  152.         ]]></body>
  153.       </method>
  154.  
  155.       <method name="appendError">
  156.         <parameter name="aObject"/>
  157.         <body><![CDATA[
  158.           var row = this.createConsoleRow();
  159.           var nsIScriptError = Components.interfaces.nsIScriptError;
  160.           
  161.           // Is this error actually just a non-fatal warning?
  162.           var warning = aObject.flags & nsIScriptError.warningFlag != 0;
  163.   
  164.           var typetext = warning ? "typeWarning" : "typeError";
  165.           row.setAttribute("typetext", this.mStrBundle.getString(typetext));
  166.           row.setAttribute("type", warning ? "warning" : "error");
  167.           row.setAttribute("msg", aObject.message);
  168.           if (aObject.lineNumber || aObject.sourceName) {
  169.             row.setAttribute("url", aObject.sourceName);
  170.             row.setAttribute("line", aObject.lineNumber);
  171.           } else {
  172.             row.setAttribute("hideSource", "true");
  173.           }
  174.           if (aObject.sourceLine) {
  175.             row.setAttribute("code", aObject.sourceLine.replace("\n", "", "g"));
  176.             if (aObject.columnNumber) {
  177.               row.setAttribute("col", aObject.columnNumber);
  178.               row.setAttribute("errorDots", this.repeatChar(" ", aObject.columnNumber));
  179.               row.setAttribute("errorCaret", " ");
  180.             } else {
  181.               row.setAttribute("hideCaret", "true");
  182.             }
  183.           } else {
  184.             row.setAttribute("hideCode", "true");
  185.           }
  186.           this.appendConsoleRow(row);
  187.         ]]></body>
  188.       </method>
  189.             
  190.       <method name="appendMessage">
  191.         <parameter name="aMessage"/>
  192.         <parameter name="aType"/>
  193.         <body><![CDATA[
  194.           var row = this.createConsoleRow();
  195.           row.setAttribute("type", aType || "message");
  196.           row.setAttribute("msg", aMessage);
  197.           this.appendConsoleRow(row);
  198.         ]]></body>
  199.       </method>
  200.       
  201.       <method name="clear">
  202.         <body><![CDATA[
  203.           this.mCService.logStringMessage(null);
  204.           this.mCount = 0;
  205.           
  206.           var newRows = this.mConsoleRowBox.cloneNode(false);
  207.           this.mConsoleRowBox.parentNode.replaceChild(newRows, this.mConsoleRowBox);
  208.           this.mConsoleRowBox = newRows;
  209.         ]]></body>
  210.       </method>
  211.             
  212.       <method name="copySelectedItem">
  213.         <body><![CDATA[
  214.           if (this.mSelectedItem) try {
  215.             const clipURI = "@mozilla.org/widget/clipboardhelper;1";
  216.             const clipI = Components.interfaces.nsIClipboardHelper;
  217.             var clipboard = Components.classes[clipURI].getService(clipI);
  218.  
  219.             clipboard.copyString(this.mSelectedItem.toString());
  220.           } catch (ex) {
  221.             // Unable to copy anything, die quietly
  222.           }
  223.         ]]></body>
  224.       </method>
  225.                   
  226.       <method name="createConsoleRow">
  227.         <body><![CDATA[
  228.           var row = document.createElement("box");
  229.           row.setAttribute("class", "console-row");
  230.           row._IsConsoleRow = true;
  231.           row._ConsoleBox = this;
  232.           return row;
  233.         ]]></body>
  234.       </method>
  235.             
  236.       <method name="appendConsoleRow">
  237.         <parameter name="aRow"/>
  238.         <body><![CDATA[
  239.           this.mConsoleRowBox.appendChild(aRow);
  240.           if (++this.mCount > this.limit) 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.       <!-- UTILITY FUNCTIONS -->
  253.       
  254.       <method name="repeatChar">
  255.         <parameter name="aChar"/>
  256.         <parameter name="aCol"/>
  257.         <body><![CDATA[
  258.           var str = "";
  259.           if (aCol)
  260.             for (var i = 1; i < aCol; ++i)
  261.               str += aChar;
  262.           
  263.           return str;
  264.         ]]></body>
  265.       </method>
  266.           
  267.       <constructor> this.init(); </constructor>
  268.       <destructor> this.destroy(); </destructor>
  269.     </implementation>
  270.     
  271.     <handlers>
  272.       <handler event="mousedown"><![CDATA[
  273.         if (event.button == 0 || event.button == 2) {
  274.           var target = event.originalTarget;
  275.   
  276.           while (target && !("_IsConsoleRow" in target))
  277.             target = target.parentNode;
  278.  
  279.           if (target)
  280.             this.selectedItem = target;
  281.         }
  282.       ]]></handler>
  283.     </handlers>
  284.   </binding>
  285.  
  286.   <binding id="error" extends="xul:box">
  287.     <content>
  288.       <xul:box class="console-row-internal-box" flex="1">
  289.         <xul:box class="console-row-icon" align="center" xbl:inherits="selected">
  290.           <xul:image class="console-icon" xbl:inherits="src,type"/>
  291.         </xul:box>
  292.         <xul:vbox class="console-row-content" xbl:inherits="selected" flex="1">
  293.           <xul:box class="console-row-msg" align="start">
  294.             <xul:label class="label" xbl:inherits="value=typetext"/>
  295.             <xul:description class="console-error-msg" xbl:inherits="xbl:text=msg" flex="1"/>
  296.           </xul:box>
  297.           <xul:box class="console-row-file" xbl:inherits="hidden=hideSource">
  298.             <xul:label class="label" value="&errFile.label;"/>
  299.             <xul:box class="console-error-source" xbl:inherits="url,line"/>
  300.             <spacer flex="1"/>
  301.             <xul:label class="label" value="&errLine.label;"/>
  302.             <xul:label class="label" xbl:inherits="value=line" flex="1"/>
  303.           </xul:box>
  304.           <xul:vbox class="console-row-code" xbl:inherits="selected,hidden=hideCode">
  305.             <xul:label class="monospace console-code" xbl:inherits="value=code" crop="end"/>
  306.             <xul:box xbl:inherits="hidden=hideCaret">
  307.               <xul:label class="monospace console-dots" xbl:inherits="value=errorDots"/>
  308.               <xul:label class="monospace console-caret" xbl:inherits="value=errorCaret"/>
  309.               <xul:spacer flex="1"/>
  310.             </xul:box>
  311.           </xul:vbox>
  312.         </xul:vbox>
  313.       </xul:box>
  314.     </content>
  315.  
  316.     <implementation>
  317.       
  318.       <method name="toString">
  319.         <body><![CDATA[
  320.           var msg = this.getAttribute("typetext") + " " + this.getAttribute("msg");
  321.           
  322.           var strBundle = this._ConsoleBox.mStrBundle;
  323.           
  324.           if (this.hasAttribute("line") && this.hasAttribute("url")) {
  325.             msg += "\n" + strBundle.getFormattedString("errFile", 
  326.                                         [this.getAttribute("url")]) + "\n";
  327.             if (this.hasAttribute("col")) {
  328.               msg += strBundle.getFormattedString("errLineCol",
  329.                          [this.getAttribute("line"), this.getAttribute("col")]);
  330.             } else
  331.               msg += strBundle.getFormattedString("errLine", [this.getAttribute("line")]);
  332.           }
  333.           
  334.           if (this.hasAttribute("code"))
  335.             msg += "\n" + strBundle.getString("errCode") + "\n" + this.getAttribute("code");
  336.           
  337.           return msg;
  338.         ]]></body>
  339.       </method>
  340.       
  341.     </implementation>
  342.     
  343.   </binding>
  344.   
  345.   <binding id="message" extends="xul:box">
  346.     <content>
  347.       <xul:box class="console-internal-box" flex="1">
  348.         <xul:box class="console-row-icon" align="center">
  349.           <xul:image class="console-icon" xbl:inherits="src,type"/>
  350.         </xul:box>
  351.         <xul:vbox class="console-row-content" xbl:inherits="selected" flex="1">
  352.           <xul:vbox class="console-row-msg" flex="1">
  353.             <xul:description class="console-msg-text" xbl:inherits="xbl:text=msg"/>
  354.           </xul:vbox>
  355.         </xul:vbox>
  356.       </xul:box>
  357.     </content>
  358.  
  359.     <implementation>
  360.       <method name="toString">
  361.         <body><![CDATA[
  362.           return this.getAttribute("msg");
  363.         ]]></body>
  364.       </method>
  365.     </implementation>
  366.   </binding>
  367.  
  368.   <binding id="console-error-source" extends="xul:box">
  369.     <content>
  370.       <xul:label class="text-link" xbl:inherits="value=url" crop="right"/>
  371.     </content>
  372.  
  373.     <handlers>
  374.       <handler event="click"><![CDATA[
  375.           var url = this.getAttribute("url");
  376.           var line = getAttribute("line");  
  377.           window.openDialog(
  378.             "chrome://global/content/viewSource.xul", "_blank", 
  379.             "all,dialog=no", url, null, null, line);
  380.       ]]></handler>
  381.     </handlers>
  382.   </binding>
  383.  
  384. </bindings>
  385.  
  386.