[niepce] workspace: clear the content when the selection changes



commit 2f7a51ee3976d9b4f917ce4b588d3b0835146da4
Author: Hubert Figuière <hub figuiere net>
Date:   Tue Oct 23 22:49:35 2018 -0400

    workspace: clear the content when the selection changes

 src/niepce/ui/imageliststore.cpp      | 11 ++++++++---
 src/niepce/ui/imageliststore.hpp      |  4 +++-
 src/niepce/ui/moduleshell.cpp         | 10 +++++++---
 src/niepce/ui/moduleshell.hpp         | 10 ++++++++--
 src/niepce/ui/niepcewindow.cpp        |  2 ++
 src/niepce/ui/selectioncontroller.cpp |  5 +++++
 src/niepce/ui/selectioncontroller.hpp |  2 ++
 src/niepce/ui/workspacecontroller.cpp |  1 +
 src/niepce/ui/workspacecontroller.hpp |  8 +++++---
 9 files changed, 41 insertions(+), 12 deletions(-)
---
diff --git a/src/niepce/ui/imageliststore.cpp b/src/niepce/ui/imageliststore.cpp
index cbc4d28..32a9ec3 100644
--- a/src/niepce/ui/imageliststore.cpp
+++ b/src/niepce/ui/imageliststore.cpp
@@ -102,6 +102,13 @@ void ImageListStore::add_libfile(const eng::LibFilePtr & f)
     m_idmap[engine_db_libfile_id(f.get())] = riter;
 }
 
+void ImageListStore::clear_content()
+{
+    // clear the map before the list.
+    m_idmap.clear();
+    clear();
+}
+
 void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
 {
     auto type = engine_library_notification_type(&ln);
@@ -118,10 +125,8 @@ void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
             m_current_folder = 0;
             m_current_keyword = param->container;
         }
+        clear_content();
         DBG_OUT("received folder content file # %lu", l->size());
-        // clear the map before the list.
-        m_idmap.clear();
-        clear();
         for_each(l->cbegin(), l->cend(), [this] (const eng::LibFilePtr & f) {
                 this->add_libfile(f);
             });
diff --git a/src/niepce/ui/imageliststore.hpp b/src/niepce/ui/imageliststore.hpp
index 4f29a04..8aed829 100644
--- a/src/niepce/ui/imageliststore.hpp
+++ b/src/niepce/ui/imageliststore.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/imageliststore.h
  *
- * Copyright (C) 2008 Hubert Figuiere
+ * Copyright (C) 2008-2018 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -75,6 +75,8 @@ public:
     void set_parent_controller(const fwk::Controller::WeakPtr & ctrl)
         { m_controller = ctrl; }
 
+    // Should be called when the content will change
+    void clear_content();
     void on_lib_notification(const eng::LibNotification &n);
     void on_tnail_notification(const eng::ThumbnailNotification &n);
 protected:
diff --git a/src/niepce/ui/moduleshell.cpp b/src/niepce/ui/moduleshell.cpp
index 86b7e1e..7738830 100644
--- a/src/niepce/ui/moduleshell.cpp
+++ b/src/niepce/ui/moduleshell.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - niepce/ui/moduleshell.cpp
  *
- * Copyright (C) 2007-2017 Hubert Figuière
+ * Copyright (C) 2007-2018 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -200,7 +200,7 @@ Gtk::Widget * ModuleShell::buildWidget()
 
     m_selection_controller->add_selectable(m_gridview);
     m_selection_controller->signal_selected
-        .connect(sigc::mem_fun(*this, &ModuleShell::on_selected));
+        .connect(sigc::mem_fun(*this, &ModuleShell::on_image_selected));
     m_selection_controller->signal_activated
         .connect(sigc::mem_fun(*this, &ModuleShell::on_image_activated));
 
@@ -240,8 +240,12 @@ void ModuleShell::on_ready()
 {
 }
 
+void ModuleShell::on_content_will_change()
+{
+    m_selection_controller->content_will_change();
+}
 
-void ModuleShell::on_selected(eng::library_id_t id)
+void ModuleShell::on_image_selected(eng::library_id_t id)
 {
     DBG_OUT("selected callback %Ld", (long long)id);
     if(id > 0) {
diff --git a/src/niepce/ui/moduleshell.hpp b/src/niepce/ui/moduleshell.hpp
index 2a102d1..36e76c6 100644
--- a/src/niepce/ui/moduleshell.hpp
+++ b/src/niepce/ui/moduleshell.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/moduleshell.hpp
  *
- * Copyright (C) 2007-2017 Hubert Figuière
+ * Copyright (C) 2007-2018 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -83,8 +83,14 @@ public:
     Glib::RefPtr<Gio::Menu> getMenu() const
         { return m_menu; }
 
+    /** called when the content will change
+     * the content being what the grid view displays.
+     */
+    void on_content_will_change();
+
     /** called when something is selected by the shared selection */
-    void on_selected(eng::library_id_t id);
+    void on_image_selected(eng::library_id_t id);
+    /** called when an image is activate in the shared selection */
     void on_image_activated(eng::library_id_t id);
 
     virtual Gtk::Widget * buildWidget() override;
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index 9a4f662..33dccb5 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -138,6 +138,8 @@ NiepceWindow::_createModuleShell()
     auto workspace_actions = Gio::SimpleActionGroup::create();
     gtkWindow().insert_action_group("workspace", workspace_actions);
     m_workspacectrl = WorkspaceController::Ptr(new WorkspaceController(workspace_actions));
+    m_workspacectrl->libtree_selection_changed.connect(
+        sigc::mem_fun(*m_moduleshell, &ModuleShell::on_content_will_change));
 
     m_notifcenter->signal_lib_notification
         .connect(sigc::mem_fun(*m_workspacectrl,
diff --git a/src/niepce/ui/selectioncontroller.cpp b/src/niepce/ui/selectioncontroller.cpp
index d6d8dc7..5b33196 100644
--- a/src/niepce/ui/selectioncontroller.cpp
+++ b/src/niepce/ui/selectioncontroller.cpp
@@ -314,6 +314,11 @@ void SelectionController::set_properties(const fwk::PropertyBagPtr & props,
     }
 }
 
+void SelectionController::content_will_change()
+{
+    m_imageliststore->clear_content();
+}
+
 void SelectionController::write_metadata()
 {
     eng::library_id_t selection = get_selection();
diff --git a/src/niepce/ui/selectioncontroller.hpp b/src/niepce/ui/selectioncontroller.hpp
index cdb849f..575ddfc 100644
--- a/src/niepce/ui/selectioncontroller.hpp
+++ b/src/niepce/ui/selectioncontroller.hpp
@@ -100,6 +100,8 @@ public:
     void set_properties(const fwk::PropertyBagPtr & props,
                         const fwk::PropertyBagPtr & old);
 
+    /** the content will change */
+    void content_will_change();
     /** Write the file(s) metadata to disk. */
     void write_metadata();
     void move_to_trash();
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index 5b28b77..cd3e8d3 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -281,6 +281,7 @@ void WorkspaceController::on_libtree_selection()
 
     Glib::RefPtr<Gio::SimpleAction>::cast_dynamic(
         m_action_group->lookup_action("DeleteFolder"))->set_enabled(type == FOLDER_ITEM);
+    libtree_selection_changed.emit();
 }
 
 void WorkspaceController::on_row_expanded_collapsed(const Gtk::TreeIter& iter,
diff --git a/src/niepce/ui/workspacecontroller.hpp b/src/niepce/ui/workspacecontroller.hpp
index 4598503..22d2d69 100644
--- a/src/niepce/ui/workspacecontroller.hpp
+++ b/src/niepce/ui/workspacecontroller.hpp
@@ -75,14 +75,16 @@ public:
         Gtk::TreeModelColumn<Glib::ustring> m_count;
         Gtk::TreeModelColumn<int> m_count_n;
     };
-    
+
     virtual void on_ready() override;
-    
+
     void on_lib_notification(const eng::LibNotification &);
     void on_count_notification(int);
     void on_libtree_selection();
-    
+
     virtual Gtk::Widget * buildWidget() override;
+
+    sigc::signal<void> libtree_selection_changed;
 private:
     /** Return the selected folder id. 0 if not a folder or no selection*/
     eng::library_id_t get_selected_folder_id();


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