[niepce: 5/22] Provide an interface to get the module menu. Add back the module shell menu to the menu bar. Various



commit 5569d0106b4d5d4ef1e1a33de5287644afa02f73
Author: Hubert Figuière <hub figuiere net>
Date:   Thu Jul 17 23:57:22 2014 -0400

    Provide an interface to get the module menu.
    Add back the module shell menu to the menu bar.
    Various C++11 changes.

 src/niepce/modules/darkroom/darkroommodule.cpp |    6 +-
 src/niepce/modules/darkroom/darkroommodule.hpp |    9 +++-
 src/niepce/modules/map/mapmodule.cpp           |    5 +-
 src/niepce/modules/map/mapmodule.hpp           |    4 +-
 src/niepce/ui/gridviewmodule.hpp               |    4 +-
 src/niepce/ui/ilibrarymodule.hpp               |    6 ++-
 src/niepce/ui/moduleshell.cpp                  |   48 ++++++++++--------------
 src/niepce/ui/moduleshell.hpp                  |    4 ++
 src/niepce/ui/moduleshellwidget.cpp            |   13 ++++--
 src/niepce/ui/moduleshellwidget.hpp            |   16 +++++--
 src/niepce/ui/niepcewindow.cpp                 |    2 +
 11 files changed, 68 insertions(+), 49 deletions(-)
---
diff --git a/src/niepce/modules/darkroom/darkroommodule.cpp b/src/niepce/modules/darkroom/darkroommodule.cpp
index 0213d6b..eb7def3 100644
--- a/src/niepce/modules/darkroom/darkroommodule.cpp
+++ b/src/niepce/modules/darkroom/darkroommodule.cpp
@@ -110,10 +110,10 @@ Gtk::Widget * DarkroomModule::buildWidget(const Glib::RefPtr<Gtk::UIManager> & m
     m_imagecanvas->set_image(m_image);
 
     // build the toolbar.
-    Gtk::Toolbar * toolbar = Gtk::manage(new Gtk::Toolbar);
+    auto toolbar = Gtk::manage(new Gtk::Toolbar);
 
     Glib::RefPtr<Gio::Action> an_action;
-    Gtk::ToolButton * tool_item = new Gtk::ToolButton();
+    auto tool_item = new Gtk::ToolButton();
     gtk_actionable_set_action_name(GTK_ACTIONABLE(tool_item->gobj()),
                                    "shell.PrevImage");
     tool_item->set_icon_name("go-previous");
@@ -156,7 +156,7 @@ Gtk::Widget * DarkroomModule::buildWidget(const Glib::RefPtr<Gtk::UIManager> & m
 
 void DarkroomModule::on_selected(eng::library_id_t id)
 {
-    eng::LibFile::Ptr file = m_shell.get_selection_controller()->get_file(id);
+    auto file = m_shell.get_selection_controller()->get_file(id);
     DBG_OUT("selection is %ld", id);
     set_image(file);
 }
diff --git a/src/niepce/modules/darkroom/darkroommodule.hpp b/src/niepce/modules/darkroom/darkroommodule.hpp
index c563b01..57c8b3d 100644
--- a/src/niepce/modules/darkroom/darkroommodule.hpp
+++ b/src/niepce/modules/darkroom/darkroommodule.hpp
@@ -1,7 +1,7 @@
 /*
- * niepce - modules/darkroom/darkroommodule.h
+ * niepce - modules/darkroom/darkroommodule.hpp
  *
- * Copyright (C) 2008-2013 Hubert Figuiere
+ * Copyright (C) 2008-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
@@ -35,7 +35,7 @@
 #include "niepce/ui/imoduleshell.hpp"
 #include "modules/darkroom/imagecanvas.hpp"
 #include "modules/darkroom/toolboxcontroller.hpp"
-       
+
 namespace fwk {
 class Dock;
 }
@@ -56,6 +56,9 @@ public:
 
     virtual void set_active(bool active);
 
+    virtual Glib::RefPtr<Gio::MenuModel> getMenu()
+        { return Glib::RefPtr<Gio::MenuModel>(); }
+
 protected:
     void reload_image();
 
diff --git a/src/niepce/modules/map/mapmodule.cpp b/src/niepce/modules/map/mapmodule.cpp
index 4102ace..2dab8e7 100644
--- a/src/niepce/modules/map/mapmodule.cpp
+++ b/src/niepce/modules/map/mapmodule.cpp
@@ -55,7 +55,7 @@ Gtk::Widget * MapModule::buildWidget(const Glib::RefPtr<Gtk::UIManager> & manage
 
     m_map = fwk::MapController::Ptr(new fwk::MapController());
     add(m_map);
-    Gtk::Widget* w = m_map->buildWidget(manager);
+    auto w = m_map->buildWidget(manager);
     if (w) {
         m_box->pack_start(*w);
     }
@@ -74,8 +74,7 @@ MapModule::on_lib_notification(const eng::LibNotification &ln)
     {
         DBG_ASSERT(ln.param.type() == typeid(eng::LibMetadata::Ptr),
                    "incorrect data type for the notification");
-        eng::LibMetadata::Ptr lm
-            = boost::any_cast<eng::LibMetadata::Ptr>(ln.param);
+        auto lm = boost::any_cast<eng::LibMetadata::Ptr>(ln.param);
         DBG_OUT("received metadata in MapModule");
 
         if (lm) {
diff --git a/src/niepce/modules/map/mapmodule.hpp b/src/niepce/modules/map/mapmodule.hpp
index 712d62b..689f905 100644
--- a/src/niepce/modules/map/mapmodule.hpp
+++ b/src/niepce/modules/map/mapmodule.hpp
@@ -42,9 +42,11 @@ public:
 
     MapModule(const ui::IModuleShell & shell);
 
+    /* ILibraryModule */
     virtual void dispatch_action(const std::string & action_name);
-
     virtual void set_active(bool active);
+    virtual Glib::RefPtr<Gio::MenuModel> getMenu()
+        { return Glib::RefPtr<Gio::MenuModel>(); }
 
     void on_lib_notification(const eng::LibNotification &ln);
 
diff --git a/src/niepce/ui/gridviewmodule.hpp b/src/niepce/ui/gridviewmodule.hpp
index 6b77efd..772efed 100644
--- a/src/niepce/ui/gridviewmodule.hpp
+++ b/src/niepce/ui/gridviewmodule.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/gridviewmodule.hpp
  *
- * Copyright (C) 2009-2013 Hubert Figuiere
+ * Copyright (C) 2009-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
@@ -65,6 +65,8 @@ public:
   /* ILibraryModule */
   virtual void dispatch_action(const std::string & action_name);
   virtual void set_active(bool active);
+  virtual Glib::RefPtr<Gio::MenuModel> getMenu()
+    { return Glib::RefPtr<Gio::MenuModel>(); }
 
   /* IImageSelectable */
   virtual Gtk::IconView * image_list();
diff --git a/src/niepce/ui/ilibrarymodule.hpp b/src/niepce/ui/ilibrarymodule.hpp
index 8f6d9e2..1645efb 100644
--- a/src/niepce/ui/ilibrarymodule.hpp
+++ b/src/niepce/ui/ilibrarymodule.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - niepce/ui/niepcelibrarymodule.hpp
  *
- * Copyright (C) 2009-2013 Hubert Figuiere
+ * Copyright (C) 2009-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
@@ -24,6 +24,8 @@
 #include <string>
 #include <memory>
 
+#include <giomm/menumodel.h>
+
 #include "fwk/toolkit/uicontroller.hpp"
 
 namespace ui {
@@ -42,6 +44,8 @@ public:
       @param active true if brought to the front, false if defocused.
    */
   virtual void set_active(bool active) = 0;
+  /** Get the module menu */
+  virtual Glib::RefPtr<Gio::MenuModel> getMenu() = 0;
 };
 
 
diff --git a/src/niepce/ui/moduleshell.cpp b/src/niepce/ui/moduleshell.cpp
index 213fa06..d857053 100644
--- a/src/niepce/ui/moduleshell.cpp
+++ b/src/niepce/ui/moduleshell.cpp
@@ -48,49 +48,40 @@ Gtk::Widget * ModuleShell::buildWidget(const Glib::RefPtr<Gtk::UIManager> & mana
     m_selection_controller = SelectionController::Ptr(new SelectionController);
     add(m_selection_controller);
 
-    Glib::RefPtr<Gio::Menu> menu = Gio::Menu::create();
-//    m_actionGroup->add(Gtk::Action::create("MenuImage", _("_Image")));
+    m_menu = Gio::Menu::create();
 
+    // "go-previous"
     fwk::add_action(m_actionGroup, "PrevImage",
                     sigc::mem_fun(*m_selection_controller,
                                   &SelectionController::select_previous),
-                    menu, _("Back"), "shell", "Left");
+                    m_menu, _("Back"), "shell", "Left");
 
+    // "go-next"
     fwk::add_action(m_actionGroup, "NextImage",
                     sigc::mem_fun(*m_selection_controller,
                                   &SelectionController::select_next),
-                    menu, _("Forward"), "shell", "Right");
+                    m_menu, _("Forward"), "shell", "Right");
 
+    auto section = Gio::Menu::create();
+    m_menu->append_section(section);
+
+    // "object-rotate-left"
     fwk::add_action(m_actionGroup, "RotateLeft",
                     sigc::bind(
                         sigc::mem_fun(*m_selection_controller,
                                       &SelectionController::rotate), -90),
-                    menu, _("Rotate Left"), "shell", "bracketleft");
+                    section, _("Rotate Left"), "shell", "bracketleft");
 
+    // "object-rotate-right"
     fwk::add_action(m_actionGroup, "RotateRight",
                     sigc::bind(
                         sigc::mem_fun(*m_selection_controller,
                                       &SelectionController::rotate), 90),
-                    menu, _("Rotate Right"), "shell", "bracketright");
+                    section, _("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));
+    section = Gio::Menu::create();
+    m_menu->append_section(section);
 #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")),
@@ -249,7 +240,7 @@ void ModuleShell::action_edit_delete()
 void ModuleShell::add_library_module(const ILibraryModule::Ptr & module,
                                                    const std::string & label)
 {
-    Gtk::Widget * w = module->buildWidget(Glib::RefPtr<Gtk::UIManager>());
+    auto w = module->buildWidget(Glib::RefPtr<Gtk::UIManager>());
     if(w) {
         add(module);
         m_shell.append_page(*w, label);
@@ -267,7 +258,7 @@ void ModuleShell::on_selected(eng::library_id_t id)
     DBG_OUT("selected callback %Ld", (long long)id);
     if(id > 0) {
         m_libraryclient->requestMetadata(id);
-    }          
+    }
     else  {
         m_gridview->display_none();
     }
@@ -276,10 +267,10 @@ void ModuleShell::on_selected(eng::library_id_t id)
 void ModuleShell::on_image_activated(eng::library_id_t id)
 {
     DBG_OUT("on image activated %Ld", (long long)id);
-    Glib::RefPtr<ImageListStore> store = m_selection_controller->get_list_store();
-    Gtk::TreeIter iter = store->get_iter_from_id(id);
+    auto store = m_selection_controller->get_list_store();
+    auto iter = store->get_iter_from_id(id);
     if(iter) {
-        eng::LibFile::Ptr libfile = (*iter)[store->columns().m_libfile];
+        auto libfile = (*iter)[store->columns().m_libfile];
         m_darkroom->set_image(libfile);
         m_shell.activate_page(1);
     }
@@ -294,6 +285,7 @@ void ModuleShell::on_module_deactivated(int idx)
 void ModuleShell::on_module_activated(int idx)
 {
     DBG_ASSERT((idx >= 0) && ((unsigned)idx < m_modules.size()), "wrong module index");
+    m_shell.getMenuButton().set_menu_model(m_modules[idx]->getMenu());
     m_modules[idx]->set_active(true);
 }
 
diff --git a/src/niepce/ui/moduleshell.hpp b/src/niepce/ui/moduleshell.hpp
index e37711d..deec37d 100644
--- a/src/niepce/ui/moduleshell.hpp
+++ b/src/niepce/ui/moduleshell.hpp
@@ -77,6 +77,9 @@ public:
             return m_libraryclient;
         }
 
+    Glib::RefPtr<Gio::Menu> getMenu() const
+        { return m_menu; }
+
     /** 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);
@@ -96,6 +99,7 @@ private:
 
     // managed widgets...
     ModuleShellWidget             m_shell;
+    Glib::RefPtr<Gio::Menu>       m_menu;
 
     ui::SelectionController::Ptr  m_selection_controller;
     std::vector<ILibraryModule::Ptr> m_modules;
diff --git a/src/niepce/ui/moduleshellwidget.cpp b/src/niepce/ui/moduleshellwidget.cpp
index 001c6b4..db484c2 100644
--- a/src/niepce/ui/moduleshellwidget.cpp
+++ b/src/niepce/ui/moduleshellwidget.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/moduleshellwidget.cpp
  *
- * Copyright (C) 2007-2009 Hubert Figuiere
+ * Copyright (C) 2007-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
@@ -25,14 +25,19 @@
 namespace ui {
 
 ModuleShellWidget::ModuleShellWidget()
-    : Gtk::Box(Gtk::ORIENTATION_VERTICAL),
-      m_currentpage(-1)
+    : Gtk::Box(Gtk::ORIENTATION_VERTICAL)
+    , m_mainbox(Gtk::ORIENTATION_HORIZONTAL)
+    , m_mainbar(Gtk::ORIENTATION_HORIZONTAL)
+    , m_currentpage(-1)
 {
     set_spacing(4);
     m_mainbar.set_layout(Gtk::BUTTONBOX_START);
     m_mainbar.set_spacing(4);
+    m_menubutton.set_direction(Gtk::ARROW_NONE);
     m_notebook.set_show_tabs(false);
-    pack_start(m_mainbar, Gtk::PACK_SHRINK);
+    m_mainbox.pack_end(m_menubutton, Gtk::PACK_SHRINK);
+    m_mainbox.pack_start(m_mainbar, Gtk::PACK_EXPAND_WIDGET);
+    pack_start(m_mainbox, Gtk::PACK_SHRINK);
     pack_start(m_notebook);
 }
 
diff --git a/src/niepce/ui/moduleshellwidget.hpp b/src/niepce/ui/moduleshellwidget.hpp
index 7d6e888..bca0274 100644
--- a/src/niepce/ui/moduleshellwidget.hpp
+++ b/src/niepce/ui/moduleshellwidget.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/moduleshellwidget.hpp
  *
- * Copyright (C) 2007-2009 Hubert Figuiere
+ * Copyright (C) 2007-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
@@ -26,9 +26,10 @@
 #include <gtkmm/notebook.h>
 #include <gtkmm/box.h>
 #include <gtkmm/buttonbox.h>
+#include <gtkmm/menubutton.h>
 
 namespace Gtk {
-       class ToggleButton;
+class ToggleButton;
 }
 
 namespace ui {
@@ -39,17 +40,22 @@ class ModuleShellWidget
 {
 public:
     ModuleShellWidget();
-    
+
     int append_page(Gtk::Widget & w, const Glib::ustring & label);
     void activate_page(int);
 
+    Gtk::MenuButton & getMenuButton()
+        { return m_menubutton; }
+
     sigc::signal<void, int> signal_activated;
     sigc::signal<void, int> signal_deactivated;
 protected:
-    
+
     void set_current_page(int, Gtk::ToggleButton *);
 private:
-    Gtk::HButtonBox         m_mainbar;
+    Gtk::Box                m_mainbox;
+    Gtk::ButtonBox          m_mainbar;
+    Gtk::MenuButton         m_menubutton;
     Gtk::Notebook           m_notebook;
     int                     m_currentpage;
     std::vector<std::pair<Gtk::ToggleButton*, sigc::connection> > m_buttons;
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index 0e3581d..5b47c9b 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -85,6 +85,8 @@ NiepceWindow::_createModuleShell()
     m_moduleshell->buildWidget(m_uimanager);
 
     add(m_moduleshell);
+    auto shell_menu = m_moduleshell->getMenu();
+    m_menu->append_submenu(_("Image"), shell_menu);
 
     m_notifcenter->signal_lib_notification
         .connect(sigc::mem_fun(


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