[niepce: 3/22] Use the new actions in the modules.



commit b702d00c7b2aff34e7760d1a9fb851bddf08fed2
Author: Hubert Figuière <hub figuiere net>
Date:   Thu Jul 17 20:37:57 2014 -0400

    Use the new actions in the modules.

 src/niepce/modules/darkroom/darkroommodule.cpp |   31 ++++++----
 src/niepce/modules/darkroom/darkroommodule.hpp |   15 ++---
 src/niepce/modules/map/mapmodule.cpp           |    4 +-
 src/niepce/modules/map/mapmodule.hpp           |    4 +-
 src/niepce/ui/imoduleshell.hpp                 |    2 +-
 src/niepce/ui/moduleshell.cpp                  |   75 +++++++++++++++---------
 src/niepce/ui/moduleshell.hpp                  |   19 +++---
 7 files changed, 86 insertions(+), 64 deletions(-)
---
diff --git a/src/niepce/modules/darkroom/darkroommodule.cpp b/src/niepce/modules/darkroom/darkroommodule.cpp
index 3522ca7..0213d6b 100644
--- a/src/niepce/modules/darkroom/darkroommodule.cpp
+++ b/src/niepce/modules/darkroom/darkroommodule.cpp
@@ -29,11 +29,9 @@
 
 namespace dr {
 
-DarkroomModule::DarkroomModule(const ui::IModuleShell & shell, 
-                               const Glib::RefPtr<Gtk::ActionGroup> & action_group)
+DarkroomModule::DarkroomModule(const ui::IModuleShell & shell)
     : m_shell(shell)
     , m_vbox(Gtk::ORIENTATION_VERTICAL)
-    , m_actionGroup(action_group)
     , m_image(new ncr::Image)
     , m_active(false)
     , m_need_reload(true)
@@ -114,22 +112,29 @@ Gtk::Widget * DarkroomModule::buildWidget(const Glib::RefPtr<Gtk::UIManager> & m
     // build the toolbar.
     Gtk::Toolbar * toolbar = Gtk::manage(new Gtk::Toolbar);
 
-    Glib::RefPtr<Gtk::Action> an_action;
-    Gtk::ToolItem * tool_item;
-    an_action = m_actionGroup->get_action("PrevImage");
-    tool_item = an_action->create_tool_item();
+    Glib::RefPtr<Gio::Action> an_action;
+    Gtk::ToolButton * tool_item = new Gtk::ToolButton();
+    gtk_actionable_set_action_name(GTK_ACTIONABLE(tool_item->gobj()),
+                                   "shell.PrevImage");
+    tool_item->set_icon_name("go-previous");
     toolbar->append(*manage(tool_item));
 
-    an_action = m_actionGroup->get_action("NextImage");
-    tool_item = an_action->create_tool_item();
+    tool_item = new Gtk::ToolButton();
+    gtk_actionable_set_action_name(GTK_ACTIONABLE(tool_item->gobj()),
+                                   "shell.NextImage");
+    tool_item->set_icon_name("go-next");
     toolbar->append(*manage(tool_item));
 
-    an_action = m_actionGroup->get_action("RotateLeft");
-    tool_item = an_action->create_tool_item();
+    tool_item = new Gtk::ToolButton();
+    gtk_actionable_set_action_name(GTK_ACTIONABLE(tool_item->gobj()),
+                                   "shell.RotateLeft");
+    tool_item->set_icon_name("object-rotate-left");
     toolbar->append(*manage(tool_item));
 
-    an_action = m_actionGroup->get_action("RotateRight");
-    tool_item = an_action->create_tool_item();
+    tool_item = new Gtk::ToolButton();
+    gtk_actionable_set_action_name(GTK_ACTIONABLE(tool_item->gobj()),
+                                   "shell.RotateRight");
+    tool_item->set_icon_name("object-rotate-right");
     toolbar->append(*manage(tool_item));
 
     m_vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
diff --git a/src/niepce/modules/darkroom/darkroommodule.hpp b/src/niepce/modules/darkroom/darkroommodule.hpp
index 5dfae85..c563b01 100644
--- a/src/niepce/modules/darkroom/darkroommodule.hpp
+++ b/src/niepce/modules/darkroom/darkroommodule.hpp
@@ -47,21 +47,20 @@ class DarkroomModule
 {
 public:
     typedef std::shared_ptr<DarkroomModule> Ptr;
-    
-    DarkroomModule(const ui::IModuleShell & shell, 
-                   const Glib::RefPtr<Gtk::ActionGroup> & action_group);
-    
+
+    DarkroomModule(const ui::IModuleShell & shell);
+
     void set_image(const eng::LibFile::Ptr & file);
-    
+
     virtual void dispatch_action(const std::string & action_name);
 
     virtual void set_active(bool active);
-    
+
 protected:
-       void reload_image();
+    void reload_image();
 
     virtual Gtk::Widget * buildWidget(const Glib::RefPtr<Gtk::UIManager> &);
-    
+
 private:
     void on_selected(eng::library_id_t id);
 
diff --git a/src/niepce/modules/map/mapmodule.cpp b/src/niepce/modules/map/mapmodule.cpp
index db1d9bb..4102ace 100644
--- a/src/niepce/modules/map/mapmodule.cpp
+++ b/src/niepce/modules/map/mapmodule.cpp
@@ -26,10 +26,8 @@
 
 namespace mapm {
 
-MapModule::MapModule(const ui::IModuleShell & shell,
-                               const Glib::RefPtr<Gtk::ActionGroup> & action_group)
+MapModule::MapModule(const ui::IModuleShell & shell)
     : m_shell(shell)
-    , m_actionGroup(action_group)
     , m_box(nullptr)
     , m_active(false)
 {
diff --git a/src/niepce/modules/map/mapmodule.hpp b/src/niepce/modules/map/mapmodule.hpp
index 66cf4d8..712d62b 100644
--- a/src/niepce/modules/map/mapmodule.hpp
+++ b/src/niepce/modules/map/mapmodule.hpp
@@ -40,8 +40,7 @@ class MapModule
 public:
     typedef std::shared_ptr<MapModule> Ptr;
 
-    MapModule(const ui::IModuleShell & shell,
-                   const Glib::RefPtr<Gtk::ActionGroup> & action_group);
+    MapModule(const ui::IModuleShell & shell);
 
     virtual void dispatch_action(const std::string & action_name);
 
@@ -56,7 +55,6 @@ private:
     void on_selected(eng::library_id_t id);
 
     const ui::IModuleShell &     m_shell;
-    Glib::RefPtr<Gtk::ActionGroup> m_actionGroup;
     Gtk::Box*                    m_box;
     fwk::MapController::Ptr           m_map;
 
diff --git a/src/niepce/ui/imoduleshell.hpp b/src/niepce/ui/imoduleshell.hpp
index 0897cab..2b00693 100644
--- a/src/niepce/ui/imoduleshell.hpp
+++ b/src/niepce/ui/imoduleshell.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/imoduleshell.hpp
  *
- * Copyright (C) 2011 Hubert Figuiere
+ * Copyright (C) 2011-2014 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
diff --git a/src/niepce/ui/moduleshell.cpp b/src/niepce/ui/moduleshell.cpp
index 5862dd3..213fa06 100644
--- a/src/niepce/ui/moduleshell.cpp
+++ b/src/niepce/ui/moduleshell.cpp
@@ -29,6 +29,7 @@
 #include "engine/db/library.hpp"
 #include "engine/db/libfile.hpp"
 #include "fwk/toolkit/application.hpp"
+#include "fwk/toolkit/gtkutils.hpp"
 #include "moduleshell.hpp"
 #include "niepcewindow.hpp"
 #include "metadatapanecontroller.hpp"
@@ -40,35 +41,56 @@ Gtk::Widget * ModuleShell::buildWidget(const Glib::RefPtr<Gtk::UIManager> & mana
     if(m_widget) {
         return m_widget;
     }
-    DBG_ASSERT(manager, "manager is NULL");
 
     m_widget = &m_shell;
-    m_ui_manager = manager;
+    m_shell.insert_action_group("shell", m_actionGroup);
 
     m_selection_controller = SelectionController::Ptr(new SelectionController);
     add(m_selection_controller);
 
-    Glib::RefPtr<Gtk::Action> an_action;
-
-    m_actionGroup->add(Gtk::Action::create("MenuImage", _("_Image")));
-
-    m_actionGroup->add(Gtk::Action::create_with_icon_name("PrevImage", "go-previous", _("Back"), ""),
-                          Gtk::AccelKey(GDK_KEY_Left, Gdk::ModifierType(0)),
-                          sigc::mem_fun(*m_selection_controller,
-                                        &SelectionController::select_previous));
-    m_actionGroup->add(Gtk::Action::create_with_icon_name("NextImage", "go-next", _("Forward"), ""),
-                          Gtk::AccelKey(GDK_KEY_Right, Gdk::ModifierType(0)),
-                          sigc::mem_fun(*m_selection_controller,
-                                        &SelectionController::select_next));
-
-    an_action = Gtk::Action::create_with_icon_name("RotateLeft", "object-rotate-left", _("Rotate Left"), "");
-    m_actionGroup->add(an_action, Gtk::AccelKey("["), sigc::bind(
-                           sigc::mem_fun(*m_selection_controller,
-                                         &SelectionController::rotate), -90));
-    an_action = Gtk::Action::create_with_icon_name("RotateRight", "object-rotate-right", _("Rotate Right"), 
"");
-    m_actionGroup->add(an_action, Gtk::AccelKey("]"), sigc::bind(
-                           sigc::mem_fun(*m_selection_controller,
-                                         &SelectionController::rotate), 90));
+    Glib::RefPtr<Gio::Menu> menu = Gio::Menu::create();
+//    m_actionGroup->add(Gtk::Action::create("MenuImage", _("_Image")));
+
+    fwk::add_action(m_actionGroup, "PrevImage",
+                    sigc::mem_fun(*m_selection_controller,
+                                  &SelectionController::select_previous),
+                    menu, _("Back"), "shell", "Left");
+
+    fwk::add_action(m_actionGroup, "NextImage",
+                    sigc::mem_fun(*m_selection_controller,
+                                  &SelectionController::select_next),
+                    menu, _("Forward"), "shell", "Right");
+
+    fwk::add_action(m_actionGroup, "RotateLeft",
+                    sigc::bind(
+                        sigc::mem_fun(*m_selection_controller,
+                                      &SelectionController::rotate), -90),
+                    menu, _("Rotate Left"), "shell", "bracketleft");
+
+    fwk::add_action(m_actionGroup, "RotateRight",
+                    sigc::bind(
+                        sigc::mem_fun(*m_selection_controller,
+                                      &SelectionController::rotate), 90),
+                    menu, _("Rotate Right"), "shell", "bracketright");
+
+//    m_actionGroup->add(Gtk::Action::create_with_icon_name("PrevImage", "go-previous", _("Back"), ""),
+//                          Gtk::AccelKey(GDK_KEY_Left, Gdk::ModifierType(0)),
+//                          sigc::mem_fun(*m_selection_controller,
+//                                        &SelectionController::select_previous));
+#if 0
+//    m_actionGroup->add(Gtk::Action::create_with_icon_name("NextImage", "go-next", _("Forward"), ""),
+//                          Gtk::AccelKey(GDK_KEY_Right, Gdk::ModifierType(0)),
+//                          sigc::mem_fun(*m_selection_controller,
+//                                        &SelectionController::select_next));
+
+//    an_action = Gtk::Action::create_with_icon_name("RotateLeft", "object-rotate-left", _("Rotate Left"), 
"");
+//    m_actionGroup->add(an_action, Gtk::AccelKey("["), sigc::bind(
+//                           sigc::mem_fun(*m_selection_controller,
+//                                         &SelectionController::rotate), -90));
+//    an_action = Gtk::Action::create_with_icon_name("RotateRight", "object-rotate-right", _("Rotate 
Right"), "");
+//    m_actionGroup->add(an_action, Gtk::AccelKey("]"), sigc::bind(
+//                           sigc::mem_fun(*m_selection_controller,
+//                                         &SelectionController::rotate), 90));
 
     m_actionGroup->add(Gtk::Action::create("SetLabel", _("Set _Label")));
     m_actionGroup->add(Gtk::Action::create("SetLabel6", _("Label _6")),
@@ -151,8 +173,7 @@ Gtk::Widget * ModuleShell::buildWidget(const Glib::RefPtr<Gtk::UIManager> & mana
                                            _("Write metadata")),
                        sigc::mem_fun(*m_selection_controller,
                                      &SelectionController::write_metadata));
-
-    manager->insert_action_group(m_actionGroup);
+#endif
 
 
     Glib::ustring ui_info =
@@ -192,8 +213,8 @@ Gtk::Widget * ModuleShell::buildWidget(const Glib::RefPtr<Gtk::UIManager> & mana
         "    </menu>"
         "  </menubar>"
         "</ui>";
-    m_ui_merge_id = manager->add_ui_from_string(ui_info);
-    DBG_ASSERT(m_ui_merge_id, "merge failed");
+//    m_ui_merge_id = manager->add_ui_from_string(ui_info);
+//    DBG_ASSERT(m_ui_merge_id, "merge failed");
 
     m_gridview = GridViewModule::Ptr(
         new GridViewModule(*this, m_selection_controller->get_list_store()));
@@ -205,10 +226,10 @@ Gtk::Widget * ModuleShell::buildWidget(const Glib::RefPtr<Gtk::UIManager> & mana
     m_selection_controller->signal_activated
         .connect(sigc::mem_fun(*this, &ModuleShell::on_image_activated));
 
-    m_darkroom = dr::DarkroomModule::Ptr(new dr::DarkroomModule(*this, m_actionGroup));
+    m_darkroom = dr::DarkroomModule::Ptr(new dr::DarkroomModule(*this));
     add_library_module(m_darkroom, _("Darkroom"));
 
-    m_mapm = mapm::MapModule::Ptr(new mapm::MapModule(*this, m_actionGroup));
+    m_mapm = mapm::MapModule::Ptr(new mapm::MapModule(*this));
     add_library_module(m_mapm, _("Map"));
 
     m_shell.signal_activated.connect(sigc::mem_fun(*this, &ModuleShell::on_module_activated));
@@ -228,7 +249,7 @@ void ModuleShell::action_edit_delete()
 void ModuleShell::add_library_module(const ILibraryModule::Ptr & module,
                                                    const std::string & label)
 {
-    Gtk::Widget * w = module->buildWidget(m_ui_manager);
+    Gtk::Widget * w = module->buildWidget(Glib::RefPtr<Gtk::UIManager>());
     if(w) {
         add(module);
         m_shell.append_page(*w, label);
diff --git a/src/niepce/ui/moduleshell.hpp b/src/niepce/ui/moduleshell.hpp
index 3741029..e37711d 100644
--- a/src/niepce/ui/moduleshell.hpp
+++ b/src/niepce/ui/moduleshell.hpp
@@ -23,6 +23,8 @@
 
 #include <vector>
 
+#include <giomm/simpleactiongroup.h>
+
 #include "moduleshellwidget.hpp"
 #include "libraryclient/libraryclient.hpp"
 #include "fwk/toolkit/uicontroller.hpp"
@@ -46,10 +48,10 @@ class ModuleShell
 public:
     typedef std::shared_ptr<ModuleShell> Ptr;
     typedef std::weak_ptr<ModuleShell> WeakPtr;
-    
+
     ModuleShell(const libraryclient::LibraryClient::Ptr & libclient)
         : m_libraryclient(libclient)
-        , m_actionGroup(Gtk::ActionGroup::create("ModuleShell"))
+        , m_actionGroup(Gio::SimpleActionGroup::create())
         {
         }
 
@@ -63,8 +65,8 @@ public:
             return m_mapm;
         }
     const Glib::RefPtr<ImageListStore> & get_list_store() const
-        { 
-            return m_selection_controller->get_list_store(); 
+        {
+            return m_selection_controller->get_list_store();
         }
     virtual const SelectionController::Ptr & get_selection_controller() const
         {
@@ -78,7 +80,7 @@ public:
     /** called when something is selected by the shared selection */
     void on_selected(eng::library_id_t id);
     void on_image_activated(eng::library_id_t id);
-    
+
     virtual Gtk::Widget * buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager);
 
     void action_edit_delete();
@@ -90,12 +92,11 @@ protected:
     void on_module_activated(int idx);
 private:
     libraryclient::LibraryClient::Ptr m_libraryclient;
-    Glib::RefPtr<Gtk::ActionGroup> m_actionGroup;
-    
+    Glib::RefPtr<Gio::SimpleActionGroup> m_actionGroup;
+
     // managed widgets...
     ModuleShellWidget             m_shell;
-    Glib::RefPtr<Gtk::UIManager>  m_ui_manager;
-    
+
     ui::SelectionController::Ptr  m_selection_controller;
     std::vector<ILibraryModule::Ptr> m_modules;
     // these should be dynamic


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