Skip to content
Permalink
Browse files

panel-context-menu.c: avoid deprecated GtkImageMenuItem

avoid deprecated:

gtk_image_menu_item_new_with_mnemonic
gtk_image_menu_item_set_image
  • Loading branch information...
sc0w committed Apr 19, 2018
1 parent 49a3b4a commit 86701517e7d7cb3d2c08a40d76af97308f18902c
Showing with 45 additions and 26 deletions.
  1. +24 −0 mate-panel/libpanel-util/panel-gtk.c
  2. +3 −0 mate-panel/libpanel-util/panel-gtk.h
  3. +3 −0 mate-panel/menu.c
  4. +15 −26 mate-panel/panel-context-menu.c
@@ -159,3 +159,27 @@ panel_file_chooser_dialog_new (const gchar *title,

return result;
}

GtkWidget *
panel_image_menu_item_new_from_icon (const gchar *icon_name,
const gchar *label_name)
{
GtkWidget *icon;
GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

if (icon_name)
icon = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
else
icon = gtk_image_new ();

GtkWidget *label_menu = gtk_label_new_with_mnemonic (g_strconcat (label_name, " ", NULL));

This comment has been minimized.

Copy link
@muktupavels

muktupavels Jun 24, 2018

Contributor

Memory leak...

This comment has been minimized.

Copy link
@sc0w

sc0w Dec 3, 2018

Author Member

Fixed with 9628efb

GtkWidget *menuitem = gtk_menu_item_new ();

gtk_container_add (GTK_CONTAINER (box), icon);
gtk_container_add (GTK_CONTAINER (box), label_menu);

gtk_container_add (GTK_CONTAINER (menuitem), box);
gtk_widget_show_all (menuitem);

return menuitem;

This comment has been minimized.

Copy link
@TomaszGasior

TomaszGasior Jun 20, 2018

How to disable visibility of menu item icons with this implementation?

This comment has been minimized.

Copy link
@lukefromdc

lukefromdc Jun 20, 2018

Member

What I did for the icons I added to M-S-D's display popup menu was to make the icon loading conditional on the value of the "menus-have-icons" gsettings key. I packed a box into the menuitem (which can have only one child), and into the box packed the image conditionally and the label unconditionally, using this code in msd-xrandr.manager.c:

        /*Load the icon unless the user has icons in menus turned off*/
        icon_settings = g_settings_new ("org.mate.interface");
        if (g_settings_get_boolean (icon_settings, "menus-have-icons")){
            gtk_container_add (GTK_CONTAINER (box), image);
            }
        gtk_container_add (GTK_CONTAINER (box), label);
        gtk_container_add (GTK_CONTAINER (item), box);

To see how it works, open mate-control-center, go to "display" and set it to add a tray icon. Turn icons in menus on and off, popping up this menu each time. You will see that this can indeed be user selectable

This comment has been minimized.

Copy link
@lukefromdc

lukefromdc Jun 20, 2018

Member

See #820
please review and test, this makes loading menu icons conditional on whether you have the icons turned on or off. Affects everything changed by the commit in question here, does not affect main menu menuitems or a few outliers I will try to track down

}
@@ -46,6 +46,9 @@ GtkWidget* panel_file_chooser_dialog_new (const gchar *title,
const gchar *first_button_text,
...);

GtkWidget* panel_image_menu_item_new_from_icon (const gchar *icon_name,
const gchar *label_name);

#ifdef __cplusplus
}
#endif
@@ -163,6 +163,9 @@ panel_create_menu (void)
GtkWidget *retval;

retval = gtk_menu_new ();

gtk_menu_set_reserve_toggle_size (GTK_MENU (retval), FALSE);

gtk_widget_set_name (retval, "mate-panel-main-menu");

g_signal_connect (retval, "key_press_event",
@@ -36,6 +36,7 @@

#include <libpanel-util/panel-error.h>
#include <libpanel-util/panel-show.h>
#include <libpanel-util/panel-gtk.h>

#include "panel-util.h"
#include "panel.h"
@@ -228,11 +229,9 @@ panel_context_menu_build_edition (PanelWidget *panel_widget,
GtkWidget *menu)
{
GtkWidget *menuitem;
GtkWidget *image;

menuitem = gtk_image_menu_item_new_with_mnemonic (_("_Add to Panel…"));
image = gtk_image_new_from_icon_name ("list-add", GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
menuitem = panel_image_menu_item_new_from_icon ("list-add", _("_Add to Panel…"));

gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
g_signal_connect (G_OBJECT (menuitem), "activate",
@@ -241,10 +240,8 @@ panel_context_menu_build_edition (PanelWidget *panel_widget,
if (!panel_profile_id_lists_are_writable ())
gtk_widget_set_sensitive (menuitem, FALSE);

menuitem = gtk_image_menu_item_new_with_mnemonic (_("_Properties"));
image = gtk_image_new_from_icon_name ("document-properties",
GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
menuitem = panel_image_menu_item_new_from_icon ("document-properties", _("_Properties"));

gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
g_signal_connect_swapped (menuitem, "activate",
@@ -253,18 +250,15 @@ panel_context_menu_build_edition (PanelWidget *panel_widget,

add_menu_separator (menu);

menuitem = gtk_image_menu_item_new_with_mnemonic (_("_Reset Panel"));
image = gtk_image_new_from_icon_name ("document-revert", GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
menuitem = panel_image_menu_item_new_from_icon ("document-revert", _("_Reset Panel"));

gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
g_signal_connect_swapped (menuitem, "activate",
G_CALLBACK (query_panel_reset), panel_widget->toplevel);

menuitem = gtk_image_menu_item_new_with_mnemonic (_("_Delete This Panel"));
image = gtk_image_new_from_icon_name ("edit-delete",
GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
menuitem = panel_image_menu_item_new_from_icon ("edit-delete", _("_Delete This Panel"));

gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
g_signal_connect_swapped (G_OBJECT (menuitem), "activate",
@@ -276,9 +270,8 @@ panel_context_menu_build_edition (PanelWidget *panel_widget,

add_menu_separator (menu);

menuitem = gtk_image_menu_item_new_with_mnemonic (_("_New Panel"));
image = gtk_image_new_from_icon_name ("document-new", GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
menuitem = panel_image_menu_item_new_from_icon ("document-new", _("_New Panel"));

gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
g_signal_connect (menuitem, "activate",
@@ -295,7 +288,6 @@ panel_context_menu_create (PanelWidget *panel)
{
GtkWidget *retval;
GtkWidget *menuitem;
GtkWidget *image;

if (panel->master_widget) {
gpointer *pointer;
@@ -320,18 +312,15 @@ panel_context_menu_create (PanelWidget *panel)
if (!panel_lockdown_get_locked_down ())
panel_context_menu_build_edition (panel, retval);

menuitem = gtk_image_menu_item_new_with_mnemonic (_("_Help"));
image = gtk_image_new_from_icon_name ("help-browser", GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
menuitem = panel_image_menu_item_new_from_icon ("help-browser", _("_Help"));

gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (retval), menuitem);
g_signal_connect (menuitem, "activate",
G_CALLBACK (panel_context_menu_show_help), NULL);

menuitem = gtk_image_menu_item_new_with_mnemonic (_("A_bout Panels"));
image = gtk_image_new_from_icon_name ("help-about",
GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
menuitem = panel_image_menu_item_new_from_icon ("help-about", _("A_bout Panels"));

gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (retval), menuitem);
g_signal_connect (menuitem, "activate",

0 comments on commit 8670151

Please sign in to comment.
You can’t perform that action at this time.