Replace drive drop-down plus text field with a paths drop-down

This commit is contained in:
David Rowe 2016-05-20 18:48:51 +12:00
parent 11aeaba114
commit b2bbf72be2

View file

@ -68,16 +68,12 @@ ModalWindow {
Component.onCompleted: { Component.onCompleted: {
console.log("Helper " + helper + " drives " + drives) console.log("Helper " + helper + " drives " + drives)
drivesSelector.onCurrentTextChanged.connect(function(){
root.dir = helper.pathToUrl(drivesSelector.currentText);
})
// HACK: The following two lines force the model to initialize properly such that: // HACK: The following lines force the model to initialize properly such that the go-up button
// - Selecting a different drive at the initial screen updates the path displayed. // works properly from the initial screen.
// - The go-up button works properly from the initial screen. var initialFolder = folderListModel.folder;
var initialFolder = currentDirectory.lastValidFolder; fileTableModel.folder = helper.pathToUrl(drives[0]);
root.dir = helper.pathToUrl(drivesSelector.currentText); fileTableModel.folder = initialFolder;
root.dir = helper.pathToUrl(initialFolder);
iconText = root.title !== "" ? hifi.glyphs.scriptUpload : ""; iconText = root.title !== "" ? hifi.glyphs.scriptUpload : "";
} }
@ -97,15 +93,6 @@ ModalWindow {
} }
spacing: hifi.dimensions.contentSpacing.x spacing: hifi.dimensions.contentSpacing.x
// FIXME implement back button
//VrControls.ButtonAwesome {
// id: backButton
// text: "\uf0a8"
// size: currentDirectory.height
// enabled: d.backStack.length != 0
// MouseArea { anchors.fill: parent; onClicked: d.navigateBack() }
//}
GlyphButton { GlyphButton {
id: upButton id: upButton
glyph: hifi.glyphs.levelUp glyph: hifi.glyphs.levelUp
@ -124,20 +111,10 @@ ModalWindow {
enabled: d.homeDestination ? true : false enabled: d.homeDestination ? true : false
onClicked: d.navigateHome(); onClicked: d.navigateHome();
} }
}
ComboBox { ComboBox {
id: drivesSelector id: pathSelector
width: 62
model: drives
visible: drives.length > 1
currentIndex: 0
}
}
TextField {
id: currentDirectory
property var lastValidFolder: helper.urlToPath(fileTableModel.folder)
height: homeButton.height
anchors { anchors {
top: parent.top top: parent.top
topMargin: hifi.dimensions.contentMargin.y topMargin: hifi.dimensions.contentMargin.y
@ -146,23 +123,54 @@ ModalWindow {
right: parent.right right: parent.right
} }
function capitalizeDrive(path) { property var lastValidFolder: helper.urlToPath(fileTableModel.folder)
// Consistently capitalize drive letter for Windows.
if (/[a-zA-Z]:/.test(path)) { function calculatePathChoices(folder) {
return path.charAt(0).toUpperCase() + path.slice(1); var folders = folder.split("/"),
} choices = [],
return path; i, length;
if (folders[folders.length - 1] === "") {
folders.pop();
} }
onLastValidFolderChanged: text = capitalizeDrive(lastValidFolder); if (folders[0] !== "") {
choices.push(folders[0]);
// FIXME add support auto-completion }
onAccepted: {
if (!helper.validFolder(text)) { for (i = 1, length = folders.length; i < length; i++) {
text = lastValidFolder; choices.push(choices[i - 1] + "/" + folders[i]);
return }
choices.reverse();
if (drives && drives.length > 1) {
choices.push("This PC");
}
if (choices.length > 0) {
pathSelector.model = choices;
}
}
onLastValidFolderChanged: {
var folder = d.capitalizeDrive(lastValidFolder);
calculatePathChoices(folder);
}
onCurrentTextChanged: {
var folder = currentText;
if (/^[a-zA-z]:$/.test(folder)) {
folder = "file:///" + folder + "/";
} else if (folder === "This PC") {
folder = "file:///";
} else {
folder = helper.pathToUrl(folder);
}
if (helper.urlToPath(folder).toLowerCase() !== helper.urlToPath(fileTableModel.folder).toLowerCase()) {
fileTableModel.folder = folder;
} }
fileTableModel.folder = helper.pathToUrl(text);
} }
} }
@ -219,12 +227,10 @@ ModalWindow {
showDirsFirst: true showDirsFirst: true
showDotAndDotDot: false showDotAndDotDot: false
showFiles: !root.selectDirectory showFiles: !root.selectDirectory
// For some reason, declaring these bindings directly in the targets doesn't
// work for setting the initial state
Component.onCompleted: { Component.onCompleted: {
currentDirectory.lastValidFolder = helper.urlToPath(folder);
showFiles = !root.selectDirectory showFiles = !root.selectDirectory
} }
onFolderChanged: { onFolderChanged: {
fileTableModel.update(); // Update once the data from the folder change is available. fileTableModel.update(); // Update once the data from the folder change is available.
} }
@ -310,7 +316,6 @@ ModalWindow {
update(); update();
} }
} }
currentDirectory.lastValidFolder = helper.urlToPath(folder);
} }
function isFolder(row) { function isFolder(row) {