Bug 679753 - Remove Scratchpad's status bar, the Environment menu and the Tools menu; r=rcampbell

This commit is contained in:
Cedric Vivier 2011-10-26 19:35:32 +08:00
parent 82d54b90d0
commit e6311667a3
9 changed files with 75 additions and 89 deletions

View File

@ -84,10 +84,10 @@ var Scratchpad = {
executionContext: SCRATCHPAD_CONTEXT_CONTENT,
/**
* Retrieve the xul:statusbarpanel DOM element. The status bar tells the
* current code execution context.
* Retrieve the xul:notificationbox DOM element. It notifies the user when
* the current code execution context is SCRATCHPAD_CONTEXT_BROWSER.
*/
get statusbarStatus() document.getElementById("scratchpad-status"),
get notificationBox() document.getElementById("scratchpad-notificationbox"),
/**
* Get the selected text from the editor.
@ -599,11 +599,15 @@ var Scratchpad = {
*/
setContentContext: function SP_setContentContext()
{
if (this.executionContext == SCRATCHPAD_CONTEXT_CONTENT) {
return;
}
let content = document.getElementById("sp-menu-content");
document.getElementById("sp-menu-browser").removeAttribute("checked");
content.setAttribute("checked", true);
this.executionContext = SCRATCHPAD_CONTEXT_CONTENT;
this.statusbarStatus.label = content.getAttribute("label");
this.notificationBox.removeAllNotifications(false);
this.resetContext();
},
@ -612,11 +616,20 @@ var Scratchpad = {
*/
setBrowserContext: function SP_setBrowserContext()
{
if (this.executionContext == SCRATCHPAD_CONTEXT_BROWSER) {
return;
}
let browser = document.getElementById("sp-menu-browser");
document.getElementById("sp-menu-content").removeAttribute("checked");
browser.setAttribute("checked", true);
this.executionContext = SCRATCHPAD_CONTEXT_BROWSER;
this.statusbarStatus.label = browser.getAttribute("label");
this.notificationBox.appendNotification(
this.strings.GetStringFromName("browserContext.notification"),
SCRATCHPAD_CONTEXT_BROWSER,
null,
this.notificationBox.PRIORITY_WARNING_HIGH,
null);
this.resetContext();
},
@ -657,17 +670,14 @@ var Scratchpad = {
return;
}
let chromeContextMenu = document.getElementById("sp-menu-browser");
let errorConsoleMenu = document.getElementById("sp-menu-errorConsole");
let errorConsoleCommand = document.getElementById("sp-cmd-errorConsole");
let chromeContextCommand = document.getElementById("sp-cmd-browserContext");
let chrome = Services.prefs.getBoolPref(DEVTOOLS_CHROME_ENABLED);
if (chrome) {
chromeContextMenu.removeAttribute("hidden");
errorConsoleMenu.removeAttribute("hidden");
errorConsoleCommand.removeAttribute("disabled");
let environmentMenu = document.getElementById("sp-environment-menu");
let errorConsoleCommand = document.getElementById("sp-cmd-errorConsole");
let chromeContextCommand = document.getElementById("sp-cmd-browserContext");
environmentMenu.removeAttribute("hidden");
chromeContextCommand.removeAttribute("disabled");
errorConsoleCommand.removeAttribute("disabled");
}
this.editor = new SourceEditor();

View File

@ -261,12 +261,18 @@
accesskey="&display.accesskey;"
key="sp-key-display"
command="sp-cmd-display"/>
<menuseparator/>
<menuitem id="sp-text-resetContext"
label="&resetContext2.label;"
accesskey="&resetContext2.accesskey;"
command="sp-cmd-resetContext"/>
</menupopup>
</menu>
<menu id="sp-environment-menu"
label="&environmentMenu.label;"
accesskey="&environmentMenu.accesskey;">
accesskey="&environmentMenu.accesskey;"
hidden="true">
<menupopup id="sp-menu-environment">
<menuitem id="sp-menu-content"
label="&contentContext.label;"
@ -274,33 +280,11 @@
command="sp-cmd-contentContext"
checked="true"
type="radio"/>
<menuitem id="sp-menu-browser" hidden="true"
<menuitem id="sp-menu-browser"
command="sp-cmd-browserContext"
label="&browserContext.label;"
accesskey="&browserContext.accesskey;"
type="radio"/>
<menuseparator/>
<menuitem id="sp-menu-resetContext"
command="sp-cmd-resetContext"
label="&resetContext.label;"
accesskey="&resetContext.accesskey;"/>
</menupopup>
</menu>
<menu id="sp-tools-menu"
label="&toolsMenu.label;"
accesskey="&toolsMenu.accesskey;">
<menupopup id="sp-menu-tools">
<menuitem id="sp-menu-errorConsole" hidden="true"
label="&errorConsoleCmd.label;"
accesskey="&errorConsoleCmd.accesskey;"
key="sp-key-errorConsole"
command="sp-cmd-errorConsole"/>
<menuitem id="sp-menu-webConsole"
label="&webConsoleCmd.label;"
accesskey="&webConsoleCmd.accesskey;"
key="sp-key-webConsole"
command="sp-cmd-webConsole"/>
</menupopup>
</menu>
</menubar>
@ -329,15 +313,16 @@
accesskey="&display.accesskey;"
key="sp-key-display"
command="sp-cmd-display"/>
<menuseparator/>
<menuitem id="sp-text-resetContext"
label="&resetContext2.label;"
accesskey="&resetContext2.accesskey;"
command="sp-cmd-resetContext"/>
</menupopup>
</popupset>
<hbox id="scratchpad-editor" flex="1" context="scratchpad-text-popup" />
<notificationbox id="scratchpad-notificationbox" flex="1">
<hbox id="scratchpad-editor" flex="1" context="scratchpad-text-popup" />
</notificationbox>
<statusbar id="scratchpad-statusbar" align="end">
<statusbarpanel id="scratchpad-status"
label="&contentContext.label;"
class="statusbarpanel-iconic-text"/>
<spacer flex="1"/>
</statusbar>
</window>

View File

@ -35,11 +35,11 @@ function runTests()
let sp = gScratchpadWindow.Scratchpad;
ok(sp, "Scratchpad object exists in new window");
let chromeContextMenu = gScratchpadWindow.document.
getElementById("sp-menu-browser");
ok(chromeContextMenu, "Chrome context menuitem element exists");
ok(!chromeContextMenu.hasAttribute("hidden"),
"Chrome context menuitem is visible");
let environmentMenu = gScratchpadWindow.document.
getElementById("sp-environment-menu");
ok(environmentMenu, "Environment menu element exists");
ok(!environmentMenu.hasAttribute("hidden"),
"Environment menu is visible");
let errorConsoleCommand = gScratchpadWindow.document.
getElementById("sp-cmd-errorConsole");
@ -47,12 +47,6 @@ function runTests()
ok(!errorConsoleCommand.hasAttribute("disabled"),
"Error console command is enabled");
let errorConsoleMenu = gScratchpadWindow.document.
getElementById("sp-menu-errorConsole");
ok(errorConsoleMenu, "Error console menu element exists");
ok(!errorConsoleMenu.hasAttribute("hidden"),
"Error console menuitem is visible");
let chromeContextCommand = gScratchpadWindow.document.
getElementById("sp-cmd-browserContext");
ok(chromeContextCommand, "Chrome context command element exists");

View File

@ -28,11 +28,11 @@ function runTests()
let contentMenu = gScratchpadWindow.document.getElementById("sp-menu-content");
let chromeMenu = gScratchpadWindow.document.getElementById("sp-menu-browser");
let statusbar = sp.statusbarStatus;
let notificationBox = sp.notificationBox;
ok(contentMenu, "found #sp-menu-content");
ok(chromeMenu, "found #sp-menu-browser");
ok(statusbar, "found Scratchpad.statusbarStatus");
ok(notificationBox, "found Scratchpad.notificationBox");
sp.setContentContext();
@ -45,8 +45,8 @@ function runTests()
ok(!chromeMenu.hasAttribute("checked"),
"chrome menuitem is not checked");
is(statusbar.getAttribute("label"), contentMenu.getAttribute("label"),
"statusbar label is correct");
ok(!notificationBox.currentNotification,
"there is no notification in content context");
sp.setText("window.foobarBug636725 = 'aloha';");
@ -69,8 +69,8 @@ function runTests()
ok(!contentMenu.hasAttribute("checked"),
"content menuitem is not checked");
is(statusbar.getAttribute("label"), chromeMenu.getAttribute("label"),
"statusbar label is correct");
ok(notificationBox.currentNotification,
"there is a notification in browser context");
sp.setText("2'", 31, 33);

View File

@ -32,11 +32,11 @@ function runTests()
is(typeof sp.inspect, "function", "Scratchpad.inspect() exists");
is(typeof sp.display, "function", "Scratchpad.display() exists");
let chromeContextMenu = gScratchpadWindow.document.
getElementById("sp-menu-browser");
ok(chromeContextMenu, "Chrome context menuitem element exists");
is(chromeContextMenu.getAttribute("hidden"), "true",
"Chrome context menuitem is hidden");
let environmentMenu = gScratchpadWindow.document.
getElementById("sp-environment-menu");
ok(environmentMenu, "Environment menu element exists");
ok(environmentMenu.hasAttribute("hidden"),
"Environment menu is not visible");
let errorConsoleCommand = gScratchpadWindow.document.
getElementById("sp-cmd-errorConsole");
@ -44,12 +44,6 @@ function runTests()
is(errorConsoleCommand.getAttribute("disabled"), "true",
"Error console command is disabled");
let errorConsoleMenu = gScratchpadWindow.document.
getElementById("sp-menu-errorConsole");
ok(errorConsoleMenu, "Error console menu element exists");
is(errorConsoleMenu.getAttribute("hidden"), "true",
"Error console menu item is hidden");
let chromeContextCommand = gScratchpadWindow.document.
getElementById("sp-cmd-browserContext");
ok(chromeContextCommand, "Chrome context command element exists");

View File

@ -38,11 +38,11 @@ function runTests()
let contentMenu = gScratchpadWindow.document.getElementById("sp-menu-content");
let browserMenu = gScratchpadWindow.document.getElementById("sp-menu-browser");
let statusbar = sp.statusbarStatus;
let notificationBox = sp.notificationBox;
ok(contentMenu, "found #sp-menu-content");
ok(browserMenu, "found #sp-menu-browser");
ok(statusbar, "found Scratchpad.statusbarStatus");
ok(notificationBox, "found Scratchpad.notificationBox");
sp.setContentContext();
@ -55,8 +55,8 @@ function runTests()
ok(!browserMenu.hasAttribute("checked"),
"chrome menuitem is not checked");
is(statusbar.getAttribute("label"), contentMenu.getAttribute("label"),
"statusbar label is correct");
is(notificationBox.currentNotification, null,
"there is no notification currently shown for content context");
sp.setText("window.foosbug653108 = 'aloha';");

View File

@ -36,11 +36,9 @@ function runTests()
"sp-text-run": "run",
"sp-text-inspect": "inspect",
"sp-text-display": "display",
"sp-text-resetContext": "resetContext",
"sp-menu-content": "setContentContext",
"sp-menu-browser": "setBrowserContext",
"sp-menu-resetContext": "resetContext",
"sp-menu-errorConsole": "openErrorConsole",
"sp-menu-webConsole": "openWebConsole",
"sp-menu-undo": "undo",
"sp-menu-redo": "redo",
};

View File

@ -95,22 +95,23 @@
<!ENTITY browserContext.label "Browser">
<!ENTITY browserContext.accesskey "B">
<!-- LOCALIZATION NOTE (resetContext.label): This command allows the developer
<!-- LOCALIZATION NOTE (resetContext2.label): This command allows the developer
- to reset/clear the global object of the environment where the code executes.
-->
<!ENTITY resetContext.label "Reset">
<!ENTITY resetContext.accesskey "R">
<!ENTITY resetContext2.label "Reset Variables">
<!ENTITY resetContext2.accesskey "T">
<!ENTITY executeMenu.label "Execute">
<!ENTITY executeMenu.accesskey "X">
<!ENTITY toolsMenu.label "Tools">
<!ENTITY toolsMenu.accesskey "T">
<!ENTITY errorConsoleCmd.label "Error Console">
<!ENTITY errorConsoleCmd.accesskey "C">
<!-- LOCALIZATION NOTE (errorConsoleCmd.commandkey): This command key launches
- the browser Error Console, the key should be identical to the property of
- the same name in browser.dtd.
-->
<!ENTITY errorConsoleCmd.commandkey "j">
<!ENTITY webConsoleCmd.label "Web Console">
<!ENTITY webConsoleCmd.accesskey "W">
<!-- LOCALIZATION NOTE (webConsoleCmd.commandkey): This command key launches
- the browser WebConsole, the key should be identical to the property of
- the same name in browser.dtd.
-->
<!ENTITY webConsoleCmd.commandkey "k">

View File

@ -33,3 +33,7 @@ saveFile.failed=The file save operation failed.
# how to use the Scratchpad. Note that this should be a valid JavaScript
# comment inside /* and */.
scratchpadIntro=/*\n * This is a JavaScript Scratchpad.\n *\n * Enter some JavaScript, then Right Click or choose from the Execute Menu:\n * 1. Run to evaluate the selected text,\n * 2. Inspect to bring up an Object Inspector on the result, or,\n * 3. Display to insert the result in a comment after the selection.\n */\n\n
# LOCALIZATION NOTE (notification.browserContext): This is the message displayed
# over the top of the editor when the user has switched to browser context.
browserContext.notification=This scratchpad executes in the Browser context.