From 00f299345c19c5b1f37e6c3aff5c4c5820b6fcf0 Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Thu, 27 Sep 2018 21:25:39 -0400 Subject: [PATCH] feat(ui): use relative path in portable build if possible (fixes #956) Applicable only to the subdirectories within path to the executable. --- src/libs/ui/settingsdialog.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libs/ui/settingsdialog.cpp b/src/libs/ui/settingsdialog.cpp index c3d7a7522..d7eb73a65 100644 --- a/src/libs/ui/settingsdialog.cpp +++ b/src/libs/ui/settingsdialog.cpp @@ -143,12 +143,21 @@ void SettingsDialog::chooseCustomCssFile() void SettingsDialog::chooseDocsetStoragePath() { - const QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), - ui->docsetStorageEdit->text()); - if (dir.isEmpty()) + QString path = QFileDialog::getExistingDirectory(this, tr("Open Directory"), + ui->docsetStorageEdit->text()); + if (path.isEmpty()) { return; + } + +#ifdef PORTABLE_BUILD + // Use relative path if selected directory is under the application binary path. + if (path.startsWith(QCoreApplication::applicationDirPath() + QLatin1String("/"))) { + const QDir appDirPath(QCoreApplication::applicationDirPath()); + path = appDirPath.relativeFilePath(path); + } +#endif - ui->docsetStorageEdit->setText(QDir::toNativeSeparators(dir)); + ui->docsetStorageEdit->setText(QDir::toNativeSeparators(path)); } void SettingsDialog::loadSettings()