1 function closeWindow(aClose
, aPromptFunction
)
4 var wm
= Components
.classes
["@mozilla.org/appshell/window-mediator;1"]
5 .getService(Components
.interfaces
.nsIWindowMediator
);
6 var e
= wm
.getEnumerator(null);
8 while (e
.hasMoreElements()) {
10 if (++windowCount
== 2)
14 # Closing the last window doesn
't quit the application on OS X.
16 // If we're down to the last window and someone tries to shut down
, check to make sure we can
!
17 if (windowCount
== 1 && !canQuitApplication())
19 else if (windowCount
!= 1)
21 if (typeof(aPromptFunction
) == "function" && !aPromptFunction())
30 function canQuitApplication()
32 var os
= Components
.classes
["@mozilla.org/observer-service;1"]
33 .getService(Components
.interfaces
.nsIObserverService
);
37 var cancelQuit
= Components
.classes
["@mozilla.org/supports-PRBool;1"]
38 .createInstance(Components
.interfaces
.nsISupportsPRBool
);
39 os
.notifyObservers(cancelQuit
, "quit-application-requested", null);
41 // Something aborted the quit process.
49 function goQuitApplication()
51 if (!canQuitApplication())
54 var appStartup
= Components
.classes
['@mozilla.org/toolkit/app-startup;1'].
55 getService(Components
.interfaces
.nsIAppStartup
);
57 appStartup
.quit(Components
.interfaces
.nsIAppStartup
.eAttemptQuit
);
62 // Command Updater functions
64 function goUpdateCommand(aCommand
)
67 var controller
= top
.document
.commandDispatcher
68 .getControllerForCommand(aCommand
);
72 enabled
= controller
.isCommandEnabled(aCommand
);
74 goSetCommandEnabled(aCommand
, enabled
);
77 dump("An error occurred updating the " + aCommand
+ " command\n");
81 function goDoCommand(aCommand
)
84 var controller
= top
.document
.commandDispatcher
85 .getControllerForCommand(aCommand
);
86 if (controller
&& controller
.isCommandEnabled(aCommand
))
87 controller
.doCommand(aCommand
);
90 dump("An error occurred executing the " + aCommand
+ " command\n" + e
+ "\n");
95 function goSetCommandEnabled(aID
, aEnabled
)
97 var node
= document
.getElementById(aID
);
101 node
.removeAttribute("disabled");
103 node
.setAttribute("disabled", "true");
107 function goSetMenuValue(aCommand
, aLabelAttribute
)
109 var commandNode
= top
.document
.getElementById(aCommand
);
111 var label
= commandNode
.getAttribute(aLabelAttribute
);
113 commandNode
.setAttribute("label", label
);
117 function goSetAccessKey(aCommand
, aValueAttribute
)
119 var commandNode
= top
.document
.getElementById(aCommand
);
121 var value
= commandNode
.getAttribute(aValueAttribute
);
123 commandNode
.setAttribute("accesskey", value
);
127 // this function is used to inform all the controllers attached to a node that an event has occurred
128 // (e.g. the tree controllers need to be informed of blur events so that they can change some of the
129 // menu items back to their default values)
130 function goOnEvent(aNode
, aEvent
)
132 var numControllers
= aNode
.controllers
.getControllerCount();
135 for (var controllerIndex
= 0; controllerIndex
< numControllers
; controllerIndex
++) {
136 controller
= aNode
.controllers
.getControllerAt(controllerIndex
);
138 controller
.onEvent(aEvent
);
142 function visitLink(aEvent
) {
143 var node
= aEvent
.target
;
144 while (node
.nodeType
!= Node
.ELEMENT_NODE
)
145 node
= node
.parentNode
;
146 var url
= node
.getAttribute("link");
150 var protocolSvc
= Components
.classes
["@mozilla.org/uriloader/external-protocol-service;1"]
151 .getService(Components
.interfaces
.nsIExternalProtocolService
);
152 var ioService
= Components
.classes
["@mozilla.org/network/io-service;1"]
153 .getService(Components
.interfaces
.nsIIOService
);
154 var uri
= ioService
.newURI(url
, null, null);
156 // if the scheme is not an exposed protocol, then opening this link
157 // should be deferred to the system's external protocol handler
158 if (protocolSvc
.isExposedProtocol(uri
.scheme
)) {
159 var win
= window
.top
;
160 if (win
instanceof Components
.interfaces
.nsIDOMChromeWindow
) {
161 while (win
.opener
&& !win
.opener
.closed
)
167 protocolSvc
.loadUrl(uri
);
170 function isValidLeftClick(aEvent
, aName
)
172 return (aEvent
.button
== 0 && aEvent
.originalTarget
.localName
== aName
);
175 function setTooltipText(aID
, aTooltipText
)
177 var element
= document
.getElementById(aID
);
179 element
.setAttribute("tooltiptext", aTooltipText
);
182 function FillInTooltip ( tipElement
)
185 var textNode
= document
.getElementById("TOOLTIP-tooltipText");
187 while (textNode
.hasChildNodes())
188 textNode
.removeChild(textNode
.firstChild
);
189 var tipText
= tipElement
.getAttribute("tooltiptext");
191 var node
= document
.createTextNode(tipText
);
192 textNode
.appendChild(node
);
199 __defineGetter__("NS_ASSERT", function() {
200 delete this.NS_ASSERT
;
202 Components
.utils
.import("resource://gre/modules/debug.js", tmpScope
);
203 return this.NS_ASSERT
= tmpScope
.NS_ASSERT
;