[glom/gmenu] gmenu: LayoutWidgetUtils: Replace UIManager
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/gmenu] gmenu: LayoutWidgetUtils: Replace UIManager
- Date: Mon, 16 Sep 2013 18:52:34 +0000 (UTC)
commit 7df02153e7c358d641b3d3595094e308fc420090
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Sep 16 20:28:35 2013 +0200
gmenu: LayoutWidgetUtils: Replace UIManager
glom/mode_data/buttonglom.cc | 2 +-
glom/mode_data/datawidget/label.cc | 2 +
glom/mode_data/flowtablewithfields.cc | 1 +
glom/utility_widgets/layoutwidgetmenu.cc | 4 +-
glom/utility_widgets/layoutwidgetutils.cc | 68 +++++++++++++++++------------
glom/utility_widgets/layoutwidgetutils.h | 14 +++---
6 files changed, 53 insertions(+), 38 deletions(-)
---
diff --git a/glom/mode_data/buttonglom.cc b/glom/mode_data/buttonglom.cc
index fb1f466..7c9ffc9 100644
--- a/glom/mode_data/buttonglom.cc
+++ b/glom/mode_data/buttonglom.cc
@@ -49,7 +49,7 @@ ButtonGlom::~ButtonGlom()
void ButtonGlom::init()
{
-
+ setup_util_menu(this);
}
AppWindow* ButtonGlom::get_appwindow() const
diff --git a/glom/mode_data/datawidget/label.cc b/glom/mode_data/datawidget/label.cc
index 0e015e8..ad6b96c 100644
--- a/glom/mode_data/datawidget/label.cc
+++ b/glom/mode_data/datawidget/label.cc
@@ -56,6 +56,8 @@ Label::~Label()
void Label::init()
{
+ setup_util_menu(this);
+
add(m_label);
m_label.show();
set_events(Gdk::ALL_EVENTS_MASK);
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index c3f3230..07f6a91 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -56,6 +56,7 @@ FlowTableWithFields::FlowTableWithFields(const Glib::ustring& table_name)
m_table_name(table_name),
m_find_mode(false)
{
+ setup_util_menu(this);
}
FlowTableWithFields::~FlowTableWithFields()
diff --git a/glom/utility_widgets/layoutwidgetmenu.cc b/glom/utility_widgets/layoutwidgetmenu.cc
index f7d7150..a3a3dc4 100644
--- a/glom/utility_widgets/layoutwidgetmenu.cc
+++ b/glom/utility_widgets/layoutwidgetmenu.cc
@@ -213,8 +213,8 @@ void LayoutWidgetMenu::on_menupopup_activate_delete()
Gtk::Widget* parent = dynamic_cast<Gtk::Widget*>(this);
if(!parent)
{
- // Should never happen!
- std::cerr << "LayoutWidgetUtils is no Gtk::Widget" << std::endl;
+ // Should never happen:
+ std::cerr << G_STRFUNC << ": this is not a Gtk::Widget" << std::endl;
return;
}
diff --git a/glom/utility_widgets/layoutwidgetutils.cc b/glom/utility_widgets/layoutwidgetutils.cc
index dc99524..d0c45e5 100644
--- a/glom/utility_widgets/layoutwidgetutils.cc
+++ b/glom/utility_widgets/layoutwidgetutils.cc
@@ -21,6 +21,8 @@
*/
#include "layoutwidgetutils.h"
+#include <gtkmm/builder.h>
+#include <giomm/menu.h>
#include <glibmm/i18n.h>
#include <iostream>
@@ -30,14 +32,8 @@ namespace Glom
LayoutWidgetUtils::LayoutWidgetUtils() :
m_pPopupMenuUtils(0)
{
- m_refActionGroup = Gtk::ActionGroup::create();
-
- m_refActionGroup->add(Gtk::Action::create("UtilMenu", "Utility Menu") );
- m_refUtilProperties = Gtk::Action::create("UtilProperties", _("Properties"));
- m_refUtilDelete = Gtk::Action::create("UtilDelete", _("_Delete"));
-#ifndef GLOM_ENABLE_CLIENT_ONLY
- setup_util_menu();
-#endif
+ //Derived class's constructors must call this:
+ //setup_util_menu(this);
}
LayoutWidgetUtils::~LayoutWidgetUtils()
@@ -46,29 +42,39 @@ LayoutWidgetUtils::~LayoutWidgetUtils()
}
#ifndef GLOM_ENABLE_CLIENT_ONLY
-void LayoutWidgetUtils::setup_util_menu()
+void LayoutWidgetUtils::setup_util_menu(Gtk::Widget* widget)
{
- m_refUIManager = Gtk::UIManager::create();
-
- m_refActionGroup->add(m_refUtilProperties,
+#ifndef GLOM_ENABLE_CLIENT_ONLY
+ m_refActionGroup = Gio::SimpleActionGroup::create();
+
+ m_refUtilProperties = m_refActionGroup->add_action("properties",
sigc::mem_fun(*this, &LayoutWidgetUtils::on_menu_properties_activate) );
- m_refActionGroup->add(m_refUtilDelete,
+ m_refUtilDelete = m_refActionGroup->add_action("delete",
sigc::mem_fun(*this, &LayoutWidgetUtils::on_menu_delete_activate) );
-
- m_refUIManager->insert_action_group(m_refActionGroup);
+
+ widget->insert_action_group("utility", m_refActionGroup);
+
+ Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create();
+
+ Glib::ustring ui_info =
+ "<interface>"
+ " <menu id='UtilMenu'>"
+ " <section>"
+ " <item>"
+ " <attribute name='label' translatable='yes'>Properties</attribute>"
+ " <attribute name='action'>utility.properties</attribute>"
+ " </item>"
+ " <item>"
+ " <attribute name='label' translatable='yes'>_Delete</attribute>"
+ " <attribute name='action'>utility.delete</attribute>"
+ " </item>"
+ " </section>"
+ " </menu>"
+ "</interface";
try
{
- Glib::ustring ui_info =
- "<ui>"
- " <popup name='UtilMenu'>"
- " <menuitem action='UtilProperties'/>"
- " <separator />"
- " <menuitem action='UtilDelete' />"
- " </popup>"
- "</ui>";
-
- m_refUIManager->add_ui_from_string(ui_info);
+ builder->add_from_string(ui_info);
}
catch(const Glib::Error& ex)
{
@@ -76,9 +82,15 @@ void LayoutWidgetUtils::setup_util_menu()
}
//Get the menu:
- m_pPopupMenuUtils = dynamic_cast<Gtk::Menu*>( m_refUIManager->get_widget("/UtilMenu") );
- if(!m_pPopupMenuUtils)
- g_warning("menu not found");
+ Glib::RefPtr<Glib::Object> object =
+ builder->get_object("UtilMenu");
+ Glib::RefPtr<Gio::Menu> gmenu =
+ Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
+ if(!gmenu)
+ g_warning("GMenu not found");
+
+ m_pPopupMenuUtils = new Gtk::Menu(gmenu);
+#endif
}
void LayoutWidgetUtils::on_menu_delete_activate()
diff --git a/glom/utility_widgets/layoutwidgetutils.h b/glom/utility_widgets/layoutwidgetutils.h
index 959976d..5a622a3 100644
--- a/glom/utility_widgets/layoutwidgetutils.h
+++ b/glom/utility_widgets/layoutwidgetutils.h
@@ -25,8 +25,8 @@
#include <gtkmm/widget.h>
#include <gtkmm/menu.h>
+#include <giomm/simpleactiongroup.h>
#include "layoutwidgetbase.h"
-#include <gtkmm/uimanager.h>
namespace Glom
{
@@ -38,7 +38,8 @@ public:
virtual ~LayoutWidgetUtils();
protected:
- void setup_util_menu();
+ void setup_util_menu(Gtk::Widget* widget);
+
Gtk::Menu* m_pPopupMenuUtils;
#ifndef GLOM_ENABLE_CLIENT_ONLY
virtual void on_menu_properties_activate();
@@ -47,11 +48,10 @@ protected:
virtual void on_menu_delete_activate();
#endif // !GLOM_ENABLE_CLIENT_ONLY
-//private:
- Glib::RefPtr<Gtk::Action> m_refUtilProperties;
- Glib::RefPtr<Gtk::Action> m_refUtilDelete;
- Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup;
- Glib::RefPtr<Gtk::UIManager> m_refUIManager;
+private:
+ Glib::RefPtr<Gio::SimpleAction> m_refUtilProperties;
+ Glib::RefPtr<Gio::SimpleAction> m_refUtilDelete;
+ Glib::RefPtr<Gio::SimpleActionGroup> m_refActionGroup;
};
} // namespace Glom
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]