diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index 7e2d8ff12..22a6ef601 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -494,6 +494,36 @@ void MainWindow::on_actionOpenRecent_triggered() 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() { on_actionOpenRecent_triggered(); diff --git a/mapeditor/mainwindow.h b/mapeditor/mainwindow.h index 7c3a8b2f3..6147e4bf5 100644 --- a/mapeditor/mainwindow.h +++ b/mapeditor/mainwindow.h @@ -62,6 +62,8 @@ private slots: void on_actionOpenRecent_triggered(); + void on_menuOpenRecent_aboutToShow(); + void on_actionOpenRecentMore_triggered(); void on_actionSave_as_triggered();