From e3deb3978f9f4a0d22cf1427ffe8e323af344b1d Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 13 Jan 2015 21:54:59 -0300 Subject: [PATCH] update the menu bar (specifically, View > Show ...) after changes with "/" --- gui.c | 39 +++++++++++++++++++++++++++++++++------ gui.h | 3 +++ gui_canvas.c | 1 + 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/gui.c b/gui.c index 0e5053f..74792cc 100644 --- a/gui.c +++ b/gui.c @@ -11,6 +11,7 @@ */ +#include #include #include @@ -132,26 +133,52 @@ static GtkItemFactoryEntry menu_entries[] = { }; +static GtkItemFactory *menu_factory; + + static void make_menu_bar(GtkWidget *hbox) { - GtkItemFactory *factory; GtkWidget *bar; - factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "", NULL); - gtk_item_factory_create_items(factory, + menu_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "", + NULL); + gtk_item_factory_create_items(menu_factory, sizeof(menu_entries)/sizeof(*menu_entries), menu_entries, NULL); - bar = gtk_item_factory_get_widget(factory, ""); + bar = gtk_item_factory_get_widget(menu_factory, ""); gtk_box_pack_start(GTK_BOX(hbox), bar, TRUE, TRUE, 0); gtk_widget_set_sensitive( - gtk_item_factory_get_item(factory, "/File/Save"), !no_save); + gtk_item_factory_get_item(menu_factory, "/File/Save"), !no_save); gtk_widget_set_sensitive( - gtk_item_factory_get_item(factory, "/File/Reload"), + gtk_item_factory_get_item(menu_factory, "/File/Reload"), no_save && !!save_file_name); } +void update_menu_bar(void) +{ + const char *s; + + switch (sidebar) { + case sidebar_var: + s = "/View/Show variables"; + break; + case sidebar_code: + s = "/View/Show code"; + break; + case sidebar_pkg: + s = "/View/Show packages"; + break; + default: + abort(); + } + gtk_check_menu_item_set_active( + GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(menu_factory, s)), + TRUE); +} + + static gboolean toggle_all(GtkWidget *widget, GdkEventButton *event, gpointer data) { diff --git a/gui.h b/gui.h index 7f8f876..ab3939a 100644 --- a/gui.h +++ b/gui.h @@ -26,6 +26,9 @@ extern int show_bright; extern int no_save; +/* update the menu bar after configuration changes */ +void update_menu_bar(void); + /* update everything after a model change */ void change_world(void); diff --git a/gui_canvas.c b/gui_canvas.c index 332bd7c..9a989e6 100644 --- a/gui_canvas.c +++ b/gui_canvas.c @@ -452,6 +452,7 @@ static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event, break; case '/': sidebar = sidebar == sidebar_last ? 0 : sidebar + 1; + update_menu_bar(); change_world(); break; }