1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-23 20:25:32 +02:00

eeshow/gui.c: replace ugly and fragile "prev" logic with a simple search

This commit is contained in:
Werner Almesberger 2016-08-04 08:49:54 -03:00
parent 258876ef2c
commit ff17f0e492

View File

@ -46,8 +46,6 @@ struct gui_sheet {
struct aoi *aois; /* areas of interest; in schematics coord */ struct aoi *aois; /* areas of interest; in schematics coord */
struct gui_sheet *prev; /* previous in stack */
struct gui_sheet *next; struct gui_sheet *next;
}; };
@ -216,6 +214,33 @@ static void zoom_to_extents(struct gui_ctx *ctx)
} }
/* ----- Navigate sheets --------------------------------------------------- */
static void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet)
{
ctx->curr_sheet = sheet;
overlay_remove_all(&ctx->overlays);
zoom_to_extents(ctx);
}
static bool go_up_sheet(struct gui_ctx *ctx)
{
struct gui_sheet *sheet;
const struct sch_obj *obj;
for (sheet = ctx->sheets; sheet; sheet = sheet->next)
for (obj = sheet->sch->objs; obj; obj = obj->next)
if (obj->type == sch_obj_sheet &&
obj->u.sheet.sheet == ctx->curr_sheet->sch) {
go_to_sheet(ctx, sheet);
return 1;
}
return 0;
}
/* ----- Event handlers ---------------------------------------------------- */ /* ----- Event handlers ---------------------------------------------------- */
@ -285,16 +310,6 @@ static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
} }
static void set_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet)
{
if (sheet->prev == sheet)
sheet->prev = NULL;
ctx->curr_sheet = sheet;
overlay_remove_all(&ctx->overlays);
zoom_to_extents(ctx);
}
static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event, static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
gpointer data) gpointer data)
{ {
@ -317,12 +332,11 @@ static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
break; break;
case GDK_KEY_Home: case GDK_KEY_Home:
if (sheet != ctx->sheets) if (sheet != ctx->sheets)
set_sheet(ctx, ctx->sheets); go_to_sheet(ctx, ctx->sheets);
break; break;
case GDK_KEY_BackSpace: case GDK_KEY_BackSpace:
case GDK_KEY_Delete: case GDK_KEY_Delete:
if (sheet->prev) go_up_sheet(ctx);
set_sheet(ctx, sheet->prev);
break; break;
case GDK_KEY_q: case GDK_KEY_q:
gtk_main_quit(); gtk_main_quit();
@ -373,10 +387,8 @@ struct sheet_aoi_ctx {
static void close_subsheet(void *user) static void close_subsheet(void *user)
{ {
struct gui_ctx *ctx = user; struct gui_ctx *ctx = user;
const struct gui_sheet *curr_sheet = ctx->curr_sheet;
if (curr_sheet->prev) go_up_sheet(ctx);
set_sheet(ctx, curr_sheet->prev);
} }
@ -391,8 +403,7 @@ static void select_subsheet(void *user)
if (sheet->sch == obj->u.sheet.sheet) { if (sheet->sch == obj->u.sheet.sheet) {
const char *name; const char *name;
sheet->prev = ctx->curr_sheet; go_to_sheet(ctx, sheet);
set_sheet(ctx, sheet);
name = sheet->sch->title ? sheet->sch->title : name = sheet->sch->title ? sheet->sch->title :
obj->u.sheet.name; obj->u.sheet.name;
overlay_add(&ctx->overlays, name, overlay_add(&ctx->overlays, name,
@ -452,7 +463,6 @@ static void get_sheets(struct gui_ctx *ctx, const struct sheet *sheets)
for (sheet = sheets; sheet; sheet = sheet->next) { for (sheet = sheets; sheet; sheet = sheet->next) {
gui_sheet = alloc_type(struct gui_sheet); gui_sheet = alloc_type(struct gui_sheet);
gui_sheet->sch = sheet; gui_sheet->sch = sheet;
gui_sheet->prev = NULL;
render(ctx, gui_sheet); render(ctx, gui_sheet);
mark_aois(ctx, gui_sheet); mark_aois(ctx, gui_sheet);