mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Make the XP filepicker throw up alerts when the user picks a location
that the user does not have permissions to write to. Bug 114399, patch by Antonio Xu <antonio.xu@sun.com>, r=bryner, sr=jag
This commit is contained in:
parent
c4d44ab97c
commit
83ce43a0cf
@ -161,9 +161,35 @@ function changeFilter(filterTypes)
|
||||
window.setCursor("auto");
|
||||
}
|
||||
|
||||
function showFileSavingErrorDialog(file){
|
||||
var errorTitle =
|
||||
gFilePickerBundle.getFormattedString("errorSavingFileTitle",
|
||||
[file.unicodePath]);
|
||||
var errorMessage =
|
||||
gFilePickerBundle.getFormattedString("saveWithoutPermissionMessage_file",
|
||||
[file.unicodePath]);
|
||||
var promptService =
|
||||
Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
|
||||
|
||||
promptService.alert(window, errorTitle, errorMessage)
|
||||
}
|
||||
|
||||
function openOnOK()
|
||||
{
|
||||
var dir = outlinerView.getSelectedFile();
|
||||
if (!dir.isReadable()) {
|
||||
var errorTitle =
|
||||
gFilePickerBundle.getFormattedString("errorOpenFileDoesntExistTitle",
|
||||
[dir.unicodePath]);
|
||||
var errorMessage =
|
||||
gFilePickerBundle.getFormattedString("errorDirNotReadableMessage",
|
||||
[dir.unicodePath]);
|
||||
var promptService =
|
||||
Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
|
||||
promptService.alert(window, errorTitle, errorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dir)
|
||||
gotoDirectory(dir);
|
||||
retvals.file = dir;
|
||||
@ -243,15 +269,22 @@ function selectOnOK()
|
||||
break;
|
||||
case nsIFilePicker.modeSave:
|
||||
if (isFile) { // can only be true if file.exists()
|
||||
// we need to pop up a dialog asking if you want to save
|
||||
var message = gFilePickerBundle.getFormattedString("confirmFileReplacing",
|
||||
[file.unicodePath]);
|
||||
var rv = window.confirm(message);
|
||||
if (rv) {
|
||||
ret = nsIFilePicker.returnReplace;
|
||||
retvals.directory = file.parent.unicodePath;
|
||||
} else {
|
||||
if (!file.isWritable()) {
|
||||
showFileSavingErrorDialog(file);
|
||||
ret = nsIFilePicker.returnCancel;
|
||||
} else {
|
||||
// we need to pop up a dialog asking if you want to save
|
||||
var message =
|
||||
gFilePickerBundle.getFormattedString("confirmFileReplacing",
|
||||
[file.unicodePath]);
|
||||
|
||||
var rv = window.confirm(message);
|
||||
if (rv) {
|
||||
ret = nsIFilePicker.returnReplace;
|
||||
retvals.directory = file.parent.unicodePath;
|
||||
} else {
|
||||
ret = nsIFilePicker.returnCancel;
|
||||
}
|
||||
}
|
||||
} else if (isDir) {
|
||||
if (!sfile.equals(file)) {
|
||||
@ -262,7 +295,7 @@ function selectOnOK()
|
||||
ret = nsIFilePicker.returnCancel;
|
||||
} else {
|
||||
var parent = file.parent;
|
||||
if (parent.exists() && parent.isDirectory()) {
|
||||
if (parent.exists() && parent.isDirectory() && parent.isWritable()) {
|
||||
ret = nsIFilePicker.returnOK;
|
||||
retvals.directory = parent.unicodePath;
|
||||
} else {
|
||||
@ -271,14 +304,22 @@ function selectOnOK()
|
||||
oldParent = parent;
|
||||
parent = parent.parent;
|
||||
}
|
||||
errorTitle = gFilePickerBundle.getFormattedString("errorSavingFileTitle",
|
||||
[file.unicodePath]);
|
||||
var errorTitle =
|
||||
gFilePickerBundle.getFormattedString("errorSavingFileTitle",
|
||||
[file.unicodePath]);
|
||||
var errorMessage;
|
||||
if (parent.isFile()) {
|
||||
errorMessage = gFilePickerBundle.getFormattedString("saveParentIsFileMessage",
|
||||
[parent.unicodePath, file.unicodePath]);
|
||||
errorMessage =
|
||||
gFilePickerBundle.getFormattedString("saveParentIsFileMessage",
|
||||
[parent.unicodePath, file.unicodePath]);
|
||||
} else {
|
||||
errorMessage = gFilePickerBundle.getFormattedString("saveParentDoesntExistMessage",
|
||||
[oldParent.unicodePath, file.unicodePath]);
|
||||
errorMessage =
|
||||
gFilePickerBundle.getFormattedString("saveParentDoesntExistMessage",
|
||||
[oldParent.unicodePath, file.unicodePath]);
|
||||
}
|
||||
if (!parent.isWritable()) {
|
||||
errorMessage =
|
||||
gFilePickerBundle.getFormattedString("saveWithoutPermissionMessage_dir", [file.unicodePath]);
|
||||
}
|
||||
promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
||||
.getService(Components.interfaces.nsIPromptService);
|
||||
|
@ -21,10 +21,14 @@ noButtonLabel=No
|
||||
|
||||
errorOpenFileDoesntExistTitle=Error opening %S
|
||||
errorOpenFileDoesntExistMessage=File %S doesn't exist
|
||||
errorDirNotReadableMessage=Directory %S is not readable or does not exist.
|
||||
|
||||
errorSavingFileTitle=Error saving %S
|
||||
saveParentIsFileMessage=%S is a file, can't save %S
|
||||
saveParentDoesntExistMessage=Path %S doesn't exist, can't save %S
|
||||
|
||||
saveWithoutPermissionMessage_file=File %S is not writable.
|
||||
saveWithoutPermissionMessage_dir=Cannot create file. Directory %S is not writable.
|
||||
|
||||
noPermissionTitle=Error opening directory
|
||||
noPermissionError=You do not have the permissions necessary to view this directory.
|
||||
|
Loading…
Reference in New Issue
Block a user