[glom] gmenu: Use Menu API for small context menus
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] gmenu: Use Menu API for small context menus
- Date: Wed, 25 Sep 2013 08:16:11 +0000 (UTC)
commit fa0c6597b2a7f9cba29c9a8b96e6de392a873c74
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Sep 24 13:13:12 2013 +0200
gmenu: Use Menu API for small context menus
glom/mode_data/box_data_calendar_related.cc | 39 +---------
glom/mode_data/db_adddel/db_adddel.cc | 49 ++-----------
glom/print_layout/canvas_print_layout.cc | 45 ++----------
glom/utility_widgets/adddel/adddel.cc | 39 +---------
.../utility_widgets/canvas/test_canvas_editable.cc | 34 ++--------
glom/utility_widgets/imageglom.cc | 66 +++--------------
glom/utility_widgets/imageglom.h | 2 -
glom/utility_widgets/layoutwidgetmenu.cc | 76 +++----------------
glom/utility_widgets/layoutwidgetutils.cc | 39 +---------
glom/utility_widgets/notebooklabelglom.cc | 40 +---------
10 files changed, 56 insertions(+), 373 deletions(-)
---
diff --git a/glom/mode_data/box_data_calendar_related.cc b/glom/mode_data/box_data_calendar_related.cc
index b6983aa..75918bb 100644
--- a/glom/mode_data/box_data_calendar_related.cc
+++ b/glom/mode_data/box_data_calendar_related.cc
@@ -519,46 +519,15 @@ void Box_Data_Calendar_Related::setup_menu(Gtk::Widget* /* this */)
}
#endif // !GLOM_ENABLE_CLIENT_ONLY
- Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create();
-
insert_action_group("context", m_refActionGroup);
//TODO: add_accel_group(m_refUIManager->get_accel_group());
- const Glib::ustring ui_info =
- "<interface>"
- " <menu id='ContextMenu'>"
- " <section>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Edit</attribute>"
- " <attribute name='action'>context.edit</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Layout</attribute>"
- " <attribute name='action'>context.layout</attribute>"
- " </item>"
- " </section>"
- " </menu>"
- "</interface>";
-
- try
- {
- builder->add_from_string(ui_info);
- }
- catch(const Glib::Error& ex)
- {
- std::cerr << G_STRFUNC << ": building menus failed: " << ex.what();
- }
-
- //Get the menu:
- 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");
+ Glib::RefPtr<Gio::Menu> menu = Gio::Menu::create();
+ menu->append(_("_Edit"), "context.edit");
+ menu->append(_("_Layout"), "context.layout");
- m_pMenuPopup = new Gtk::Menu(gmenu);
+ m_pMenuPopup = new Gtk::Menu(menu);
#ifndef GLOM_ENABLE_CLIENT_ONLY
if(pApp)
diff --git a/glom/mode_data/db_adddel/db_adddel.cc b/glom/mode_data/db_adddel/db_adddel.cc
index 867d4b5..23d5c06 100644
--- a/glom/mode_data/db_adddel/db_adddel.cc
+++ b/glom/mode_data/db_adddel/db_adddel.cc
@@ -252,56 +252,19 @@ void DbAddDel::setup_menu(Gtk::Widget* /* widget */)
}
#endif // !GLOM_ENABLE_CLIENT_ONLY
- Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create();
-
insert_action_group("context", m_refActionGroup);
//TODO: add_accel_group(builder->get_accel_group());
- const Glib::ustring ui_info =
- "<interface>"
- " <menu id='ContextMenu'>"
- " <section>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Edit</attribute>"
- " <attribute name='action'>context.edit</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Add</attribute>"
- " <attribute name='action'>context.add</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Delete</attribute>"
- " <attribute name='action'>context.delete</attribute>"
- " </item>"
+ Glib::RefPtr<Gio::Menu> menu = Gio::Menu::create();
+ menu->append(_("_Edit"), "context.edit");
+ menu->append(_("_Add"), "context.add");
+ menu->append(_("_Delete"), "context.delete");
#ifndef GLOM_ENABLE_CLIENT_ONLY
- " <item>"
- " <attribute name='label' translatable='yes'>_Layout</attribute>"
- " <attribute name='action'>context.layout</attribute>"
- " </item>"
+ menu->append(_("_Layout"), "context.layout");
#endif
- " </section>"
- " </menu>"
- "</interface>";
-
- try
- {
- builder->add_from_string(ui_info);
- }
- catch(const Glib::Error& ex)
- {
- std::cerr << G_STRFUNC << ": building menus failed: " << ex.what();
- }
-
- //Get the menu:
- 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_pMenuPopup = new Gtk::Menu(gmenu);
+ m_pMenuPopup = new Gtk::Menu(menu);
if(get_allow_user_actions())
diff --git a/glom/print_layout/canvas_print_layout.cc b/glom/print_layout/canvas_print_layout.cc
index 97fa2a6..1fd3e44 100644
--- a/glom/print_layout/canvas_print_layout.cc
+++ b/glom/print_layout/canvas_print_layout.cc
@@ -288,46 +288,11 @@ void Canvas_PrintLayout::setup_context_menu()
insert_action_group("context", m_context_menu_action_group);
- Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create();
-
- const Glib::ustring ui_info =
- "<interface>"
- " <menu id='ContextMenu'>"
- " <section>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Edit</attribute>"
- " <attribute name='action'>context.edit</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Formatting</attribute>"
- " <attribute name='action'>context.formatting</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>_delete</attribute>"
- " <attribute name='action'>context.delete</attribute>"
- " </item>"
- " </section>"
- " </menu>"
- "</interface>";
-
- try
- {
- builder->add_from_string(ui_info);
- }
- catch(const Glib::Error& ex)
- {
- std::cerr << G_STRFUNC << ": building menus failed: " << ex.what();
- }
-
- //Get the menu:
- 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_context_menu = new Gtk::Menu(gmenu);
+ Glib::RefPtr<Gio::Menu> menu = Gio::Menu::create();
+ menu->append(_("_Edit"), "context.edit");
+ menu->append(_("_Formatting"), "context.formatting");
+ menu->append(_("_Delete"), "context.delete");
+ m_context_menu = new Gtk::Menu(menu);
}
diff --git a/glom/utility_widgets/adddel/adddel.cc b/glom/utility_widgets/adddel/adddel.cc
index c39cd98..134fc6d 100644
--- a/glom/utility_widgets/adddel/adddel.cc
+++ b/glom/utility_widgets/adddel/adddel.cc
@@ -244,44 +244,13 @@ void AddDel::setup_menu(Gtk::Widget* /* widget */)
insert_action_group("context", m_refActionGroup);
- Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create();
-
//TODO: add_accel_group(builder->get_accel_group());
- const Glib::ustring ui_info =
- "<interface>"
- " <menu id='ContextMenu'>"
- " <section>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Edit</attribute>"
- " <attribute name='action'>context.edit</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Delete</attribute>"
- " <attribute name='action'>context.delete</attribute>"
- " </item>"
- " </section>"
- " </menu>"
- "</interface>";
-
- try
- {
- builder->add_from_string(ui_info);
- }
- catch(const Glib::Error& ex)
- {
- std::cerr << G_STRFUNC << ": building menus failed: " << ex.what();
- }
-
- //Get the menu:
- 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");
+ Glib::RefPtr<Gio::Menu> menu = Gio::Menu::create();
+ menu->append(_("_Edit"), "context.edit");
+ menu->append(_("_Delete"), "context.delete");
- m_pMenuPopup = new Gtk::Menu(gmenu);
+ m_pMenuPopup = new Gtk::Menu(menu);
}
bool AddDel::on_button_press_event_Popup(GdkEventButton *event)
diff --git a/glom/utility_widgets/canvas/test_canvas_editable.cc
b/glom/utility_widgets/canvas/test_canvas_editable.cc
index 77c3af5..9b4b348 100644
--- a/glom/utility_widgets/canvas/test_canvas_editable.cc
+++ b/glom/utility_widgets/canvas/test_canvas_editable.cc
@@ -179,36 +179,12 @@ private:
m_context_menu_action_group->add(action,
sigc::mem_fun(*this, &MyCanvas::on_context_menu_delete) );
- m_context_menu_builder = Gtk::Builder::create();
- m_context_menu_builder->insert_action_group(m_context_menu_action_group);
-
- try
- {
- Glib::ustring ui_info =
- "<interface>"
- " <menu id='ContextMenu'>"
- " <section>
- " <item>
- " <attribute name='label' translatable='yes'>Edit</attribute>"
- " <attribute name='action'>context.edit</attribute>"
- " </item>
- " <item>
- " <attribute name='label' translatable='yes'>Delete</attribute>"
- " <attribute name='action'>context.delete</attribute>"
- " </item>"
- " </section>"
- " </menu>
- "</interface>";
-
- m_context_menu_builder->add_from_string(ui_info);
- }
- catch(const Glib::Error& ex)
- {
- std::cerr << G_STRFUNC << ": building menus failed: " << ex.what();
- }
-
+ Glib::RefPtr<Gio::Menu> menu = Gio::Menu::create();
+ menu->append(_("_Edit"), "context.edit");
+ menu->append(_("_Delete"), "context.delete");
+
//Get the menu:
- m_context_menu = dynamic_cast<Gtk::Menu*>( m_context_menu_builder->get_widget("/ContextMenu") );
+ m_context_menu = new Gtk::Menu(menu);
}
Gtk::Menu* m_context_menu;
diff --git a/glom/utility_widgets/imageglom.cc b/glom/utility_widgets/imageglom.cc
index 0bd81de..e2eb125 100644
--- a/glom/utility_widgets/imageglom.cc
+++ b/glom/utility_widgets/imageglom.cc
@@ -925,16 +925,16 @@ void ImageGlom::setup_menu_usermode()
//Create the Gio::ActionGroup and associate it with this widget:
m_refActionGroup_UserModePopup = Gio::SimpleActionGroup::create();
- m_refActionOpenFile = m_refActionGroup_UserModePopup->add_action("openfile",
+ m_refActionOpenFile = m_refActionGroup_UserModePopup->add_action("open-file",
sigc::mem_fun(*this, &ImageGlom::on_menupopup_activate_open_file) );
- m_refActionOpenFileWith = m_refActionGroup_UserModePopup->add_action("openfilewith",
+ m_refActionOpenFileWith = m_refActionGroup_UserModePopup->add_action("open-fil-ewith",
sigc::mem_fun(*this, &ImageGlom::on_menupopup_activate_open_file_with) );
- m_refActionSaveFile = m_refActionGroup_UserModePopup->add_action("savefile",
+ m_refActionSaveFile = m_refActionGroup_UserModePopup->add_action("save-file",
sigc::mem_fun(*this, &ImageGlom::on_menupopup_activate_save_file) );
- m_refActionSelectFile = m_refActionGroup_UserModePopup->add_action("selectfile",
+ m_refActionSelectFile = m_refActionGroup_UserModePopup->add_action("select-file",
sigc::mem_fun(*this, &ImageGlom::on_menupopup_activate_select_file) );
m_refActionCopy = m_refActionGroup_UserModePopup->add_action("copy",
@@ -951,58 +951,16 @@ void ImageGlom::setup_menu_usermode()
//Create the UI for the menu whose items will activate the actions,
//when this UI (a GtkMenu) is added and shown:
- m_refBuilder_UserModePopup = Gtk::Builder::create();
- try
- {
- Glib::ustring ui_info =
- "<interface>"
- " <menu id='ContextMenu_UserMode'>"
- " <section>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Open File</attribute>"
- " <attribute name='action'>imagecontext.openfile</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>Open File With</attribute>"
- " <attribute name='action'>imagecontext.openfilewith</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>Select File</attribute>"
- " <attribute name='action'>imagecontext.selectfile</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Copy</attribute>"
- " <attribute name='action'>imagecontext.copy</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Paste</attribute>"
- " <attribute name='action'>imagecontext.paste</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>_Clear</attribute>"
- " <attribute name='action'>imagecontext.clear</attribute>"
- " </item>"
- " </section>"
- " </menu>"
- "</interface>";
-
- m_refBuilder_UserModePopup->add_from_string(ui_info);
- }
- catch(const Glib::Error& ex)
- {
- std::cerr << G_STRFUNC << ": building menus failed: " << ex.what();
- }
-
- //Get the menu:
- Glib::RefPtr<Glib::Object> object =
- m_refBuilder_UserModePopup->get_object("ContextMenu_UserMode");
- Glib::RefPtr<Gio::Menu> gmenu =
- Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
- if(!gmenu)
- g_warning("GMenu not found");
+ Glib::RefPtr<Gio::Menu> menu = Gio::Menu::create();
+ menu->append(_("_Open File"), "context.open-file");
+ menu->append(_("Open File With"), "context.open-file-with");
+ menu->append(_("Select Fie"), "context.select-file");
+ menu->append(_("_Copy"), "context.copy");
+ menu->append(_("_Paste"), "context.paste");
+ menu->append(_("_Clear"), "context.clear");
- m_pMenuPopup_UserMode = new Gtk::Menu(gmenu);
+ m_pMenuPopup_UserMode = new Gtk::Menu(menu);
}
void ImageGlom::do_choose_image()
diff --git a/glom/utility_widgets/imageglom.h b/glom/utility_widgets/imageglom.h
index a0926b4..52d11d0 100644
--- a/glom/utility_widgets/imageglom.h
+++ b/glom/utility_widgets/imageglom.h
@@ -123,8 +123,6 @@ private:
//TODO: Use just the Gio::ActionGroup type when it derives from Gio::ActionMap.
Glib::RefPtr<Gio::SimpleActionGroup> m_refActionGroup_UserModePopup;
- Glib::RefPtr<Gtk::Builder> m_refBuilder_UserModePopup;
-
//We use Gio::SimpleAction rather than Gio::Action
//because Gio::Action has no way to enable/disable it.
Glib::RefPtr<Gio::SimpleAction> m_refActionOpenFile, m_refActionOpenFileWith,
diff --git a/glom/utility_widgets/layoutwidgetmenu.cc b/glom/utility_widgets/layoutwidgetmenu.cc
index a3a3dc4..7bf86c4 100644
--- a/glom/utility_widgets/layoutwidgetmenu.cc
+++ b/glom/utility_widgets/layoutwidgetmenu.cc
@@ -115,70 +115,18 @@ void LayoutWidgetMenu::setup_menu(Gtk::Widget* widget)
pApp->update_userlevel_ui(); //Update our action's sensitivity.
}
- Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create();
-
- //TODO: add_accel_group(m_refUIManager->get_accel_group());
-
- const Glib::ustring ui_info =
- "<interface>"
- " <menu id='ContextMenu'>"
- " <section>"
- " <item>"
- " <attribute name='label' translatable='yes'>Choose Field</attribute>"
- " <attribute name='action'>context.choose-field</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>Field Layout Properties</attribute>"
- " <attribute name='action'>context.field-layout-properties</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>Add Related Records</attribute>"
- " <attribute name='action'>context.add-related-records</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>Add Notebook</attribute>"
- " <attribute name='action'>context.add-notebook</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>Add Group</attribute>"
- " <attribute name='action'>context.add-group</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>Add Button</attribute>"
- " <attribute name='action'>context.add-button</attribute>"
- " </item>"
- " <item>"
- " <attribute name='label' translatable='yes'>Add Text</attribute>"
- " <attribute name='action'>context.add-text</attribute>"
- " </item>"
- " </section>"
- " <section>"
- " <item>"
- " <attribute name='label' translatable='yes'>Delete</attribute>"
- " <attribute name='action'>context.delete</attribute>"
- " </item>"
- " </section>"
- " </menu>"
- "</interface>";
-
- try
- {
- builder->add_from_string(ui_info);
- }
- catch(const Glib::Error& ex)
- {
- std::cerr << G_STRFUNC << ": building menus failed: " << ex.what();
- }
-
- //Get the menu:
- 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_pMenuPopup = new Gtk::Menu(gmenu);
+ Glib::RefPtr<Gio::Menu> menu = Gio::Menu::create();
+ menu->append(_("Choose Field"), "context.choose-field");
+ menu->append(_("Field Layout Properties"), "context.field-layout-properties");
+ menu->append(_("Add Related Records"), "context.add-related-records");
+ menu->append(_("Add Notebook"), "context.add-notebook");
+ menu->append(_("Add Group"), "context.add-group");
+ menu->append(_("Add Button"), "context.add-button");
+ menu->append(_("Add Text"), "context.add-text");
+ menu->append(_("Delete"), "context.delete");
+
+
+ m_pMenuPopup = new Gtk::Menu(menu);
if(pApp)
m_refContextLayout->set_enabled(pApp->get_userlevel() == AppState::USERLEVEL_DEVELOPER);
diff --git a/glom/utility_widgets/layoutwidgetutils.cc b/glom/utility_widgets/layoutwidgetutils.cc
index d0c45e5..51f4c67 100644
--- a/glom/utility_widgets/layoutwidgetutils.cc
+++ b/glom/utility_widgets/layoutwidgetutils.cc
@@ -54,42 +54,11 @@ void LayoutWidgetUtils::setup_util_menu(Gtk::Widget* widget)
widget->insert_action_group("utility", m_refActionGroup);
- Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create();
+ Glib::RefPtr<Gio::Menu> menu = Gio::Menu::create();
+ menu->append(_("Properties"), "context.properties");
+ menu->append(_("_Delete"), "context.delete");
- 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
- {
- builder->add_from_string(ui_info);
- }
- catch(const Glib::Error& ex)
- {
- std::cerr << G_STRFUNC << ": building menus failed: " << ex.what();
- }
-
- //Get the menu:
- 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);
+ m_pPopupMenuUtils = new Gtk::Menu(menu);
#endif
}
diff --git a/glom/utility_widgets/notebooklabelglom.cc b/glom/utility_widgets/notebooklabelglom.cc
index cba56be..a4eecec 100644
--- a/glom/utility_widgets/notebooklabelglom.cc
+++ b/glom/utility_widgets/notebooklabelglom.cc
@@ -120,43 +120,11 @@ void NotebookLabel::setup_menu(Gtk::Widget* /* widget */)
insert_action_group("context", m_refActionGroup);
+ Glib::RefPtr<Gio::Menu> menu = Gio::Menu::create();
+ menu->append(_("New Group"), "context.new-group");
+ menu->append(_("_Delete"), "context.delete");
- 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
- {
- builder->add_from_string(ui_info);
- }
- catch(const Glib::Error& ex)
- {
- std::cerr << G_STRFUNC << ": building menus failed: " << ex.what() << std::endl;
- }
-
- //Get the menu:
- 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);
+ m_pPopupMenu = new Gtk::Menu(menu);
}
bool NotebookLabel::on_button_press_event(GdkEventButton *event)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]