Commit fa0c6597 authored by Murray Cumming's avatar Murray Cumming
Browse files

gmenu: Use Menu API for small context menus

parent 6517a7c3
......@@ -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)
......
......@@ -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())
......
......@@ -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);
}
......
......@@ -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)
......
......@@ -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;
......
......@@ -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()
......
......@@ -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,
......
......@@ -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);
......
......@@ -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
}
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment