Skip to content
This repository
Browse code

update

  • Loading branch information...
commit 3b9b72be587d2ffd668a7381ba4900215e727a8f 1 parent ce6b1a1
Paul Rouget authored
36 bootstrap.js
@@ -19,11 +19,13 @@ function startup() {
19 19 window.removeEventListener("load", winWatcherLoad, false);
20 20 if (isBrowserWindow(window)) {
21 21 JSTermManager.addControlsToWindow(window);
  22 + JSTermManager.trackTabs(window);
22 23 trackedWindows.add(window);
23 24 }
24 25 }, false);
25 26 } else if (aTopic == "domwindowclosed") {
26 27 let window = aSubject.QueryInterface(Ci.nsIDOMWindow);
  28 + JSTermManager.untrackTabs(window);
27 29 trackedWindows.delete(window);
28 30 }
29 31 },
@@ -40,6 +42,7 @@ function startup() {
40 42 let window = winEnum.getNext().QueryInterface(Ci.nsIDOMWindow);
41 43 if (isBrowserWindow(window)) {
42 44 JSTermManager.addControlsToWindow(window);
  45 + JSTermManager.trackTabs(window);
43 46 trackedWindows.add(window);
44 47 }
45 48 }
@@ -53,6 +56,7 @@ function shutdown() {
53 56 let window = winEnum.getNext().QueryInterface(Ci.nsIDOMWindow);
54 57 if (trackedWindows && trackedWindows.has(window)) {
55 58 JSTermManager.removeControlsFromWindow(window);
  59 + JSTermManager.untrackTabs(window);
56 60 for (let b of window.gBrowser.browsers) {
57 61 JSTermManager.closeForBrowser(b);
58 62 }
@@ -69,6 +73,7 @@ function uninstall() {}
69 73
70 74 let JSTermManager = {
71 75 _map: new WeakMap(),
  76 + _listeners: new WeakMap(),
72 77
73 78 addControlsToWindow: function(aWindow) {
74 79 let doc = aWindow.document;
@@ -89,6 +94,24 @@ let JSTermManager = {
89 94 let button = aWindow.document.querySelector("#developer-toolbar-jsterm");
90 95 button.parentNode.removeChild(button);
91 96 },
  97 + trackTabs: function(aWindow) {
  98 + let tabs = aWindow.gBrowser.tabContainer;
  99 + let update = this.updateCheckboxStatus.bind(this, aWindow);
  100 + tabs.addEventListener("TabSelect", update, true);
  101 + this._listeners.set(aWindow, update);
  102 + aWindow.addEventListener("unload", function onClose(aEvent) {
  103 + tabs.removeEventListener("TabSelect", update, true);
  104 + aWindow.removeEventListener("unload", onClose, false);
  105 + }, false);
  106 + },
  107 + untrackTabs: function(aWindow) {
  108 + let tabs = aWindow.gBrowser.tabContainer;
  109 + let update = this._listeners.get(aWindow);
  110 + if (update) {
  111 + this._listeners.delete(aWindow);
  112 + tabs.removeEventListener("TabSelect", update, true);
  113 + }
  114 + },
92 115 isOpenForBrowser: function(aBrowser) {
93 116 return this._map.has(aBrowser);
94 117 },
@@ -104,7 +127,7 @@ let JSTermManager = {
104 127 return;
105 128 let term = new JSTerm(aBrowser);
106 129 this._map.set(aBrowser, term);
107   - this.updateCheckboxStatus(aBrowser);
  130 + this.updateCheckboxStatus(aBrowser.ownerDocument.defaultView);
108 131 },
109 132 closeForBrowser: function(aBrowser) {
110 133 let term = this._map.get(aBrowser);
@@ -112,9 +135,16 @@ let JSTermManager = {
112 135 return;
113 136 term.destroy();
114 137 this._map.delete(aBrowser);
115   - this.updateCheckboxStatus(aBrowser);
  138 + this.updateCheckboxStatus(aBrowser.ownerDocument.defaultView);
116 139 },
117   - updateCheckboxStatus: function(aBrowser) {
  140 + updateCheckboxStatus: function(aWindow) {
  141 + let selectedBrowser = aWindow.gBrowser.selectedBrowser;
  142 + let checked = this.isOpenForBrowser(selectedBrowser);
  143 + let button = aWindow.document.querySelector("#developer-toolbar-jsterm");
  144 + if (checked)
  145 + button.setAttribute("checked", "true");
  146 + else
  147 + button.setAttribute("checked", "false");
118 148 },
119 149 }
120 150
83 chrome/jsterm.js
@@ -5,12 +5,12 @@ Cu.import("resource:///modules/WebConsoleUtils.jsm");
5 5
6 6 /**
7 7 * Todo
8   - * . ctrl-c should copy the output selection if any
9   - * . delete listeners & map
10 8 * . checkbox status
11   - * . highlight common DOM keywords
  9 + * . undock
12 10 * . save history and share it
  11 + * . ctrl-c should copy the output selection if any
13 12 * . make tree width persistent
  13 + * . delete listeners & map
14 14 */
15 15
16 16 const JSTERM_MARK = "orion.annotation.jstermobject";
@@ -252,6 +252,11 @@ let JSTermUI = {
252 252 error = ex;
253 253 }
254 254
  255 + this.dumpEntryResult(result, error, code);
  256 +
  257 + },
  258 +
  259 + dumpEntryResult: function(result, error, code) {
255 260 if (error) {
256 261 error = error.toString();
257 262 if (this.isMultiline(error) || this.isMultiline(code) || this.printedSomething) {
@@ -259,49 +264,51 @@ let JSTermUI = {
259 264 } else {
260 265 this.output.setText(" // error: " + error, this.output.getCharCount());
261 266 }
  267 + return;
  268 + }
  269 +
  270 + let isAnObject = (typeof result) == "object";
  271 + let isAFunction = (typeof result) == "function";
  272 +
  273 + let resultStr;
  274 + if (result == undefined) {
  275 + resultStr = "undefined";
  276 + } else if ((typeof result) == "string") {
  277 + resultStr = "\"" + result + "\"";
262 278 } else {
263   - if ((typeof result) == "string") {
264   - result = "\"" + result + "\"";
265   - }
  279 + resultStr = result.toString();
  280 + }
266 281
267   - let isAnObject = (typeof result) == "object";
268   - let resultStr;
  282 + if (code == resultStr ||
  283 + (result == undefined && this.printedSomething)) {
  284 + return;
  285 + }
269 286
270   - if (result == undefined) {
271   - resultStr = "undefined";
272   - } else {
273   - resultStr = result.toString();
274   - }
  287 + if (isAnObject) {
  288 + resultStr += " [+]";
  289 + }
275 290
276   - if (isAnObject) {
277   - resultStr += " [+]";
  291 + if (this.isMultiline(resultStr)) {
  292 + if (!isAFunction) {
  293 + resultStr = "\n/*\n" + resultStr + "\n*/";
  294 + } else {
  295 + resultStr = "\n" + resultStr;
278 296 }
279   -
280   - if (code == resultStr) {
281   - // Do nothing
  297 + } else {
  298 + if (this.isMultiline(code) || this.printedSomething) {
  299 + resultStr = "\n// " + resultStr;
282 300 } else {
283   - if (this.isMultiline(code) || this.printedSomething) {
284   - if (result == undefined && this.printedSomething) {
285   - // Do nothing. I don't think it's interesting to print "undefined" in this case.
286   - } else if (this.isMultiline(resultStr)) {
287   - this.output.setText("\n/*\n" + resultStr + "\n*/", this.output.getCharCount());
288   - } else {
289   - this.output.setText("\n// " + resultStr, this.output.getCharCount());
290   - }
291   - } else {
292   - if (this.isMultiline(resultStr)) {
293   - this.output.setText("\n/*\n" + resultStr + "\n*/", this.output.getCharCount());
294   - } else {
295   - this.output.setText(" // " + resultStr, this.output.getCharCount());
296   - }
297   - }
298   - if (isAnObject) {
299   - let line = this.output.getLineCount() - 1;
300   - this.objects.set(line, result);
301   - this.markRange(line);
302   - }
  301 + resultStr = " // " + resultStr;
303 302 }
304 303 }
  304 +
  305 + this.output.setText(resultStr, this.output.getCharCount());
  306 +
  307 + if (isAnObject) {
  308 + let line = this.output.getLineCount() - 1;
  309 + this.objects.set(line, result);
  310 + this.markRange(line);
  311 + }
305 312 },
306 313
307 314 isMultiline: function(text) {
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.