From fa2e087a8fdbc0c676858308d2435667d87d22c0 Mon Sep 17 00:00:00 2001 From: Rodolfo Ribeiro Gomes Date: Oct 10 2019 07:28:12 +0000 Subject: WorkspaceHandler emits signal for list changing --- diff --git a/synfig-studio/src/gui/app.cpp b/synfig-studio/src/gui/app.cpp index 257b28c..cf1556b 100644 --- a/synfig-studio/src/gui/app.cpp +++ b/synfig-studio/src/gui/app.cpp @@ -1703,6 +1703,7 @@ App::App(const synfig::String& basepath, int *argc, char ***argv): studio_init_cb.task(_("Loading Custom Workspace List...")); workspaces = new WorkspaceHandler(); + workspaces->signal_list_changed().connect( sigc::mem_fun(signal_custom_workspaces_changed_, &sigc::signal::emit) ); load_custom_workspaces(); studio_init_cb.task(_("Init auto recovery...")); @@ -2271,7 +2272,6 @@ void App::load_custom_workspaces() workspaces->clear(); std::string filename = get_config_file("workspaces"); workspaces->load(filename); - signal_custom_workspaces_changed_(); } static void trim_string(std::string &text) @@ -2330,7 +2330,6 @@ void App::save_custom_workspace() return; workspaces->set_workspace(name, tpl); } - signal_custom_workspaces_changed_(); } void diff --git a/synfig-studio/src/gui/workspacehandler.cpp b/synfig-studio/src/gui/workspacehandler.cpp index 6808ea5..586dc0c 100644 --- a/synfig-studio/src/gui/workspacehandler.cpp +++ b/synfig-studio/src/gui/workspacehandler.cpp @@ -78,16 +78,24 @@ WorkspaceHandler::add_workspace(const std::string& name, const std::string& tpl) if (has_workspace(valid_name)) return false; workspaces[valid_name] = tpl; + signal_list_changed_.emit(); return true; } void WorkspaceHandler::remove_workspace(const std::string& name) { - workspaces.erase(name); + size_t count = workspaces.erase(name); + if (count > 0) + signal_list_changed_.emit(); +} + void WorkspaceHandler::clear() { + size_t previous_size = workspaces.size(); workspaces.clear(); + if (previous_size > 0) + signal_list_changed_.emit(); } bool @@ -140,6 +148,7 @@ WorkspaceHandler::load(const std::string& filename) { std::ifstream ifs(filename); std::string line; + int count = 0; while (ifs && !ifs.eof()) { getline(ifs, line); if (line.empty()) @@ -159,5 +168,13 @@ WorkspaceHandler::load(const std::string& filename) std::string tpl = line.substr(pos+1); workspaces[name] = tpl; + count++; } + if (count > 0) + signal_list_changed_.emit(); +} + +sigc::signal& WorkspaceHandler::signal_list_changed() +{ + return signal_list_changed_; } diff --git a/synfig-studio/src/gui/workspacehandler.h b/synfig-studio/src/gui/workspacehandler.h index 7ddca3d..8867991 100644 --- a/synfig-studio/src/gui/workspacehandler.h +++ b/synfig-studio/src/gui/workspacehandler.h @@ -28,6 +28,7 @@ #include #include #include +#include namespace studio { @@ -59,9 +60,12 @@ public: /// stores custom workspace layouts in a config file bool save(const std::string& filename); + sigc::signal & signal_list_changed(); + private: std::map workspaces; + sigc::signal signal_list_changed_; }; }