mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 266629: cannot upload files with "~" as the first character of the file name, and other XPFE synchronization patches, r=neil
This commit is contained in:
parent
3171ef77f1
commit
9d3c4cdf4e
@ -23,7 +23,7 @@
|
||||
# Contributor(s):
|
||||
# Stuart Parmenter <pavlov@netscape.com>
|
||||
# Brian Ryner <bryner@brianryner.com>
|
||||
# Jan Varga <varga@nixcorp.com>
|
||||
# Jan Varga <varga@ku.sk>
|
||||
# Peter Annema <disttsc@bart.nl>
|
||||
# Johann Petrak <johann@ai.univie.ac.at>
|
||||
# Akkana Peck <akkana@netscape.com>
|
||||
@ -43,18 +43,18 @@
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||
const nsIDirectoryServiceProvider = Components.interfaces.nsIDirectoryServiceProvider;
|
||||
const nsIDirectoryServiceProvider_CONTRACTID = "@mozilla.org/file/directory_service;1";
|
||||
const nsIProperties = Components.interfaces.nsIProperties;
|
||||
const NS_DIRECTORYSERVICE_CONTRACTID = "@mozilla.org/file/directory_service;1";
|
||||
const nsITreeBoxObject = Components.interfaces.nsITreeBoxObject;
|
||||
const nsIFileView = Components.interfaces.nsIFileView;
|
||||
const nsFileView_CONTRACTID = "@mozilla.org/filepicker/fileview;1";
|
||||
const NS_FILEVIEW_CONTRACTID = "@mozilla.org/filepicker/fileview;1";
|
||||
const nsITreeView = Components.interfaces.nsITreeView;
|
||||
const nsILocalFile = Components.interfaces.nsILocalFile;
|
||||
const nsIFile = Components.interfaces.nsIFile;
|
||||
const nsLocalFile_CONTRACTID = "@mozilla.org/file/local;1";
|
||||
const nsIPromptService_CONTRACTID = "@mozilla.org/embedcomp/prompt-service;1";
|
||||
const NS_LOCALFILE_CONTRACTID = "@mozilla.org/file/local;1";
|
||||
const NS_PROMPTSERVICE_CONTRACTID = "@mozilla.org/embedcomp/prompt-service;1";
|
||||
|
||||
var sfile = Components.classes[nsLocalFile_CONTRACTID].createInstance(nsILocalFile);
|
||||
var sfile = Components.classes[NS_LOCALFILE_CONTRACTID].createInstance(nsILocalFile);
|
||||
var retvals;
|
||||
var filePickerMode;
|
||||
var homeDir;
|
||||
@ -74,7 +74,7 @@ function filepickerLoad() {
|
||||
|
||||
textInput = document.getElementById("textInput");
|
||||
okButton = document.documentElement.getButton("accept");
|
||||
treeView = Components.classes[nsFileView_CONTRACTID].createInstance(nsIFileView);
|
||||
treeView = Components.classes[NS_FILEVIEW_CONTRACTID].createInstance(nsIFileView);
|
||||
|
||||
if (window.arguments) {
|
||||
var o = window.arguments[0];
|
||||
@ -140,16 +140,13 @@ function filepickerLoad() {
|
||||
treeView.showOnlyDirectories = true;
|
||||
}
|
||||
|
||||
// set up the right icon
|
||||
// The dialog defaults to an "open" icon, change it to "save" if applicable
|
||||
if (filePickerMode == nsIFilePicker.modeSave)
|
||||
okButton.setAttribute("icon","save");
|
||||
else
|
||||
okButton.setAttribute("icon","open");
|
||||
okButton.setAttribute("icon", "save");
|
||||
|
||||
// start out with a filename sort
|
||||
handleColumnClick("FilenameColumn");
|
||||
|
||||
document.documentElement.setAttribute("ondialogcancel", "return onCancel();");
|
||||
try {
|
||||
setOKAction();
|
||||
} catch (exception) {
|
||||
@ -167,8 +164,7 @@ function filepickerLoad() {
|
||||
|
||||
// Start out with the ok button disabled since nothing will be
|
||||
// selected and nothing will be in the text field.
|
||||
okButton.disabled = true;
|
||||
textInput.focus();
|
||||
okButton.disabled = filePickerMode != nsIFilePicker.modeGetFolder;
|
||||
|
||||
// This allows the window to show onscreen before we begin
|
||||
// loading the file list
|
||||
@ -178,17 +174,17 @@ function filepickerLoad() {
|
||||
|
||||
function setInitialDirectory(directory)
|
||||
{
|
||||
// get the home dir
|
||||
var dirServiceProvider = Components.classes[nsIDirectoryServiceProvider_CONTRACTID]
|
||||
.getService(nsIDirectoryServiceProvider);
|
||||
var persistent = new Object();
|
||||
homeDir = dirServiceProvider.getFile("Home", persistent);
|
||||
// Start in the user's home directory
|
||||
var dirService = Components.classes[NS_DIRECTORYSERVICE_CONTRACTID]
|
||||
.getService(nsIProperties);
|
||||
homeDir = dirService.get("Home", Components.interfaces.nsIFile);
|
||||
|
||||
if (directory) {
|
||||
sfile.initWithPath(directory);
|
||||
if (!sfile.exists() || !sfile.isDirectory())
|
||||
directory = false;
|
||||
}
|
||||
if (!directory || !(sfile.exists() && sfile.isDirectory())) {
|
||||
// Start in the user's home directory
|
||||
if (!directory) {
|
||||
sfile.initWithPath(homeDir.path);
|
||||
}
|
||||
|
||||
@ -217,7 +213,7 @@ function showErrorDialog(titleStrName, messageStrName, file)
|
||||
var errorMessage =
|
||||
gFilePickerBundle.getFormattedString(messageStrName, [file.path]);
|
||||
var promptService =
|
||||
Components.classes[nsIPromptService_CONTRACTID].getService(Components.interfaces.nsIPromptService);
|
||||
Components.classes[NS_PROMPTSERVICE_CONTRACTID].getService(Components.interfaces.nsIPromptService);
|
||||
|
||||
promptService.alert(window, errorTitle, errorMessage);
|
||||
}
|
||||
@ -225,23 +221,9 @@ function showErrorDialog(titleStrName, messageStrName, file)
|
||||
function openOnOK()
|
||||
{
|
||||
var dir = treeView.selectedFiles.queryElementAt(0, nsIFile);
|
||||
if (!dir.isReadable()) {
|
||||
showErrorDialog("errorOpenFileDoesntExistTitle",
|
||||
"errorDirNotReadableMessage",
|
||||
dir);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dir)
|
||||
gotoDirectory(dir);
|
||||
|
||||
retvals.fileList = new Array(dir);
|
||||
|
||||
retvals.buttonStatus = nsIFilePicker.returnCancel;
|
||||
|
||||
var filterMenuList = document.getElementById("filterMenuList");
|
||||
retvals.filterIndex = filterMenuList.selectedIndex;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -333,8 +315,8 @@ function selectOnOK()
|
||||
gFilePickerBundle.getFormattedString("confirmFileReplacing",
|
||||
[file.path]);
|
||||
|
||||
promptService = Components.classes[nsIPromptService_CONTRACTID].getService(Components.interfaces.nsIPromptService);
|
||||
var rv = promptService.confirm(window, title, message);
|
||||
promptService = Components.classes[NS_PROMPTSERVICE_CONTRACTID].getService(Components.interfaces.nsIPromptService);
|
||||
var rv = promptService.confirm(window, confirmTitle, message);
|
||||
if (rv) {
|
||||
ret = nsIFilePicker.returnReplace;
|
||||
retvals.directory = file.parent.path;
|
||||
@ -375,7 +357,7 @@ function selectOnOK()
|
||||
errorMessage =
|
||||
gFilePickerBundle.getFormattedString("saveWithoutPermissionMessage_dir", [parent.path]);
|
||||
}
|
||||
promptService = Components.classes[nsIPromptService_CONTRACTID].getService(Components.interfaces.nsIPromptService);
|
||||
promptService = Components.classes[NS_PROMPTSERVICE_CONTRACTID].getService(Components.interfaces.nsIPromptService);
|
||||
promptService.alert(window, errorTitle, errorMessage);
|
||||
ret = nsIFilePicker.returnCancel;
|
||||
}
|
||||
@ -508,11 +490,10 @@ function onKeypress(e) {
|
||||
}
|
||||
|
||||
function doEnabling() {
|
||||
if (filePickerMode != nsIFilePicker.modeGetFolder)
|
||||
// Maybe add check if textInput.value would resolve to an existing
|
||||
// file or directory in .modeOpen. Too costly I think.
|
||||
var enable = (textInput.value != "");
|
||||
|
||||
okButton.disabled = !enable;
|
||||
okButton.disabled = (textInput.value == "")
|
||||
}
|
||||
|
||||
function onTreeFocus(event) {
|
||||
@ -524,7 +505,7 @@ function setOKAction(file) {
|
||||
var buttonLabel;
|
||||
var buttonIcon = "open"; // used in all but one case
|
||||
|
||||
if (file && file.isDirectory() && filePickerMode != nsIFilePicker.modeGetFolder) {
|
||||
if (file && file.isDirectory()) {
|
||||
document.documentElement.setAttribute("ondialogaccept", "return openOnOK();");
|
||||
buttonLabel = gFilePickerBundle.getString("openButtonLabel");
|
||||
}
|
||||
@ -586,7 +567,7 @@ function onFileSelected(/* nsIArray */ selectedFileList) {
|
||||
if (validFileSelected) {
|
||||
setOKAction(file);
|
||||
okButton.disabled = invalidSelection;
|
||||
} else
|
||||
} else if (filePickerMode != nsIFilePicker.modeGetFolder)
|
||||
okButton.disabled = (textInput.value == "");
|
||||
}
|
||||
|
||||
@ -619,7 +600,7 @@ function onDirectoryChanged(target)
|
||||
{
|
||||
var path = target.getAttribute("label");
|
||||
|
||||
var file = Components.classes[nsLocalFile_CONTRACTID].createInstance(nsILocalFile);
|
||||
var file = Components.classes[NS_LOCALFILE_CONTRACTID].createInstance(nsILocalFile);
|
||||
file.initWithPath(path);
|
||||
|
||||
if (!sfile.equals(file)) {
|
||||
@ -674,7 +655,7 @@ function goHome() {
|
||||
function newDir() {
|
||||
var file;
|
||||
var promptService =
|
||||
Components.classes[nsIPromptService_CONTRACTID].getService(Components.interfaces.nsIPromptService);
|
||||
Components.classes[NS_PROMPTSERVICE_CONTRACTID].getService(Components.interfaces.nsIPromptService);
|
||||
var dialogTitle =
|
||||
gFilePickerBundle.getString("promptNewDirTitle");
|
||||
var dialogMsg =
|
||||
@ -749,7 +730,6 @@ function gotoDirectory(directory) {
|
||||
|
||||
window.setCursor("auto");
|
||||
|
||||
treeView.QueryInterface(nsITreeView).selection.clearSelection();
|
||||
if (filePickerMode == nsIFilePicker.modeGetFolder) {
|
||||
textInput.value = "";
|
||||
}
|
||||
@ -829,7 +809,18 @@ function processPathEntry(path, fileArray)
|
||||
var filePath;
|
||||
var file;
|
||||
|
||||
if (path[0] == '~')
|
||||
try {
|
||||
file = sfile.clone().QueryInterface(nsILocalFile);
|
||||
} catch(e) {
|
||||
dump("Couldn't clone\n"+e);
|
||||
return false;
|
||||
}
|
||||
|
||||
var tilde_file = file.clone();
|
||||
tilde_file.append("~");
|
||||
if (path[0] == '~' && // Expand ~ to $HOME, except:
|
||||
!(path == "~" && tilde_file.exists()) && // If ~ was entered and such a file exists, don't expand
|
||||
(path.length == 1 || path[1] == "/")) // We don't want to expand ~file to ${HOME}file
|
||||
filePath = homeDir.path + path.substring(1);
|
||||
else
|
||||
filePath = path;
|
||||
@ -837,13 +828,6 @@ function processPathEntry(path, fileArray)
|
||||
// Unescape quotes
|
||||
filePath = filePath.replace(/\\\"/g, "\"");
|
||||
|
||||
try{
|
||||
file = sfile.clone().QueryInterface(nsILocalFile);
|
||||
} catch(e) {
|
||||
dump("Couldn't clone\n"+e);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (filePath[0] == '/') /* an absolute path was entered */
|
||||
file.initWithPath(filePath);
|
||||
else if ((filePath.indexOf("/../") > 0) ||
|
||||
|
@ -114,6 +114,6 @@
|
||||
<checkbox label="&showHiddenFiles.label;" oncommand="toggleShowHidden();"
|
||||
flex="1" align="left" accesskey="&showHiddenFiles.accesskey;"/>
|
||||
<button dlgtype="cancel" icon="cancel" class="dialog-button"/>
|
||||
<button dlgtype="accept" icon="accept" class="dialog-button"/>
|
||||
<button dlgtype="accept" icon="open" class="dialog-button"/>
|
||||
</hbox>
|
||||
</dialog>
|
||||
|
Loading…
Reference in New Issue
Block a user