Console cleanup: it is now independent from communicator.

Adding access keys and shortcut to focus the command line
This commit is contained in:
chanial%noos.fr 2003-03-02 04:15:09 +00:00
Родитель 74ec75b150
Коммит d9b2fb3639
4 изменённых файлов: 75 добавлений и 195 удалений

Просмотреть файл

@ -36,7 +36,7 @@
#
# ***** END LICENSE BLOCK *****
var gConsole, gConsoleBundle;
var gConsole, gConsoleBundle, gTextBoxEval;
/* :::::::: Console Initialization ::::::::::::::: */
@ -44,8 +44,7 @@ window.onload = function()
{
gConsole = document.getElementById("ConsoleBox");
gConsoleBundle = document.getElementById("ConsoleBundle");
top.controllers.insertControllerAt(0, ConsoleController);
gTextBoxEval = document.getElementById("TextboxEval")
updateSortCommand(gConsole.sortOrder);
updateModeCommand(gConsole.mode);
@ -98,18 +97,6 @@ function updateModeCommand(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();
@ -120,9 +107,9 @@ function isItemSelected()
return gConsole.selectedItem != null;
}
function UpdateCopyMenu()
function updateCopyMenu()
{
goUpdateCommand("cmd_copy");
goSetCommandEnabled("cmd_copy", isItemSelected())
}
function onEvalKeyPress(aEvent)
@ -133,7 +120,7 @@ function onEvalKeyPress(aEvent)
function evaluateTypein()
{
var code = document.getElementById("TextboxEval").value;
var code = gTextBoxEval.value;
var iframe = document.getElementById("Evaluator");
iframe.setAttribute("src", "javascript: " + code);
}
@ -148,76 +135,10 @@ function displayResult()
// 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;
}

Просмотреть файл

@ -24,14 +24,8 @@
<?xml-stylesheet href="chrome://global/skin/console/console.css" type="text/css"?>
<?xml-stylesheet href="chrome://global/content/console.css" type="text/css"?>
<?xul-overlay href="chrome://global/content/globalOverlay.xul"?>
<?xul-overlay href="chrome://communicator/content/utilityOverlay.xul"?>
<!DOCTYPE window [
<!ENTITY % console SYSTEM "chrome://global/locale/console.dtd"> %console;
<!ENTITY % util SYSTEM "chrome://communicator/locale/utilityOverlay.dtd"> %util;
<!ENTITY % globalRegionDTD SYSTEM "chrome://global-region/locale/region.dtd"> %globalRegionDTD;
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" > %brandDTD;
]>
<window id="JSConsoleWindow"
@ -46,11 +40,16 @@
<script type="application/x-javascript" src="chrome://global/content/console.js"/>
<stringbundle id="ConsoleBundle" src="chrome://global/locale/console.properties"/>
<commandset commandupdater="true"
events="select"
oncommandupdate="updateCopyMenu()">
<command id="cmd_copy" oncommand="copyItemToClipboard()"/>
<command id="cmd_close" oncommand="window.close()"/>
<broadcaster id="Console:clear" label="&clear.label;" oncommand="clearConsole();"/>
</commandset>
<broadcaster id="Console:clear" label="&clear.label;"
accesskey="&clear.accesskey;"
oncommand="clearConsole();"/>
<broadcaster id="Console:sortAscend" label="&sortFirst.label;"
accesskey="&sortFirst.accesskey;"
oncommand="changeSortOrder('forward');"/>
@ -58,40 +57,47 @@
accesskey="&sortLast.accesskey;"
oncommand="changeSortOrder('reverse');"/>
<broadcaster id="Console:toggleToolbarMode" label="&toolbarMode.label;"
oncommand="toggleToolbar(this);" checked="true"
_toolbar="ToolbarMode"/>
<broadcaster id="Console:toggleToolbarEval" label="&toolbarEval.label;"
oncommand="toggleToolbar(this);" checked="true"
_toolbar="ToolbarEval"/>
<broadcasterset id="ModeBroadcasters">
<broadcaster id="Console:modeAll" label="&all.label;"
<broadcaster id="Console:modeAll"
label="&all.label;" accesskey="&all.accesskey;"
oncommand="changeMode('All');"/>
<broadcaster id="Console:modeErrors" label="&errors.label;"
<broadcaster id="Console:modeErrors"
label="&errors.label;" accesskey="&errors.accesskey;"
oncommand="changeMode('Errors');"/>
<broadcaster id="Console:modeWarnings" label="&warnings.label;"
<broadcaster id="Console:modeWarnings"
label="&warnings.label;" accesskey="&warnings.accesskey;"
oncommand="changeMode('Warnings');"/>
<broadcaster id="Console:modeMessages" label="&messages.label;"
<broadcaster id="Console:modeMessages"
label="&messages.label;" accesskey="&messages.accesskey;"
oncommand="changeMode('Messages');"/>
</broadcasterset>
<keyset>
<key id="key_copy"/>
<key id="key_close"/>
<key id="key_copy"
key="&copyCmd.commandkey;"
modifiers="accel"
command="cmd_copy"/>
<key id="key_close"
key="&closeCmd.commandkey;"
modifiers="accel"
oncommand="window.close()"/>
<key id="key_focus1" key="&focus1.commandkey;" modifiers="accel"
oncommand="gTextBoxEval.focus()"/>
<key id="key_focus2" key="&focus2.commandkey;" modifiers="alt"
oncommand="gTextBoxEval.focus()"/>
</keyset>
<popupset id="ContextMenus">
<popup id="ConsoleContext" onpopupshowing="UpdateCopyMenu()">
<popup id="ConsoleContext">
<menuitem type="radio" observes="Console:sortAscend"/>
<menuitem type="radio" observes="Console:sortDescend"/>
<menuseparator/>
<menuitem id="menu_copy_cm" observes="cmd_copy" label="&copyCmd.label;" accesskey="&copyCmd.accesskey;"/>
<menuitem id="menu_copy_cm" observes="cmd_copy" label="&copyCmd.label;" key="key_copy" accesskey="&copyCmd.accesskey;"/>
</popup>
</popupset>
<toolbox>
<toolbar class="chromeclass-toolbar" id="ToolbarMode" grippytooltiptext="&modeToolbar.tooltip;">
<toolbar class="chromeclass-toolbar" id="ToolbarMode">
<toolbarbutton type="radio" group="mode" observes="Console:modeAll"/>
<toolbarbutton type="radio" group="mode" observes="Console:modeErrors"/>
<toolbarbutton type="radio" group="mode" observes="Console:modeWarnings"/>
@ -100,7 +106,7 @@
<toolbarbutton observes="Console:clear"/>
</toolbar>
<toolbar class="chromeclass-toolbar" id="ToolbarEval" grippytooltiptext="&entryToolbar.tooltip;">
<toolbar class="chromeclass-toolbar" id="ToolbarEval">
<textbox id="TextboxEval" class="toolbar" value="" onkeypress="onEvalKeyPress(event)" flex="1"/>
<toolbarbutton id="ButtonEval" label="&evaluate.label;" oncommand="evaluateTypein()"/>
</toolbar>

Просмотреть файл

@ -62,7 +62,9 @@
this.mSelectedItem.removeAttribute("selected");
this.mSelectedItem = val;
if (val)
val.setAttribute("selected", "true");
document.commandDispatcher.updateCommands("select");
]]></setter>
</property>
@ -92,6 +94,7 @@
this.mMode = this.getAttribute("mode") || "All";
this.appendInitialItems();
this.selectedItem = null; // fires command updater
]]></body>
</method>
@ -206,6 +209,7 @@
var newRows = this.mConsoleRowBox.cloneNode(false);
this.mConsoleRowBox.parentNode.replaceChild(newRows, this.mConsoleRowBox);
this.mConsoleRowBox = newRows;
this.selectedItem = null;
]]></body>
</method>
@ -294,7 +298,6 @@
while (target && !("_IsConsoleRow" in target))
target = target.parentNode;
if (target)
this.selectedItem = target;
}
]]></handler>

Просмотреть файл

@ -1,50 +0,0 @@
# 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 Communicator client code, released
# March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998-1999 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): ______________________________________.
<!ENTITY console.title "JavaScript Console">
<!ENTITY menuBar.tooltip "Menu Bar">
<!ENTITY modeToolbar.tooltip "Mode Toolbar">
<!ENTITY entryToolbar.tooltip "Javascript Entry Toolbar">
<!ENTITY errFile.label "Source File:">
<!ENTITY errLine.label "Line:">
<!ENTITY errColumn.label "Column:">
<!ENTITY all.label "All">
<!ENTITY all.accesskey "A">
<!ENTITY errors.label "Errors">
<!ENTITY errors.accesskey "r">
<!ENTITY warnings.label "Warnings">
<!ENTITY warnings.accesskey "n">
<!ENTITY messages.label "Messages">
<!ENTITY messages.accesskey "M">
<!ENTITY clear.label "Clear">
<!ENTITY clear.accesskey "l">
<!ENTITY evaluate.label "Evaluate">
<!ENTITY sortFirst.label "First > Last Sort Order">
<!ENTITY sortFirst.accesskey "f">
<!ENTITY sortLast.label "Last > First Sort Order">
<!ENTITY sortLast.accesskey "l">
<!ENTITY toolbarsCmd.label "Show/Hide">
<!ENTITY toolbarsCmd.accesskey "w">
<!ENTITY toolbarMode.label "Mode">
<!ENTITY toolbarEval.label "JavaScript Entry">