Subversion Repositories general

Compare Revisions

Regard whitespace Rev 1423 → Rev 1424

/mozilla/nomodal/trunk/src/components/Prompt.js
41,37 → 41,17
},
 
// -----------------------------------------------------------------------------------------------------------------
showDialog: function(aParent, params)
showDialog: function(showModal, aParent, params, args)
{
// parent interfaces
var parentRequestor = aParent.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var parentDocShell = parentRequestor.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell);
var parentInt = parentRequestor.getInterface(Components.interfaces.nsIDOMWindowInternal);
var parentDom = parentRequestor.getInterface(Components.interfaces.nsIDOMWindow);
var mainWin = this.windowMediator.getMostRecentWindow("navigator:browser");
var tabBrowser = mainWin.gBrowser;
 
var parentTab;
for(var i = 0, l = tabBrowser.browsers.length; i < l; ++i) {
var b = tabBrowser.getBrowserAtIndex(i);
if(b.contentWindow == aParent) {
parentTab = tabBrowser.tabContainer.childNodes[i];
}
}
 
// disable all dynamics in the window
var jsAllowed = parentDocShell.allowJavascript;
parentDocShell.allowJavascript = false;
parentDocShell.suspendRefreshURIs();
 
// params
if(!params.dialogTitle) {
if(!args) {
if(!params.dialogTitle && params.dialogTitleKey) {
params.dialogTitle = this.commonBundle.GetStringFromName(params.dialogTitleKey);
}
 
var args = Components.classes["@mozilla.org/embedcomp/dialogparam;1"]
args = Components.classes["@mozilla.org/embedcomp/dialogparam;1"]
.createInstance(Components.interfaces.nsIDialogParamBlock);
 
args.SetString(0, params.text);
args.SetString(1, params.checkboxMsg);
args.SetString(2, params.iconClass);
93,10 → 73,37
args.SetInt (5, params.defaultButton);
args.SetInt (6, params.delayButtonEnable);
args.SetInt (7, params.soundEventId);
}
 
if(!showModal) {
// parent interfaces
var parentRequestor = aParent.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var parentDocShell = parentRequestor.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell);
var parentInt = parentRequestor.getInterface(Components.interfaces.nsIDOMWindowInternal);
var parentDom = parentRequestor.getInterface(Components.interfaces.nsIDOMWindow);
var mainWin = this.windowMediator.getMostRecentWindow("navigator:browser");
var tabBrowser = mainWin.gBrowser;
 
var parentTab;
for(var i = 0, l = tabBrowser.browsers.length; i < l; ++i) {
var b = tabBrowser.getBrowserAtIndex(i);
if(b.contentWindow == aParent) {
parentTab = tabBrowser.tabContainer.childNodes[i];
}
}
 
// disable all dynamics in the window
var jsAllowed = parentDocShell.allowJavascript;
parentDocShell.allowJavascript = false;
parentDocShell.suspendRefreshURIs();
}
 
// show the dialog
var win = this.windowWatcher.openWindow(aParent, "chrome://global/content/commonDialog.xul",
"_blank", "centerscreen,chrome,titlebar" /*,dependent*/, args);
var win = this.windowWatcher.openWindow(aParent, params.url,
"_blank", "centerscreen,chrome,titlebar" + (showModal ? ",modal" : ""), args);
 
if(!showModal) {
win.openInProgress = true;
 
var winRequestor = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
160,8 → 167,9
 
// wait until the dialog is closed
while(!winInt.closed && this.threadManager.currentThread.processNextEvent(true));
}
 
if(!parentInt.closed) {
if(!showModal && !parentInt.closed) {
// restore
aParent.removeEventListener('click', parentClick, true);
aParent.removeEventListener('unload', parentUnload, true);
169,6 → 177,7
 
parentDocShell.resumeRefreshURIs();
parentDocShell.allowJavascript = jsAllowed;
}
 
// eval the answer
params.buttonPressed = args.GetInt(0);
175,12 → 184,6
params.checkboxState = args.GetInt(1);
params.editfield1Value = args.GetString(6);
params.editfield2Value = args.GetString(7);
 
return true;
}
else {
return false;
}
},
 
// -----------------------------------------------------------------------------------------------------------------
187,7 → 190,13
// interface nsIPromptService
alert: function(aParent, aDialogTitle, aText)
{
if(this.isEnabled(aParent, 'alert')) {
this.alertCheck(aParent, aDialogTitle, aText, null, null);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
alertCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState)
{
var params = {
dialogTitleKey: "Alert",
dialogTitle: aDialogTitle,
200,27 → 209,50
url: "chrome://global/content/commonDialog.xul",
};
 
this.showDialog(aParent, params);
if(aCheckMsg && aCheckState) {
params.checkboxMsg = aCheckMsg;
params.checkboxState = (aCheckState.value ? 1 : 0);
}
else {
NoModal_Prompt.origin.alert(aParent, aDialogTitle, aText);
 
this.showDialog(!this.isEnabled(aParent, 'alert'), aParent, params);
 
var res = (params.buttonPressed == 0);
if(res) {
if(aCheckState) {
aCheckState.value = (params.checkboxState == 1);
}
}
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
alertCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState)
confirm: function(aParent, aDialogTitle, aText)
{
return NoModal_Prompt.origin.alertCheck(aParent, aDialogTitle, aText, aCheckMsg, aCheckState);
var params = {
dialogTitleKey: "Confirm",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 2,
numberEditfields: 0,
iconClass: "question-icon",
openingSound: "_moz_confirmdialog",
soundEventId: 2,
url: "chrome://global/content/commonDialog.xul",
};
 
this.showDialog(!this.isEnabled(aParent, 'confirm'), aParent, params);
 
var res = (params.buttonPressed == 0);
 
return res;
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
confirm: function(aParent, aDialogTitle, aText)
confirmCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState)
{
if(this.isEnabled(aParent, 'confirm')) {
var params = {
dialogTitleKey: "Confirm",
dialogTitleKey: "ConfirmCheck",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 2,
231,20 → 263,21
url: "chrome://global/content/commonDialog.xul",
};
 
this.showDialog(aParent, params);
if(aCheckMsg && aCheckState) {
params.checkboxMsg = aCheckMsg;
params.checkboxState = (aCheckState.value ? 1 : 0);
}
 
return (params.buttonPressed == 0);
this.showDialog(!this.isEnabled(aParent, 'confirm'), aParent, params);
 
var res = (params.buttonPressed == 0);
if(res) {
if(aCheckState) {
aCheckState.value = (params.checkboxState == 1);
}
else {
return NoModal_Prompt.origin.confirm(aParent, aDialogTitle, aText);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
confirmCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.confirmCheck(aParent, aDialogTitle, aText, aCheckMsg, aCheckState);
return res;
},
 
// -----------------------------------------------------------------------------------------------------------------
252,8 → 285,75
confirmEx: function(aParent, aDialogTitle, aText, aButtonFlags, aButton0Title, aButton1Title, aButton2Title,
aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.confirmEx(aParent, aDialogTitle, aText, aButtonFlags, aButton0Title,
aButton1Title, aButton2Title, aCheckMsg, aCheckState);
var params = {
dialogTitleKey: "Confirm",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 0,
numberEditfields: 0,
iconClass: "question-icon",
openingSound: "_moz_confirmdialog",
soundEventId: 2,
url: "chrome://global/content/commonDialog.xul",
};
 
var buttonIds = [ 'button0Text', 'button1Text', 'button2Text' ];
var buttonStrings = [ aButton0Title, aButton1Title, aButton2Title ];
 
params.defaultButton = ((aButtonFlags & 0x03000000) >> 24);
params.delayButtonEnable = (aButtonFlags & Components.interfaces.nsIPromptService.BUTTON_DELAY_ENABLE);
 
for(var i = 0; i < 3; i++) {
var buttonText;
switch(aButtonFlags & 0xff) {
case Components.interfaces.nsIPromptService.BUTTON_TITLE_OK:
buttonText = this.commonBundle.GetStringFromName("OK");
break;
case Components.interfaces.nsIPromptService.BUTTON_TITLE_CANCEL:
buttonText = this.commonBundle.GetStringFromName("Cancel");
break;
case Components.interfaces.nsIPromptService.BUTTON_TITLE_YES:
buttonText = this.commonBundle.GetStringFromName("Yes");
break;
case Components.interfaces.nsIPromptService.BUTTON_TITLE_NO:
buttonText = this.commonBundle.GetStringFromName("No");
break;
case Components.interfaces.nsIPromptService.BUTTON_TITLE_SAVE:
buttonText = this.commonBundle.GetStringFromName("Save");
break;
case Components.interfaces.nsIPromptService.BUTTON_TITLE_DONT_SAVE:
buttonText = this.commonBundle.GetStringFromName("DontSave");
break;
case Components.interfaces.nsIPromptService.BUTTON_TITLE_REVERT:
buttonText = this.commonBundle.GetStringFromName("Revert");
break;
case Components.interfaces.nsIPromptService.BUTTON_TITLE_IS_STRING:
buttonText = buttonStrings[i];
break;
}
 
if(buttonText) {
params[buttonIds[i]] = buttonText;
++params.numberButtons;
}
aButtonFlags >>= 8;
}
 
if(aCheckMsg && aCheckState) {
params.checkboxMsg = aCheckMsg;
params.checkboxState = (aCheckState.value ? 1 : 0);
}
 
this.showDialog(!this.isEnabled(aParent, 'confirm'), aParent, params);
 
var res = (params.buttonPressed == 0);
if(res) {
if(aCheckState) {
aCheckState.value = (params.checkboxState == 1);
}
}
 
return res;
},
 
// -----------------------------------------------------------------------------------------------------------------
260,7 → 360,6
// interface nsIPromptService
prompt: function(aParent, aDialogTitle, aText, aValue, aCheckMsg, aCheckState)
{
if(this.isEnabled(aParent, 'confirm')) {
var params = {
dialogTitleKey: "Prompt",
dialogTitle: aDialogTitle,
279,7 → 378,7
params.checkboxState = (aCheckState.value ? 1 : 0);
}
 
this.showDialog(aParent, params);
this.showDialog(!this.isEnabled(aParent, 'prompt'), aParent, params);
 
var res = (params.buttonPressed == 0);
if(res) {
291,10 → 390,6
}
 
return res;
}
else {
return NoModal_Prompt.origin.prompt(aParent, aDialogTitle, aText, aValue, aCheckMsg, aCheckState);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
301,7 → 396,6
// interface nsIPromptService
promptUsernameAndPassword: function(aParent, aDialogTitle, aText, aUsername, aPassword, aCheckMsg, aCheckState)
{
if(this.isEnabled(aParent, 'promptUsernameAndPassword')) {
var params = {
dialogTitleKey: "PromptUsernameAndPassword2",
dialogTitle: aDialogTitle,
321,7 → 415,7
params.checkboxState = (aCheckState.value ? 1 : 0);
}
 
this.showDialog(aParent, params);
this.showDialog(!this.isEnabled(aParent, 'promptUsernameAndPassword'), aParent, params);
 
var res = (params.buttonPressed == 0);
if(res) {
334,11 → 428,6
}
 
return res;
}
else {
return NoModal_Prompt.origin.promptUsernameAndPassword(aParent, aDialogTitle, aText, aUsername, aPassword,
aCheckMsg, aCheckState);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
345,7 → 434,6
// interface nsIPromptService
promptPassword: function(aParent, aDialogTitle, aText, aPassword, aCheckMsg, aCheckState)
{
if(this.isEnabled(aParent, 'promptPassword')) {
var params = {
dialogTitleKey: "PromptPassword2",
dialogTitle: aDialogTitle,
365,7 → 453,7
params.checkboxState = (aCheckState.value ? 1 : 0);
}
 
this.showDialog(aParent, params);
this.showDialog(!this.isEnabled(aParent, 'promptPassword'), aParent, params);
 
var res = (params.buttonPressed == 0);
if(res) {
377,10 → 465,6
}
 
return res;
}
else {
return NoModal_Prompt.origin.promptPassword(aParent, aDialogTitle, aText, aPassword, aCheckMsg, aCheckState);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
387,7 → 471,32
// interface nsIPromptService
select: function(aParent, aDialogTitle, aText, aCount, aSelectList, aOutSelection)
{
return NoModal_Prompt.origin.select(aParent, aDialogTitle, aText, aCount, aSelectList, aOutSelection);
// note: the selectDialog.xul uses another params numbering
if(!aDialogTitle) {
aDialogTitle = this.commonBundle.GetStringFromName("Select");
}
 
var args = Components.classes["@mozilla.org/embedcomp/dialogparam;1"]
.createInstance(Components.interfaces.nsIDialogParamBlock);
args.SetNumberStrings(aCount+2);
 
args.SetString(0, aDialogTitle);
args.SetString(1, aText);
args.SetInt(2, aCount);
for(var i = 0; i < aCount; ++i) {
args.SetString(i+2, aSelectList[i]);
}
 
var params = {
url: "chrome://global/content/selectDialog.xul",
};
 
this.showDialog(!this.isEnabled(aParent, 'select'), aParent, params);
 
aOutSelection.value = args.GetInt(2);
var res = (params.buttonPressed == 0);
 
return res;
},
 
// -----------------------------------------------------------------------------------------------------------------
394,12 → 503,7
// interface nsIPromptService2
promptAuth: function(aParent, aChannel, level, authInfo, checkboxLabel, checkValue)
{
if(this.isEnabled(aParent, 'promptAuth')) {
return this.promptPasswordAdapter(aParent, aChannel, level, authInfo, checkboxLabel, checkValue);
}
else {
return NoModal_Prompt.origin.promptAuth(aParent, aChannel, level, authInfo, checkboxLabel, checkValue);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
406,7 → 510,7
// interface nsIPromptService2
asyncPromptAuth: function(aParent, aChannel, aCallback, aContext, level, authInfo, checkboxLabel, checkValue)
{
return NoModal_Prompt.origin.asyncPromptAuth(aParent, aChannel, level, authInfo, checkboxLabel, checkValue);
return null; // NS_ERROR_NOT_IMPLEMENTED
},
 
// -----------------------------------------------------------------------------------------------------------------
500,9 → 604,5
// =====================================================================================================================
function NSGetModule(compMgr, fileSpec)
{
NoModal_Prompt.origin = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
NoModal_Prompt.origin.QueryInterface(Components.interfaces.nsIPromptService2);
 
return XPCOMUtils.generateModule([NoModal_Prompt]);
}