[glom/gmenu] gmenu: NotebookLabelGlom: Replace UIManager



commit 12b8fb80ce65c8d1729a5e967b4755f983d02c94
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Sep 16 21:54:02 2013 +0200

    gmenu: NotebookLabelGlom: Replace UIManager

 glom/appwindow.cc                         |    2 +-
 glom/utility_widgets/notebooklabelglom.cc |   60 +++++++++++++++++-----------
 glom/utility_widgets/notebooklabelglom.h  |   10 ++---
 3 files changed, 41 insertions(+), 31 deletions(-)
---
diff --git a/glom/appwindow.cc b/glom/appwindow.cc
index 15a5234..f1ea8b5 100644
--- a/glom/appwindow.cc
+++ b/glom/appwindow.cc
@@ -171,7 +171,7 @@ void AppWindow::on_connection_avahi_done()
 void AppWindow::init()
 {  
   GlomBakery::AppWindow_WithDoc::init(); //Create document and ask to show it in the UI.
-  init_layout(); // start setting up layout after we've gotten all widgets from UIManager
+  init_layout();
   show();
 }
 
diff --git a/glom/utility_widgets/notebooklabelglom.cc b/glom/utility_widgets/notebooklabelglom.cc
index efb4381..cba56be 100644
--- a/glom/utility_widgets/notebooklabelglom.cc
+++ b/glom/utility_widgets/notebooklabelglom.cc
@@ -20,6 +20,8 @@
 
 #include "notebooklabelglom.h"
 #include <glom/appwindow.h>
+#include <gtkmm/menu.h>
+#include <giomm/menu.h>
 #include <glibmm/i18n.h>
 
 #include <iostream>
@@ -109,42 +111,52 @@ void NotebookLabel::on_menu_delete_activate()
 
 void NotebookLabel::setup_menu(Gtk::Widget* /* widget */)
 {
-  m_refUIManager = Gtk::UIManager::create();
-  m_refActionGroup = Gtk::ActionGroup::create();
+  m_refActionGroup = Gio::SimpleActionGroup::create();
 
-  m_refActionGroup->add(Gtk::Action::create("NotebookMenu", "Notebook Menu") );
-  m_refNewGroup = Gtk::Action::create("NewGroup", _("New Group"));
-  m_refDelete = Gtk::Action::create("Delete", _("_Delete"));
-  
-  m_refActionGroup->add(m_refNewGroup,
+  m_refNewGroup = m_refActionGroup->add_action("new-group",
     sigc::mem_fun(*this, &NotebookLabel::on_menu_new_group_activate) );
-  m_refActionGroup->add(m_refDelete,
+  m_refDelete = m_refActionGroup->add_action("delete",
     sigc::mem_fun(*this, &NotebookLabel::on_menu_delete_activate) );
-    
-  m_refUIManager->insert_action_group(m_refActionGroup);
+ 
+  insert_action_group("context", m_refActionGroup);
+
+
+  Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create();
+
+  const Glib::ustring ui_info =
+    "<interface>"
+    "  <menu id='ContextMenu'>"
+    "    <section>"
+    "      <item>"
+    "        <attribute name='label' translatable='yes'>New Group</attribute>"
+    "        <attribute name='action'>context.new-group</attribute>"
+    "      </item>"
+    "      <item>"
+    "        <attribute name='label' translatable='yes'>_Delete</attribute>"
+    "        <attribute name='action'>context.delete</attribute>"
+    "      </item>"
+    "    </section>"
+    "  </menu>"
+    "</interface>";
 
   try
   {
-    Glib::ustring ui_info = 
-        "<ui>"
-        "  <popup name='NotebookMenu'>"
-        "    <menuitem action='NewGroup'/>"
-        "    <separator />"
-        "    <menuitem action='Delete' />"
-        "  </popup>"
-        "</ui>";
-
-    m_refUIManager->add_ui_from_string(ui_info);
+    builder->add_from_string(ui_info);
   }
   catch(const Glib::Error& ex)
   {
-    std::cerr << G_STRFUNC << ": building menus failed: " <<  ex.what();
+    std::cerr << G_STRFUNC << ": building menus failed: " <<  ex.what() << std::endl;
   }
 
   //Get the menu:
-  m_pPopupMenu = dynamic_cast<Gtk::Menu*>( m_refUIManager->get_widget("/NotebookMenu") ); 
-  if(!m_pPopupMenu)
-    g_warning("menu not found");
+  Glib::RefPtr<Glib::Object> object =
+    builder->get_object("ContextMenu");
+  Glib::RefPtr<Gio::Menu> gmenu =
+    Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
+  if(!gmenu)
+    g_warning("GMenu not found");
+
+  m_pPopupMenu = new Gtk::Menu(gmenu);
 }
 
 bool NotebookLabel::on_button_press_event(GdkEventButton *event)
diff --git a/glom/utility_widgets/notebooklabelglom.h b/glom/utility_widgets/notebooklabelglom.h
index 1eed1d4..6dc0092 100644
--- a/glom/utility_widgets/notebooklabelglom.h
+++ b/glom/utility_widgets/notebooklabelglom.h
@@ -25,8 +25,7 @@
 #include <gtkmm/eventbox.h>
 #include <gtkmm/label.h>
 #include <gtkmm/menu.h>
-#include <gtkmm/builder.h>
-#include <gtkmm/uimanager.h>
+#include <giomm/simpleactiongroup.h>
 
 namespace Glom
 {
@@ -59,10 +58,9 @@ private:
     
   virtual bool on_button_press_event(GdkEventButton *event);
   
-  Glib::RefPtr<Gtk::Action> m_refNewGroup;
-  Glib::RefPtr<Gtk::Action> m_refDelete;  
-  Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup;
-  Glib::RefPtr<Gtk::UIManager> m_refUIManager;
+  Glib::RefPtr<Gio::SimpleAction> m_refNewGroup;
+  Glib::RefPtr<Gio::SimpleAction> m_refDelete;  
+  Glib::RefPtr<Gio::SimpleActionGroup> m_refActionGroup;
 };
 
 } //namespace Glom


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