From dc0e038535485d921ebcf051b72744487e9f2464 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Thu, 4 Feb 2016 13:51:43 -0800 Subject: [PATCH] Add drive selection to the file dialog --- .../resources/qml/dialogs/FileDialog.qml | 19 +++++++++++++++++++ libraries/ui/src/FileDialogHelper.cpp | 8 ++++++++ libraries/ui/src/FileDialogHelper.h | 1 + tests/ui/qml/main.qml | 8 +------- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/interface/resources/qml/dialogs/FileDialog.qml b/interface/resources/qml/dialogs/FileDialog.qml index a482b76c70..10dd4897e3 100644 --- a/interface/resources/qml/dialogs/FileDialog.qml +++ b/interface/resources/qml/dialogs/FileDialog.qml @@ -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 { diff --git a/libraries/ui/src/FileDialogHelper.cpp b/libraries/ui/src/FileDialogHelper.cpp index 56b9695444..82ad877573 100644 --- a/libraries/ui/src/FileDialogHelper.cpp +++ b/libraries/ui/src/FileDialogHelper.cpp @@ -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; +} diff --git a/libraries/ui/src/FileDialogHelper.h b/libraries/ui/src/FileDialogHelper.h index 0142473533..2119b77917 100644 --- a/libraries/ui/src/FileDialogHelper.h +++ b/libraries/ui/src/FileDialogHelper.h @@ -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); diff --git a/tests/ui/qml/main.qml b/tests/ui/qml/main.qml index d20b580b5a..a55f042227 100644 --- a/tests/ui/qml/main.qml +++ b/tests/ui/qml/main.qml @@ -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: {