mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-26 21:01:31 +02:00
eeshow/gui.c: add navigation in history
This commit is contained in:
parent
b067cf9a38
commit
acbce9a214
67
eeshow/gui.c
67
eeshow/gui.c
@ -52,6 +52,7 @@ struct gui_sheet {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct gui_hist {
|
struct gui_hist {
|
||||||
|
struct gui_ctx *ctx; /* back link */
|
||||||
struct hist *hist;
|
struct hist *hist;
|
||||||
struct gui_sheet *sheets; /* NULL if failed */
|
struct gui_sheet *sheets; /* NULL if failed */
|
||||||
struct gui_hist *next;
|
struct gui_hist *next;
|
||||||
@ -238,18 +239,67 @@ static void zoom_to_extents(struct gui_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ----- Need this for jumping around -------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
static void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet);
|
||||||
|
static bool go_up_sheet(struct gui_ctx *ctx);
|
||||||
|
|
||||||
|
|
||||||
/* ----- Revision history -------------------------------------------------- */
|
/* ----- Revision history -------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
static void hide_history(void *user)
|
static void hide_history(struct gui_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct gui_ctx *ctx = user;
|
|
||||||
|
|
||||||
overlay_remove_all(&ctx->vcs_overlays);
|
overlay_remove_all(&ctx->vcs_overlays);
|
||||||
redraw(ctx);
|
redraw(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static struct gui_sheet *find_corresponding_sheet(struct gui_ctx *ctx,
|
||||||
|
struct gui_sheet *sheets)
|
||||||
|
{
|
||||||
|
struct gui_sheet *sheet, *plan_b;
|
||||||
|
const char *title = ctx->curr_sheet->sch->title;
|
||||||
|
|
||||||
|
/* plan A: try to find sheet with same name */
|
||||||
|
|
||||||
|
if (title)
|
||||||
|
for (sheet = sheets; sheet; sheet = sheet->next)
|
||||||
|
if (sheet->sch->title &&
|
||||||
|
!strcmp(title, sheet->sch->title))
|
||||||
|
return sheet;
|
||||||
|
|
||||||
|
/* plan B: use sheet in same position in sheet sequence */
|
||||||
|
|
||||||
|
plan_b = ctx->curr_hist->sheets;
|
||||||
|
for (sheet = sheets; sheet; sheet = sheet->next) {
|
||||||
|
if (plan_b == ctx->curr_sheet)
|
||||||
|
return sheet;
|
||||||
|
plan_b = plan_b->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* plan C: just go to the top */
|
||||||
|
return sheets;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void click_history(void *user)
|
||||||
|
{
|
||||||
|
struct gui_hist *h = user;
|
||||||
|
struct gui_ctx *ctx = h->ctx;
|
||||||
|
|
||||||
|
if (h->sheets && h != ctx->curr_hist) {
|
||||||
|
struct gui_sheet *sheet;
|
||||||
|
|
||||||
|
sheet = find_corresponding_sheet(ctx, h->sheets);
|
||||||
|
ctx->curr_hist = h;
|
||||||
|
go_to_sheet(ctx, sheet);
|
||||||
|
}
|
||||||
|
hide_history(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void show_history(struct gui_ctx *ctx)
|
static void show_history(struct gui_ctx *ctx)
|
||||||
{
|
{
|
||||||
struct gui_hist *h = ctx->hist;
|
struct gui_hist *h = ctx->hist;
|
||||||
@ -260,7 +310,7 @@ static void show_history(struct gui_ctx *ctx)
|
|||||||
// @@@ \n doesn't work with cairo_show_text :-(
|
// @@@ \n doesn't work with cairo_show_text :-(
|
||||||
if (asprintf(&s, "commit\n%s", vcs_git_summary(h->hist))) {}
|
if (asprintf(&s, "commit\n%s", vcs_git_summary(h->hist))) {}
|
||||||
overlay_add(&ctx->vcs_overlays, s, &ctx->aois,
|
overlay_add(&ctx->vcs_overlays, s, &ctx->aois,
|
||||||
NULL, hide_history, ctx);
|
NULL, click_history, h);
|
||||||
}
|
}
|
||||||
redraw(ctx);
|
redraw(ctx);
|
||||||
}
|
}
|
||||||
@ -277,9 +327,6 @@ static void show_history_cb(void *user)
|
|||||||
/* ----- Navigate sheets --------------------------------------------------- */
|
/* ----- Navigate sheets --------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
static bool go_up_sheet(struct gui_ctx *ctx);
|
|
||||||
|
|
||||||
|
|
||||||
static void close_subsheet(void *user)
|
static void close_subsheet(void *user)
|
||||||
{
|
{
|
||||||
struct gui_ctx *ctx = user;
|
struct gui_ctx *ctx = user;
|
||||||
@ -295,7 +342,8 @@ static void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet)
|
|||||||
if (ctx->hist) {
|
if (ctx->hist) {
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
if (asprintf(&s, "%.40s", vcs_git_summary(ctx->hist->hist))) {}
|
if (asprintf(&s, "%.40s",
|
||||||
|
vcs_git_summary(ctx->curr_hist->hist))) {}
|
||||||
overlay_add(&ctx->sheet_overlays, s, &ctx->aois,
|
overlay_add(&ctx->sheet_overlays, s, &ctx->aois,
|
||||||
NULL, show_history_cb, ctx);
|
NULL, show_history_cb, ctx);
|
||||||
}
|
}
|
||||||
@ -649,6 +697,7 @@ if (!ahc->limit)
|
|||||||
ahc->limit--;
|
ahc->limit--;
|
||||||
for (anchor = &ctx->hist; *anchor; anchor = &(*anchor)->next);
|
for (anchor = &ctx->hist; *anchor; anchor = &(*anchor)->next);
|
||||||
*anchor = alloc_type(struct gui_hist);
|
*anchor = alloc_type(struct gui_hist);
|
||||||
|
(*anchor)->ctx = ctx;
|
||||||
(*anchor)->hist = h;
|
(*anchor)->hist = h;
|
||||||
sch = parse_sheets(h, ahc->n_args, ahc->args, ahc->recurse);
|
sch = parse_sheets(h, ahc->n_args, ahc->args, ahc->recurse);
|
||||||
(*anchor)->sheets = sch ? get_sheets(ctx, sch) : NULL;
|
(*anchor)->sheets = sch ? get_sheets(ctx, sch) : NULL;
|
||||||
@ -665,7 +714,7 @@ static void get_revisions(struct gui_ctx *ctx,
|
|||||||
.n_args = n_args,
|
.n_args = n_args,
|
||||||
.args = args,
|
.args = args,
|
||||||
.recurse = recurse,
|
.recurse = recurse,
|
||||||
.limit = 10,
|
.limit = 30,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!vcs_git_try(sch_name)) {
|
if (!vcs_git_try(sch_name)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user