From 7f3867521e871cec9ae9eb1f2dba7593b675a3a4 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Thu, 9 Jul 2020 13:13:52 +0200 Subject: [PATCH] Fixed mechanism to properly restore last session (verify validity of last file saved, i.e not empty or unsaved session). --- Mixer.cpp | 11 +++++++++-- RenderingManager.h | 2 +- Session.h | 2 +- Settings.cpp | 6 ++++-- Settings.h | 10 ++++++++-- UserInterfaceManager.cpp | 4 +++- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Mixer.cpp b/Mixer.cpp index 842cfcf..d1bb443 100644 --- a/Mixer.cpp +++ b/Mixer.cpp @@ -41,9 +41,11 @@ static void loadSession(const std::string& filename, Session *session) if (creator.load(filename)) { // loaded ok session->setFilename(filename); + + // internal update flag sessionSwapRequested_ = true; - // cosmetics load ok + // notification Log::Notify("Session %s loaded. %d source(s) created.", filename.c_str(), session->numSource()); } else { @@ -65,7 +67,8 @@ static void importSession(const std::string& filename, Session *session) SessionCreator creator( session ); if (creator.load(filename)) { - // cosmetics load ok + + // internal update flag sessionImportRequested_ = true; Log::Notify("Session %s loaded. %d source(s) imported.", filename.c_str(), session->numSource()); @@ -134,8 +137,11 @@ static void saveSession(const std::string& filename, Session *session) // all ok session->setFilename(filename); // cosmetics saved ok + Rendering::manager().mainWindow().setTitle(filename); Settings::application.recentSessions.push(filename); Log::Notify("Session %s saved.", filename.c_str()); + + // set session filename } else { // error loading @@ -155,6 +161,7 @@ Mixer::Mixer() : session_(nullptr), back_session_(nullptr), current_view_(nullpt // auto load if Settings ask to if ( Settings::application.recentSessions.load_at_start && + Settings::application.recentSessions.valid_file && Settings::application.recentSessions.filenames.size() > 0 ) load( Settings::application.recentSessions.filenames.front() ); else diff --git a/RenderingManager.h b/RenderingManager.h index df7e079..01d9fea 100644 --- a/RenderingManager.h +++ b/RenderingManager.h @@ -44,7 +44,7 @@ public: bool init(int id, GLFWwindow *share = NULL); void setIcon(const std::string &resource); - void setTitle(const std::string &title); + void setTitle(const std::string &title = ""); // show window (fullscreen if needed) void show(); diff --git a/Session.h b/Session.h index e60b72b..b1abd4b 100644 --- a/Session.h +++ b/Session.h @@ -62,9 +62,9 @@ public: protected: RenderView render_; + std::string filename_; Source *failedSource_; SourceList sources_; - std::string filename_; std::map config_; bool active_; }; diff --git a/Settings.cpp b/Settings.cpp index 49471bf..ffa2d2b 100644 --- a/Settings.cpp +++ b/Settings.cpp @@ -124,6 +124,7 @@ void Settings::Save() recentsession->SetAttribute("path", application.recentSessions.path.c_str()); recentsession->SetAttribute("autoload", application.recentSessions.load_at_start); recentsession->SetAttribute("autosave", application.recentSessions.save_on_exit); + recentsession->SetAttribute("valid", application.recentSessions.valid_file); for(auto it = application.recentSessions.filenames.begin(); it != application.recentSessions.filenames.end(); it++) { XMLElement *fileNode = xmlDoc.NewElement("path"); @@ -292,8 +293,6 @@ void Settings::Load() application.recentSessions.path = std::string(path_); else application.recentSessions.path = SystemToolkit::home_path(); - pSession->QueryBoolAttribute("autoload", &application.recentSessions.load_at_start); - pSession->QueryBoolAttribute("autosave", &application.recentSessions.save_on_exit); application.recentSessions.filenames.clear(); XMLElement* path = pSession->FirstChildElement("path"); for( ; path ; path = path->NextSiblingElement()) @@ -302,6 +301,9 @@ void Settings::Load() if (p) application.recentSessions.push( std::string (p) ); } + pSession->QueryBoolAttribute("autoload", &application.recentSessions.load_at_start); + pSession->QueryBoolAttribute("autosave", &application.recentSessions.save_on_exit); + pSession->QueryBoolAttribute("valid", &application.recentSessions.valid_file); } // recent session filenames XMLElement * pFolder = pElement->FirstChildElement("Folder"); diff --git a/Settings.h b/Settings.h index 81337dc..27b6123 100644 --- a/Settings.h +++ b/Settings.h @@ -39,7 +39,7 @@ struct WindowConfig bool fullscreen; std::string monitor; - WindowConfig() : name(""), x(15), y(15), w(1280), h(720), monitor(""), fullscreen(false) { } + WindowConfig() : name(""), x(15), y(15), w(1280), h(720), fullscreen(false), monitor("") { } }; @@ -60,20 +60,26 @@ struct History { std::string path; std::list filenames; + bool valid_file; bool load_at_start; bool save_on_exit; History() { path = "Recent Files"; + valid_file = false; load_at_start = false; save_on_exit = false; } void push(std::string filename) { - if (filename.empty()) return; + if (filename.empty()) { + valid_file = false; + return; + } filenames.remove(filename); filenames.push_front(filename); if (filenames.size() > MAX_RECENT_HISTORY) filenames.pop_back(); + valid_file = true; } }; diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index b77ce03..fa19142 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -247,6 +247,7 @@ void UserInterface::handleKeyboard() } else if (ImGui::IsKeyPressed( GLFW_KEY_O )) { // Open session + sessionFileDialogImport_ = false; std::thread (SessionFileDialogOpen, Settings::application.recentSessions.path).detach(); navigator.hidePannel(); } @@ -616,7 +617,7 @@ void UserInterface::showMenuOptions() ImGui::MenuItem( ICON_FA_ARROW_CIRCLE_RIGHT " Smooth transition", nullptr, &Settings::application.smooth_transition); ImGui::Separator(); - ImGui::MenuItem( ICON_FA_HISTORY " Load most recent on start", nullptr, &Settings::application.recentSessions.load_at_start); + ImGui::MenuItem( ICON_FA_HISTORY " Restore session on start", nullptr, &Settings::application.recentSessions.load_at_start); ImGui::MenuItem( ICON_FA_FILE_DOWNLOAD " Save on exit", nullptr, &Settings::application.recentSessions.save_on_exit); } @@ -1669,6 +1670,7 @@ void Navigator::RenderMainPannel() const char *tooltip[2] = {"Clear history", "Clear history"}; if (ImGuiToolkit::IconToggle(12,14,11,14, &reset, tooltip)) { Settings::application.recentSessions.filenames.clear(); + Settings::application.recentSessions.valid_file = false; // reload the list next time selection_session_mode_changed = true; }