Skip to content
Browse files

update

  • Loading branch information...
1 parent ce6b1a1 commit 3b9b72be587d2ffd668a7381ba4900215e727a8f @paulrouget committed Jul 18, 2012
Showing with 78 additions and 41 deletions.
  1. +33 −3 bootstrap.js
  2. +45 −38 chrome/jsterm.js
  3. BIN jsterm.xpi
View
36 bootstrap.js
@@ -19,11 +19,13 @@ function startup() {
window.removeEventListener("load", winWatcherLoad, false);
if (isBrowserWindow(window)) {
JSTermManager.addControlsToWindow(window);
+ JSTermManager.trackTabs(window);
trackedWindows.add(window);
}
}, false);
} else if (aTopic == "domwindowclosed") {
let window = aSubject.QueryInterface(Ci.nsIDOMWindow);
+ JSTermManager.untrackTabs(window);
trackedWindows.delete(window);
}
},
@@ -40,6 +42,7 @@ function startup() {
let window = winEnum.getNext().QueryInterface(Ci.nsIDOMWindow);
if (isBrowserWindow(window)) {
JSTermManager.addControlsToWindow(window);
+ JSTermManager.trackTabs(window);
trackedWindows.add(window);
}
}
@@ -53,6 +56,7 @@ function shutdown() {
let window = winEnum.getNext().QueryInterface(Ci.nsIDOMWindow);
if (trackedWindows && trackedWindows.has(window)) {
JSTermManager.removeControlsFromWindow(window);
+ JSTermManager.untrackTabs(window);
for (let b of window.gBrowser.browsers) {
JSTermManager.closeForBrowser(b);
}
@@ -69,6 +73,7 @@ function uninstall() {}
let JSTermManager = {
_map: new WeakMap(),
+ _listeners: new WeakMap(),
addControlsToWindow: function(aWindow) {
let doc = aWindow.document;
@@ -89,6 +94,24 @@ let JSTermManager = {
let button = aWindow.document.querySelector("#developer-toolbar-jsterm");
button.parentNode.removeChild(button);
},
+ trackTabs: function(aWindow) {
+ let tabs = aWindow.gBrowser.tabContainer;
+ let update = this.updateCheckboxStatus.bind(this, aWindow);
+ tabs.addEventListener("TabSelect", update, true);
+ this._listeners.set(aWindow, update);
+ aWindow.addEventListener("unload", function onClose(aEvent) {
+ tabs.removeEventListener("TabSelect", update, true);
+ aWindow.removeEventListener("unload", onClose, false);
+ }, false);
+ },
+ untrackTabs: function(aWindow) {
+ let tabs = aWindow.gBrowser.tabContainer;
+ let update = this._listeners.get(aWindow);
+ if (update) {
+ this._listeners.delete(aWindow);
+ tabs.removeEventListener("TabSelect", update, true);
+ }
+ },
isOpenForBrowser: function(aBrowser) {
return this._map.has(aBrowser);
},
@@ -104,17 +127,24 @@ let JSTermManager = {
return;
let term = new JSTerm(aBrowser);
this._map.set(aBrowser, term);
- this.updateCheckboxStatus(aBrowser);
+ this.updateCheckboxStatus(aBrowser.ownerDocument.defaultView);
},
closeForBrowser: function(aBrowser) {
let term = this._map.get(aBrowser);
if (!term)
return;
term.destroy();
this._map.delete(aBrowser);
- this.updateCheckboxStatus(aBrowser);
+ this.updateCheckboxStatus(aBrowser.ownerDocument.defaultView);
},
- updateCheckboxStatus: function(aBrowser) {
+ updateCheckboxStatus: function(aWindow) {
+ let selectedBrowser = aWindow.gBrowser.selectedBrowser;
+ let checked = this.isOpenForBrowser(selectedBrowser);
+ let button = aWindow.document.querySelector("#developer-toolbar-jsterm");
+ if (checked)
+ button.setAttribute("checked", "true");
+ else
+ button.setAttribute("checked", "false");
},
}
View
83 chrome/jsterm.js
@@ -5,12 +5,12 @@ Cu.import("resource:///modules/WebConsoleUtils.jsm");
/**
* Todo
- * . ctrl-c should copy the output selection if any
- * . delete listeners & map
* . checkbox status
- * . highlight common DOM keywords
+ * . undock
* . save history and share it
+ * . ctrl-c should copy the output selection if any
* . make tree width persistent
+ * . delete listeners & map
*/
const JSTERM_MARK = "orion.annotation.jstermobject";
@@ -252,56 +252,63 @@ let JSTermUI = {
error = ex;
}
+ this.dumpEntryResult(result, error, code);
+
+ },
+
+ dumpEntryResult: function(result, error, code) {
if (error) {
error = error.toString();
if (this.isMultiline(error) || this.isMultiline(code) || this.printedSomething) {
this.output.setText("\n/* error:\n" + error + "\n*/", this.output.getCharCount());
} else {
this.output.setText(" // error: " + error, this.output.getCharCount());
}
+ return;
+ }
+
+ let isAnObject = (typeof result) == "object";
+ let isAFunction = (typeof result) == "function";
+
+ let resultStr;
+ if (result == undefined) {
+ resultStr = "undefined";
+ } else if ((typeof result) == "string") {
+ resultStr = "\"" + result + "\"";
} else {
- if ((typeof result) == "string") {
- result = "\"" + result + "\"";
- }
+ resultStr = result.toString();
+ }
- let isAnObject = (typeof result) == "object";
- let resultStr;
+ if (code == resultStr ||
+ (result == undefined && this.printedSomething)) {
+ return;
+ }
- if (result == undefined) {
- resultStr = "undefined";
- } else {
- resultStr = result.toString();
- }
+ if (isAnObject) {
+ resultStr += " [+]";
+ }
- if (isAnObject) {
- resultStr += " [+]";
+ if (this.isMultiline(resultStr)) {
+ if (!isAFunction) {
+ resultStr = "\n/*\n" + resultStr + "\n*/";
+ } else {
+ resultStr = "\n" + resultStr;
}
-
- if (code == resultStr) {
- // Do nothing
+ } else {
+ if (this.isMultiline(code) || this.printedSomething) {
+ resultStr = "\n// " + resultStr;
} else {
- if (this.isMultiline(code) || this.printedSomething) {
- if (result == undefined && this.printedSomething) {
- // Do nothing. I don't think it's interesting to print "undefined" in this case.
- } else if (this.isMultiline(resultStr)) {
- this.output.setText("\n/*\n" + resultStr + "\n*/", this.output.getCharCount());
- } else {
- this.output.setText("\n// " + resultStr, this.output.getCharCount());
- }
- } else {
- if (this.isMultiline(resultStr)) {
- this.output.setText("\n/*\n" + resultStr + "\n*/", this.output.getCharCount());
- } else {
- this.output.setText(" // " + resultStr, this.output.getCharCount());
- }
- }
- if (isAnObject) {
- let line = this.output.getLineCount() - 1;
- this.objects.set(line, result);
- this.markRange(line);
- }
+ resultStr = " // " + resultStr;
}
}
+
+ this.output.setText(resultStr, this.output.getCharCount());
+
+ if (isAnObject) {
+ let line = this.output.getLineCount() - 1;
+ this.objects.set(line, result);
+ this.markRange(line);
+ }
},
isMultiline: function(text) {
View
BIN jsterm.xpi
Binary file not shown.

0 comments on commit 3b9b72b

Please sign in to comment.
Something went wrong with that request. Please try again.