Added support for automatically saving and opening recent folder (#1149)

This commit is contained in:
Gaurav Kumar Ghildiyal 2019-01-29 23:07:09 +05:30 committed by xarkes
parent 410eb7aba4
commit 339d1328c3
4 changed files with 23 additions and 2 deletions

View File

@ -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

View File

@ -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();

View File

@ -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());
}
}

View File

@ -1,6 +1,8 @@
#include "OpenFileDialog.h"
#include "ui_OpenFileDialog.h"
#include "common/Configuration.h"
#include <QFileDialog>
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());
}
}