Skip to content

Commit

Permalink
Settings: support default import dir
Browse files Browse the repository at this point in the history
Based on discussion in 31abd8e

Default is 'Last used directory', old behavior is 'Project directory'.
  • Loading branch information
rodlie committed Jul 22, 2024
1 parent 87e78d8 commit ee73499
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/app/GUI/Settings/generalsettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
}
}
}
2 changes: 2 additions & 0 deletions src/app/GUI/Settings/generalsettingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QCheckBox>
#include <QSpinBox>
#include <QSlider>
#include <QComboBox>

class GeneralSettingsWidget : public SettingsWidget
{
Expand All @@ -43,6 +44,7 @@ class GeneralSettingsWidget : public SettingsWidget
QSpinBox *mAutoSaveTimer;
QCheckBox *mDefaultInterfaceScaling;
QSlider *mInterfaceScaling;
QComboBox *mImportFileDir;
};

#endif // GENERALSETTINGSWIDGET_H
16 changes: 14 additions & 2 deletions src/app/GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions src/core/Private/esettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ eSettings::eSettings(const int cpuThreads,
fDefaultInterfaceScaling,
"defaultInterfaceScaling", true);

gSettings << std::make_shared<eIntSetting>(
fImportFileDirOpt,
"ImportFileDirOpt", ImportFileDirRecent);

gSettings << std::make_shared<eBoolSetting>(
fCanvasRtlSupport,
"rtlTextSupport", false);
Expand Down
6 changes: 6 additions & 0 deletions src/core/Private/esettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class CORE_EXPORT eSettings : public QObject
AdjustSceneAlways,
AdjustSceneNever
};
enum ImportFileDirOpt {
ImportFileDirRecent,
ImportFileDirProject
};
eSettings(const int cpuThreads,
const intKB ramKB);

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ee73499

Please sign in to comment.