зеркало из https://github.com/mozilla/pjs.git
Fix a couple of xp filepicker bugs, r=pavlov, r=bryner, a=brendan:
- 51118 throws exception on double-clicks not on treerows - 52188 Disable/enable Open/Save/Select when appropriate - 55685 doesn't change to typed directories in save mode - 55830 Make input field and file filter line up
This commit is contained in:
Родитель
2fb1047c63
Коммит
a7d3560f81
|
@ -42,6 +42,7 @@ var homeDir;
|
||||||
|
|
||||||
var directoryTree;
|
var directoryTree;
|
||||||
var textInput;
|
var textInput;
|
||||||
|
var okButton;
|
||||||
|
|
||||||
var bundle = srGetStrBundle("chrome://global/locale/filepicker.properties");
|
var bundle = srGetStrBundle("chrome://global/locale/filepicker.properties");
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@ function onLoad() {
|
||||||
|
|
||||||
directoryTree = document.getElementById("directoryTree");
|
directoryTree = document.getElementById("directoryTree");
|
||||||
textInput = document.getElementById("textInput");
|
textInput = document.getElementById("textInput");
|
||||||
|
okButton = document.getElementById("ok");
|
||||||
|
|
||||||
if (window.arguments) {
|
if (window.arguments) {
|
||||||
var o = window.arguments[0];
|
var o = window.arguments[0];
|
||||||
|
@ -110,7 +112,6 @@ function onLoad() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buttonLabel) {
|
if (buttonLabel) {
|
||||||
var okButton = document.getElementById("ok");
|
|
||||||
okButton.setAttribute("value", buttonLabel);
|
okButton.setAttribute("value", buttonLabel);
|
||||||
}
|
}
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
|
@ -135,6 +136,7 @@ function onLoad() {
|
||||||
retvals.buttonStatus = nsIFilePicker.returnCancel;
|
retvals.buttonStatus = nsIFilePicker.returnCancel;
|
||||||
|
|
||||||
gotoDirectory(sfile);
|
gotoDirectory(sfile);
|
||||||
|
doEnabling();
|
||||||
textInput.focus();
|
textInput.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,21 +245,37 @@ function onOK()
|
||||||
gotoDirectory(file);
|
gotoDirectory(file);
|
||||||
}
|
}
|
||||||
textInput.value = "";
|
textInput.value = "";
|
||||||
|
doEnabling();
|
||||||
ret = nsIFilePicker.returnCancel;
|
ret = nsIFilePicker.returnCancel;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case nsIFilePicker.modeSave:
|
case nsIFilePicker.modeSave:
|
||||||
if (isFile) {
|
if (isFile) { // can only be true if file.exists()
|
||||||
// we need to pop up a dialog asking if you want to save
|
// we need to pop up a dialog asking if you want to save
|
||||||
rv = window.confirm(file.path + " " + bundle.GetStringFromName("confirmFileReplacing"));
|
rv = window.confirm(file.path + " " + bundle.GetStringFromName("confirmFileReplacing"));
|
||||||
if (rv)
|
if (rv) {
|
||||||
ret = nsIFilePicker.returnReplace;
|
ret = nsIFilePicker.returnReplace;
|
||||||
else
|
retvals.directory = file.parent.path;
|
||||||
|
} else {
|
||||||
ret = nsIFilePicker.returnCancel;
|
ret = nsIFilePicker.returnCancel;
|
||||||
retvals.directory = file.parent.path;
|
}
|
||||||
} else if (!file.exists()) {
|
} else if (isDir) {
|
||||||
ret = nsIFilePicker.returnOK;
|
if (!sfile.equals(file)) {
|
||||||
retvals.directory = file.parent.path;
|
gotoDirectory(file);
|
||||||
|
}
|
||||||
|
textInput.value = "";
|
||||||
|
doEnabling();
|
||||||
|
ret = nsIFilePicker.returnCancel;
|
||||||
|
} else {
|
||||||
|
var parent = file.parent;
|
||||||
|
if (parent.exists() && parent.isDirectory()) {
|
||||||
|
ret = nsIFilePicker.returnOK;
|
||||||
|
retvals.directory = parent.path;
|
||||||
|
} else {
|
||||||
|
// See bug 55026, do nothing for now, leaves typed text as clue.
|
||||||
|
// window.alert("Directory "+parent.path+" doesn't seem to exist, can't save "+file.path);
|
||||||
|
ret = nsIFilePicker.returnCancel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case nsIFilePicker.modeGetFolder:
|
case nsIFilePicker.modeGetFolder:
|
||||||
|
@ -289,14 +307,18 @@ function onCancel()
|
||||||
|
|
||||||
function onClick(e) {
|
function onClick(e) {
|
||||||
if ( e.detail == 2 ) {
|
if ( e.detail == 2 ) {
|
||||||
var file = URLpathToFile(e.target.parentNode.getAttribute("path"));
|
var path = e.target.parentNode.getAttribute("path");
|
||||||
|
|
||||||
if (file.isDirectory()) {
|
if (path) {
|
||||||
gotoDirectory(file);
|
var file = URLpathToFile(path);
|
||||||
}
|
if (file) {
|
||||||
else if (file.isFile()) {
|
if (file.isDirectory()) {
|
||||||
/* what about symlinks? what if they symlink to a directory? */
|
gotoDirectory(file);
|
||||||
return doOKButton();
|
}
|
||||||
|
else if (file.isFile()) {
|
||||||
|
doOKButton();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,15 +328,38 @@ function onKeypress(e) {
|
||||||
goUp();
|
goUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function doEnabling() {
|
||||||
|
// Maybe add check if textInput.value would resolve to an existing
|
||||||
|
// 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onSelect(e) {
|
function onSelect(e) {
|
||||||
if (e.target.selectedItems.length != 1)
|
if (e.target.selectedItems.length != 1)
|
||||||
return;
|
return;
|
||||||
var file = URLpathToFile(e.target.selectedItems[0].firstChild.getAttribute("path"));
|
var path = e.target.selectedItems[0].firstChild.getAttribute("path");
|
||||||
|
|
||||||
if (file.isFile() || (filePickerMode == nsIFilePicker.modeGetFolder)) {
|
if (path) {
|
||||||
/* Note, if we're in GetFolder mode, everything in the display list
|
var file = URLpathToFile(path);
|
||||||
will be a directory, so we don't need an extra check */
|
if (file) {
|
||||||
textInput.value = file.leafName;
|
/* Put the leafName of the selected item in the input field if:
|
||||||
|
- GetFolder mode : a directory was selected (only option)
|
||||||
|
- Open or Save mode: a file was selected */
|
||||||
|
if ((filePickerMode == nsIFilePicker.modeGetFolder) || file.isFile()) {
|
||||||
|
textInput.value = file.leafName;
|
||||||
|
doEnabling();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,7 +370,9 @@ function onDirectoryChanged(target)
|
||||||
var file = Components.classes[nsILocalFile_CONTRACTID].createInstance(nsILocalFile);
|
var file = Components.classes[nsILocalFile_CONTRACTID].createInstance(nsILocalFile);
|
||||||
file.initWithPath(path);
|
file.initWithPath(path);
|
||||||
|
|
||||||
gotoDirectory(file);
|
if (!sfile.equals(file)) {
|
||||||
|
gotoDirectory(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addToHistory(directoryName) {
|
function addToHistory(directoryName) {
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
|
|
||||||
<box flex="1">
|
<box flex="1">
|
||||||
<tree id="directoryTree" flex="1" onkeypress="onKeypress(event)"
|
<tree id="directoryTree" flex="1" onkeypress="onKeypress(event)"
|
||||||
onselect="onSelect(event)" datasources="rdf:files">
|
onselect="onSelect(event)" datasources="rdf:files">
|
||||||
<template id="fileFilter">
|
<template id="fileFilter">
|
||||||
<!-- This is the rule for files matching the filter -->
|
<!-- This is the rule for files matching the filter -->
|
||||||
<rule id="matchRule.0">
|
<rule id="matchRule.0">
|
||||||
|
@ -79,9 +79,9 @@
|
||||||
|
|
||||||
<treecolgroup>
|
<treecolgroup>
|
||||||
<treecol flex="1" id="FilenameColumn" resource="http://home.netscape.com/NC-rdf#Name" sortActive="true" sortDirection="ascending"/>
|
<treecol flex="1" id="FilenameColumn" resource="http://home.netscape.com/NC-rdf#Name" sortActive="true" sortDirection="ascending"/>
|
||||||
<splitter class="tree-splitter"/>
|
<splitter class="tree-splitter"/>
|
||||||
<treecol flex="1" id="ContentLengthColumn" resource="http://home.netscape.com/NC-rdf#Content-Length"/>
|
<treecol flex="1" id="ContentLengthColumn" resource="http://home.netscape.com/NC-rdf#Content-Length"/>
|
||||||
<splitter class="tree-splitter"/>
|
<splitter class="tree-splitter"/>
|
||||||
<treecol flex="1" id="LastModifiedDateColumn" resource="http//home.netscape.com/WEB-rdf#LastModifiedDate"/>
|
<treecol flex="1" id="LastModifiedDateColumn" resource="http//home.netscape.com/WEB-rdf#LastModifiedDate"/>
|
||||||
</treecolgroup>
|
</treecolgroup>
|
||||||
<treehead>
|
<treehead>
|
||||||
|
@ -95,15 +95,23 @@
|
||||||
</tree>
|
</tree>
|
||||||
</box>
|
</box>
|
||||||
|
|
||||||
<box autostretch="never" style="margin-top: 5px">
|
<grid style="margin-top: 5px">
|
||||||
<text value="&textInput.label;"/>
|
<columns>
|
||||||
<textfield id="textInput" flex="1"/>
|
<column/>
|
||||||
</box>
|
<column flex="1"/>
|
||||||
|
</columns>
|
||||||
|
|
||||||
<box autostretch="never" id="filterBox" hidden="true">
|
<rows>
|
||||||
<text value="&filterMenuList.label;"/>
|
<row>
|
||||||
<menulist id="filterMenuList" flex="1" oncommand="onFilterChanged(event.target);"/>
|
<text value="&textInput.label;"/>
|
||||||
</box>
|
<textfield id="textInput" flex="1" oninput="doEnabling()"/>
|
||||||
|
</row>
|
||||||
|
<row id="filterBox" hidden="true">
|
||||||
|
<text value="&filterMenuList.label;"/>
|
||||||
|
<menulist id="filterMenuList" flex="1" oncommand="onFilterChanged(event.target);"/>
|
||||||
|
</row>
|
||||||
|
</rows>
|
||||||
|
</grid>
|
||||||
|
|
||||||
<box id="okCancelButtons"/>
|
<box id="okCancelButtons"/>
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче