used different approach for populating open recent menu

Fixes #1243
This commit is contained in:
itsmattkc
2020-11-16 10:23:23 +11:00
parent 81c98e1026
commit 9a1917d160
4 changed files with 28 additions and 7 deletions
+11 -5
View File
@@ -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();
}
}
+5
View File
@@ -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
+10 -2
View File
@@ -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_) {
+2
View File
@@ -96,6 +96,8 @@ private slots:
*/
void PopulateOpenRecent();
void RepopulateOpenRecent();
/**
* @brief Clears open recent items when menu closes
*/