Browse Source

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

Joakim Thorén 11 months ago
parent
commit
7d53150bdb
2 changed files with 32 additions and 0 deletions
  1. 30 0
      mapeditor/mainwindow.cpp
  2. 2 0
      mapeditor/mainwindow.h

+ 30 - 0
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();

+ 2 - 0
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();