Skip to content

Commit

Permalink
Creating PromptService so that the XUL specific calls can be encapsul…
Browse files Browse the repository at this point in the history
…ated and hidden away. Also fixing the incorrect doctype
  • Loading branch information
samitbadle committed Sep 14, 2014
1 parent dfb5197 commit 72bfb94
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 23 deletions.
54 changes: 54 additions & 0 deletions ide/main/src/content/browser/mozilla/prompt-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Encapsulate the low level calls into a service that is functionally useful and avoids use of cryptic numbers
*/
var PromptService = (function() {
function PromptService() {
}

PromptService.prototype.svc = function() {
if (!this._svc) {
this._svc = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);

this.saveFlags = this._svc.BUTTON_TITLE_SAVE * this._svc.BUTTON_POS_0 +
this._svc.BUTTON_TITLE_CANCEL * this._svc.BUTTON_POS_1 +
this._svc.BUTTON_TITLE_DONT_SAVE * this._svc.BUTTON_POS_2;

this.yesNoFlags = this._svc.BUTTON_TITLE_YES * this._svc.BUTTON_POS_0 +
this._svc.BUTTON_TITLE_NO * this._svc.BUTTON_POS_1;

this.yesNoCancelFlags = this._svc.BUTTON_TITLE_YES * this._svc.BUTTON_POS_0 +
this._svc.BUTTON_TITLE_CANCEL * this._svc.BUTTON_POS_1 +
this._svc.BUTTON_TITLE_NO * this._svc.BUTTON_POS_2;
}
return this._svc;
};

PromptService.prototype.save = function(prompt, title) {
title = title || "Save?";
var btn = this.svc().confirmEx(window, title, prompt, this.saveFlags, null, null, null, null, {});
return {
save: btn == 0,
cancel: btn == 1,
dontSave: btn == 2
};
};

PromptService.prototype.yesNo = function(prompt, title) {
var btn = this.svc().confirmEx(window, title, prompt, this.yesNoFlags, null, null, null, null, {});
return {
yes: btn == 0,
no: btn == 1
};
};

PromptService.prototype.yesNoCancel = function(prompt, title) {
var btn = this.svc().confirmEx(window, title, prompt, this.yesNoCancelFlags, null, null, null, null, {});
return {
yes: btn == 0,
no: btn == 2,
cancel: btn == 1
};
};

return new PromptService();
})();
32 changes: 12 additions & 20 deletions ide/main/src/content/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,28 +469,20 @@ Editor.prototype.confirmClose = function () {
"Would you like to save the " + changedTestCases + " changed test case/s?",
"Would you like to save the test suite and the " + changedTestCases + " changed test case/s?"
][promptType];
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);

var flags =
promptService.BUTTON_TITLE_SAVE * promptService.BUTTON_POS_0 +
promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1 +
promptService.BUTTON_TITLE_DONT_SAVE * promptService.BUTTON_POS_2;

var result = promptService.confirmEx(window, "Save?", prompt, flags, null, null, null, null, {});

switch (result) {
case 0:
if (curSuite.isTempSuite()) {
//For temp suites, just save the test case (as there is only one test case)
return this.saveTestCase();
}
//For all others, save the suite (perhaps unnecessary) and all test cases that have changed
return this.app.saveTestSuite(true);
case 1:
return false;
case 2:
return true;
var result = PromptService.save(prompt, "Save?");
if (result.save) {
if (curSuite.isTempSuite()) {
//For temp suites, just save the test case (as there is only one test case)
return this.saveTestCase();
}
//For all others, save the suite (perhaps unnecessary) and all test cases that have changed
return this.app.saveTestSuite(true);
} else if (result.cancel) {
return false;
}
//result.dontSave
return true;
}
} else {
//TODO: Why is there no current suite???
Expand Down
6 changes: 3 additions & 3 deletions ide/main/src/content/selenium-ide-common.xul
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ See the License for the specific language governing permissions and
limitations under the License.
-->

<!DOCTYPE window [
<!DOCTYPE overlay [
<!ENTITY % browserDTD SYSTEM "chrome://browser/locale/browser.dtd">
%browserDTD;
<!ENTITY % baseMenuOverlayDTD SYSTEM "chrome://browser/locale/baseMenuOverlay.dtd">
%baseMenuOverlayDTD;
<!ENTITY % seleniumIdeDTD SYSTEM "chrome://selenium-ide/locale/selenium-ide.dtd">
%seleniumIdeDTD;
]>
<overlay id="selenium-ide-common"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<overlay id="selenium-ide-common" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
<script type="application/x-javascript" src="chrome://global/content/nsDragAndDrop.js"/>
<script type="application/x-javascript" src="chrome://selenium-ide/content/dnd-observers.js"/>
Expand Down Expand Up @@ -53,6 +52,7 @@ limitations under the License.
<script type="application/x-javascript" src="chrome://selenium-ide/content/locatorBuilders.js"/>
<script type="application/x-javascript" src="chrome://selenium-ide/content/application.js"/>
<script type="application/x-javascript" src="chrome://selenium-ide/content/storedHistory.js"/>
<script type="application/x-javascript" src="chrome://selenium-ide/content/browser/mozilla/prompt-service.js"/>
<script type="application/x-javascript" src="chrome://selenium-ide/content/editor.js"/>
<script type="application/x-javascript" src="chrome://selenium-ide/content/sidebar-editor.js"/>
<script type="application/x-javascript" src="chrome://selenium-ide/content/standalone-editor.js"/>
Expand Down

0 comments on commit 72bfb94

Please sign in to comment.