Skip to content
Browse files

update

  • Loading branch information...
1 parent 60e2254 commit b80fa8d698dad53c8462e3e61540f177890db6da @paulrouget committed
Showing with 1,077 additions and 1,418 deletions.
  1. +1 −1 Makefile
  2. +16 −271 bootstrap.js
  3. +1 −2 chrome/jsterm.css
  4. +1,058 −1,128 chrome/jsterm.js
  5. +1 −16 chrome/jsterm.xul
  6. BIN jsterm.xpi
View
2 Makefile
@@ -6,4 +6,4 @@ FILES = chrome/ \
all:
rm -f jsterm.xpi && zip -r jsterm.xpi $(FILES)
- wget --post-file=$(PWD)/jsterm.xpi http://localhost:8888/
+ wget --post-file=$(PWD)/jsterm.xpi http://localhost:8899/
View
287 bootstrap.js
@@ -3,70 +3,25 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
Cu.import("resource://gre/modules/Services.jsm");
-//Cu.import("resource://jsterm/modules/JSTermManager.jsm");
+Cu.import("resource:///modules/devtools/gDevTools.jsm");
-let trackedWindows;
-let wObserver;
+let manifest = {
+ id: "jsterm",
+ label: "JSTerm",
+ url: "chrome://jsterm/content/jsterm.xul",
+ build: function(aIFrameWindow, aTarget) {
+ dump("BUILD\n");
+ return new JSTerm(aIFrameWindow, aTarget);
+ },
+};
function startup() {
- function isBrowserWindow(aWindow) {
- let winType = aWindow.document.documentElement.getAttribute("windowtype");
- return winType === "navigator:browser";
- }
-
- wObserver = {
- observe: function(aSubject, aTopic, aData) {
- if (aTopic == "domwindowopened") {
- let window = aSubject.QueryInterface(Ci.nsIDOMWindow);
- window.addEventListener("load", function winWatcherLoad() {
- 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);
- }
- },
- }
-
- let wWatcher = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(Ci.nsIWindowWatcher);
- let winEnum = wWatcher.getWindowEnumerator();
- wWatcher.registerNotification(wObserver);
-
- trackedWindows = new Set();
-
- let winEnum = wWatcher.getWindowEnumerator();
- while (winEnum.hasMoreElements()) {
- let window = winEnum.getNext().QueryInterface(Ci.nsIDOMWindow);
- if (isBrowserWindow(window)) {
- JSTermManager.addControlsToWindow(window);
- JSTermManager.trackTabs(window);
- trackedWindows.add(window);
- }
- }
+ dump("REGISTER: " + gDevTools + "\n");
+ gDevTools.registerTool(manifest);
}
function shutdown() {
- let wWatcher = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(Ci.nsIWindowWatcher);
- wWatcher.unregisterNotification(wObserver);
- let winEnum = wWatcher.getWindowEnumerator();
- while (winEnum.hasMoreElements()) {
- 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);
- }
- }
- }
- trackedWindows = null;
- wObserver = null;
+ gDevTools.unregisterTool(manifest.id);
}
function install() {}
@@ -74,222 +29,12 @@ function uninstall() {}
/* ***** resource **** */
-let JSTermManager = {
- _map: new WeakMap(),
- _listeners: new WeakMap(),
- where: "in_browser",
-
- addControlsToWindow: function(aWindow) {
- let strings = Services.strings.createBundle("chrome://jsterm/locale/jsterm.properties");
-
- let doc = aWindow.document;
-
- aWindow.JSTermManager = this;
-
- let command = doc.createElement("command");
- command.id = "Tools:JSTerm";
- command.setAttribute("oncommand", "JSTermManager.toggleForBrowser(this)");
- doc.querySelector("#mainCommandSet").appendChild(command);
-
- let broadcaster = doc.createElement("broadcaster");
- broadcaster.id = "devtoolsMenuBroadcaster_JSTerm";
- broadcaster.setAttribute("label", strings.GetStringFromName("JSTerm.menu.label"));
- broadcaster.setAttribute("type", "checkbox");
- broadcaster.setAttribute("autocheck", "false");
- broadcaster.setAttribute("key", "key_JSTerm");
- broadcaster.setAttribute("command", "Tools:JSTerm");
- doc.querySelector("#mainBroadcasterSet").appendChild(broadcaster);
-
- let menubaritem = doc.createElement("menuitem");
- menubaritem.classList.add("jsterm-addon");
- menubaritem.id = "menu_JSTerm";
- menubaritem.setAttribute("observes", "devtoolsMenuBroadcaster_JSTerm");
- let webConsoleMenu = doc.querySelector("#webConsole");
- doc.querySelector("#menuWebDeveloperPopup").insertBefore(menubaritem, webConsoleMenu);
-
- let appmenuPopup = doc.querySelector("#appmenu_webDeveloper_popup");
- if (appmenuPopup) { // no appmenu on Mac
- let appmenuitem = doc.createElement("menuitem");
- appmenuitem.classList.add("jsterm-addon");
- appmenuitem.id = "appmenu_JSTerm";
- appmenuitem.setAttribute("observes", "devtoolsMenuBroadcaster_JSTerm");
- let webConsoleAppMenu = doc.querySelector("#appmenu_webConsole");
- appmenuPopup.insertBefore(appmenuitem, webConsoleAppMenu);
- }
-
- let key = doc.createElement("key");
- key.classList.add("jsterm-addon");
- key.id = "key_JSTerm";
- key.setAttribute("key", strings.GetStringFromName("JSTerm.key"));
- key.setAttribute("command", "Tools:JSTerm");
- key.setAttribute("modifiers", "accel,alt")
- doc.querySelector("#mainKeyset").appendChild(key);
-
- let button = doc.createElement("toolbarbutton");
- button.setAttribute("observes", "devtoolsMenuBroadcaster_JSTerm");
- button.classList.add("developer-toolbar-button");
- button.classList.add("jsterm-addon");
- button.id = "developer-toolbar-jsterm";
- button.setAttribute("style", "-moz-image-region: rect(0, 16px, 16px, 0);");
- let before = doc.querySelector("#developer-toolbar-webconsole");
- doc.querySelector("#developer-toolbar").insertBefore(button, before);
- },
- removeControlsFromWindow: function(aWindow) {
- let elts = aWindow.document.querySelectorAll(".jsterm-addon,#devtoolsMenuBroadcaster_JSTerm");
- for (let e of elts) {
- try{
- e.parentNode.removeChild(e);
- }catch(e){}
- }
- let cmd = aWindow.document.getElementById("Tools:JSTerm");
- cmd.parentNode.removeChild(cmd);
- },
- 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 update = this._listeners.get(aWindow);
- if (update) {
- let tabs = aWindow.gBrowser.tabContainer;
- this._listeners.delete(aWindow);
- tabs.removeEventListener("TabSelect", update, true);
- }
- },
- isOpenForBrowser: function(aBrowser) {
- return this._map.has(aBrowser);
- },
- toggleForBrowser: function(aTarget) {
- let browser = aTarget.ownerDocument.defaultView.gBrowser.selectedBrowser;
- if (this.isOpenForBrowser(browser)) {
- this.closeForBrowser(browser);
- } else {
- this.openForBrowser(browser);
- }
- },
- openForBrowser: function(aBrowser) {
- if (this.isOpenForBrowser(aBrowser))
- return;
- let term = new JSTerm(aBrowser);
- this._map.set(aBrowser, term);
- this.updateCheckboxStatus(aBrowser.ownerDocument.defaultView);
- },
- closeForBrowser: function(aBrowser) {
- JSTermGlobalHistory.saveToPref();
- let term = this._map.get(aBrowser);
- if (!term)
- return;
- term.destroy();
- this._map.delete(aBrowser);
- this.updateCheckboxStatus(aBrowser.ownerDocument.defaultView);
- },
- moveTermTo: function(aBrowser, aWhere) {
- this.where = aWhere;
- let term = this._map.get(aBrowser);
- if (!term)
- return;
- term.rebuildUI();
- },
-
- isTermDocked: function(aBrowser) {
- let term = this._map.get(aBrowser);
- return term.docked;
- },
-
- updateCheckboxStatus: function(aWindow) {
- let selectedBrowser = aWindow.gBrowser.selectedBrowser;
- let checked = this.isOpenForBrowser(selectedBrowser);
- let broadcaster = aWindow.document.querySelector("#devtoolsMenuBroadcaster_JSTerm");
- if (checked)
- broadcaster.setAttribute("checked", "true");
- else
- broadcaster.setAttribute("checked", "false");
- },
-}
-
-function JSTerm(aBrowser) {
- this.browser = aBrowser;
- this.chromeDoc = aBrowser.ownerDocument;
- this.chromeWin = this.chromeDoc.defaultView;
- this.buildUI();
- this.savedContent = null;
+function JSTerm(aIFrameWindow, aTarget) {
+ aIFrameWindow.JSTermUI.init(JSTermGlobalHistory, aTarget);
}
JSTerm.prototype = {
- buildUI: function() {
- const CHROME_URL = "chrome://jsterm/content/jsterm.xul";
- const CHROME_WINDOW_FLAGS = "chrome,centerscreen,resizable,dialog=no";
-
- let termWindow;
- let doc = this.chromeDoc;
-
- this.docked = (JSTermManager.where == "in_browser");
-
- if (this.docked) {
- let nbox = this.chromeWin.gBrowser.getNotificationBox(this.browser);
- let splitter = doc.createElement("splitter");
- splitter.className = "devtools-horizontal-splitter jsterm-splitter";
-
- let container = doc.createElement("vbox");
- container.setAttribute("flex", "1");
- container.className = "jsterm-container";
- container.height = 200;
-
- let iframe = doc.createElement("iframe");
- iframe.setAttribute("src", CHROME_URL);
- iframe.setAttribute("flex", "1")
-
- container.appendChild(iframe);
- nbox.appendChild(splitter);
- nbox.appendChild(container);
-
- termWindow = iframe.contentWindow;
- } else {
- termWindow = Services.ww.openWindow(null, CHROME_URL, "_blank", CHROME_WINDOW_FLAGS, {});
- }
-
- termWindow.onload = function() {
- termWindow.JSTermUI.init(JSTermManager,
- JSTermGlobalHistory,
- this.browser,
- this.chromeWin,
- this.savedContent);
- }.bind(this);
-
- this.termWindow = termWindow;
- },
-
- rebuildUI: function() {
- this.savedContent = this.termWindow.JSTermUI.getContent();
- this.destroyUI();
- this.buildUI();
- },
-
- destroyUI: function() {
- let nbox = this.chromeWin.gBrowser.getNotificationBox(this.browser);
- let container = nbox.querySelector(".jsterm-container");
- if (container) {
- let splitter = nbox.querySelector(".jsterm-splitter");
- splitter.parentNode.removeChild(splitter);
- container.parentNode.removeChild(container);
- } else {
- this.termWindow.close()
- }
- },
-
- destroy: function() {
- this.destroyUI();
- this.termWindow = null;
- this.browser = null;
- this.chromeDoc = null;
- this.chromeWin = null;
- }
+ destroy: function(){},
}
View
3 chrome/jsterm.css
@@ -1,6 +1,5 @@
window {
- background-color: #131c26;
- background-image: url("chrome://browser/skin/devtools/responsive-background.png");
+ background-color: rgb(20,20,20);
color: white;
font-family: Monaco, monospace;
font-size: 12px;
View
2,186 chrome/jsterm.js
1,058 additions, 1,128 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
17 chrome/jsterm.xul
@@ -9,24 +9,9 @@
<window id="jsterm-window"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- title="JSTerm"
- windowtype="devtools:jsterm"
- fullscreenbutton="true"
- macanimationtype="document"
- screenX="4" screenY="4"
- width="640" height="480"
- onunload="JSTermUI.closeIfInWindow()"
- persist="screenX screenY width height sizemode">
-
+ title="JSTerm">
<script type="application/javascript" src="jsterm.js"/>
- <keyset id="jsterm-keyset">
- <key id="jsterm-key-close"
- key="&JSTerm.closeKey;"
- oncommand="JSTermUI.closeIfInWindow()"
- modifiers="accel"/>
- </keyset>
-
<hbox flex="1">
<vbox flex="1">
<vbox id="editors-container" flex="1" onclick="JSTermUI.focus()">
View
BIN jsterm.xpi
Binary file not shown.

0 comments on commit b80fa8d

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