From 181bbb7f216f6c61e0597991728376fb803291fb Mon Sep 17 00:00:00 2001 From: ispyisail Date: Mon, 14 Sep 2026 15:25:51 +1200 Subject: [PATCH] Fix bugtracker #97: "Recently opened" never updates during a session The File > Recently-opened submenu was filled once, at editor construction, by copying the QActions that RecentFiles' menu happened to hold at that moment: recentfile->addActions(QETApp::projectsRecentFiles()->menu()->actions()); RecentFiles::buildMenu() runs on every fileWasOpened(), clears its menu and creates fresh QActions. The editor's copy therefore never gained an entry, and the list only ever looked correct after a restart. The submenu is now the RecentFiles menu itself. QMenu::addMenu() adds the submenu's menuAction() rather than reparenting it, so several editor windows can share the one live menu, which is what an application-wide recent-files list should do anyway. Measured with a temporary probe comparing the live menu against what the File menu actually shows, after one file had been opened in the same session: without the fix live=1 shownInFileMenu=0 with the fix live=1 shownInFileMenu=1 ctest 4/4, GUI starts clean with the menu bar intact. Qt 5.15.18. Co-Authored-By: Claude Opus 5 --- sources/qetdiagrameditor.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index b624a66fb..cf6f7d8fd 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -903,8 +903,20 @@ void QETDiagramEditor::setUpMenu() insertMenu(help_menu_, windows_menu); // File menu - QMenu *recentfile = menu_fichier -> addMenu(QET::Icons::DocumentOpenRecent, tr("&Récemment ouverts")); - recentfile->addActions(QETApp::projectsRecentFiles()->menu()->actions()); + // Add the RecentFiles menu itself, not a copy of the actions it + // happened to hold at construction time. RecentFiles::buildMenu() + // clears that menu and creates fresh QActions every time a file is + // opened, so a snapshot taken here never gained an entry again and + // the list only looked right after a restart (bugtracker #97). + // + // The menu is an application-wide singleton and several editor + // windows may exist. QMenu::addMenu() adds the submenu's menuAction() + // rather than reparenting it, so every window shows the same live + // menu, which is the intent. + QMenu *recentfile = QETApp::projectsRecentFiles()->menu(); + recentfile->setTitle(tr("&Récemment ouverts")); + recentfile->setIcon(QET::Icons::DocumentOpenRecent); + menu_fichier->addMenu(recentfile); connect(QETApp::projectsRecentFiles(), &RecentFiles::fileOpeningRequested, this, &QETDiagramEditor::openRecentFile); menu_fichier -> addActions(m_file_actions_group.actions()); menu_fichier -> addSeparator();