menu.c (4169B)
1 /* 2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client 3 * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 #include <glib.h> 21 #include <glib/gi18n.h> 22 #include <gtk/gtk.h> 23 24 #include "menu.h" 25 #include "utils.h" 26 #include "gtkutils.h" 27 #include "defs.h" 28 29 GtkActionGroup *cm_menu_create_action_group(const gchar *name, GtkActionEntry *entries, 30 gint num_entries, gpointer data) 31 { 32 GtkActionGroup *group = gtk_action_group_new(name); 33 gtk_action_group_add_actions(group, entries, num_entries, data); 34 gtk_ui_manager_insert_action_group(gtkut_ui_manager(), group, 0); 35 return group; 36 } 37 38 GtkActionGroup *cm_menu_create_action_group_full(GtkUIManager *manager, const gchar *name, GtkActionEntry *entries, 39 gint num_entries, gpointer data) 40 { 41 GtkActionGroup *group = gtk_action_group_new(name); 42 gtk_action_group_add_actions(group, entries, num_entries, data); 43 gtk_ui_manager_insert_action_group(manager, group, 0); 44 return group; 45 } 46 47 void cm_menu_set_sensitive(gchar *menu, gboolean sensitive) 48 { 49 GtkUIManager *gui_manager = gtkut_ui_manager(); 50 gchar *path = g_strdup_printf("Menus/%s", menu); 51 52 cm_menu_set_sensitive_full(gui_manager, path, sensitive); 53 g_free(path); 54 } 55 56 void cm_toggle_menu_set_active(gchar *menu, gboolean active) 57 { 58 GtkUIManager *gui_manager = gtkut_ui_manager(); 59 gchar *path = g_strdup_printf("Menus/%s", menu); 60 61 cm_toggle_menu_set_active_full(gui_manager, path, active); 62 g_free(path); 63 } 64 65 void cm_menu_set_sensitive_full(GtkUIManager *gui_manager, const gchar *menu, gboolean sensitive) 66 { 67 GtkWidget *widget; 68 gchar *path = g_strdup_printf("/%s/", menu); 69 70 widget = gtk_ui_manager_get_widget(gui_manager, path); 71 if( !GTK_IS_WIDGET(widget) ) { 72 g_message("Blah, '%s' is not a widget.\n", path); 73 } 74 75 if( !GTK_IS_MENU_ITEM(widget) ) { 76 g_message("Blah, '%s' is not a menu item.\n", path); 77 } 78 79 gtk_widget_set_sensitive(widget, sensitive); 80 81 if (strcmp(menu, "Menus/SummaryViewPopup/Reedit") == 0) 82 (sensitive)? gtk_widget_show(widget) : gtk_widget_hide(widget); 83 84 g_free(path); 85 } 86 87 gchar *cm_menu_item_get_shortcut(GtkUIManager *gui_manager, gchar *menu) 88 { 89 GtkWidget *widget; 90 gchar *path = g_strdup_printf("/%s/", menu); 91 const gchar *accel = NULL; 92 GtkAccelKey key; 93 94 widget = gtk_ui_manager_get_widget(gui_manager, path); 95 if( !GTK_IS_WIDGET(widget) ) { 96 g_message("Blah, '%s' is not a widget.\n", path); 97 } 98 99 if( !GTK_IS_MENU_ITEM(widget) ) { 100 g_message("Blah, '%s' is not a menu item.\n", path); 101 } 102 103 g_free(path); 104 105 accel = gtk_menu_item_get_accel_path(GTK_MENU_ITEM(widget)); 106 107 if (accel && gtk_accel_map_lookup_entry(accel, &key)) 108 return gtk_accelerator_get_label (key.accel_key, key.accel_mods); 109 else 110 return g_strdup(_("None")); 111 112 } 113 114 void cm_toggle_menu_set_active_full(GtkUIManager *gui_manager, gchar *menu, gboolean active) 115 { 116 GtkWidget *widget; 117 gchar *path = g_strdup_printf("/%s/", menu); 118 119 widget = gtk_ui_manager_get_widget(gui_manager, path); 120 if( !GTK_IS_WIDGET(widget) ) { 121 g_message("Blah, '%s' is not a widget.\n", path); 122 } 123 124 if( !GTK_CHECK_MENU_ITEM(widget) ) { 125 g_message("Blah, '%s' is not a check menu item.\n", path); 126 } 127 128 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), active); 129 g_free(path); 130 } 131 132 void menu_set_sensitive_all(GtkMenuShell *menu_shell, gboolean sensitive) 133 { 134 GList *children = gtk_container_get_children(GTK_CONTAINER(menu_shell)); 135 GList *cur; 136 137 for (cur = children; cur != NULL; cur = cur->next) 138 gtk_widget_set_sensitive(GTK_WIDGET(cur->data), sensitive); 139 140 g_list_free(children); 141 }