From ee7349984380fc11ae7c6598640d68e997bb2077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole-Andr=C3=A9=20Rodlie?= Date: Mon, 22 Jul 2024 14:32:14 +0200 Subject: [PATCH] Settings: support default import dir Based on discussion in https://github.com/friction2d/friction/commit/31abd8eb14862503bf82cb4df505fe66ba98a1b1 Default is 'Last used directory', old behavior is 'Project directory'. --- .../GUI/Settings/generalsettingswidget.cpp | 30 +++++++++++++++++++ src/app/GUI/Settings/generalsettingswidget.h | 2 ++ src/app/GUI/mainwindow.cpp | 16 ++++++++-- src/core/Private/esettings.cpp | 4 +++ src/core/Private/esettings.h | 6 ++++ 5 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/app/GUI/Settings/generalsettingswidget.cpp b/src/app/GUI/Settings/generalsettingswidget.cpp index 966a12f55..85ff11724 100644 --- a/src/app/GUI/Settings/generalsettingswidget.cpp +++ b/src/app/GUI/Settings/generalsettingswidget.cpp @@ -41,6 +41,7 @@ GeneralSettingsWidget::GeneralSettingsWidget(QWidget *parent) , mAutoSaveTimer(nullptr) , mDefaultInterfaceScaling(nullptr) , mInterfaceScaling(nullptr) + , mImportFileDir(nullptr) { const auto mGeneralWidget = new QWidget(this); mGeneralWidget->setContentsMargins(0, 0, 0, 0); @@ -122,6 +123,27 @@ GeneralSettingsWidget::GeneralSettingsWidget(QWidget *parent) mGeneralLayout->addWidget(mScaleWidget); + const auto mImportWidget = new QGroupBox(this); + mImportWidget->setTitle(tr("Import")); + mImportWidget->setContentsMargins(0, 0, 0, 0); + const auto mImportLayout = new QVBoxLayout(mImportWidget); + + const auto mImportFileWidget = new QWidget(this); + mImportFileWidget->setContentsMargins(0, 0, 0, 0); + const auto mImportFileLayout = new QHBoxLayout(mImportFileWidget); + + const auto mImportFileLabel = new QLabel(tr("Default import directory"), this); + mImportFileDir = new QComboBox(this); + mImportFileDir->addItem(tr("Last used directory"), eSettings::ImportFileDirRecent); + mImportFileDir->addItem(tr("Project directory"), eSettings::ImportFileDirProject); + + mImportFileLayout->addWidget(mImportFileLabel); + mImportFileLayout->addWidget(mImportFileDir); + + mImportLayout->addWidget(mImportFileWidget); + + mGeneralLayout->addWidget(mImportWidget); + mGeneralLayout->addStretch(); addWidget(mGeneralWidget); @@ -150,6 +172,7 @@ void GeneralSettingsWidget::applySettings() mSett.fDefaultInterfaceScaling = mDefaultInterfaceScaling->isChecked(); mSett.fInterfaceScaling = mInterfaceScaling->value() * 0.01; + mSett.fImportFileDirOpt = mImportFileDir->currentData().toInt(); eSizesUI::font.updateSize(); eSizesUI::widget.updateSize(); } @@ -170,4 +193,11 @@ void GeneralSettingsWidget::updateSettings(bool restore) mDefaultInterfaceScaling->setChecked(mSett.fDefaultInterfaceScaling); mInterfaceScaling->setValue(mDefaultInterfaceScaling->isChecked() ? 100 : 100 * mSett.fInterfaceScaling); + + for (int i = 0; i < mImportFileDir->count(); i++) { + if (mImportFileDir->itemData(i).toInt() == mSett.fImportFileDirOpt) { + mImportFileDir->setCurrentIndex(i); + return; + } + } } diff --git a/src/app/GUI/Settings/generalsettingswidget.h b/src/app/GUI/Settings/generalsettingswidget.h index 0676cb871..ff9339aa3 100644 --- a/src/app/GUI/Settings/generalsettingswidget.h +++ b/src/app/GUI/Settings/generalsettingswidget.h @@ -29,6 +29,7 @@ #include #include #include +#include class GeneralSettingsWidget : public SettingsWidget { @@ -43,6 +44,7 @@ class GeneralSettingsWidget : public SettingsWidget QSpinBox *mAutoSaveTimer; QCheckBox *mDefaultInterfaceScaling; QSlider *mInterfaceScaling; + QComboBox *mImportFileDir; }; #endif // GENERALSETTINGSWIDGET_H diff --git a/src/app/GUI/mainwindow.cpp b/src/app/GUI/mainwindow.cpp index 3ea3f86d4..e114234a9 100644 --- a/src/app/GUI/mainwindow.cpp +++ b/src/app/GUI/mainwindow.cpp @@ -1904,8 +1904,20 @@ bool MainWindow::closeProject() void MainWindow::importFile() { disableEventFilter(); - const QString defPath = mDocument.fEvFile.isEmpty() ? - AppSupport::getSettings("files", "recentImportDir", QDir::homePath()).toString() : mDocument.fEvFile; + + const auto recentDir = AppSupport::getSettings("files", + "recentImportDir", + QDir::homePath()).toString(); + QString defPath = QDir::homePath(); + switch (eSettings::instance().fImportFileDirOpt) { + case eSettings::ImportFileDirRecent: + defPath = recentDir; + break; + case eSettings::ImportFileDirProject: + defPath = mDocument.fEvFile.isEmpty() ? recentDir : mDocument.fEvFile; + break; + default:; + } const QString title = tr("Import File(s)", "ImportDialog_Title"); const QString fileType = tr("Files %1", "ImportDialog_FileTypes"); diff --git a/src/core/Private/esettings.cpp b/src/core/Private/esettings.cpp index 525257e91..bfb714766 100644 --- a/src/core/Private/esettings.cpp +++ b/src/core/Private/esettings.cpp @@ -196,6 +196,10 @@ eSettings::eSettings(const int cpuThreads, fDefaultInterfaceScaling, "defaultInterfaceScaling", true); + gSettings << std::make_shared( + fImportFileDirOpt, + "ImportFileDirOpt", ImportFileDirRecent); + gSettings << std::make_shared( fCanvasRtlSupport, "rtlTextSupport", false); diff --git a/src/core/Private/esettings.h b/src/core/Private/esettings.h index 733998e54..57279f82c 100644 --- a/src/core/Private/esettings.h +++ b/src/core/Private/esettings.h @@ -60,6 +60,10 @@ class CORE_EXPORT eSettings : public QObject AdjustSceneAlways, AdjustSceneNever }; + enum ImportFileDirOpt { + ImportFileDirRecent, + ImportFileDirProject + }; eSettings(const int cpuThreads, const intKB ramKB); @@ -90,6 +94,8 @@ class CORE_EXPORT eSettings : public QObject AccPreference fAccPreference = AccPreference::defaultPreference; bool fPathGpuAcc = true; + int fImportFileDirOpt = ImportFileDirRecent; + bool fHddCache = true; QString fHddCacheFolder = ""; // "" - use system default temporary files folder intMB fHddCacheMBCap = intMB(0); // <= 0 - no cap