home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / 01_03.iso / software / ghostzilla_hit / files / ghostzilla-1.0-plus-install.exe / chrome / toolkit.jar / content / global / console.js < prev    next >
Encoding:
JavaScript  |  2002-04-09  |  5.6 KB  |  222 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Netscape Public License
  6.  * Version 1.1 (the "License"); you may not use this file except in
  7.  * compliance with the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/NPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is 
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  * Contributor(s): Joe Hewitt <hewitt@netscape.com>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or 
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the NPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the NPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. var gConsole, gConsoleBundle;
  40.  
  41. /* :::::::: Console Initialization ::::::::::::::: */
  42.  
  43. window.onload = function()
  44. {
  45.   gConsole = document.getElementById("ConsoleBox");
  46.   gConsoleBundle = document.getElementById("ConsoleBundle");
  47.   
  48.   top.controllers.insertControllerAt(0, ConsoleController);
  49.   
  50.   updateSortCommand(gConsole.sortOrder);
  51.   updateModeCommand(gConsole.mode);
  52.  
  53.   var iframe = document.getElementById("Evaluator");
  54.   iframe.addEventListener("load", displayResult, true);
  55. }
  56.  
  57. /* :::::::: Console UI Functions ::::::::::::::: */
  58.  
  59. function changeMode(aMode)
  60. {
  61.   switch (aMode) {
  62.     case "Errors":
  63.     case "Warnings":
  64.     case "Messages":
  65.       gConsole.mode = aMode;
  66.       break;
  67.     case "All":
  68.       gConsole.mode = null;
  69.   }
  70.   
  71.   document.persist("ConsoleBox", "mode");
  72. }
  73.  
  74. function clearConsole()
  75. {
  76.   gConsole.clear();
  77. }
  78.  
  79. function changeSortOrder(aOrder)
  80. {
  81.   updateSortCommand(gConsole.sortOrder = aOrder);
  82. }
  83.  
  84. function updateSortCommand(aOrder)
  85. {
  86.   var orderString = aOrder == 'reverse' ? "Descend" : "Ascend";
  87.   var bc = document.getElementById("Console:sort"+orderString);
  88.   bc.setAttribute("checked", true);  
  89.  
  90.   orderString = aOrder == 'reverse' ? "Ascend" : "Descend";
  91.   bc = document.getElementById("Console:sort"+orderString);
  92.   bc.setAttribute("checked", false);
  93. }
  94.  
  95. function updateModeCommand(aMode)
  96. {
  97.   var bc = document.getElementById("Console:mode" + aMode);
  98.   bc.setAttribute("checked", true);
  99. }
  100.  
  101. function toggleToolbar(aEl)
  102. {
  103.   var bc = document.getElementById(aEl.getAttribute("observes"));
  104.   var truth = bc.getAttribute("checked");
  105.   bc.setAttribute("checked", truth != "true");
  106.   var toolbar = document.getElementById(bc.getAttribute("_toolbar"));
  107.   toolbar.setAttribute("hidden", truth);
  108.  
  109.   document.persist(toolbar.id, "hidden");
  110.   document.persist(bc.id, "checked");
  111. }
  112.  
  113. function copyItemToClipboard()
  114. {
  115.   gConsole.copySelectedItem();
  116. }
  117.  
  118. function isItemSelected()
  119. {
  120.   return gConsole.selectedItem != null;
  121. }
  122.  
  123. function UpdateCopyMenu()
  124. {
  125.   goUpdateCommand("cmd_copy");
  126. }
  127.  
  128. function onEvalKeyPress(aEvent)
  129. {
  130.   if (aEvent.keyCode == 13)
  131.     evaluateTypein();
  132. }
  133.  
  134. function evaluateTypein()
  135. {
  136.   var code = document.getElementById("TextboxEval").value;
  137.   var iframe = document.getElementById("Evaluator");
  138.   iframe.setAttribute("src", "javascript: " + code);
  139. }
  140.  
  141. function displayResult()
  142. {
  143.   var result = Evaluator.document.documentElement.lastChild.firstChild;
  144.   if (result && result.data)
  145.     gConsole.mCService.logStringMessage(result.data);
  146.     // or could use appendMessage which doesn't persist
  147. }
  148.  
  149. /* :::::::: Command Controller for the Window ::::::::::::::: */
  150.  
  151. var ConsoleController = 
  152. {
  153.   isCommandEnabled: function (aCommand)
  154.   {
  155.     switch (aCommand) {
  156.       case "cmd_copy":
  157.         return isItemSelected();
  158.       default:
  159.         return false;
  160.     }
  161.   },
  162.   
  163.   supportsCommand: function (aCommand) 
  164.   {
  165.     switch (aCommand) {
  166.       case "cmd_copy":
  167.         return true;
  168.       default:
  169.         return false;
  170.     }
  171.   },
  172.   
  173.   doCommand: function (aCommand)
  174.   {
  175.     switch (aCommand) {
  176.       case "cmd_copy":
  177.         copyItemToClipboard();
  178.         break;
  179.       default:
  180.         break;
  181.     }
  182.   },
  183.   
  184.   onEvent: function (aEvent) 
  185.   {
  186.   }
  187. };
  188.  
  189. // XXX DEBUG
  190.  
  191. function debug(aText)
  192. {
  193.   var csClass = Components.classes['@mozilla.org/consoleservice;1'];
  194.   var cs = csClass.getService(Components.interfaces.nsIConsoleService);
  195.   cs.logStringMessage(aText);
  196. }
  197.  
  198. function getStackTrace()
  199. {
  200.   var frame = Components.stack.caller;
  201.   var str = "";
  202.   while (frame) {
  203.     if (frame.filename)
  204.       str += frame.filename + ", Line " + frame.lineNumber;
  205.     else
  206.       str += "[" + gConsoleBundle.getString("noFile") + "]";
  207.     
  208.     str += " --> ";
  209.     
  210.     if (frame.functionName)
  211.       str += frame.functionName;
  212.     else
  213.       str += "[" + gConsoleBundle.getString("noFunction") + "]";
  214.       
  215.     str += "\n";
  216.     
  217.     frame = frame.caller;
  218.   }
  219.   
  220.   return str;
  221. }
  222.