Skip to content

Commit 72bfb94

Browse files
committed
Creating PromptService so that the XUL specific calls can be encapsulated and hidden away. Also fixing the incorrect doctype
1 parent dfb5197 commit 72bfb94

File tree

3 files changed

+69
-23
lines changed

3 files changed

+69
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Encapsulate the low level calls into a service that is functionally useful and avoids use of cryptic numbers
3+
*/
4+
var PromptService = (function() {
5+
function PromptService() {
6+
}
7+
8+
PromptService.prototype.svc = function() {
9+
if (!this._svc) {
10+
this._svc = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
11+
12+
this.saveFlags = this._svc.BUTTON_TITLE_SAVE * this._svc.BUTTON_POS_0 +
13+
this._svc.BUTTON_TITLE_CANCEL * this._svc.BUTTON_POS_1 +
14+
this._svc.BUTTON_TITLE_DONT_SAVE * this._svc.BUTTON_POS_2;
15+
16+
this.yesNoFlags = this._svc.BUTTON_TITLE_YES * this._svc.BUTTON_POS_0 +
17+
this._svc.BUTTON_TITLE_NO * this._svc.BUTTON_POS_1;
18+
19+
this.yesNoCancelFlags = this._svc.BUTTON_TITLE_YES * this._svc.BUTTON_POS_0 +
20+
this._svc.BUTTON_TITLE_CANCEL * this._svc.BUTTON_POS_1 +
21+
this._svc.BUTTON_TITLE_NO * this._svc.BUTTON_POS_2;
22+
}
23+
return this._svc;
24+
};
25+
26+
PromptService.prototype.save = function(prompt, title) {
27+
title = title || "Save?";
28+
var btn = this.svc().confirmEx(window, title, prompt, this.saveFlags, null, null, null, null, {});
29+
return {
30+
save: btn == 0,
31+
cancel: btn == 1,
32+
dontSave: btn == 2
33+
};
34+
};
35+
36+
PromptService.prototype.yesNo = function(prompt, title) {
37+
var btn = this.svc().confirmEx(window, title, prompt, this.yesNoFlags, null, null, null, null, {});
38+
return {
39+
yes: btn == 0,
40+
no: btn == 1
41+
};
42+
};
43+
44+
PromptService.prototype.yesNoCancel = function(prompt, title) {
45+
var btn = this.svc().confirmEx(window, title, prompt, this.yesNoCancelFlags, null, null, null, null, {});
46+
return {
47+
yes: btn == 0,
48+
no: btn == 2,
49+
cancel: btn == 1
50+
};
51+
};
52+
53+
return new PromptService();
54+
})();

ide/main/src/content/editor.js

+12-20
Original file line numberDiff line numberDiff line change
@@ -469,28 +469,20 @@ Editor.prototype.confirmClose = function () {
469469
"Would you like to save the " + changedTestCases + " changed test case/s?",
470470
"Would you like to save the test suite and the " + changedTestCases + " changed test case/s?"
471471
][promptType];
472-
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
473472

474-
var flags =
475-
promptService.BUTTON_TITLE_SAVE * promptService.BUTTON_POS_0 +
476-
promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1 +
477-
promptService.BUTTON_TITLE_DONT_SAVE * promptService.BUTTON_POS_2;
478-
479-
var result = promptService.confirmEx(window, "Save?", prompt, flags, null, null, null, null, {});
480-
481-
switch (result) {
482-
case 0:
483-
if (curSuite.isTempSuite()) {
484-
//For temp suites, just save the test case (as there is only one test case)
485-
return this.saveTestCase();
486-
}
487-
//For all others, save the suite (perhaps unnecessary) and all test cases that have changed
488-
return this.app.saveTestSuite(true);
489-
case 1:
490-
return false;
491-
case 2:
492-
return true;
473+
var result = PromptService.save(prompt, "Save?");
474+
if (result.save) {
475+
if (curSuite.isTempSuite()) {
476+
//For temp suites, just save the test case (as there is only one test case)
477+
return this.saveTestCase();
478+
}
479+
//For all others, save the suite (perhaps unnecessary) and all test cases that have changed
480+
return this.app.saveTestSuite(true);
481+
} else if (result.cancel) {
482+
return false;
493483
}
484+
//result.dontSave
485+
return true;
494486
}
495487
} else {
496488
//TODO: Why is there no current suite???

ide/main/src/content/selenium-ide-common.xul

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
-->
1717

18-
<!DOCTYPE window [
18+
<!DOCTYPE overlay [
1919
<!ENTITY % browserDTD SYSTEM "chrome://browser/locale/browser.dtd">
2020
%browserDTD;
2121
<!ENTITY % baseMenuOverlayDTD SYSTEM "chrome://browser/locale/baseMenuOverlay.dtd">
2222
%baseMenuOverlayDTD;
2323
<!ENTITY % seleniumIdeDTD SYSTEM "chrome://selenium-ide/locale/selenium-ide.dtd">
2424
%seleniumIdeDTD;
2525
]>
26-
<overlay id="selenium-ide-common"
27-
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
26+
<overlay id="selenium-ide-common" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
2827
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
2928
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
3029
<script type="application/x-javascript" src="chrome://selenium-ide/content/dnd-observers.js"/>
@@ -53,6 +52,7 @@ limitations under the License.
5352
<script type="application/x-javascript" src="chrome://selenium-ide/content/locatorBuilders.js"/>
5453
<script type="application/x-javascript" src="chrome://selenium-ide/content/application.js"/>
5554
<script type="application/x-javascript" src="chrome://selenium-ide/content/storedHistory.js"/>
55+
<script type="application/x-javascript" src="chrome://selenium-ide/content/browser/mozilla/prompt-service.js"/>
5656
<script type="application/x-javascript" src="chrome://selenium-ide/content/editor.js"/>
5757
<script type="application/x-javascript" src="chrome://selenium-ide/content/sidebar-editor.js"/>
5858
<script type="application/x-javascript" src="chrome://selenium-ide/content/standalone-editor.js"/>

0 commit comments

Comments
 (0)