0
0
mirror of https://github.com/keepassxreboot/keepassxc.git synced 2024-09-20 04:12:15 +02:00

Show last used databases in file menu.

Refs #36
This commit is contained in:
Florian Geyer 2012-07-23 21:12:19 +02:00
parent a16f7e7cca
commit 0755702fe3
3 changed files with 40 additions and 0 deletions

View File

@ -39,6 +39,12 @@ MainWindow::MainWindow()
toggleViewAction->setText(tr("Show toolbar"));
m_ui->menuView->addAction(toggleViewAction);
m_clearHistoryAction = new QAction("Clear history", m_ui->menuFile);
m_lastDatabasesActions = new QActionGroup(m_ui->menuRecentDatabases);
connect(m_clearHistoryAction, SIGNAL(triggered()), this, SLOT(clearLastDatabases()));
connect(m_lastDatabasesActions, SIGNAL(triggered(QAction*)), this, SLOT(openRecentDatabase(QAction*)));
connect(m_ui->menuRecentDatabases, SIGNAL(aboutToShow()), this, SLOT(updateLastDatabasesMenu()));
Qt::Key globalAutoTypeKey = static_cast<Qt::Key>(config()->get("GlobalAutoTypeKey").toInt());
Qt::KeyboardModifiers globalAutoTypeModifiers = static_cast<Qt::KeyboardModifiers>(
config()->get("GlobalAutoTypeModifiers").toInt());
@ -145,6 +151,28 @@ MainWindow::~MainWindow()
{
}
void MainWindow::updateLastDatabasesMenu() {
m_ui->menuRecentDatabases->clear();
QStringList lastDatabases = config()->get("LastDatabases", QVariant()).toStringList();
Q_FOREACH (const QString& database, lastDatabases) {
QAction* action = m_ui->menuRecentDatabases->addAction(database);
m_lastDatabasesActions->addAction(action);
}
m_ui->menuRecentDatabases->addSeparator();
m_ui->menuRecentDatabases->addAction(m_clearHistoryAction);
}
void MainWindow::openRecentDatabase(QAction* action)
{
openDatabase(action->text());
}
void MainWindow::clearLastDatabases()
{
config()->set("LastDatabases", QVariant());
}
void MainWindow::openDatabase(const QString& fileName, const QString& pw, const QString& keyFile)
{
m_ui->tabWidget->openDatabase(fileName, pw, keyFile);

View File

@ -18,6 +18,7 @@
#ifndef KEEPASSX_MAINWINDOW_H
#define KEEPASSX_MAINWINDOW_H
#include <QtGui/QActionGroup>
#include <QtGui/QMainWindow>
#include "gui/DatabaseWidget.h"
@ -48,6 +49,9 @@ private Q_SLOTS:
void switchToDatabases();
void switchToSettings();
void databaseTabChanged(int tabIndex);
void openRecentDatabase(QAction* action);
void clearLastDatabases();
void updateLastDatabasesMenu();
private:
static void setShortcut(QAction* action, QKeySequence::StandardKey standard, int fallback = 0);
@ -55,6 +59,8 @@ private:
static const QString BaseWindowTitle;
const QScopedPointer<Ui::MainWindow> m_ui;
QAction* m_clearHistoryAction;
QActionGroup* m_lastDatabasesActions;
Q_DISABLE_COPY(MainWindow)
};

View File

@ -77,8 +77,14 @@
<property name="title">
<string>Database</string>
</property>
<widget class="QMenu" name="menuRecentDatabases">
<property name="title">
<string>Recent databases</string>
</property>
</widget>
<addaction name="actionDatabaseNew"/>
<addaction name="actionDatabaseOpen"/>
<addaction name="menuRecentDatabases"/>
<addaction name="actionDatabaseSave"/>
<addaction name="actionDatabaseSaveAs"/>
<addaction name="actionDatabaseClose"/>