diff options
author | waker <wakeroid@gmail.com> | 2012-04-24 21:15:49 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2012-04-24 21:15:49 +0200 |
commit | 2bc3805d6b6d6fbcf3a8284f00ada82ce71fa909 (patch) | |
tree | 1049727bb8e8f56869ecbbe0afad117dc6406302 /plugins/gtkui/actions.c | |
parent | cb64b22d7206a534ebddbb961868b41449abe3bb (diff) |
gtkui: automatically reinit main menu on actions change
Diffstat (limited to 'plugins/gtkui/actions.c')
-rw-r--r-- | plugins/gtkui/actions.c | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/plugins/gtkui/actions.c b/plugins/gtkui/actions.c index f96caee4..1cb67d49 100644 --- a/plugins/gtkui/actions.c +++ b/plugins/gtkui/actions.c @@ -40,8 +40,38 @@ on_actionitem_activate (GtkMenuItem *menuitem, } void -add_mainmenu_actions (GtkWidget *mainwin) +remove_actions (GtkWidget *widget, void *data) { + if (GTK_IS_MENU_ITEM (widget)) { + const char *name = gtk_menu_item_get_label (GTK_MENU_ITEM (widget)); + } + const char *name = g_object_get_data (G_OBJECT (widget), "plugaction"); + if (name) { + gtk_container_remove (GTK_CONTAINER (data), widget); + } + if (GTK_IS_MENU_ITEM (widget)) { + GtkWidget *menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); + if (menu) { + gtk_container_foreach (GTK_CONTAINER (menu), remove_actions, menu); + // if menu is empty -- remove parent menu item + GList *lst = gtk_container_get_children (GTK_CONTAINER (menu)); + if (lst) { + g_list_free (lst); + } + else { + gtk_container_remove (data, widget); + } + } + } +} + +void +add_mainmenu_actions (void) { + GtkWidget *menubar = lookup_widget (mainwin, "menubar1"); + // remove all plugaction_*** menu items and empty submenus + gtk_container_foreach (GTK_CONTAINER (menubar), remove_actions, menubar); + + // add new DB_plugin_t **plugins = deadbeef->plug_get_list(); int i; @@ -76,7 +106,7 @@ add_mainmenu_actions (GtkWidget *mainwin) char *prev_title = NULL; - GtkWidget *current = lookup_widget (mainwin, "menubar1"); + GtkWidget *current = menubar; GtkWidget *previous; while (1) @@ -106,6 +136,7 @@ add_mainmenu_actions (GtkWidget *mainwin) g_signal_connect ((gpointer) actionitem, "activate", G_CALLBACK (on_actionitem_activate), action); + g_object_set_data_full (G_OBJECT (actionitem), "plugaction", strdup (action->name), free); break; } *slash = 0; @@ -130,7 +161,7 @@ add_mainmenu_actions (GtkWidget *mainwin) current = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (newitem), current); - GLADE_HOOKUP_OBJECT (mainwin, current, "Plugins_menu"); + GLADE_HOOKUP_OBJECT (mainwin, current, menuname); } prev_title = ptr; ptr = slash + 1; |