feat(ui): use relative path in portable build if possible (fixes #956)

Applicable only to the subdirectories within path to the executable.
This commit is contained in:
Oleg Shparber 2018-09-27 21:25:39 -04:00
parent 83a8bb75fe
commit 00f299345c

View File

@ -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;
}
ui->docsetStorageEdit->setText(QDir::toNativeSeparators(dir));
#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(path));
}
void SettingsDialog::loadSettings()