From 339d1328c3dba4960d8ea40bdf7dad936f4d9646 Mon Sep 17 00:00:00 2001 From: Gaurav Kumar Ghildiyal Date: Tue, 29 Jan 2019 23:07:09 +0530 Subject: [PATCH] Added support for automatically saving and opening recent folder (#1149) --- src/common/Configuration.cpp | 12 ++++++++++++ src/common/Configuration.h | 3 +++ src/dialogs/NewFileDialog.cpp | 4 +++- src/dialogs/OpenFileDialog.cpp | 6 +++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/common/Configuration.cpp b/src/common/Configuration.cpp index 7087d751..c75ce2b9 100644 --- a/src/common/Configuration.cpp +++ b/src/common/Configuration.cpp @@ -95,6 +95,18 @@ void Configuration::setDirProjects(const QString &dir) s.setValue("dir.projects", QDir::toNativeSeparators(dir)); } +QString Configuration::getRecentFolder() +{ + QString recentFolder = s.value("dir.recentFolder", QDir::homePath()).toString(); + + return QDir::toNativeSeparators(recentFolder); +} + +void Configuration::setRecentFolder(const QString &dir) +{ + s.setValue("dir.recentFolder", QDir::toNativeSeparators(dir)); +} + /** * @brief Configuration::setFilesTabLastClicked * Set the new file dialog last clicked tab diff --git a/src/common/Configuration.h b/src/common/Configuration.h index c2b88f62..67d21383 100644 --- a/src/common/Configuration.h +++ b/src/common/Configuration.h @@ -72,6 +72,9 @@ public: QString getDirProjects(); void setDirProjects(const QString &dir); + QString getRecentFolder(); + void setRecentFolder(const QString &dir); + void setNewFileLastClicked(int lastClicked); int getNewFileLastClicked(); diff --git a/src/dialogs/NewFileDialog.cpp b/src/dialogs/NewFileDialog.cpp index 4ce19a67..4bf13094 100644 --- a/src/dialogs/NewFileDialog.cpp +++ b/src/dialogs/NewFileDialog.cpp @@ -84,11 +84,13 @@ void NewFileDialog::on_loadFileButton_clicked() void NewFileDialog::on_selectFileButton_clicked() { - const QString &fileName = QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, tr("Select file"), QDir::homePath())); + QString currentDir = Config()->getRecentFolder(); + const QString &fileName = QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, tr("Select file"), currentDir)); if (!fileName.isEmpty()) { ui->newFileEdit->setText(fileName); ui->loadFileButton->setFocus(); + Config()->setRecentFolder(QFileInfo(fileName).absolutePath()); } } diff --git a/src/dialogs/OpenFileDialog.cpp b/src/dialogs/OpenFileDialog.cpp index 02eeaa27..d437521d 100644 --- a/src/dialogs/OpenFileDialog.cpp +++ b/src/dialogs/OpenFileDialog.cpp @@ -1,6 +1,8 @@ #include "OpenFileDialog.h" #include "ui_OpenFileDialog.h" +#include "common/Configuration.h" + #include OpenFileDialog::OpenFileDialog(QWidget *parent): @@ -14,10 +16,12 @@ OpenFileDialog::~OpenFileDialog() {} void OpenFileDialog::on_selectFileButton_clicked() { - QString fileName = QFileDialog::getOpenFileName(this, tr("Select file"), QDir::homePath()); + QString currentDir = Config()->getRecentFolder(); + QString fileName = QFileDialog::getOpenFileName(this, tr("Select file"), currentDir); if (!fileName.isEmpty()) { ui->filenameLineEdit->setText(fileName); + Config()->setRecentFolder(QFileInfo(fileName).absolutePath()); } }