From b9ba764e0ff9c153ae34c1c2f8bbeadf5bddc763 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Thu, 25 Apr 2019 12:24:02 -0700 Subject: [PATCH] fix openDirectory (cherry picked from commit 609e58a0ddcff0ace1d75a85fafd73bfa4a5eacd) --- interface/src/Application.cpp | 21 +++++++++++++++++++++ interface/src/Application.h | 2 ++ libraries/ui/src/FileDialogHelper.cpp | 11 +++-------- libraries/ui/src/FileDialogHelper.h | 3 +++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 184c153f0e..ba28eb6068 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2443,6 +2443,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo DependencyManager::get()->preloadSounds(); DependencyManager::get()->createKeyboard(); + FileDialogHelper::setOpenDirectoryOperator([this](const QString& path) { openDirectory(path); }); QDesktopServices::setUrlHandler("file", this, "showUrlHandler"); QDesktopServices::setUrlHandler("", this, "showUrlHandler"); auto drives = QDir::drives(); @@ -9251,6 +9252,26 @@ QString Application::getGraphicsCardType() { return GPUIdent::getInstance()->getName(); } +void Application::openDirectory(const QString& path) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "openDirectory", Q_ARG(const QString&, path)); + return; + } + + QString dirPath = path; + const QString FILE_SCHEME = "file:///"; + if (dirPath.startsWith(FILE_SCHEME)) { + dirPath.remove(0, FILE_SCHEME.length()); + } + QFileInfo fileInfo(dirPath); + if (fileInfo.isDir()) { + auto scheme = QUrl(path).scheme(); + QDesktopServices::unsetUrlHandler(scheme); + QDesktopServices::openUrl(path); + QDesktopServices::setUrlHandler(scheme, this, "showUrlHandler"); + } +} + void Application::showUrlHandler(const QUrl& url) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "showUrlHandler", Q_ARG(const QUrl&, url)); diff --git a/interface/src/Application.h b/interface/src/Application.h index 96feeba39f..d3b4ab1d44 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -344,6 +344,8 @@ public: void toggleAwayMode(); #endif + void openDirectory(const QString& path); + signals: void svoImportRequested(const QString& url); diff --git a/libraries/ui/src/FileDialogHelper.cpp b/libraries/ui/src/FileDialogHelper.cpp index e6a48da01b..4fa4e0bd54 100644 --- a/libraries/ui/src/FileDialogHelper.cpp +++ b/libraries/ui/src/FileDialogHelper.cpp @@ -17,6 +17,7 @@ #include #include +std::function FileDialogHelper::_openDiretoryOperator = nullptr; QUrl FileDialogHelper::home() { return pathToUrl(QStandardPaths::standardLocations(QStandardPaths::HomeLocation)[0]); @@ -111,14 +112,8 @@ QStringList FileDialogHelper::drives() { } void FileDialogHelper::openDirectory(const QString& path) { - QString dirPath = path; - const QString FILE_SCHEME = "file://"; - if (dirPath.startsWith(FILE_SCHEME)) { - dirPath.remove(0, FILE_SCHEME.length()); - } - QFileInfo fileInfo(dirPath); - if (fileInfo.isDir()) { - QDesktopServices::openUrl(path); + if (_openDiretoryOperator) { + _openDiretoryOperator(path); } } diff --git a/libraries/ui/src/FileDialogHelper.h b/libraries/ui/src/FileDialogHelper.h index 12fd60daac..55561a40dd 100644 --- a/libraries/ui/src/FileDialogHelper.h +++ b/libraries/ui/src/FileDialogHelper.h @@ -16,6 +16,7 @@ #include #include +#include class FileDialogHelper : public QObject { Q_OBJECT @@ -62,6 +63,7 @@ public: Q_INVOKABLE QUrl saveHelper(const QString& saveText, const QUrl& currentFolder, const QStringList& selectionFilters); Q_INVOKABLE QList urlToList(const QUrl& url); + static void setOpenDirectoryOperator(std::function openDiretoryOperator) { _openDiretoryOperator = openDiretoryOperator; } Q_INVOKABLE void openDirectory(const QString& path); Q_INVOKABLE void monitorDirectory(const QString& path); @@ -72,6 +74,7 @@ signals: private: QFileSystemWatcher _fsWatcher; QString _fsWatcherPath; + static std::function _openDiretoryOperator; };