Create context menu items w/o accelerators

This commit is contained in:
Christian Dywan 2008-08-10 19:54:22 +02:00
parent b38e3f429e
commit 6e910ee107
3 changed files with 55 additions and 20 deletions

View file

@ -705,9 +705,6 @@ midori_web_view_populate_popup_cb (GtkWidget* web_view,
const gchar* uri;
GtkAction* action;
GtkWidget* menuitem;
gchar* stock_id;
GtkStockItem stockitem;
GtkWidget* image;
if (MIDORI_IS_WEB_VIEW (web_view)
&& midori_web_view_has_selection (MIDORI_WEB_VIEW (web_view)))
@ -718,16 +715,8 @@ midori_web_view_populate_popup_cb (GtkWidget* web_view,
uri = midori_web_view_get_link_uri (MIDORI_WEB_VIEW (web_view));
if (uri)
{
/* Create the menuitem manually instead of from the action
because otherwise the menuitem has an accelerator label. */
action = _action_by_name (browser, "BookmarkAdd");
g_object_get (action, "stock-id", &stock_id, NULL);
gtk_stock_lookup (stock_id, &stockitem);
menuitem = gtk_image_menu_item_new_with_mnemonic (stockitem.label);
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
g_free (stock_id);
gtk_widget_show (menuitem);
menuitem = sokoke_action_create_popup_menu_item (action);
g_signal_connect (menuitem, "activate",
G_CALLBACK (midori_web_view_bookmark_add_cb), web_view);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
@ -741,22 +730,22 @@ midori_web_view_populate_popup_cb (GtkWidget* web_view,
if (!uri && !has_selection)
{
action = _action_by_name (browser, "UndoTabClose");
menuitem = gtk_action_create_menu_item (action);
menuitem = sokoke_action_create_popup_menu_item (action);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
menuitem = gtk_separator_menu_item_new ();
gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
action = _action_by_name (browser, "BookmarkAdd");
menuitem = gtk_action_create_menu_item (action);
menuitem = sokoke_action_create_popup_menu_item (action);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
action = _action_by_name (browser, "SaveAs");
menuitem = gtk_action_create_menu_item (action);
menuitem = sokoke_action_create_popup_menu_item (action);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
action = _action_by_name (browser, "SourceView");
menuitem = gtk_action_create_menu_item (action);
menuitem = sokoke_action_create_popup_menu_item (action);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
action = _action_by_name (browser, "Print");
menuitem = gtk_action_create_menu_item (action);
menuitem = sokoke_action_create_popup_menu_item (action);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
}
}

View file

@ -304,7 +304,7 @@ sokoke_xfce_header_new (const gchar* icon,
const gchar* title)
{
/* Create an xfce header with icon and title
This returns NULL if the desktop is not xfce */
This returns NULL if the desktop is not Xfce */
if (sokoke_get_desktop () == SOKOKE_DESKTOP_XFCE)
{
GtkWidget* entry = gtk_entry_new ();
@ -579,7 +579,7 @@ gint
sokoke_object_get_int (gpointer object,
const gchar* property)
{
gint value;
gint value = 0;
g_return_val_if_fail (object != NULL, FALSE);
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
@ -593,7 +593,7 @@ gboolean
sokoke_object_get_boolean (gpointer object,
const gchar* property)
{
gboolean value;
gboolean value = FALSE;
g_return_val_if_fail (object != NULL, FALSE);
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
@ -602,3 +602,46 @@ sokoke_object_get_boolean (gpointer object,
g_object_get (object, property, &value, NULL);
return value;
}
/**
* sokoke_action_create_popup_menu_item:
* @action: a #GtkAction
*
* Creates a menu item from an action, much like
* gtk_action_create_menu_item() but it won't
* display an accelerator.
*
* Return value: a new #GtkMenuItem
**/
GtkWidget*
sokoke_action_create_popup_menu_item (GtkAction* action)
{
gchar* label;
gchar* stock_id;
gboolean sensitive;
GtkStockItem stockitem;
GtkWidget* menuitem;
GtkWidget* image;
g_object_get (action, "label", &label,
"stock-id", &stock_id, "sensitive", &sensitive, NULL);
if (label)
{
menuitem = gtk_image_menu_item_new_with_mnemonic (label);
g_free (label);
}
else
{
gtk_stock_lookup (stock_id, &stockitem);
menuitem = gtk_image_menu_item_new_with_mnemonic (stockitem.label);
gtk_stock_item_free (&stockitem);
}
gtk_widget_set_sensitive (menuitem, sensitive);
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
gtk_widget_show (menuitem);
g_free (stock_id);
return menuitem;
}

View file

@ -128,4 +128,7 @@ gboolean
sokoke_object_get_boolean (gpointer object,
const gchar* property);
GtkWidget*
sokoke_action_create_popup_menu_item (GtkAction* action);
#endif /* !__SOKOKE_H__ */