refactor saveLastDir code

This commit is contained in:
thez3ro 2017-11-22 22:12:43 +01:00
parent cd1e0571a5
commit 135e8419ae
No known key found for this signature in database
GPG Key ID: F628F9E41DD7C073
2 changed files with 17 additions and 20 deletions

View File

@ -42,11 +42,8 @@ QString FileDialog::getOpenFileName(QWidget* parent, const QString& caption, QSt
if (parent) {
parent->activateWindow();
}
if (!result.isEmpty() && m_nextSaveLastDir) {
config()->set("LastDir", QFileInfo(result).absolutePath());
}
m_nextSaveLastDir = true;
saveLastDir(result);
return result;
}
}
@ -73,11 +70,9 @@ QStringList FileDialog::getOpenFileNames(QWidget *parent, const QString &caption
parent->activateWindow();
}
if (!results.isEmpty() && m_nextSaveLastDir) {
config()->set("LastDir", QFileInfo(results[0]).absolutePath());
if (!results.isEmpty()) {
saveLastDir(results[0]);
}
m_nextSaveLastDir = true;
return results;
}
}
@ -126,11 +121,7 @@ QString FileDialog::getSaveFileName(QWidget* parent, const QString& caption, QSt
parent->activateWindow();
}
if (!result.isEmpty() && m_nextSaveLastDir) {
config()->set("LastDir", QFileInfo(result).absolutePath());
}
m_nextSaveLastDir = true;
saveLastDir(result);
return result;
}
}
@ -155,11 +146,7 @@ QString FileDialog::getExistingDirectory(QWidget *parent, const QString &caption
parent->activateWindow();
}
if (!dir.isEmpty() && m_nextSaveLastDir) {
config()->set("LastDir", QFileInfo(dir).absolutePath());
}
m_nextSaveLastDir = true;
saveLastDir(dir);
return dir;
}
}
@ -181,13 +168,21 @@ void FileDialog::setNextDirName(const QString &dirName)
void FileDialog::setNextForgetDialog()
{
m_nextSaveLastDir = false;
m_forgetLastDir = true;
}
FileDialog::FileDialog()
{
}
void FileDialog::saveLastDir(QString dir) {
if (!dir.isEmpty() && !m_forgetLastDir) {
config()->set("LastDir", QFileInfo(dir).absolutePath());
}
m_forgetLastDir = false;
}
FileDialog* FileDialog::instance()
{
if (!m_instance) {

View File

@ -52,7 +52,9 @@ private:
QString m_nextFileName;
QStringList m_nextFileNames;
QString m_nextDirName;
bool m_nextSaveLastDir = true;
bool m_forgetLastDir = false;
void saveLastDir(QString);
static FileDialog* m_instance;