From 325a732e1c125c326002c9a22c76f4aab2b8f61c Mon Sep 17 00:00:00 2001 From: werner Date: Thu, 31 Dec 2009 16:13:49 +0000 Subject: [PATCH] One could add a new frame if a frame with an underscore as its name already existed, thus creating a structure that could be saved but no longer loaded. Likewise, one could add new variables/loops/columns if there was already one named "_", thus creating the same problem. - gui_frame.c (pop_up_frame): disable "Add frame" if we already have a frame named "_" - gui_frame.c (pop_up_frame): disable "Add variable" and "Add loop" if we already have a variable or loop named "_" - gui_frame.c (pop_up_single_var, pop_up_table_var): disable "Add column" if we already have a variable or loop named "_" git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5765 99fdad57-331a-0410-800a-d7fa5415bdb3 --- gui_frame.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/gui_frame.c b/gui_frame.c index 725341b..6bc634b 100644 --- a/gui_frame.c +++ b/gui_frame.c @@ -139,11 +139,52 @@ static GtkItemFactoryEntry popup_frame_entries[] = { }; +static gboolean can_add_frame(void) +{ + const struct frame *frame; + + for (frame = frames; frame; frame = frame->next) + if (frame->name && !strcmp(frame->name, "_")) + return FALSE; + return TRUE; +} + + +static gboolean can_add_var(const struct frame *frame) +{ + const struct table *table; + const struct var *var; + const struct loop *loop; + + for (table = frame->tables; table; table = table->next) + for (var = table->vars; var; var = var->next) + if (!strcmp(var->name, "_")) + return FALSE; + for (loop = frame->loops; loop; loop = loop->next) + if (!strcmp(loop->var.name, "_")) + return FALSE; + return TRUE; +} + + static void pop_up_frame(struct frame *frame, GdkEventButton *event) { + gboolean add_var; + gtk_widget_set_sensitive( gtk_item_factory_get_item(factory_frame, "/Delete frame"), frame != root_frame); + + gtk_widget_set_sensitive( + gtk_item_factory_get_item(factory_frame, "/Add frame"), + can_add_frame()); + + add_var = can_add_var(frame); + gtk_widget_set_sensitive( + gtk_item_factory_get_item(factory_frame, "/Add variable"), add_var); + gtk_widget_set_sensitive( + gtk_item_factory_get_item(factory_frame, "/Add loop"), add_var); + pop_up(popup_frame_widget, event, frame); } @@ -247,6 +288,9 @@ static GtkItemFactoryEntry popup_single_var_entries[] = { static void pop_up_single_var(struct var *var, GdkEventButton *event) { + gtk_widget_set_sensitive( + gtk_item_factory_get_item(factory_single_var, "/Add column"), + can_add_var(var->frame)); pop_up(popup_single_var_widget, event, var); } @@ -288,6 +332,9 @@ static void pop_up_table_var(struct var *var, GdkEventButton *event) gtk_widget_set_sensitive( gtk_item_factory_get_item(factory_table_var, "/Delete column"), var->table->vars->next != NULL); + gtk_widget_set_sensitive( + gtk_item_factory_get_item(factory_table_var, "/Add column"), + can_add_var(var->frame)); pop_up(popup_table_var_widget, event, var); } @@ -388,7 +435,7 @@ static void popup_del_loop(void) static GtkItemFactoryEntry popup_loop_var_entries[] = { - { "/Delete loop", NULL, popup_del_loop, 0, "" }, + { "/Delete loop", NULL, popup_del_loop, 0, "" }, { "/sep2", NULL, NULL, 0, "" }, { "/Close", NULL, NULL, 0, "" }, { NULL }