Remember opened databases on quit.

Refs #36
This commit is contained in:
Florian Geyer 2013-03-24 23:21:59 +01:00
parent ba3baf3595
commit f0985ff9d9
5 changed files with 22 additions and 0 deletions

View File

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

View File

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

View File

@ -74,6 +74,7 @@ public Q_SLOTS:
Q_SIGNALS:
void tabNameChanged();
void databaseWithFileClosed(QString filePath);
private Q_SLOTS:
void updateTabName(Database* db);

View File

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

View File

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