From 73389fba76766394f0fa11c9e48f68b5913099af Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 9 Jan 2015 00:57:36 -0300 Subject: [PATCH] sanitize show var/code handling; switch to enum for future changes --- gui.c | 20 ++++++++++++++------ gui.html | 2 +- gui_canvas.c | 14 ++++++-------- gui_frame.c | 17 +++++++++++------ gui_frame.h | 12 +++++++++--- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/gui.c b/gui.c index b4d2fb4..cc89ff9 100644 --- a/gui.c +++ b/gui.c @@ -1,8 +1,8 @@ /* * gui.c - Editor GUI core * - * Written 2009-2012 by Werner Almesberger - * Copyright 2009-2012 by Werner Almesberger + * Written 2009-2012, 2015 by Werner Almesberger + * Copyright 2009-2012, 2015 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -81,11 +81,16 @@ static void save_as_fpd(void) /* ----- view callbacks ---------------------------------------------------- */ -static void swap_var_code(void) +static void show_var(void) { - extern int show_vars; + sidebar = sidebar_var; + change_world(); +} - show_vars = !show_vars; + +static void show_code(void) +{ + sidebar = sidebar_code; change_world(); } @@ -111,7 +116,10 @@ static GtkItemFactoryEntry menu_entries[] = { { "/View/Zoom all", NULL, zoom_to_extents,0, "" }, { "/View/Zoom frame", NULL, zoom_to_frame, 0, "" }, { "/View/sep1", NULL, NULL, 0, "" }, - { "/View/Swap var&code",NULL, swap_var_code, 0, "" }, + { "/View/Show variables", + NULL, show_var, 0, "" }, + { "/View/Show code", NULL, show_code, 0, + "/View/Show variables" }, }; diff --git a/gui.html b/gui.html index 8f5207a..d6e976e 100644 --- a/gui.html +++ b/gui.html @@ -149,7 +149,7 @@ dimension is expected, or the removal of a variable that's still used somewhere.

If the location of the error is not obvious, the list of objects can be -shown by selecting "Swap var&code" from the View menu. The object +shown by selecting "Show code" from the View menu. The object in which the error occurred is shown in red. If the error occurred in a loop variable, the variable name is shown in red. diff --git a/gui_canvas.c b/gui_canvas.c index 7b65e93..75b3ae5 100644 --- a/gui_canvas.c +++ b/gui_canvas.c @@ -1,8 +1,8 @@ /* * gui_canvas.c - GUI, canvas * - * Written 2009, 2010, 2012 by Werner Almesberger - * Copyright 2009, 2010, 2012 by Werner Almesberger + * Written 2009, 2010, 2012, 2015 by Werner Almesberger + * Copyright 2009, 2010, 2012, 2015 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,6 +25,7 @@ #include "gui_tool.h" #include "gui.h" #include "gui_frame_drag.h" +#include "gui_frame.h" #include "gui_canvas.h" @@ -450,12 +451,9 @@ static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event, change_world(); break; case '/': -{ -/* @@@ find a better place for this */ -extern int show_vars; - show_vars = !show_vars; -change_world(); -} + sidebar = sidebar == sidebar_var ? sidebar_code : sidebar_var; + change_world(); + break; } return TRUE; } diff --git a/gui_frame.c b/gui_frame.c index e52425d..a4ec687 100644 --- a/gui_frame.c +++ b/gui_frame.c @@ -1,8 +1,8 @@ /* * gui_frame.c - GUI, frame window * - * Written 2009, 2010, 2012 by Werner Almesberger - * Copyright 2009, 2010, 2012 by Werner Almesberger + * Written 2009, 2010, 2012, 2015 by Werner Almesberger + * Copyright 2009, 2010, 2012, 2015 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +31,7 @@ #include "gui_frame.h" -int show_vars = 1; +enum sidebar sidebar = sidebar_var; /* ----- add elements, shared ---------------------------------------------- */ @@ -1851,21 +1851,26 @@ void build_frames(GtkWidget *vbox, int wrap_width) gtk_table_attach_defaults(GTK_TABLE(tab), refs, 1, 2, n*2+1, n*2+2); - if (show_vars) { + switch (sidebar) { + case sidebar_var: vars = build_vars(frame, wrap_width); gtk_table_attach_defaults(GTK_TABLE(tab), vars, 1, 2, n*2+2, n*2+3); dont_build_items(frame); - } else { + break; + case sidebar_code: items = build_items(frame); gtk_table_attach_defaults(GTK_TABLE(tab), items, 1, 2, n*2+2, n*2+3); + break; + default: + abort(); } n++; } - if (!show_vars) { + if (sidebar == sidebar_code) { meas = build_meas(frames); gtk_table_attach_defaults(GTK_TABLE(tab), meas, 1, 2, n*2+2, n*2+3); diff --git a/gui_frame.h b/gui_frame.h index 0b54f43..15d3270 100644 --- a/gui_frame.h +++ b/gui_frame.h @@ -1,8 +1,8 @@ /* * gui_frame.h - GUI, frame window * - * Written 2009, 2010, 2012 by Werner Almesberger - * Copyright 2009, 2010, 2012 by Werner Almesberger + * Written 2009, 2010, 2012, 2015 by Werner Almesberger + * Copyright 2009, 2010, 2012, 2015 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,13 @@ #include "obj.h" -extern int show_vars; +enum sidebar { + sidebar_var, /* show variables */ + sidebar_code, /* show code */ +}; + + +extern enum sidebar sidebar; void reselect_var(struct var *var);