From 636f84ad6c94eac913ad45ea47ea1452e702d4e0 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 4 Jan 2020 11:25:52 -0800 Subject: [PATCH] Fixed recent file being removed from menu when cancelling saving the current file. --- common/lc_mainwindow.cpp | 22 +++++++++++++++++----- common/lc_mainwindow.h | 3 +++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 8448bfed..463c908c 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -2210,19 +2210,32 @@ bool lcMainWindow::OpenProject(const QString& FileName) lcSetProfileString(LC_PROFILE_PROJECTS_PATH, QFileInfo(LoadFileName).absolutePath()); } + return OpenProjectFile(LoadFileName); +} + +void lcMainWindow::OpenRecentProject(int RecentFileIndex) +{ + if (!SaveProjectIfModified()) + return; + + if (!OpenProjectFile(mRecentFiles[RecentFileIndex])) + RemoveRecentFile(RecentFileIndex); +} + +bool lcMainWindow::OpenProjectFile(const QString& FileName) +{ Project* NewProject = new Project(); - if (NewProject->Load(LoadFileName)) + if (NewProject->Load(FileName)) { gApplication->SetProject(NewProject); - AddRecentFile(LoadFileName); + AddRecentFile(FileName); UpdateAllViews(); return true; } delete NewProject; - return false; } @@ -2495,8 +2508,7 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) case LC_FILE_RECENT2: case LC_FILE_RECENT3: case LC_FILE_RECENT4: - if (!OpenProject(mRecentFiles[CommandId - LC_FILE_RECENT1])) - RemoveRecentFile(CommandId - LC_FILE_RECENT1); + OpenRecentProject(CommandId - LC_FILE_RECENT1); break; case LC_FILE_EXIT: diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 355f6313..66ab81c8 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -292,6 +292,7 @@ public: void NewProject(); bool OpenProject(const QString& FileName); + void OpenRecentProject(int RecentFileIndex); void MergeProject(); void ImportLDD(); void ImportInventory(); @@ -373,6 +374,8 @@ protected: void ShowRenderDialog(); void ShowPrintDialog(); + bool OpenProjectFile(const QString& FileName); + lcModelTabWidget* GetTabWidgetForModel(lcModel* Model) const { for (int TabIdx = 0; TabIdx < mModelTabWidget->count(); TabIdx++)