Add drive selection to the file dialog

This commit is contained in:
Bradley Austin Davis 2016-02-04 13:51:43 -08:00
parent 64597f9d9f
commit dc0e038535
4 changed files with 29 additions and 7 deletions

View file

@ -36,6 +36,7 @@ ModalWindow {
// Set from OffscreenUi::getOpenFile()
property int options; // <-- FIXME unused
property bool selectDirectory: false;
property bool showHidden: false;
// FIXME implement
@ -43,10 +44,18 @@ ModalWindow {
property bool saveDialog: false;
property var helper: fileDialogHelper
property alias model: fileTableView.model
property var drives: helper.drives()
signal selectedFile(var file);
signal canceled();
Component.onCompleted: {
console.log("Helper " + helper + " drives " + drives)
drivesSelector.onCurrentTextChanged.connect(function(){
root.dir = helper.pathToUrl(drivesSelector.currentText);
})
}
Rectangle {
anchors.fill: parent
color: "white"
@ -78,6 +87,16 @@ ModalWindow {
size: 32
onClicked: d.navigateHome();
}
VrControls.ComboBox {
id: drivesSelector
width: 48
height: homeButton.height
model: drives
visible: drives.length > 1
currentIndex: 0
}
}
TextField {

View file

@ -95,3 +95,11 @@ bool FileDialogHelper::urlIsWritable(const QUrl& url) {
// No file, get the parent directory and check if writable
return QFileInfo(fileInfo.absoluteDir().absolutePath()).isWritable();
}
QStringList FileDialogHelper::drives() {
QStringList result;
for (const auto& drive : QDir::drives()) {
result << drive.absolutePath();
}
return result;
}

View file

@ -47,6 +47,7 @@ public:
Q_INVOKABLE QUrl home();
Q_INVOKABLE QStringList standardPath(StandardLocation location);
Q_INVOKABLE QStringList drives();
Q_INVOKABLE QString urlToPath(const QUrl& url);
Q_INVOKABLE bool urlIsDir(const QUrl& url);
Q_INVOKABLE bool urlIsFile(const QUrl& url);

View file

@ -118,13 +118,7 @@ ApplicationWindow {
Button {
text: "Open File"
property var builder: Component {
FileDialog {
folder: "file:///C:/users/bdavis";
filterModel: ListModel {
ListElement { text: "Javascript Files (*.js)"; filter: "*.js" }
ListElement { text: "All Files (*.*)"; filter: "*.*" }
}
}
FileDialog { }
}
onClicked: {