Fixed mechanism to properly restore last session (verify validity of

last file saved, i.e not empty or unsaved session).
This commit is contained in:
brunoherbelin
2020-07-09 13:13:52 +02:00
parent 0e33d80a8f
commit 7f3867521e
6 changed files with 26 additions and 9 deletions

View File

@@ -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

View File

@@ -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();

View File

@@ -62,9 +62,9 @@ public:
protected:
RenderView render_;
std::string filename_;
Source *failedSource_;
SourceList sources_;
std::string filename_;
std::map<View::Mode, Group*> config_;
bool active_;
};

View File

@@ -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");

View File

@@ -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<std::string> 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;
}
};

View File

@@ -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;
}