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
parent 9c312c01ec
commit bccb238eaa
4 changed files with 93 additions and 165 deletions

View File

@ -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;
}

View File

@ -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"
@ -42,15 +36,20 @@
screenX="10" screenY="10"
persist="screenX screenY width height">
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
<script type="application/x-javascript" src="chrome://global/content/console.js"/>
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
<script type="application/x-javascript" src="chrome://global/content/console.js"/>
<stringbundle id="ConsoleBundle" src="chrome://global/locale/console.properties"/>
<command id="cmd_copy" oncommand="copyItemToClipboard()"/>
<command id="cmd_close" oncommand="window.close()"/>
<stringbundle id="ConsoleBundle" src="chrome://global/locale/console.properties"/>
<broadcaster id="Console:clear" label="&clear.label;" oncommand="clearConsole();"/>
<commandset commandupdater="true"
events="select"
oncommandupdate="updateCopyMenu()">
<command id="cmd_copy" oncommand="copyItemToClipboard()"/>
</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,57 +57,64 @@
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;" accesskey="&all.accesskey;"
oncommand="changeMode('All');"/>
<broadcaster id="Console:modeErrors"
label="&errors.label;" accesskey="&errors.accesskey;"
oncommand="changeMode('Errors');"/>
<broadcaster id="Console:modeWarnings"
label="&warnings.label;" accesskey="&warnings.accesskey;"
oncommand="changeMode('Warnings');"/>
<broadcaster id="Console:modeMessages"
label="&messages.label;" accesskey="&messages.accesskey;"
oncommand="changeMode('Messages');"/>
</broadcasterset>
<broadcasterset id="ModeBroadcasters">
<broadcaster id="Console:modeAll" label="&all.label;"
oncommand="changeMode('All');"/>
<broadcaster id="Console:modeErrors" label="&errors.label;"
oncommand="changeMode('Errors');"/>
<broadcaster id="Console:modeWarnings" label="&warnings.label;"
oncommand="changeMode('Warnings');"/>
<broadcaster id="Console:modeMessages" label="&messages.label;"
oncommand="changeMode('Messages');"/>
</broadcasterset>
<keyset>
<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>
<keyset>
<key id="key_copy"/>
<key id="key_close"/>
</keyset>
<popupset id="ContextMenus">
<popup id="ConsoleContext" onpopupshowing="UpdateCopyMenu()">
<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;"/>
</popup>
</popupset>
<popupset id="ContextMenus">
<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;" key="key_copy" accesskey="&copyCmd.accesskey;"/>
</popup>
</popupset>
<toolbox>
<toolbar class="chromeclass-toolbar" id="ToolbarMode" grippytooltiptext="&modeToolbar.tooltip;">
<toolbarbutton type="radio" group="mode" observes="Console:modeAll"/>
<toolbarbutton type="radio" group="mode" observes="Console:modeErrors"/>
<toolbarbutton type="radio" group="mode" observes="Console:modeWarnings"/>
<toolbarbutton type="radio" group="mode" observes="Console:modeMessages"/>
<toolbarseparator/>
<toolbarbutton observes="Console:clear"/>
</toolbar>
<toolbox>
<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"/>
<toolbarbutton type="radio" group="mode" observes="Console:modeMessages"/>
<toolbarseparator/>
<toolbarbutton observes="Console:clear"/>
</toolbar>
<toolbar class="chromeclass-toolbar" id="ToolbarEval" grippytooltiptext="&entryToolbar.tooltip;">
<textbox id="TextboxEval" class="toolbar" value="" onkeypress="onEvalKeyPress(event)" flex="1"/>
<toolbarbutton id="ButtonEval" label="&evaluate.label;" oncommand="evaluateTypein()"/>
</toolbar>
</toolbox>
<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>
</toolbox>
<vbox id="ConsoleBox" class="console-box" flex="1" context="ConsoleContext" persist="sortOrder"/>
<vbox id="ConsoleBox" class="console-box" flex="1" context="ConsoleContext" persist="sortOrder"/>
<iframe name="Evaluator" id="Evaluator" collapsed="true"/>
<iframe name="Evaluator" id="Evaluator" collapsed="true"/>
</window>

View File

@ -62,7 +62,9 @@
this.mSelectedItem.removeAttribute("selected");
this.mSelectedItem = val;
val.setAttribute("selected", "true");
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,8 +298,7 @@
while (target && !("_IsConsoleRow" in target))
target = target.parentNode;
if (target)
this.selectedItem = target;
this.selectedItem = target;
}
]]></handler>
</handlers>

View File

@ -20,31 +20,29 @@
<!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 all.label "All">
<!ENTITY all.accesskey "A">
<!ENTITY errors.label "Errors">
<!ENTITY errors.accesskey "E">
<!ENTITY warnings.label "Warnings">
<!ENTITY warnings.accesskey "W">
<!ENTITY messages.label "Messages">
<!ENTITY messages.accesskey "M">
<!ENTITY clear.label "Clear">
<!ENTITY clear.accesskey "l">
<!ENTITY evaluate.label "Evaluate">
<!ENTITY clear.label "Clear">
<!ENTITY clear.accesskey "C">
<!ENTITY evaluate.label "Evaluate">
<!ENTITY sortFirst.label "First > Last Sort Order">
<!ENTITY copyCmd.label "Copy">
<!ENTITY copyCmd.accesskey "C">
<!ENTITY copyCmd.commandkey "C">
<!ENTITY sortFirst.label "First > Last Sort Order">
<!ENTITY sortFirst.accesskey "f">
<!ENTITY sortLast.label "Last > First Sort Order">
<!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">
<!ENTITY closeCmd.commandkey "w">
<!ENTITY focus1.commandkey "l">
<!ENTITY focus2.commandkey "d">