[niepce: 2/22] Move to the new Gtk action framework.



commit 9755bf213846bfaf23dbf5ca609d4dc2aa7dfb0b
Author: Hubert Figuière <hub figuiere net>
Date:   Tue Jul 15 23:28:20 2014 -0400

    Move to the new Gtk action framework.

 camerawire/src/cwapplication.cpp    |    5 +-
 camerawire/src/cwapplication.hpp    |    2 +-
 magellan/src/mgapplication.cpp      |    5 +-
 magellan/src/mgapplication.hpp      |    2 +-
 src/fwk/toolkit/application.cpp     |   65 +++++++++++--
 src/fwk/toolkit/application.hpp     |   32 ++++--
 src/fwk/toolkit/frame.cpp           |   40 +++++---
 src/fwk/toolkit/frame.hpp           |   34 ++++---
 src/fwk/toolkit/gtkutils.cpp        |   28 +++++-
 src/fwk/toolkit/gtkutils.hpp        |   19 ++++-
 src/niepce/ui/niepceapplication.cpp |   14 ++-
 src/niepce/ui/niepceapplication.hpp |    4 +-
 src/niepce/ui/niepcewindow.cpp      |  177 +++++++++++++++++------------------
 src/niepce/ui/niepcewindow.hpp      |    9 +-
 14 files changed, 279 insertions(+), 157 deletions(-)
---
diff --git a/camerawire/src/cwapplication.cpp b/camerawire/src/cwapplication.cpp
index 74f13e3..a21fae9 100644
--- a/camerawire/src/cwapplication.cpp
+++ b/camerawire/src/cwapplication.cpp
@@ -41,9 +41,10 @@ namespace cw {
   }
 
 
-  fwk::Frame::Ptr CwApplication::makeMainFrame()
+  fwk::AppFrame::Ptr CwApplication::makeMainFrame()
   {
-    return fwk::Frame::Ptr(new CwWindow);
+    m_main_frame = fwk::AppFrame::Ptr(new CwWindow);
+    return m_main_frame;
   }
 
 }
diff --git a/camerawire/src/cwapplication.hpp b/camerawire/src/cwapplication.hpp
index 3f17b83..ae6280d 100644
--- a/camerawire/src/cwapplication.hpp
+++ b/camerawire/src/cwapplication.hpp
@@ -33,7 +33,7 @@ class CwApplication
 public:
   static fwk::Application::Ptr create(int & argc, char** & argv);
 
-  virtual fwk::Frame::Ptr makeMainFrame();
+  virtual fwk::AppFrame::Ptr makeMainFrame();
 protected:
   CwApplication(int & argc, char** & argv);
 
diff --git a/magellan/src/mgapplication.cpp b/magellan/src/mgapplication.cpp
index 979b322..ad6661a 100644
--- a/magellan/src/mgapplication.cpp
+++ b/magellan/src/mgapplication.cpp
@@ -41,9 +41,10 @@ namespace mg {
   }
 
 
-  fwk::Frame::Ptr MgApplication::makeMainFrame()
+  fwk::AppFrame::Ptr MgApplication::makeMainFrame()
   {
-    return fwk::Frame::Ptr(new MgWindow);
+    m_main_frame = fwk::AppFrame::Ptr(new MgWindow);
+    return m_main_frame;
   }
 
 }
diff --git a/magellan/src/mgapplication.hpp b/magellan/src/mgapplication.hpp
index f2fb255..9d8b64a 100644
--- a/magellan/src/mgapplication.hpp
+++ b/magellan/src/mgapplication.hpp
@@ -33,7 +33,7 @@ class MgApplication
 public:
   static fwk::Application::Ptr create(int & argc, char** & argv);
 
-  virtual fwk::Frame::Ptr makeMainFrame();
+  virtual fwk::AppFrame::Ptr makeMainFrame();
 protected:
   MgApplication(int & argc, char** & argv);
 
diff --git a/src/fwk/toolkit/application.cpp b/src/fwk/toolkit/application.cpp
index 5e30fb1..497e7c5 100644
--- a/src/fwk/toolkit/application.cpp
+++ b/src/fwk/toolkit/application.cpp
@@ -1,8 +1,7 @@
-
 /*
  * niepce - framework/application.cpp
  *
- * Copyright (C) 2007-2013 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
@@ -28,6 +27,7 @@
 
 #include "fwk/base/debug.hpp"
 #include "fwk/utils/modulemanager.hpp"
+#include "fwk/toolkit/gtkutils.hpp"
 #include "application.hpp"
 #include "uicontroller.hpp"
 #include "frame.hpp"
@@ -40,11 +40,12 @@ Application::Ptr Application::m_application;
 Application::Application(int & argc, char** &argv, const char* app_id,
                          const char * name)
     : m_config(Configuration::make_config_path(name))
-    , m_refUIManager(Gtk::UIManager::create())
     , m_module_manager(new ModuleManager())
     , m_gtkapp(Gtk::Application::create(argc, argv, app_id))
 {
     Clutter::init(argc, argv);
+    m_gtkapp->signal_startup().connect(
+        sigc::mem_fun(*this, &Application::on_startup));
 }
 
 
@@ -90,21 +91,65 @@ void Application::set_use_dark_theme(bool value)
  * @return main return code
  */
 int Application::main(const Application::Ptr & app,
-                      int /*argc*/, char ** /*argv*/)
+                      int argc, char ** argv)
 {
     bool use_dark = app->get_use_dark_theme();
     Glib::RefPtr<Gtk::Settings> settings = Gtk::Settings::get_default();
     settings->set_property("gtk-application-prefer-dark-theme", use_dark);
 
-    Frame::Ptr window(app->makeMainFrame());
+    AppFrame::Ptr window = app->makeMainFrame();
     app->_add(window, false);
-    // signal_run() is gone in Gtkmm3. Call directly. Should work.
     app->_ready();
-    app->m_gtkapp->run(window->gtkWindow());
+    app->m_gtkapp->run(window->gtkWindow(), argc, argv);
 
     return 0;
 }
 
+void Application::on_startup()
+{
+    set_menubar(m_main_frame->get_menu());
+    init_actions();
+}
+
+void Application::init_actions()
+{
+    Glib::RefPtr<Gio::Menu> menu;
+    Glib::RefPtr<Gio::Menu> section;
+
+    menu = Gio::Menu::create();
+
+    section = Gio::Menu::create();
+
+    menu->append_section(section);
+    section->append(_("New"), "action");
+    fwk::add_action(m_gtkapp, "OpenLibrary",
+                    sigc::mem_fun(*this,
+                                  &Application::on_action_file_open),
+                    section, _("Open"), "app", "<Primary>o");
+
+
+    section = Gio::Menu::create();
+    menu->append_section(section);
+    fwk::add_action(m_gtkapp, "Help",
+                    sigc::mem_fun(*this,
+                                  &Application::about),
+                    section, _("Help"), "app", nullptr);
+
+    fwk::add_action(m_gtkapp, "About",
+                    sigc::mem_fun(*this,
+                                  &Application::about),
+                    section, _("About"), "app", nullptr);
+
+    section = Gio::Menu::create();
+    menu->append_section(section);
+
+    fwk::add_action(m_gtkapp, "Quit",
+                    sigc::mem_fun(*this,
+                                  &Application::quit),
+                    section, _("Quit"), "app", "<Primary>q");
+
+    m_gtkapp->set_app_menu(menu);
+}
 
 void Application::terminate()
 {
@@ -141,7 +186,7 @@ void Application::_add(const Controller::Ptr & sub, bool attach)
     Controller::add(sub);
     UiController::Ptr uictrl = std::dynamic_pointer_cast<UiController>(sub);
     if(uictrl) {
-        Gtk::Widget *w = uictrl->buildWidget(uiManager());
+        Gtk::Widget *w = uictrl->buildWidget(Glib::RefPtr<Gtk::UIManager>());
         Gtk::Window *win = nullptr;
         if(attach && m_gtkapp && (win = dynamic_cast<Gtk::Window*>(w))) {
             m_gtkapp->add_window(*win);
@@ -149,6 +194,10 @@ void Application::_add(const Controller::Ptr & sub, bool attach)
     }
 }
 
+void Application::on_action_file_open()
+{
+}
+
 void Application::on_about()
 {
     Gtk::AboutDialog dlg;
diff --git a/src/fwk/toolkit/application.hpp b/src/fwk/toolkit/application.hpp
index 6a826c8..5dd7f0f 100644
--- a/src/fwk/toolkit/application.hpp
+++ b/src/fwk/toolkit/application.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - framework/application.h
  *
- * Copyright (C) 2007-2008, 2013 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
@@ -24,12 +24,13 @@
 #include <functional>
 
 #include <glibmm/refptr.h>
+#include <giomm/menu.h>
 #include <gtkmm/application.h>
 #include <gtkmm/uimanager.h>
 #include <gtkmm/icontheme.h>
 
 #include "fwk/toolkit/configuration.hpp"
-#include "fwk/toolkit/frame.hpp"
+#include "fwk/toolkit/appframe.hpp"
 #include "fwk/toolkit/undo.hpp"
 
 
@@ -37,7 +38,7 @@ namespace fwk {
 
 class ModuleManager;
 
-class Application 
+class Application
     : public Controller
 {
 public:
@@ -49,15 +50,13 @@ public:
     virtual bool get_use_dark_theme() const;
     virtual void set_use_dark_theme(bool value);
 
-    virtual Frame::Ptr makeMainFrame() = 0;
+    // MUST set m_main_frame
+    virtual AppFrame::Ptr makeMainFrame() = 0;
+    const Glib::RefPtr<Gtk::Application> & gtkApp() const
+        { return m_gtkapp; }
 
     Configuration & config()
         { return m_config; }
-    Glib::RefPtr<Gtk::UIManager> uiManager()
-        { 
-            return m_refUIManager; 
-        }
-
 
     virtual void quit();
     void about();
@@ -65,6 +64,8 @@ public:
     virtual void terminate();
 
     Glib::RefPtr<Gtk::IconTheme> getIconTheme() const;
+    void set_menubar(const Glib::RefPtr<Gio::Menu> & menu)
+        { m_gtkapp->set_menubar(menu); }
 
     static Application::Ptr app();
     static int main(const Application::Ptr & app,
@@ -75,7 +76,7 @@ public:
     UndoTransaction * begin_undo(const std::string & label);
 
     // Module management
-    /** @return the module manager 
+    /** @return the module manager
      *  It is guaranted to be safe to call from the constructor
      */
     ModuleManager * module_manager() const
@@ -84,10 +85,19 @@ protected:
     Application(int & argc, char** &argv, const char* app_id, const char *name);
     static Application::Ptr m_application;
     void _add(const Controller::Ptr & sub, bool attach = true);
+    virtual void on_action_file_open();
     virtual void on_about();
+
+    void init_actions();
+
+    const AppFrame::Ptr & get_main_frame() const
+        { return m_main_frame; }
+    /** bound the the GtkApplication startup signal */
+    void on_startup();
+
+    AppFrame::Ptr                   m_main_frame;
 private:
     Configuration                m_config;
-    Glib::RefPtr<Gtk::UIManager> m_refUIManager;
     UndoHistory                  m_undo;
     ModuleManager               *m_module_manager;
     Glib::RefPtr<Gtk::Application> m_gtkapp;
diff --git a/src/fwk/toolkit/frame.cpp b/src/fwk/toolkit/frame.cpp
index 544b42b..fc35ece 100644
--- a/src/fwk/toolkit/frame.cpp
+++ b/src/fwk/toolkit/frame.cpp
@@ -22,10 +22,12 @@
 #include <functional>
 
 #include <glibmm/i18n.h>
+#include <giomm/simpleaction.h>
 #include <gtkmm/dialog.h>
 
 #include "fwk/base/debug.hpp"
 #include "fwk/base/geometry.hpp"
+#include "fwk/toolkit/gtkutils.hpp"
 #include "frame.hpp"
 #include "application.hpp"
 
@@ -111,38 +113,44 @@ void Frame::set_title(const std::string & title)
 
 void Frame::toggle_tools_visible()
 {
-    if(m_hide_tools_action->get_active()) {
+#if 0
+    if(m_hide_tools_action->get_state()) {
         signal_hide_tools.emit();
     }
     else {
         signal_show_tools.emit();
     }
+#endif
 }
 
 void Frame::undo_state()
 {
+    DBG_ASSERT(m_undo_action, "undo action is NULL");
     fwk::UndoHistory & history(Application::app()->undo_history());
-    m_undo_action->set_sensitive(history.has_undo());
+    m_undo_action->set_enabled(history.has_undo());
     std::string s = history.next_undo();
-    m_undo_action->property_label() = Glib::ustring(_("Undo ")) + s;
+//    m_undo_action->property_label() = Glib::ustring(_("Undo ")) + s;
 }
 
 
 void Frame::redo_state()
 {
+    DBG_ASSERT(m_redo_action, "redo action is NULL");
     fwk::UndoHistory & history(Application::app()->undo_history());
-    m_redo_action->set_sensitive(history.has_redo());
+    m_redo_action->set_enabled(history.has_redo());
     std::string s = history.next_redo();
-    m_redo_action->property_label() = Glib::ustring(_("Redo ")) + s;
+//    m_redo_action->property_label() = Glib::ustring(_("Redo ")) + s;
 }
 
 
-Glib::RefPtr<Gtk::Action> Frame::create_undo_action(const Glib::RefPtr<Gtk::ActionGroup> & g)
+Glib::RefPtr<Gio::Action>
+Frame::create_undo_action(const Glib::RefPtr<Gio::ActionMap> & g,
+                          const Glib::RefPtr<Gio::Menu> & menu)
 {
-    m_undo_action = Gtk::Action::create("Undo", _("Undo"));
-    g->add(m_undo_action, Gtk::AccelKey("<control>Z"),
-           sigc::mem_fun(Application::app()->undo_history(),
-                         &UndoHistory::undo));
+    m_undo_action = fwk::add_action(g, "Undo",
+                                        sigc::mem_fun(Application::app()->undo_history(),
+                                                          &UndoHistory::undo),
+                                        menu, _("Undo"), "win", "<control>Z");
     Application::app()->undo_history().signal_changed.connect(
         sigc::mem_fun(*this, &Frame::undo_state));
     undo_state();
@@ -150,12 +158,14 @@ Glib::RefPtr<Gtk::Action> Frame::create_undo_action(const Glib::RefPtr<Gtk::Acti
 }
 
 
-Glib::RefPtr<Gtk::Action> Frame::create_redo_action(const Glib::RefPtr<Gtk::ActionGroup> & g)
+Glib::RefPtr<Gio::Action>
+Frame::create_redo_action(const Glib::RefPtr<Gio::ActionMap> & g,
+                          const Glib::RefPtr<Gio::Menu> & menu)
 {
-    m_redo_action = Gtk::Action::create("Redo", _("Redo"));
-    g->add(m_redo_action, Gtk::AccelKey("<control><shift>Z"),
-           sigc::mem_fun(Application::app()->undo_history(),
-                         &UndoHistory::redo));
+    m_redo_action = fwk::add_action(g, "Redo",
+                                    sigc::mem_fun(Application::app()->undo_history(),
+                                                  &UndoHistory::redo),
+                                    menu, _("Redo"), "win", "<control><shift>Z");
     Application::app()->undo_history().signal_changed.connect(
         sigc::mem_fun(*this, &Frame::redo_state));
     redo_state();
diff --git a/src/fwk/toolkit/frame.hpp b/src/fwk/toolkit/frame.hpp
index 6c48e65..983050e 100644
--- a/src/fwk/toolkit/frame.hpp
+++ b/src/fwk/toolkit/frame.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - fwk/toolkit/frame.hpp
  *
- * Copyright (C) 2007-2013 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,7 +26,9 @@
 #include <functional>
 
 #include <sigc++/signal.h>
-#include <gtkmm/toggleaction.h>
+#include <giomm/action.h>
+#include <giomm/actiongroup.h>
+#include <giomm/menu.h>
 #include <gtkmm/builder.h>
 
 #include "fwk/toolkit/uicontroller.hpp"
@@ -57,7 +59,7 @@ public:
             return std::static_pointer_cast<Frame>(shared_from_this());
         }
 
-               Gtk::Window & gtkWindow()
+    Gtk::Window & gtkWindow()
         {
             return *m_window; 
         }
@@ -83,26 +85,28 @@ protected:
 
     void undo_state();
     void redo_state();
-    Glib::RefPtr<Gtk::Action> create_undo_action(const Glib::RefPtr<Gtk::ActionGroup> & g);
-    Glib::RefPtr<Gtk::Action> create_redo_action(const Glib::RefPtr<Gtk::ActionGroup> & g);
+    Glib::RefPtr<Gio::Action> create_undo_action(const Glib::RefPtr<Gio::ActionMap> & g,
+                                                 const Glib::RefPtr<Gio::Menu> & menu);
+    Glib::RefPtr<Gio::Action> create_redo_action(const Glib::RefPtr<Gio::ActionMap> & g,
+                                                 const Glib::RefPtr<Gio::Menu> & menu);
 
-               /** close signal handler */
-               virtual bool _close();
-    Glib::RefPtr<Gtk::ToggleAction> m_hide_tools_action;
-    Glib::RefPtr<Gtk::Action>      m_undo_action;
-    Glib::RefPtr<Gtk::Action>      m_redo_action;
+    /** close signal handler */
+    virtual bool _close();
+    Glib::RefPtr<Gio::SimpleAction> m_hide_tools_action;
+    Glib::RefPtr<Gio::SimpleAction>      m_undo_action;
+    Glib::RefPtr<Gio::SimpleAction>      m_redo_action;
 
 private:
     /** frame have the widget set at construction time
      * from a ui file or directly.
      */
-               void connectSignals();
-               void frameRectFromConfig();
-               void frameRectToConfig();
+    void connectSignals();
+    void frameRectFromConfig();
+    void frameRectToConfig();
 
-               Gtk::Window *m_window;
+    Gtk::Window *m_window;
     Glib::RefPtr<Gtk::Builder> m_builder;
-               std::string m_layout_cfg_key;
+    std::string m_layout_cfg_key;
 };
 
 }
diff --git a/src/fwk/toolkit/gtkutils.cpp b/src/fwk/toolkit/gtkutils.cpp
index ec0952f..fb37c49 100644
--- a/src/fwk/toolkit/gtkutils.cpp
+++ b/src/fwk/toolkit/gtkutils.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - fwk/toolkit/gtkutils.cpp
  *
- * Copyright (C) 2009 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
@@ -18,11 +18,35 @@
  */
 
 
+#include "fwk/toolkit/application.hpp"
 #include "gtkutils.hpp"
 
 namespace fwk {
 
-Glib::RefPtr<Gtk::ListStore> 
+Glib::RefPtr<Gio::SimpleAction>
+add_action(const Glib::RefPtr<Gio::ActionMap> & group,
+           const char* name,
+           const Gio::ActionMap::ActivateSlot& slot,
+           const Glib::RefPtr<Gio::Menu> & menu,
+           const char* label, const char* context, const char* accel)
+{
+    Glib::RefPtr<Gio::SimpleAction> an_action
+        = Gio::SimpleAction::create(name);
+    group->add_action(an_action);
+    an_action->signal_activate()
+        .connect(sigc::hide(slot));
+    if (menu && label && context) {
+        Glib::ustring detail = Glib::ustring::compose("%1.%2", context, name);
+        menu->append(label, detail);
+        if(accel) {
+            Application::app()->gtkApp()->set_accel_for_action(detail, accel);
+        }
+    }
+    return an_action;
+}
+
+
+Glib::RefPtr<Gtk::ListStore>
 ModelRecord::inject(Gtk::TreeView & treeview)
 {
     Glib::RefPtr<Gtk::ListStore> model = Gtk::ListStore::create(*this);
diff --git a/src/fwk/toolkit/gtkutils.hpp b/src/fwk/toolkit/gtkutils.hpp
index eb4e70f..a9f071b 100644
--- a/src/fwk/toolkit/gtkutils.hpp
+++ b/src/fwk/toolkit/gtkutils.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - fwk/toolkit/gtkutils.hpp
  *
- * Copyright (C) 2009 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
@@ -22,6 +22,9 @@
 #define __FWK_GTKUTILS_H__
 
 #include <string>
+
+#include <giomm/simpleactiongroup.h>
+#include <giomm/menu.h>
 #include <gtkmm/treeview.h>
 #include <gtkmm/combobox.h>
 #include <gtkmm/liststore.h>
@@ -29,8 +32,20 @@
 
 namespace fwk {
 
+/** Helper to add an action.
+ * @param group the action group
+ * @param name the action name
+ */
+Glib::RefPtr<Gio::SimpleAction>
+add_action(const Glib::RefPtr<Gio::ActionMap> & group,
+           const char* name,
+           const Gio::ActionMap::ActivateSlot& slot,
+           const Glib::RefPtr<Gio::Menu> & menu = Glib::RefPtr<Gio::Menu>(),
+           const char* label = nullptr, const char* context = nullptr,
+           const char* accel = nullptr);
+
 
-/** a simple model record with one text column. 
+/** a simple model record with one text column.
  * This class is "abstract".
  */
 class ModelRecord
diff --git a/src/niepce/ui/niepceapplication.cpp b/src/niepce/ui/niepceapplication.cpp
index c8fdbd7..cf86408 100644
--- a/src/niepce/ui/niepceapplication.cpp
+++ b/src/niepce/ui/niepceapplication.cpp
@@ -20,13 +20,15 @@
 #include "config.h"
 
 #include <glibmm/i18n.h>
+#include <giomm/menu.h>
 #include <gtkmm/aboutdialog.h>
 
 #include "fwk/utils/modulemanager.hpp"
+#include "fwk/toolkit/appframe.hpp"
 #include "niepceapplication.hpp"
 #include "niepcewindow.hpp"
 
-using fwk::Frame;
+using fwk::AppFrame;
 using fwk::Application;
 
 namespace ui {
@@ -53,9 +55,15 @@ Application::Ptr NiepceApplication::create(int & argc, char** & argv)
 }
 
 
-Frame::Ptr NiepceApplication::makeMainFrame()
+AppFrame::Ptr NiepceApplication::makeMainFrame()
 {
-    return Frame::Ptr(new NiepceWindow);
+    m_main_frame = AppFrame::Ptr(new NiepceWindow);
+    return m_main_frame;
+}
+
+void NiepceApplication::on_action_file_open()
+{
+    
 }
 
 void NiepceApplication::on_about()
diff --git a/src/niepce/ui/niepceapplication.hpp b/src/niepce/ui/niepceapplication.hpp
index 0d0aeac..7a47e39 100644
--- a/src/niepce/ui/niepceapplication.hpp
+++ b/src/niepce/ui/niepceapplication.hpp
@@ -31,9 +31,11 @@ class NiepceApplication
 public:
     static fwk::Application::Ptr create(int & argc, char** & argv);
 
-    virtual fwk::Frame::Ptr makeMainFrame();
+    virtual fwk::AppFrame::Ptr makeMainFrame();
 protected:
     NiepceApplication(int & argc, char** & argv);
+
+    virtual void on_action_file_open();
     virtual void on_about();
 };
 
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index e1122a6..0e3581d 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -21,6 +21,7 @@
 
 #include <glibmm/i18n.h>
 #include <glibmm/miscutils.h>
+#include <giomm/menu.h>
 #include <gtkmm/window.h>
 #include <gtkmm/accelkey.h>
 #include <gtkmm/action.h>
@@ -59,13 +60,14 @@ NiepceWindow::NiepceWindow()
     : fwk::AppFrame("mainWindow-frame")
     , m_vbox(Gtk::ORIENTATION_VERTICAL)
 {
+    gtkWindow().property_hide_titlebar_when_maximized() = true;
 }
 
 
 NiepceWindow::~NiepceWindow()
 {
-    Application::Ptr pApp = Application::app();
-    pApp->uiManager()->remove_action_group(m_refActionGroup);
+//    Application::Ptr pApp = Application::app();
+//    pApp->uiManager()->remove_action_group(m_refActionGroup);
 }
 
 void
@@ -119,8 +121,7 @@ NiepceWindow::_createModuleShell()
 
     static_cast<Gtk::Window*>(m_widget)->add(m_vbox);
 
-    Gtk::Widget* pMenuBar = m_uimanager->get_widget("/MenuBar");
-    m_vbox.pack_start(*pMenuBar, Gtk::PACK_SHRINK);
+    static_cast<Gtk::ApplicationWindow&>(gtkWindow()).set_show_menubar(true);
     m_vbox.pack_start(m_hbox);
 
 
@@ -141,7 +142,7 @@ NiepceWindow::_createModuleShell()
 }
 
 
-Gtk::Widget * 
+Gtk::Widget *
 NiepceWindow::buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager)
 {
     DBG_ASSERT(manager, "manager is NULL");
@@ -154,8 +155,8 @@ NiepceWindow::buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager)
 
     m_widget = &win;
 
-    init_actions(manager);
-    init_ui(manager);
+    init_actions();
+    init_ui();
 
     m_notifcenter.reset(new niepce::NotificationCenter());
 
@@ -172,8 +173,9 @@ NiepceWindow::buildWidget(const Glib::RefPtr<Gtk::UIManager> & manager)
 }
 
 
-void NiepceWindow::init_ui(const Glib::RefPtr<Gtk::UIManager> & manager)
+void NiepceWindow::init_ui()
 {
+#if 0
     Glib::ustring ui_info =
         "<ui>"
         "  <menubar name='MenuBar'>"
@@ -217,76 +219,86 @@ void NiepceWindow::init_ui(const Glib::RefPtr<Gtk::UIManager> & manager)
         "  </toolbar>"
         "</ui>";
     m_ui_merge_id = manager->add_ui_from_string(ui_info);
-} 
-
-
+#endif
+}
 
-void NiepceWindow::init_actions(const Glib::RefPtr<Gtk::UIManager> & manager)
+void NiepceWindow::init_actions()
 {
-    Glib::RefPtr<Gtk::Action> an_action;
-
-    m_refActionGroup = Gtk::ActionGroup::create();
-
-    m_refActionGroup->add(Gtk::Action::create("MenuLibrary", _("_Library")));
-    m_refActionGroup->add(Gtk::Action::create("NewLibrary", _("New")));
-    m_refActionGroup->add(Gtk::Action::create("OpenLibrary", _("Open")),
-                          sigc::mem_fun(*this,
-                                        &NiepceWindow::on_action_file_open));
-
-    m_refActionGroup->add(Gtk::Action::create("NewFolder", _("New _Folder...")));
-    m_refActionGroup->add(Gtk::Action::create("NewProject", _("New _Project...")));
-
-    m_refActionGroup->add(Gtk::Action::create("Import", _("_Import...")),
-                          sigc::mem_fun(*this,
-                                        &NiepceWindow::on_action_file_import));
-    m_refActionGroup->add(Gtk::Action::create("Close", _("Close")),
-                          Gtk::AccelKey("<ctrl>w"),
-                          sigc::mem_fun(gtkWindow(),
-                                        &Gtk::Window::hide));
-    m_refActionGroup->add(Gtk::Action::create("Quit", _("Quit")),
-                          Gtk::AccelKey("<ctrl>q"),
-                          sigc::mem_fun(*Application::app(),
-                                        &Application::quit));
-
-    m_refActionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
-
-    create_undo_action(m_refActionGroup);
-    create_redo_action(m_refActionGroup);
+    m_menu = Gio::Menu::create();
+    Glib::RefPtr<Gio::Menu> submenu;
+    Glib::RefPtr<Gio::Menu> section;
+
+    m_action_group = Gio::SimpleActionGroup::create();
+    gtkWindow().insert_action_group("win", m_action_group);
+
+    submenu = Gio::Menu::create();
+    m_menu->append_submenu(_("Library"), submenu);
+
+    // move to the workspace
+    section = Gio::Menu::create();
+    submenu->append_section(section);
+    section->append(_("New Folder..."), "action");
+    section->append(_("New Project..."), "action");
+    fwk::add_action(m_action_group, "Import",
+                    sigc::mem_fun(*this,
+                                  &NiepceWindow::on_action_file_import),
+                    section, _("_Import..."), "win");
+
+    section = Gio::Menu::create();
+    submenu->append_section(section);
+    fwk::add_action(m_action_group, "Close",
+                    sigc::mem_fun(gtkWindow(),
+                                  &Gtk::Window::hide),
+                    section, _("Close"), "win", "<Primary>w");
+
+    submenu = Gio::Menu::create();
+    m_menu->append_submenu(_("Edit"), submenu);
+
+    section = Gio::Menu::create();
+    submenu->append_section(section);
+
+    create_undo_action(m_action_group, section);
+    create_redo_action(m_action_group, section);
 
     // FIXME: bind
-    m_refActionGroup->add(Gtk::Action::create("Cut", _("Cut")),
-                          Gtk::AccelKey("<ctrl>x"));
-    m_refActionGroup->add(Gtk::Action::create("Copy", _("Copy")),
-                          Gtk::AccelKey("<ctrl>c"));
-    m_refActionGroup->add(Gtk::Action::create("Paste", _("Paste")),
-                          Gtk::AccelKey("<ctrl>v"));
-    m_refActionGroup->add(Gtk::Action::create("Delete", _("Delete")),
-                          sigc::mem_fun(*this, &NiepceWindow::on_action_edit_delete));
-
-    m_refActionGroup->add(Gtk::Action::create("Preferences", _("Preferences...")),
-                          sigc::mem_fun(*this,
-                                        &NiepceWindow::on_preferences));
-
-
-
-
-    m_refActionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
-    m_refActionGroup->add(Gtk::Action::create("EditLabels", _("_Edit Labels...")),
-                          sigc::mem_fun(*this, &NiepceWindow::on_action_edit_labels));
-    m_hide_tools_action = Gtk::ToggleAction::create("ToggleToolsVisible",
-                                                    _("_Hide tools"));
-    m_refActionGroup->add(m_hide_tools_action,
-                          sigc::mem_fun(*this, &Frame::toggle_tools_visible));
-
-    m_refActionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));
-    m_refActionGroup->add(Gtk::Action::create("Help", _("Help")));
-    m_refActionGroup->add(Gtk::Action::create("About", _("About")),
-                          sigc::mem_fun(*Application::app(),
-                                        &Application::about));
-
-    manager->insert_action_group(m_refActionGroup);            
-               
-    gtkWindow().add_accel_group(manager->get_accel_group());
+    section = Gio::Menu::create();
+    submenu->append_section(section);
+
+    fwk::add_action(m_action_group,
+                    "Cut",
+                    Gio::ActionMap::ActivateSlot(), section,
+                    _("Cut"), "win", "<control>x");
+    fwk::add_action(m_action_group,
+                    "Copy",
+                    Gio::ActionMap::ActivateSlot(), section,
+                    _("Copy"), "win", "<control>c");
+    fwk::add_action(m_action_group,
+                    "Paste",
+                    Gio::ActionMap::ActivateSlot(), section,
+                    _("Paste"), "win" "<control>v");
+    fwk::add_action(m_action_group,
+                    "Delete",
+                    sigc::mem_fun(*this, &NiepceWindow::on_action_edit_delete),
+                    section, _("Delete"), "win", nullptr);
+    // separator
+    section = Gio::Menu::create();
+    submenu->append_section(section);
+    fwk::add_action(m_action_group, "Preferences",
+                    sigc::mem_fun(*this,
+                                  &NiepceWindow::on_preferences),
+                    section, _("Preferences..."), "win", nullptr);
+
+    submenu = Gio::Menu::create();
+    m_menu->append_submenu(_("Tools"), submenu);
+    fwk::add_action(m_action_group, "EditLabels",
+                    sigc::mem_fun(*this, &NiepceWindow::on_action_edit_labels),
+                    submenu, _("Edit Labels..."), "win", nullptr);
+
+    m_hide_tools_action
+        = fwk::add_action(m_action_group, "ToggleToolsVisible",
+                          sigc::mem_fun(*this, &Frame::toggle_tools_visible),
+                          submenu, _("Hide tools"), "win",
+                          nullptr);
 }
 
 
@@ -294,7 +306,7 @@ void NiepceWindow::on_action_file_import()
 {
     int result;
     Configuration & cfg = Application::app()->config();
-       
+
     ImportDialog::Ptr import_dialog(new ImportDialog());
 
     result = import_dialog->run_modal(shared_frame_ptr());
@@ -305,7 +317,7 @@ void NiepceWindow::on_action_file_import()
         Glib::ustring to_import = import_dialog->path_to_import();
         if(!to_import.empty()) {
             cfg.setValue("last_import_location", import_dialog->path_to_import());
-                       
+
             //DBG_OUT("%s", to_import.c_str());
             m_libClient->importFromDirectory(to_import, false);
         }
@@ -319,19 +331,6 @@ void NiepceWindow::on_action_file_import()
     }
 }
 
-
-
-void NiepceWindow::on_action_file_quit()
-{
-    Application::app()->quit();
-}
-
-
-void NiepceWindow::on_action_file_open()
-{
-    DBG_OUT("there");
-}
-
 void NiepceWindow::on_open_library()
 {
     Configuration & cfg = Application::app()->config();
diff --git a/src/niepce/ui/niepcewindow.hpp b/src/niepce/ui/niepcewindow.hpp
index cb929fa..671954f 100644
--- a/src/niepce/ui/niepcewindow.hpp
+++ b/src/niepce/ui/niepcewindow.hpp
@@ -22,6 +22,7 @@
 #define _UI_NIEPCEWINDOW_H_
 
 
+#include <giomm/simpleactiongroup.h>
 #include <gtkmm/treemodel.h>
 #include <gtkmm/box.h>
 #include <gtkmm/menubar.h>
@@ -60,8 +61,6 @@ protected:
 private:
     void on_action_file_import();
 
-    void on_action_file_quit();
-    void on_action_file_open();
     void on_open_library();
     void on_action_edit_labels();
     void on_action_edit_delete();
@@ -73,8 +72,8 @@ private:
     void create_initial_labels();
     void on_lib_notification(const eng::LibNotification & n);
 
-    void init_ui(const Glib::RefPtr<Gtk::UIManager> & manager);
-    void init_actions(const Glib::RefPtr<Gtk::UIManager> & manager);
+    void init_ui();
+    void init_actions();
 
     // UI to open library
     std::string prompt_open_library();
@@ -92,7 +91,7 @@ private:
     WorkspaceController::Ptr       m_workspacectrl;
     FilmStripController::Ptr       m_filmstrip;
     Gtk::Statusbar                 m_statusBar;
-    Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup;
+    Glib::RefPtr<Gio::SimpleActionGroup> m_action_group;
     libraryclient::LibraryClient::Ptr m_libClient;
     fwk::Configuration::Ptr        m_library_cfg;
 };


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