[niepce] shell: properly activate / deactivate modules



commit f761887e8b335ac3fa6bc96e4f2315d2f0be5b76
Author: Hubert Figuière <hub figuiere net>
Date:   Sat Jun 16 23:49:26 2018 -0400

    shell: properly activate / deactivate modules

 src/niepce/ui/moduleshellwidget.cpp | 20 +++++++++++++-------
 src/niepce/ui/moduleshellwidget.hpp |  3 +++
 2 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/src/niepce/ui/moduleshellwidget.cpp b/src/niepce/ui/moduleshellwidget.cpp
index 12abbd9..2cdb6b2 100644
--- a/src/niepce/ui/moduleshellwidget.cpp
+++ b/src/niepce/ui/moduleshellwidget.cpp
@@ -39,13 +39,14 @@ ModuleShellWidget::ModuleShellWidget()
     pack_start(m_mainbox, Gtk::PACK_SHRINK);
 
     m_mainbox.pack_start(m_switcher);
+    m_stack.property_visible_child().signal_changed().connect(
+        sigc::mem_fun(*this, &ModuleShellWidget::stack_changed));
     pack_start(m_stack);
 
     m_switcher.set_stack(m_stack);
+    m_current_module = m_stack.get_visible_child_name();
 }
 
-
-
 void
 ModuleShellWidget::appendPage(Gtk::Widget & w, const Glib::ustring & name,
                               const Glib::ustring & label)
@@ -53,14 +54,19 @@ ModuleShellWidget::appendPage(Gtk::Widget & w, const Glib::ustring & name,
     m_stack.add(w, name, label);
 }
 
+/// Callback when the module stack has changed.
+/// This allow activation / deactivation as need
+void ModuleShellWidget::stack_changed()
+{
+    signal_deactivated(m_current_module);
+    m_current_module = m_stack.get_visible_child_name();
+    signal_activated(m_current_module);
+}
+
 void ModuleShellWidget::activatePage(const std::string & name)
 {
-    Glib::ustring current_name
-        = m_stack.get_visible_child_name();
-    if(current_name != name) {
-        signal_deactivated(current_name);
+    if (m_current_module != name) {
         m_stack.set_visible_child(name);
-        signal_activated(name);
     }
 }
 
diff --git a/src/niepce/ui/moduleshellwidget.hpp b/src/niepce/ui/moduleshellwidget.hpp
index d88aa6a..7eb5227 100644
--- a/src/niepce/ui/moduleshellwidget.hpp
+++ b/src/niepce/ui/moduleshellwidget.hpp
@@ -61,6 +61,9 @@ private:
     Gtk::MenuButton         m_menubutton;
     Gtk::Stack              m_stack;
     Gtk::StackSwitcher      m_switcher;
+    std::string             m_current_module;
+
+    void stack_changed();
 };
 
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]