diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 047f4d670..c06250c48 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -88,6 +88,7 @@ void Config::init(const QString& fileName) m_settings.reset(new QSettings(fileName, QSettings::IniFormat)); m_defaults.insert("RememberLastDatabases", true); + m_defaults.insert("OpenPreviousDatabasesOnStartup", true); m_defaults.insert("ModifiedOnExpandedStateChanges", true); m_defaults.insert("AutoSaveAfterEveryChange", false); m_defaults.insert("AutoSaveOnExit", false); diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index cc87a5745..d11effbc5 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -226,6 +226,9 @@ bool DatabaseTabWidget::closeDatabase(Database* db) void DatabaseTabWidget::deleteDatabase(Database* db) { const DatabaseManagerStruct dbStruct = m_dbList.value(db); + bool emitDatabaseWithFileClosed = dbStruct.saveToFilename; + QString filePath = dbStruct.filePath; + int index = databaseIndex(db); removeTab(index); @@ -233,6 +236,10 @@ void DatabaseTabWidget::deleteDatabase(Database* db) m_dbList.remove(db); delete dbStruct.dbWidget; delete db; + + if (emitDatabaseWithFileClosed) { + Q_EMIT databaseWithFileClosed(filePath); + } } bool DatabaseTabWidget::closeAllDatabases() diff --git a/src/gui/DatabaseTabWidget.h b/src/gui/DatabaseTabWidget.h index 51dcc76f9..4ac9bf418 100644 --- a/src/gui/DatabaseTabWidget.h +++ b/src/gui/DatabaseTabWidget.h @@ -74,6 +74,7 @@ public Q_SLOTS: Q_SIGNALS: void tabNameChanged(); + void databaseWithFileClosed(QString filePath); private Q_SLOTS: void updateTabName(Database* db); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 15706bed0..c3d4c9753 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -397,12 +397,18 @@ void MainWindow::databaseTabChanged(int tabIndex) void MainWindow::closeEvent(QCloseEvent* event) { + openDatabases.clear(); + connect(m_ui->tabWidget, SIGNAL(databaseWithFileClosed(QString)), this, SLOT(rememberOpenDatabases(QString))); if (!m_ui->tabWidget->closeAllDatabases()) { event->ignore(); } else { event->accept(); } + disconnect(m_ui->tabWidget, SIGNAL(databaseWithFileClosed(QString)), this, SLOT(rememberOpenDatabases(QString))); + if (config()->get("OpenPreviousDatabasesOnStartup").toBool()) { + config()->set("OpenDatabasesOnExit", openDatabases); + } } void MainWindow::showEntryContextMenu(const QPoint& globalPos) @@ -429,3 +435,8 @@ void MainWindow::setShortcut(QAction* action, QKeySequence::StandardKey standard action->setShortcut(QKeySequence(fallback)); } } + +void MainWindow::rememberOpenDatabases(QString filePath) +{ + openDatabases.append(filePath); +} diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index b6c309145..74a3a83ce 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -57,6 +57,7 @@ private Q_SLOTS: void showEntryContextMenu(const QPoint& globalPos); void showGroupContextMenu(const QPoint& globalPos); void saveToolbarState(bool value); + void rememberOpenDatabases(QString filePath); private: static void setShortcut(QAction* action, QKeySequence::StandardKey standard, int fallback = 0); @@ -68,6 +69,7 @@ private: QAction* m_clearHistoryAction; QActionGroup* m_lastDatabasesActions; QActionGroup* m_copyAdditionalAttributeActions; + QStringList openDatabases; Q_DISABLE_COPY(MainWindow) };