diff -r 41b38b9e05a2 -r c5e8b68e34f8 src/main.cpp --- a/src/main.cpp Sun Apr 09 12:23:32 2023 +0300 +++ b/src/main.cpp Sun Apr 09 13:28:36 2023 +0300 @@ -180,16 +180,6 @@ return result; } -static void rebuildRecentFilesMenu(QMenu* menu, const QStringList& strings, QWidget* parent) -{ - menu->clear(); - for (const QString& path : strings) { - QAction* action = new QAction{path, parent}; - action->setData(path); - menu->addAction(action); - } -} - template static void forEachModel(const DocumentManager* documents, Fn&& fn) { @@ -459,27 +449,10 @@ } }; const auto updateRecentlyOpenedDocumentsMenu = [ - &documents, - &libraries, &mainWindow, - &openModelForEditing, &recentlyOpenedFiles] { - rebuildRecentFilesMenu(mainWindow.menuRecentFiles, recentlyOpenedFiles, &mainWindow); - for (QAction* action : mainWindow.menuRecentFiles->actions()) { - QString path = action->data().toString(); - QObject::connect( - action, - &QAction::triggered, - [path, &libraries, &documents, &mainWindow, &openModelForEditing]() { - const auto id = openModelFromPath(path, &libraries, &documents, &mainWindow); - if (id.has_value()) - { - openModelForEditing(id.value()); - } - } - ); - } + mainWindow.rebuildRecentFilesMenu(recentlyOpenedFiles); }; const auto restoreSettings = [ &colorTable, @@ -518,6 +491,18 @@ saveSettings(); updateRecentlyOpenedDocumentsMenu(); }; + QObject::connect( + &mainWindow, + &MainWindow::recentFileSelected, + [&libraries, &documents, &mainWindow, &openModelForEditing, &addRecentlyOpenedFile](const QString& path) { + const auto id = openModelFromPath(path, &libraries, &documents, &mainWindow); + if (id.has_value()) + { + openModelForEditing(id.value()); + addRecentlyOpenedFile(path); + } + } + ); QObject::connect(mainWindow.actionNew, &QAction::triggered, [&documents, &openModelForEditing]{ openModelForEditing(documents.newModel());