diff -r 673b8dffbe14 -r 676d0b43b577 src/main.cpp --- a/src/main.cpp Sat Apr 08 15:15:41 2023 +0300 +++ b/src/main.cpp Sat Apr 08 15:34:32 2023 +0300 @@ -425,19 +425,6 @@ libraries.storeToSettings(); settingsChanged.emit(); }; - const auto updateRecentlyOpenedDocumentsMenu = [&]{ - rebuildRecentFilesMenu(ui.menuRecentFiles, recentlyOpenedFiles, &mainWindow); - for (QAction* action : ui.menuRecentFiles->findChildren()) { - QString path = action->data().toString(); - QObject::connect( - action, - &QAction::triggered, - [path, &libraries, &documents, &mainWindow]() { - openModelFromPath(path, &libraries, &documents, &mainWindow); - } - ); - } - }; const auto executeAction = [&]( QTextDocument* model, const ModelAction& action ) { @@ -465,29 +452,6 @@ }, action); }; - const auto restoreSettings = [&]{ - recentlyOpenedFiles = setting(); - renderPreferences = loadRenderPreferences(); - libraries.restoreFromSettings(); - updateRecentlyOpenedDocumentsMenu(); - colorTable = loadColors(&libraries); - updateRenderPreferences(&ui, &renderPreferences, &documents); - ui.mdiArea->setViewMode(setting()); - ui.retranslateUi(&mainWindow); - mainWindow.setToolButtonStyle(setting()); - settingsChanged.emit(); - }; - const auto addRecentlyOpenedFile = [&](const QString& path){ - constexpr int maxRecentlyOpenedFiles = 10; - recentlyOpenedFiles.removeAll(path); - recentlyOpenedFiles.insert(0, path); - while (recentlyOpenedFiles.size() > maxRecentlyOpenedFiles) - { - recentlyOpenedFiles.removeLast(); - } - saveSettings(); - updateRecentlyOpenedDocumentsMenu(); - }; const auto openModelForEditing = [&](const ModelId modelId){ QTextDocument* model = documents.getModelById(modelId); if (model != nullptr) { @@ -560,6 +524,46 @@ subWindow->show(); } }; + const auto updateRecentlyOpenedDocumentsMenu = [&]{ + rebuildRecentFilesMenu(ui.menuRecentFiles, recentlyOpenedFiles, &mainWindow); + for (QAction* action : ui.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()); + } + } + ); + } + }; + const auto restoreSettings = [&]{ + recentlyOpenedFiles = setting(); + renderPreferences = loadRenderPreferences(); + libraries.restoreFromSettings(); + updateRecentlyOpenedDocumentsMenu(); + colorTable = loadColors(&libraries); + updateRenderPreferences(&ui, &renderPreferences, &documents); + ui.mdiArea->setViewMode(setting()); + ui.retranslateUi(&mainWindow); + mainWindow.setToolButtonStyle(setting()); + settingsChanged.emit(); + }; + const auto addRecentlyOpenedFile = [&](const QString& path){ + constexpr int maxRecentlyOpenedFiles = 10; + recentlyOpenedFiles.removeAll(path); + recentlyOpenedFiles.insert(0, path); + while (recentlyOpenedFiles.size() > maxRecentlyOpenedFiles) + { + recentlyOpenedFiles.removeLast(); + } + saveSettings(); + updateRecentlyOpenedDocumentsMenu(); + }; QObject::connect(ui.actionNew, &QAction::triggered, [&]{ openModelForEditing(documents.newModel()); });