Make "Save File" in XP FilePicker warn when you're trying to save to a non-existant directory. bug=27612, r=bryner, a=alecf

git-svn-id: svn://10.0.0.236/trunk@87001 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
disttsc%bart.nl
2001-02-14 18:36:19 +00:00
parent d4e2e853d1
commit 97d6a4320c
3 changed files with 36 additions and 19 deletions

View File

@@ -44,9 +44,11 @@ var directoryTree;
var textInput;
var okButton;
var bundle = srGetStrBundle("chrome://global/locale/filepicker.properties");
var gFilePickerBundle;
function onLoad() {
gFilePickerBundle = document.getElementById("bundle_filepicker");
dirHistory = new Array();
directoryTree = document.getElementById("directoryTree");
@@ -102,13 +104,13 @@ function onLoad() {
var buttonLabel;
switch (filePickerMode) {
case nsIFilePicker.modeOpen:
buttonLabel = bundle.GetStringFromName("openButtonLabel");
buttonLabel = gFilePickerBundle.getString("openButtonLabel");
break;
case nsIFilePicker.modeSave:
buttonLabel = bundle.GetStringFromName("saveButtonLabel");
buttonLabel = gFilePickerBundle.getString("saveButtonLabel");
break;
case nsIFilePicker.modeGetFolder:
buttonLabel = bundle.GetStringFromName("selectFolderButtonLabel");
buttonLabel = gFilePickerBundle.getString("selectFolderButtonLabel");
break;
}
@@ -123,7 +125,8 @@ function onLoad() {
doSetOKCancel(onOK, onCancel);
// get the home dir
var dirServiceProvider = Components.classes[nsIDirectoryServiceProvider_CONTRACTID].getService().QueryInterface(nsIDirectoryServiceProvider);
var dirServiceProvider = Components.classes[nsIDirectoryServiceProvider_CONTRACTID]
.getService(nsIDirectoryServiceProvider);
var persistent = new Object();
homeDir = dirServiceProvider.getFile("Home", persistent);
@@ -255,7 +258,9 @@ function onOK()
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
rv = window.confirm(file.unicodePath + " " + bundle.GetStringFromName("confirmFileReplacing"));
var message = gFilePickerBundle.getFormattedString("confirmFileReplacing",
[file.unicodePath]);
var rv = window.confirm(message);
if (rv) {
ret = nsIFilePicker.returnReplace;
retvals.directory = file.parent.unicodePath;
@@ -275,8 +280,24 @@ function onOK()
ret = nsIFilePicker.returnOK;
retvals.directory = parent.unicodePath;
} else {
// See bug 55026, do nothing for now, leaves typed text as clue.
// window.alert("Directory "+parent.unicodePath+" doesn't seem to exist, can't save "+file.unicodePath);
var oldParent = parent;
while (!parent.exists()) {
oldParent = parent;
parent = parent.parent;
}
var errorTitle = gFilePickerBundle.getFormattedString("errorSavingFileTitle",
[file.unicodePath]);
var errorMessage;
if (parent.isFile()) {
errorMessage = gFilePickerBundle.getFormattedString("saveParentIsFileMessage",
[parent.unicodePath, file.unicodePath]);
} else {
errorMessage = gFilePickerBundle.getFormattedString("saveParentDoesntExistMessage",
[oldParent.unicodePath, file.unicodePath]);
}
var commonDialogs = Components.classes["@mozilla.org/appshell/commonDialogs;1"]
.getService(Components.interfaces.nsICommonDialogs);
commonDialogs.Alert(window, errorTitle, errorMessage);
ret = nsIFilePicker.returnCancel;
}
}
@@ -336,15 +357,7 @@ function doEnabling() {
// file or directory in .modeOpen. Too costly I think.
var enable = (textInput.value != "");
if (enable) {
if (okButton.getAttribute("disabled")) {
okButton.removeAttribute("disabled");
}
} else {
if (!okButton.getAttribute("disabled")) {
okButton.setAttribute("disabled","true");
}
}
okButton.disabled = !enable;
}
function onSelect(e) {

View File

@@ -42,7 +42,7 @@
class="dialog"
persist="screenX screenY">
<script src="chrome://global/content/strres.js"/>
<stringbundle id="bundle_filepicker" src="chrome://global/locale/filepicker.properties"/>
<script src="chrome://global/content/filepicker.js"/>
<keyset id="keyset"/>

View File

@@ -13,7 +13,11 @@ xmlFilter=*.xml
xulTitle=XUL Files
xulFilter=*.xul
confirmFileReplacing=already exists. Do you want to replace it?
confirmFileReplacing=%S already exists. Do you want to replace it?
openButtonLabel=Open
saveButtonLabel=Save
selectFolderButtonLabel=Select
errorSavingFileTitle=Error saving %S
saveParentIsFileMessage=%S is a file, can't save %S
saveParentDoesntExistMessage=Path %S doesn't exist, can't save %S