mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-08 00:40:02 +01:00
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:
11
Mixer.cpp
11
Mixer.cpp
@@ -41,9 +41,11 @@ static void loadSession(const std::string& filename, Session *session)
|
|||||||
if (creator.load(filename)) {
|
if (creator.load(filename)) {
|
||||||
// loaded ok
|
// loaded ok
|
||||||
session->setFilename(filename);
|
session->setFilename(filename);
|
||||||
|
|
||||||
|
// internal update flag
|
||||||
sessionSwapRequested_ = true;
|
sessionSwapRequested_ = true;
|
||||||
|
|
||||||
// cosmetics load ok
|
// notification
|
||||||
Log::Notify("Session %s loaded. %d source(s) created.", filename.c_str(), session->numSource());
|
Log::Notify("Session %s loaded. %d source(s) created.", filename.c_str(), session->numSource());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -65,7 +67,8 @@ static void importSession(const std::string& filename, Session *session)
|
|||||||
SessionCreator creator( session );
|
SessionCreator creator( session );
|
||||||
|
|
||||||
if (creator.load(filename)) {
|
if (creator.load(filename)) {
|
||||||
// cosmetics load ok
|
|
||||||
|
// internal update flag
|
||||||
sessionImportRequested_ = true;
|
sessionImportRequested_ = true;
|
||||||
|
|
||||||
Log::Notify("Session %s loaded. %d source(s) imported.", filename.c_str(), session->numSource());
|
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
|
// all ok
|
||||||
session->setFilename(filename);
|
session->setFilename(filename);
|
||||||
// cosmetics saved ok
|
// cosmetics saved ok
|
||||||
|
Rendering::manager().mainWindow().setTitle(filename);
|
||||||
Settings::application.recentSessions.push(filename);
|
Settings::application.recentSessions.push(filename);
|
||||||
Log::Notify("Session %s saved.", filename.c_str());
|
Log::Notify("Session %s saved.", filename.c_str());
|
||||||
|
|
||||||
|
// set session filename
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// error loading
|
// error loading
|
||||||
@@ -155,6 +161,7 @@ Mixer::Mixer() : session_(nullptr), back_session_(nullptr), current_view_(nullpt
|
|||||||
|
|
||||||
// auto load if Settings ask to
|
// auto load if Settings ask to
|
||||||
if ( Settings::application.recentSessions.load_at_start &&
|
if ( Settings::application.recentSessions.load_at_start &&
|
||||||
|
Settings::application.recentSessions.valid_file &&
|
||||||
Settings::application.recentSessions.filenames.size() > 0 )
|
Settings::application.recentSessions.filenames.size() > 0 )
|
||||||
load( Settings::application.recentSessions.filenames.front() );
|
load( Settings::application.recentSessions.filenames.front() );
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
|
|
||||||
bool init(int id, GLFWwindow *share = NULL);
|
bool init(int id, GLFWwindow *share = NULL);
|
||||||
void setIcon(const std::string &resource);
|
void setIcon(const std::string &resource);
|
||||||
void setTitle(const std::string &title);
|
void setTitle(const std::string &title = "");
|
||||||
|
|
||||||
// show window (fullscreen if needed)
|
// show window (fullscreen if needed)
|
||||||
void show();
|
void show();
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
RenderView render_;
|
RenderView render_;
|
||||||
|
std::string filename_;
|
||||||
Source *failedSource_;
|
Source *failedSource_;
|
||||||
SourceList sources_;
|
SourceList sources_;
|
||||||
std::string filename_;
|
|
||||||
std::map<View::Mode, Group*> config_;
|
std::map<View::Mode, Group*> config_;
|
||||||
bool active_;
|
bool active_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ void Settings::Save()
|
|||||||
recentsession->SetAttribute("path", application.recentSessions.path.c_str());
|
recentsession->SetAttribute("path", application.recentSessions.path.c_str());
|
||||||
recentsession->SetAttribute("autoload", application.recentSessions.load_at_start);
|
recentsession->SetAttribute("autoload", application.recentSessions.load_at_start);
|
||||||
recentsession->SetAttribute("autosave", application.recentSessions.save_on_exit);
|
recentsession->SetAttribute("autosave", application.recentSessions.save_on_exit);
|
||||||
|
recentsession->SetAttribute("valid", application.recentSessions.valid_file);
|
||||||
for(auto it = application.recentSessions.filenames.begin();
|
for(auto it = application.recentSessions.filenames.begin();
|
||||||
it != application.recentSessions.filenames.end(); it++) {
|
it != application.recentSessions.filenames.end(); it++) {
|
||||||
XMLElement *fileNode = xmlDoc.NewElement("path");
|
XMLElement *fileNode = xmlDoc.NewElement("path");
|
||||||
@@ -292,8 +293,6 @@ void Settings::Load()
|
|||||||
application.recentSessions.path = std::string(path_);
|
application.recentSessions.path = std::string(path_);
|
||||||
else
|
else
|
||||||
application.recentSessions.path = SystemToolkit::home_path();
|
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();
|
application.recentSessions.filenames.clear();
|
||||||
XMLElement* path = pSession->FirstChildElement("path");
|
XMLElement* path = pSession->FirstChildElement("path");
|
||||||
for( ; path ; path = path->NextSiblingElement())
|
for( ; path ; path = path->NextSiblingElement())
|
||||||
@@ -302,6 +301,9 @@ void Settings::Load()
|
|||||||
if (p)
|
if (p)
|
||||||
application.recentSessions.push( std::string (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
|
// recent session filenames
|
||||||
XMLElement * pFolder = pElement->FirstChildElement("Folder");
|
XMLElement * pFolder = pElement->FirstChildElement("Folder");
|
||||||
|
|||||||
10
Settings.h
10
Settings.h
@@ -39,7 +39,7 @@ struct WindowConfig
|
|||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
std::string monitor;
|
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::string path;
|
||||||
std::list<std::string> filenames;
|
std::list<std::string> filenames;
|
||||||
|
bool valid_file;
|
||||||
bool load_at_start;
|
bool load_at_start;
|
||||||
bool save_on_exit;
|
bool save_on_exit;
|
||||||
|
|
||||||
History() {
|
History() {
|
||||||
path = "Recent Files";
|
path = "Recent Files";
|
||||||
|
valid_file = false;
|
||||||
load_at_start = false;
|
load_at_start = false;
|
||||||
save_on_exit = false;
|
save_on_exit = false;
|
||||||
}
|
}
|
||||||
void push(std::string filename) {
|
void push(std::string filename) {
|
||||||
if (filename.empty()) return;
|
if (filename.empty()) {
|
||||||
|
valid_file = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
filenames.remove(filename);
|
filenames.remove(filename);
|
||||||
filenames.push_front(filename);
|
filenames.push_front(filename);
|
||||||
if (filenames.size() > MAX_RECENT_HISTORY)
|
if (filenames.size() > MAX_RECENT_HISTORY)
|
||||||
filenames.pop_back();
|
filenames.pop_back();
|
||||||
|
valid_file = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -247,6 +247,7 @@ void UserInterface::handleKeyboard()
|
|||||||
}
|
}
|
||||||
else if (ImGui::IsKeyPressed( GLFW_KEY_O )) {
|
else if (ImGui::IsKeyPressed( GLFW_KEY_O )) {
|
||||||
// Open session
|
// Open session
|
||||||
|
sessionFileDialogImport_ = false;
|
||||||
std::thread (SessionFileDialogOpen, Settings::application.recentSessions.path).detach();
|
std::thread (SessionFileDialogOpen, Settings::application.recentSessions.path).detach();
|
||||||
navigator.hidePannel();
|
navigator.hidePannel();
|
||||||
}
|
}
|
||||||
@@ -616,7 +617,7 @@ void UserInterface::showMenuOptions()
|
|||||||
ImGui::MenuItem( ICON_FA_ARROW_CIRCLE_RIGHT " Smooth transition", nullptr, &Settings::application.smooth_transition);
|
ImGui::MenuItem( ICON_FA_ARROW_CIRCLE_RIGHT " Smooth transition", nullptr, &Settings::application.smooth_transition);
|
||||||
|
|
||||||
ImGui::Separator();
|
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);
|
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"};
|
const char *tooltip[2] = {"Clear history", "Clear history"};
|
||||||
if (ImGuiToolkit::IconToggle(12,14,11,14, &reset, tooltip)) {
|
if (ImGuiToolkit::IconToggle(12,14,11,14, &reset, tooltip)) {
|
||||||
Settings::application.recentSessions.filenames.clear();
|
Settings::application.recentSessions.filenames.clear();
|
||||||
|
Settings::application.recentSessions.valid_file = false;
|
||||||
// reload the list next time
|
// reload the list next time
|
||||||
selection_session_mode_changed = true;
|
selection_session_mode_changed = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user