From 164a70db7d8fba94b5702bc867caa7a1db4a6182 Mon Sep 17 00:00:00 2001 From: "blakeross%telocity.com" Date: Wed, 18 Sep 2002 02:10:04 +0000 Subject: [PATCH] Forking jsconsole. git-svn-id: svn://10.0.0.236/trunk@129866 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/browser/base/content/browser.js | 6 +- mozilla/browser/base/content/browser.xul | 5 +- mozilla/browser/base/locale/browser.dtd | 4 +- mozilla/browser/components/Makefile.in | 2 +- mozilla/browser/components/console/MANIFEST | 1 + .../browser/components/console/Makefile.in | 33 ++ .../components/console/content/console.css | 57 +++ .../components/console/content/console.js | 227 ++++++++++ .../components/console/content/console.xul | 158 +++++++ .../console/content/consoleBindings.xml | 419 ++++++++++++++++++ mozilla/browser/components/console/jar.mn | 9 + .../components/console/jsconsole-clhandler.js | 119 +++++ .../components/console/locale/console.dtd | 54 +++ .../console/locale/console.properties | 8 + 14 files changed, 1090 insertions(+), 12 deletions(-) create mode 100644 mozilla/browser/components/console/MANIFEST create mode 100644 mozilla/browser/components/console/Makefile.in create mode 100644 mozilla/browser/components/console/content/console.css create mode 100644 mozilla/browser/components/console/content/console.js create mode 100644 mozilla/browser/components/console/content/console.xul create mode 100644 mozilla/browser/components/console/content/consoleBindings.xml create mode 100644 mozilla/browser/components/console/jar.mn create mode 100644 mozilla/browser/components/console/jsconsole-clhandler.js create mode 100644 mozilla/browser/components/console/locale/console.dtd create mode 100644 mozilla/browser/components/console/locale/console.properties diff --git a/mozilla/browser/base/content/browser.js b/mozilla/browser/base/content/browser.js index ece73e60805..c73ad249c15 100644 --- a/mozilla/browser/base/content/browser.js +++ b/mozilla/browser/base/content/browser.js @@ -2412,7 +2412,7 @@ function toDownloadManager() function toJavaScriptConsole() { - toOpenWindowByType("global:console", "chrome://global/content/console.xul"); + toOpenWindowByType("global:console", "chrome://browser/content/console/console.xul"); } function javaItemEnabling() @@ -2480,10 +2480,8 @@ function OpenTaskURL( inURL ) window.open( inURL ); } -function goAboutDialog() +function openAboutDialog() { - // XXXBlake -- the about dialog should be modal, but then clicking the link in it just opens - // a blank browser window (the page isn't loaded). window.openDialog("chrome://browser/content/aboutDialog.xul", "About", "modal,centerscreen,chrome,resizable=no"); } diff --git a/mozilla/browser/base/content/browser.xul b/mozilla/browser/base/content/browser.xul index 2b9d989cddc..d0c21c7e2e8 100644 --- a/mozilla/browser/base/content/browser.xul +++ b/mozilla/browser/base/content/browser.xul @@ -671,12 +671,9 @@ Contributor(s): label="&releaseCmd.label;" oncommand="openTopWin('&releaseURL;');"/> - + oncommand="openAboutDialog();"/> diff --git a/mozilla/browser/base/locale/browser.dtd b/mozilla/browser/base/locale/browser.dtd index f9c728d7a3f..dcb7ebb06d1 100644 --- a/mozilla/browser/base/locale/browser.dtd +++ b/mozilla/browser/base/locale/browser.dtd @@ -155,11 +155,9 @@ - + - - diff --git a/mozilla/browser/components/Makefile.in b/mozilla/browser/components/Makefile.in index 42192584505..b5304bfb10e 100644 --- a/mozilla/browser/components/Makefile.in +++ b/mozilla/browser/components/Makefile.in @@ -42,6 +42,6 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS = prefwindow history bookmarks +DIRS = prefwindow history bookmarks console include $(topsrcdir)/config/rules.mk diff --git a/mozilla/browser/components/console/MANIFEST b/mozilla/browser/components/console/MANIFEST new file mode 100644 index 00000000000..f112fd12aed --- /dev/null +++ b/mozilla/browser/components/console/MANIFEST @@ -0,0 +1 @@ +jsconsole-clhandler.js diff --git a/mozilla/browser/components/console/Makefile.in b/mozilla/browser/components/console/Makefile.in new file mode 100644 index 00000000000..7bbdfd93316 --- /dev/null +++ b/mozilla/browser/components/console/Makefile.in @@ -0,0 +1,33 @@ +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +EXTRA_COMPONENTS = jsconsole-clhandler.js + +include $(topsrcdir)/config/rules.mk + diff --git a/mozilla/browser/components/console/content/console.css b/mozilla/browser/components/console/content/console.css new file mode 100644 index 00000000000..472153bee37 --- /dev/null +++ b/mozilla/browser/components/console/content/console.css @@ -0,0 +1,57 @@ + +.console-box { + -moz-binding: url("chrome://global/content/consoleBindings.xml#console-box"); + overflow: auto; +} + +.console-rows { + -moz-user-focus: normal; +} + +.console-row[type="error"], +.console-row[type="warning"] { + -moz-binding: url("chrome://global/content/consoleBindings.xml#error"); +} + +.console-row[type="message"] { + -moz-binding: url("chrome://global/content/consoleBindings.xml#message"); +} + +.console-error-msg { + white-space: normal; +} + +.console-msg-text { + white-space: pre; +} + +.console-error-source { + -moz-binding: url("chrome://global/content/consoleBindings.xml#console-error-source"); +} + +/* :::::::::: hiding and showing of rows for each mode :::::::::: */ + +.console-box[mode="Warnings"] > .console-box-internal > .console-rows + > .console-row[type="error"], +.console-box[mode="Messages"] > .console-box-internal > .console-rows + > .console-row[type="error"] +{ + display: none; +} + +.console-box[mode="Errors"] > .console-box-internal > .console-rows + > .console-row[type="warning"], +.console-box[mode="Messages"] > .console-box-internal > .console-rows + > .console-row[type="warning"] +{ + display: none; +} + +.console-box[mode="Errors"] > .console-box-internal > .console-rows + > .console-row[type="message"], +.console-box[mode="Warnings"] > .console-box-internal > .console-rows + > .console-row[type="message"] +{ + display: none; +} + diff --git a/mozilla/browser/components/console/content/console.js b/mozilla/browser/components/console/content/console.js new file mode 100644 index 00000000000..204968d5358 --- /dev/null +++ b/mozilla/browser/components/console/content/console.js @@ -0,0 +1,227 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Joe Hewitt + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +var gConsole, gConsoleBundle; + +/* :::::::: Console Initialization ::::::::::::::: */ + +window.onload = function() +{ + gConsole = document.getElementById("ConsoleBox"); + gConsoleBundle = document.getElementById("ConsoleBundle"); + + top.controllers.insertControllerAt(0, ConsoleController); + + updateSortCommand(gConsole.sortOrder); + updateModeCommand(gConsole.mode); + + var iframe = document.getElementById("Evaluator"); + iframe.addEventListener("load", displayResult, true); +} + +/* :::::::: Console UI Functions ::::::::::::::: */ + +function changeMode(aMode) +{ + switch (aMode) { + case "Errors": + case "Warnings": + case "Messages": + gConsole.mode = aMode; + break; + case "All": + gConsole.mode = null; + } + + document.persist("ConsoleBox", "mode"); +} + +function clearConsole() +{ + gConsole.clear(); +} + +function changeSortOrder(aOrder) +{ + updateSortCommand(gConsole.sortOrder = aOrder); +} + +function updateSortCommand(aOrder) +{ + var orderString = aOrder == 'reverse' ? "Descend" : "Ascend"; + var bc = document.getElementById("Console:sort"+orderString); + bc.setAttribute("checked", true); + + orderString = aOrder == 'reverse' ? "Ascend" : "Descend"; + bc = document.getElementById("Console:sort"+orderString); + bc.setAttribute("checked", false); +} + +function updateModeCommand(aMode) +{ + var bc = document.getElementById("Console:mode" + aMode); + bc.setAttribute("checked", true); +} + +function toggleToolbar(aEl) +{ + var bc = document.getElementById(aEl.getAttribute("observes")); + var truth = bc.getAttribute("checked"); + bc.setAttribute("checked", truth != "true"); + var toolbar = document.getElementById(bc.getAttribute("_toolbar")); + toolbar.setAttribute("hidden", truth); + + document.persist(toolbar.id, "hidden"); + document.persist(bc.id, "checked"); +} + +function copyItemToClipboard() +{ + gConsole.copySelectedItem(); +} + +function isItemSelected() +{ + return gConsole.selectedItem != null; +} + +function UpdateCopyMenu() +{ + goUpdateCommand("cmd_copy"); +} + +function onEvalKeyPress(aEvent) +{ + if (aEvent.keyCode == 13) + evaluateTypein(); +} + +function evaluateTypein() +{ + var code = document.getElementById("TextboxEval").value; + var iframe = document.getElementById("Evaluator"); + iframe.setAttribute("src", "javascript: " + code); +} + +function displayResult() +{ + var result = Evaluator.document.documentElement.lastChild.firstChild; + if (result && result.data) + gConsole.mCService.logStringMessage(result.data); + // or could use appendMessage which doesn't persist +} + +/* :::::::: Command Controller for the Window ::::::::::::::: */ + +var ConsoleController = +{ + isCommandEnabled: function (aCommand) + { + switch (aCommand) { + case "cmd_copy": + return isItemSelected(); + default: + return false; + } + }, + + supportsCommand: function (aCommand) + { + switch (aCommand) { + case "cmd_copy": + return true; + default: + return false; + } + }, + + doCommand: function (aCommand) + { + switch (aCommand) { + case "cmd_copy": + copyItemToClipboard(); + break; + default: + break; + } + }, + + onEvent: function (aEvent) + { + } +}; + +// XXX DEBUG + +function debug(aText) +{ + var csClass = Components.classes['@mozilla.org/consoleservice;1']; + var cs = csClass.getService(Components.interfaces.nsIConsoleService); + cs.logStringMessage(aText); +} + +function getStackTrace() +{ + var frame = Components.stack.caller; + var str = ""; + while (frame) { + if (frame.filename) + str += frame.filename + ", Line " + frame.lineNumber; + else + str += "[" + gConsoleBundle.getString("noFile") + "]"; + + str += " --> "; + + if (frame.functionName) + str += frame.functionName; + else + str += "[" + gConsoleBundle.getString("noFunction") + "]"; + + str += "\n"; + + frame = frame.caller; + } + + return str; +} + +function openAboutDialog() +{ + window.openDialog("chrome://browser/content/aboutDialog.xul", "About", "modal,centerscreen,chrome,resizable=no"); +} + diff --git a/mozilla/browser/components/console/content/console.xul b/mozilla/browser/components/console/content/console.xul new file mode 100644 index 00000000000..ab2c0ca0540 --- /dev/null +++ b/mozilla/browser/components/console/content/console.xul @@ -0,0 +1,158 @@ + + + + + + + + + + + + %console; + %util; + %globalRegionDTD; + %brandDTD; +]> + + + +