History

fix openDirectory

SamGondelman committed 7 years ago

Commit 0e4ea4a1 parent 31b3f0e4 files · +29 −8Browse files

Showing the changes to interface/src/Application.cpp (1 of 4 files). Show all

Unified · Split

interface/src/Application.cpp+21−0
@@ -2443,6 +2443,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 2442 unmodified lines
24432443 DependencyManager::get<TabletScriptingInterface>()->preloadSounds();
24442444 DependencyManager::get<Keyboard>()->createKeyboard();
24452445
2446+ FileDialogHelper::setOpenDirectoryOperator([this](const QString& path) { openDirectory(path); });
24462447 QDesktopServices::setUrlHandler("file", this, "showUrlHandler");
24472448 QDesktopServices::setUrlHandler("", this, "showUrlHandler");
24482449 auto drives = QDir::drives();
@@ -9272,6 +9273,26 @@ QString Application::getGraphicsCardType() { · 6823 unmodified lines
92729273 return GPUIdent::getInstance()->getName();
92739274 }
92749275
9276+void Application::openDirectory(const QString& path) {
9277+ if (QThread::currentThread() != thread()) {
9278+ QMetaObject::invokeMethod(this, "openDirectory", Q_ARG(const QString&, path));
9279+ return;
9280+ }
9281+
9282+ QString dirPath = path;
9283+ const QString FILE_SCHEME = "file:///";
9284+ if (dirPath.startsWith(FILE_SCHEME)) {
9285+ dirPath.remove(0, FILE_SCHEME.length());
9286+ }
9287+ QFileInfo fileInfo(dirPath);
9288+ if (fileInfo.isDir()) {
9289+ auto scheme = QUrl(path).scheme();
9290+ QDesktopServices::unsetUrlHandler(scheme);
9291+ QDesktopServices::openUrl(path);
9292+ QDesktopServices::setUrlHandler(scheme, this, "showUrlHandler");
9293+ }
9294+}
9295+
92759296 void Application::showUrlHandler(const QUrl& url) {
92769297 if (QThread::currentThread() != thread()) {
92779298 QMetaObject::invokeMethod(this, "showUrlHandler", Q_ARG(const QUrl&, url));