home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / toolkit.jar / content / global / console.js < prev    next >
Encoding:
JavaScript  |  2001-03-21  |  4.9 KB  |  206 lines

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