1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 function closeWindow(aClose, aPromptFunction)
7 # Closing the last window doesn't quit the application on OS X.
10 var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
11 .getService(Components.interfaces.nsIWindowMediator);
12 var e = wm.getEnumerator(null);
14 while (e.hasMoreElements()) {
19 if (++windowCount == 2)
23 // If we're down to the last window and someone tries to shut down, check to make sure we can!
24 if (windowCount == 1 && !canQuitApplication("lastwindow"))
26 else if (windowCount != 1)
28 if (typeof(aPromptFunction) == "function" && !aPromptFunction())
37 function canQuitApplication(aData)
39 var os = Components.classes["@mozilla.org/observer-service;1"]
40 .getService(Components.interfaces.nsIObserverService);
44 var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
45 .createInstance(Components.interfaces.nsISupportsPRBool);
46 os.notifyObservers(cancelQuit, "quit-application-requested", aData || null);
48 // Something aborted the quit process.
56 function goQuitApplication()
58 if (!canQuitApplication())
61 var appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'].
62 getService(Components.interfaces.nsIAppStartup);
64 appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
69 // Command Updater functions
71 function goUpdateCommand(aCommand)
74 var controller = top.document.commandDispatcher
75 .getControllerForCommand(aCommand);
79 enabled = controller.isCommandEnabled(aCommand);
81 goSetCommandEnabled(aCommand, enabled);
84 Components.utils.reportError("An error occurred updating the " +
85 aCommand + " command: " + e);
89 function goDoCommand(aCommand)
92 var controller = top.document.commandDispatcher
93 .getControllerForCommand(aCommand);
94 if (controller && controller.isCommandEnabled(aCommand))
95 controller.doCommand(aCommand);
98 Components.utils.reportError("An error occurred executing the " +
99 aCommand + " command: " + e);
104 function goSetCommandEnabled(aID, aEnabled)
106 var node = document.getElementById(aID);
110 node.removeAttribute("disabled");
112 node.setAttribute("disabled", "true");
116 function goSetMenuValue(aCommand, aLabelAttribute)
118 var commandNode = top.document.getElementById(aCommand);
120 var label = commandNode.getAttribute(aLabelAttribute);
122 commandNode.setAttribute("label", label);
126 function goSetAccessKey(aCommand, aValueAttribute)
128 var commandNode = top.document.getElementById(aCommand);
130 var value = commandNode.getAttribute(aValueAttribute);
132 commandNode.setAttribute("accesskey", value);
136 // this function is used to inform all the controllers attached to a node that an event has occurred
137 // (e.g. the tree controllers need to be informed of blur events so that they can change some of the
138 // menu items back to their default values)
139 function goOnEvent(aNode, aEvent)
141 var numControllers = aNode.controllers.getControllerCount();
144 for (var controllerIndex = 0; controllerIndex < numControllers; controllerIndex++) {
145 controller = aNode.controllers.getControllerAt(controllerIndex);
147 controller.onEvent(aEvent);
151 function visitLink(aEvent) {
152 var node = aEvent.target;
153 while (node.nodeType != Node.ELEMENT_NODE)
154 node = node.parentNode;
155 var url = node.getAttribute("link");
159 var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
160 .getService(Components.interfaces.nsIExternalProtocolService);
161 var ioService = Components.classes["@mozilla.org/network/io-service;1"]
162 .getService(Components.interfaces.nsIIOService);
163 var uri = ioService.newURI(url, null, null);
165 // if the scheme is not an exposed protocol, then opening this link
166 // should be deferred to the system's external protocol handler
167 if (protocolSvc.isExposedProtocol(uri.scheme)) {
168 var win = window.top;
169 if (win instanceof Components.interfaces.nsIDOMChromeWindow) {
170 while (win.opener && !win.opener.closed)
176 protocolSvc.loadUrl(uri);
179 function setTooltipText(aID, aTooltipText)
181 var element = document.getElementById(aID);
183 element.setAttribute("tooltiptext", aTooltipText);
186 this.__defineGetter__("NS_ASSERT", function() {
187 delete this.NS_ASSERT;
189 Components.utils.import("resource://gre/modules/debug.js", tmpScope);
190 return this.NS_ASSERT = tmpScope.NS_ASSERT;