From 905cc2f22ed24629e6b5fbf8666ecc9bf45aa274 Mon Sep 17 00:00:00 2001 From: deepend Date: Fri, 23 Jan 2026 13:42:11 -0700 Subject: [PATCH] Added a GTK3 helper to build icon+label menu items for the channel list context menu entries. Added a GTK3 helper for icon-name menu items and reused it when building stock icon menu entries. Added a GTK3 helper for spelling-related menu items and reused it for add/ignore/suggestions entries. --- src/fe-gtk/chanlist.c | 60 ++++++++++++++++------------------- src/fe-gtk/menu.c | 24 +++++++++++++- src/fe-gtk/sexy-spell-entry.c | 49 +++++++++++++++------------- 3 files changed, 78 insertions(+), 55 deletions(-) diff --git a/src/fe-gtk/chanlist.c b/src/fe-gtk/chanlist.c index dfb51aff..e39c2992 100644 --- a/src/fe-gtk/chanlist.c +++ b/src/fe-gtk/chanlist.c @@ -124,6 +124,28 @@ chanlist_icon_button (const char *label, const char *icon_name, return button; } + +static GtkWidget * +chanlist_icon_menu_item (const char *label, const char *icon_name, + GCallback callback, gpointer userdata) +{ + GtkWidget *item; + GtkWidget *box; + GtkWidget *image; + GtkWidget *label_widget; + + item = gtk_menu_item_new (); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); + label_widget = gtk_label_new_with_mnemonic (label); + gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (box), label_widget, FALSE, FALSE, 0); + gtk_container_add (GTK_CONTAINER (item), box); + g_signal_connect (G_OBJECT (item), "activate", callback, userdata); + gtk_widget_show_all (item); + + return item; +} #endif @@ -682,44 +704,18 @@ chanlist_button_cb (GtkTreeView *tree, GdkEventButton *event, server *serv) #if HAVE_GTK3 { GtkWidget *item; - GtkWidget *box; - GtkWidget *image; - GtkWidget *label; - item = gtk_menu_item_new (); - box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - image = gtk_image_new_from_icon_name (ICON_CHANLIST_JOIN, GTK_ICON_SIZE_MENU); - label = gtk_label_new_with_mnemonic (_("_Join Channel")); - gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); - gtk_container_add (GTK_CONTAINER (item), box); + item = chanlist_icon_menu_item (_("_Join Channel"), ICON_CHANLIST_JOIN, + G_CALLBACK (chanlist_join), serv); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (chanlist_join), serv); - gtk_widget_show_all (item); - item = gtk_menu_item_new (); - box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - image = gtk_image_new_from_icon_name (ICON_CHANLIST_COPY, GTK_ICON_SIZE_MENU); - label = gtk_label_new_with_mnemonic (_("_Copy Channel Name")); - gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); - gtk_container_add (GTK_CONTAINER (item), box); + item = chanlist_icon_menu_item (_("_Copy Channel Name"), ICON_CHANLIST_COPY, + G_CALLBACK (chanlist_copychannel), serv); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - g_signal_connect (G_OBJECT (item), "activate", - G_CALLBACK (chanlist_copychannel), serv); - gtk_widget_show_all (item); - item = gtk_menu_item_new (); - box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - image = gtk_image_new_from_icon_name (ICON_CHANLIST_COPY, GTK_ICON_SIZE_MENU); - label = gtk_label_new_with_mnemonic (_("Copy _Topic Text")); - gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); - gtk_container_add (GTK_CONTAINER (item), box); + item = chanlist_icon_menu_item (_("Copy _Topic Text"), ICON_CHANLIST_COPY, + G_CALLBACK (chanlist_copytopic), serv); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - g_signal_connect (G_OBJECT (item), "activate", - G_CALLBACK (chanlist_copytopic), serv); - gtk_widget_show_all (item); } #endif #if !HAVE_GTK3 diff --git a/src/fe-gtk/menu.c b/src/fe-gtk/menu.c index 3e2a78c5..622e584a 100644 --- a/src/fe-gtk/menu.c +++ b/src/fe-gtk/menu.c @@ -353,6 +353,27 @@ menu_quick_item (char *cmd, char *label, GtkWidget * menu, int flags, return item; } +#if HAVE_GTK3 +static GtkWidget * +menu_icon_name_item_new (const char *label, const char *icon_name) +{ + GtkWidget *item; + GtkWidget *box; + GtkWidget *image; + GtkWidget *label_widget; + + item = gtk_menu_item_new (); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); + label_widget = gtk_label_new_with_mnemonic (label); + gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (box), label_widget, FALSE, FALSE, 0); + gtk_container_add (GTK_CONTAINER (item), box); + + return item; +} +#endif + static void menu_quick_item_with_callback (void *callback, char *label, GtkWidget * menu, void *arg) @@ -2011,7 +2032,7 @@ create_icon_menu (char *labeltext, void *stock_name, int is_stock) #if HAVE_GTK3 const char *icon_name = gtkutil_icon_name_from_stock (stock_name); - img = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); + item = menu_icon_name_item_new (labeltext, icon_name); #endif #if !HAVE_GTK3 img = gtk_image_new_from_stock (stock_name, GTK_ICON_SIZE_MENU); @@ -2020,6 +2041,7 @@ create_icon_menu (char *labeltext, void *stock_name, int is_stock) else img = gtk_image_new_from_pixbuf (*((GdkPixbuf **)stock_name)); #if HAVE_GTK3 + if (!is_stock) { GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); GtkWidget *label_widget = gtk_label_new_with_mnemonic (labeltext); diff --git a/src/fe-gtk/sexy-spell-entry.c b/src/fe-gtk/sexy-spell-entry.c index 109327da..c657611e 100644 --- a/src/fe-gtk/sexy-spell-entry.c +++ b/src/fe-gtk/sexy-spell-entry.c @@ -629,6 +629,27 @@ build_suggestion_menu(SexySpellEntry *entry, GtkWidget *menu, struct EnchantDict enchant_dict_free_suggestions(dict, suggestions); } +#if HAVE_GTK3 +static GtkWidget * +sexy_spell_entry_icon_menu_item (const char *label, const char *icon_name) +{ + GtkWidget *item; + GtkWidget *box; + GtkWidget *image; + GtkWidget *label_widget; + + item = gtk_menu_item_new (); + box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); + label_widget = gtk_label_new_with_mnemonic (label); + gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (box), label_widget, FALSE, FALSE, 0); + gtk_container_add (GTK_CONTAINER (item), box); + + return item; +} +#endif + static GtkWidget * build_spelling_menu(SexySpellEntry *entry, const gchar *word) { @@ -686,14 +707,8 @@ build_spelling_menu(SexySpellEntry *entry, const gchar *word) #if HAVE_GTK3 { const char *icon_name = gtkutil_icon_name_from_stock (GTK_STOCK_ADD); - GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - GtkWidget *image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); - GtkWidget *label_widget = gtk_label_new_with_mnemonic (label); - mi = gtk_menu_item_new (); - gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (box), label_widget, FALSE, FALSE, 0); - gtk_container_add (GTK_CONTAINER (mi), box); + mi = sexy_spell_entry_icon_menu_item (label, icon_name); } #endif #if !HAVE_GTK3 @@ -744,14 +759,8 @@ build_spelling_menu(SexySpellEntry *entry, const gchar *word) #if HAVE_GTK3 { const char *icon_name = gtkutil_icon_name_from_stock (GTK_STOCK_REMOVE); - GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - GtkWidget *image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); - GtkWidget *label_widget = gtk_label_new_with_mnemonic (_("Ignore All")); - mi = gtk_menu_item_new (); - gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (box), label_widget, FALSE, FALSE, 0); - gtk_container_add (GTK_CONTAINER (mi), box); + mi = sexy_spell_entry_icon_menu_item (_("Ignore All"), icon_name); } #endif #if !HAVE_GTK3 @@ -768,7 +777,7 @@ build_spelling_menu(SexySpellEntry *entry, const gchar *word) static void sexy_spell_entry_populate_popup(SexySpellEntry *entry, GtkMenu *menu, gpointer data) { - GtkWidget *icon, *mi; + GtkWidget *mi; gint start, end; gchar *word; @@ -793,17 +802,13 @@ sexy_spell_entry_populate_popup(SexySpellEntry *entry, GtkMenu *menu, gpointer d #if HAVE_GTK3 { const char *icon_name = gtkutil_icon_name_from_stock (GTK_STOCK_SPELL_CHECK); - GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - GtkWidget *label_widget = gtk_label_new_with_mnemonic (_("Spelling Suggestions")); - icon = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); - mi = gtk_menu_item_new (); - gtk_box_pack_start (GTK_BOX (box), icon, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (box), label_widget, FALSE, FALSE, 0); - gtk_container_add (GTK_CONTAINER (mi), box); + mi = sexy_spell_entry_icon_menu_item (_("Spelling Suggestions"), icon_name); } #endif #if !HAVE_GTK3 + GtkWidget *icon; + icon = gtk_image_new_from_stock(GTK_STOCK_SPELL_CHECK, GTK_ICON_SIZE_MENU); mi = gtk_image_menu_item_new_with_label(_("Spelling Suggestions")); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), icon);