diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 39994c53ab..6a6bc08692 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(); @@ -9272,6 +9273,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 0ce01b47da..d2c59343ed 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -345,6 +345,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..6d16a1ec21 100644 --- a/libraries/ui/src/FileDialogHelper.cpp +++ b/libraries/ui/src/FileDialogHelper.cpp @@ -17,6 +17,7 @@ #include #include +std::function FileDialogHelper::_openDirectoryOperator = 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 (_openDirectoryOperator) { + _openDirectoryOperator(path); } } diff --git a/libraries/ui/src/FileDialogHelper.h b/libraries/ui/src/FileDialogHelper.h index 12fd60daac..4685c3af6f 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 openDirectoryOperator) { _openDirectoryOperator = openDirectoryOperator; } 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 _openDirectoryOperator; };