1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-08 00:39:47 +02:00

Open Recent is a submenu with recently opened files and a "More..."-action.

This commit is contained in:
Joakim Thorén 2024-11-18 22:55:46 +01:00
parent b892221b9f
commit 7d53150bdb
2 changed files with 32 additions and 0 deletions

View File

@ -494,6 +494,36 @@ void MainWindow::on_actionOpenRecent_triggered()
d.exec(); d.exec();
} }
void MainWindow::on_menuOpenRecent_aboutToShow()
{
// Clear all actions except "More...", lest the list will grow with each
// showing of the list
for (QAction* action : ui->menuOpenRecent->actions()) {
if (action != ui->actionOpenRecentMore) {
ui->menuOpenRecent->removeAction(action);
}
}
QSettings s(Ui::teamName, Ui::appName);
QStringList recentFiles = s.value(recentlyOpenedFilesSetting).toStringList();
// Dynamically populate menuOpenRecent with one action per file.
for (const QString & file : recentFiles) {
QAction *action = new QAction(file, this);
ui->menuOpenRecent->insertAction(ui->actionOpenRecentMore, action);
connect(action, &QAction::triggered, this, [this, file]() {
if(!getAnswerAboutUnsavedChanges())
return;
openMap(file);
});
}
// Finally add a separator between recent entries and "More..."
if(recentFiles.size() > 0) {
ui->menuOpenRecent->insertSeparator(ui->actionOpenRecentMore);
}
}
void MainWindow::on_actionOpenRecentMore_triggered() void MainWindow::on_actionOpenRecentMore_triggered()
{ {
on_actionOpenRecent_triggered(); on_actionOpenRecent_triggered();

View File

@ -62,6 +62,8 @@ private slots:
void on_actionOpenRecent_triggered(); void on_actionOpenRecent_triggered();
void on_menuOpenRecent_aboutToShow();
void on_actionOpenRecentMore_triggered(); void on_actionOpenRecentMore_triggered();
void on_actionSave_as_triggered(); void on_actionSave_as_triggered();