diff --git a/src/dialogs/NewFileDialog.cpp b/src/dialogs/NewFileDialog.cpp index 3a5de945..f99768d6 100644 --- a/src/dialogs/NewFileDialog.cpp +++ b/src/dialogs/NewFileDialog.cpp @@ -98,7 +98,8 @@ void NewFileDialog::on_selectProjectsDirButton_clicked() QFileDialog dialog(this); dialog.setFileMode(QFileDialog::DirectoryOnly); - QString currentDir = CutterCore::getInstance()->getConfig("dir.projects"); + auto currentDir = Config()->getDirProjects(); + if (currentDir.startsWith("~")) { currentDir = QDir::homePath() + currentDir.mid(1); } @@ -112,7 +113,7 @@ void NewFileDialog::on_selectProjectsDirButton_clicked() QString dir = dialog.selectedFiles().first(); if (!dir.isEmpty()) { - CutterCore::getInstance()->setConfig("dir.projects", dir); + Config()->setDirProjects(dir); fillProjectsList(); } } @@ -161,6 +162,9 @@ void NewFileDialog::on_actionRemove_item_triggered() // Remove selected item from recents list QListWidgetItem *item = ui->recentsListWidget->currentItem(); + if (item == nullptr) + return; + QVariant data = item->data(Qt::UserRole); QString sitem = data.toString(); @@ -251,7 +255,9 @@ bool NewFileDialog::fillProjectsList() { CutterCore *core = CutterCore::getInstance(); - ui->projectsDirEdit->setText(core->getConfig("dir.projects")); + auto currentDir = Config()->getDirProjects(); + + ui->projectsDirEdit->setText(currentDir); QStringList projects = core->getProjectNames(); projects.sort(Qt::CaseInsensitive); diff --git a/src/dialogs/SaveProjectDialog.cpp b/src/dialogs/SaveProjectDialog.cpp index 833424d3..4baee57f 100644 --- a/src/dialogs/SaveProjectDialog.cpp +++ b/src/dialogs/SaveProjectDialog.cpp @@ -5,6 +5,7 @@ #include "SaveProjectDialog.h" #include "ui_SaveProjectDialog.h" #include "utils/TempConfig.h" +#include "utils/Configuration.h" SaveProjectDialog::SaveProjectDialog(bool quit, QWidget *parent) : QDialog(parent), @@ -24,7 +25,7 @@ SaveProjectDialog::SaveProjectDialog(bool quit, QWidget *parent) : } ui->nameEdit->setText(core->getConfig("prj.name")); - ui->projectsDirEdit->setText(core->getConfig("dir.projects")); + ui->projectsDirEdit->setText(Config()->getDirProjects()); ui->simpleCheckBox->setChecked(core->getConfigb("prj.simple")); ui->filesCheckBox->setChecked(core->getConfigb("prj.files")); ui->gitCheckBox->setChecked(core->getConfigb("prj.git")); diff --git a/src/utils/Configuration.cpp b/src/utils/Configuration.cpp index b8b15164..60cd9fdf 100644 --- a/src/utils/Configuration.cpp +++ b/src/utils/Configuration.cpp @@ -58,6 +58,23 @@ void Configuration::loadInitial() applySavedAsmOptions(); } +QString Configuration::getDirProjects() +{ + auto projectsDir = s.value("dir.projects").toString(); + if (projectsDir == "") { + projectsDir = Core()->getConfig("dir.projects"); + setDirProjects(projectsDir); + } + + return projectsDir; +} + +void Configuration::setDirProjects(const QString &dir) +{ + Core()->setConfig("dir.projects", dir); + s.setValue("dir.projects", dir); +} + void Configuration::resetAll() { Core()->cmd("e-"); diff --git a/src/utils/Configuration.h b/src/utils/Configuration.h index c788dd33..74df8c87 100644 --- a/src/utils/Configuration.h +++ b/src/utils/Configuration.h @@ -47,6 +47,9 @@ public: return s.value("dark").toBool(); } + QString getDirProjects(); + void setDirProjects(const QString& dir); + // Images QString getLogoFile();