diff --git a/app/core.cpp b/app/core.cpp index 5a7f179bf..86c2f829b 100644 --- a/app/core.cpp +++ b/app/core.cpp @@ -168,9 +168,7 @@ void Core::Stop() if (recent_projects_file.open(QFile::WriteOnly | QFile::Text)) { QTextStream ts(&recent_projects_file); - foreach (const QString& s, recent_projects_) { - ts << s << "\n"; - } + ts << recent_projects_.join('\n'); recent_projects_file.close(); } @@ -254,6 +252,7 @@ void Core::SetSelectedTransitionObject(const QString &obj) void Core::ClearOpenRecentList() { recent_projects_.clear(); + emit OpenRecentListChanged(); } void Core::CreateNewProject() @@ -678,12 +677,15 @@ void Core::StartGUI(bool full_screen) if (recent_projects_file.open(QFile::ReadOnly | QFile::Text)) { QTextStream ts(&recent_projects_file); - while (!ts.atEnd()) { - recent_projects_.append(ts.readLine()); + QString s; + while (!(s = ts.readLine()).isEmpty()) { + recent_projects_.append(s); } recent_projects_file.close(); } + + emit OpenRecentListChanged(); } } @@ -953,6 +955,8 @@ void Core::PushRecentlyOpenedProject(const QString& s) } else { recent_projects_.prepend(s); } + + emit OpenRecentListChanged(); } void Core::OpenProjectInternal(const QString &filename) @@ -1089,6 +1093,8 @@ void Core::OpenProjectFromRecentList(int index) tr("The project \"%1\" doesn't exist. Would you like to remove this file from the recent list?").arg(open_fn), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { recent_projects_.removeAt(index); + + emit OpenRecentListChanged(); } } diff --git a/app/core.h b/app/core.h index 8e3b45db1..89d609a42 100644 --- a/app/core.h +++ b/app/core.h @@ -415,6 +415,11 @@ signals: */ void TimecodeDisplayChanged(Timecode::Display d); + /** + * @brief Signal emitted when a change is made to the open recent list + */ + void OpenRecentListChanged(); + private: /** * @brief Get the file filter than can be used with QFileDialog to open and save compatible projects diff --git a/app/window/mainwindow/mainmenu.cpp b/app/window/mainwindow/mainmenu.cpp index b33a3e604..1bdbe9219 100644 --- a/app/window/mainwindow/mainmenu.cpp +++ b/app/window/mainwindow/mainmenu.cpp @@ -50,8 +50,7 @@ MainMenu::MainMenu(MainWindow *parent) : file_new_menu_ = new Menu(file_menu_); MenuShared::instance()->AddItemsForNewMenu(file_new_menu_); file_open_item_ = file_menu_->AddItem("openproj", Core::instance(), &Core::OpenProject, "Ctrl+O"); - file_open_recent_menu_ = new Menu(file_menu_, this, &MainMenu::PopulateOpenRecent); - connect(file_open_recent_menu_, &Menu::aboutToHide, this, &MainMenu::CloseOpenRecentMenu); + file_open_recent_menu_ = new Menu(file_menu_); file_open_recent_separator_ = file_open_recent_menu_->addSeparator(); file_open_recent_clear_item_ = file_open_recent_menu_->AddItem("clearopenrecent", Core::instance(), &Core::ClearOpenRecentList); file_save_item_ = file_menu_->AddItem("saveproj", Core::instance(), &Core::SaveActiveProject, "Ctrl+S"); @@ -255,6 +254,9 @@ MainMenu::MainMenu(MainWindow *parent) : help_menu_->addSeparator(); help_about_item_ = help_menu_->AddItem("about", Core::instance(), &Core::DialogAboutShow); + connect(Core::instance(), &Core::OpenRecentListChanged, this, &MainMenu::RepopulateOpenRecent); + PopulateOpenRecent(); + Retranslate(); } @@ -398,6 +400,12 @@ void MainMenu::PopulateOpenRecent() } } +void MainMenu::RepopulateOpenRecent() +{ + CloseOpenRecentMenu(); + PopulateOpenRecent(); +} + void MainMenu::CloseOpenRecentMenu() { while (file_open_recent_menu_->actions().first() != file_open_recent_separator_) { diff --git a/app/window/mainwindow/mainmenu.h b/app/window/mainwindow/mainmenu.h index 622303900..3bfb691fe 100644 --- a/app/window/mainwindow/mainmenu.h +++ b/app/window/mainwindow/mainmenu.h @@ -96,6 +96,8 @@ private slots: */ void PopulateOpenRecent(); + void RepopulateOpenRecent(); + /** * @brief Clears open recent items when menu closes */