mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-26 07:08:05 +02:00
eeshow/gui/gui.c: move history list to history.c
This commit is contained in:
parent
4ae81be02a
commit
23fed29423
@ -15,7 +15,7 @@ OBJS = main.o \
|
||||
kicad/sch-parse.o kicad/sch-render.o kicad/lib-parse.o \
|
||||
kicad/lib-render.o kicad/dwg.o kicad/delta.o \
|
||||
gui/gui.o gui/over.o gui/style.o gui/aoi.o gui/fmt-pango.o gui/input.o \
|
||||
gui/progress.o gui/glabel.o gui/sheet.o \
|
||||
gui/progress.o gui/glabel.o gui/sheet.o gui/history.o \
|
||||
file/file.o file/git-util.o file/git-file.o file/git-hist.o \
|
||||
gfx/style.o gfx/fig.o gfx/record.o gfx/cro.o gfx/diff.o gfx/gfx.o \
|
||||
gfx/text.o gfx/misc.o \
|
||||
|
@ -121,6 +121,11 @@ void go_to_sheet(struct gui_ctx *ctx, struct gui_sheet *sheet);
|
||||
void do_revision_overlays(struct gui_ctx *ctx);
|
||||
void sheet_setup(struct gui_ctx *ctx);
|
||||
|
||||
/* history */
|
||||
|
||||
void hide_history(struct gui_ctx *ctx);
|
||||
void show_history(struct gui_ctx *ctx, enum selecting sel);
|
||||
|
||||
/* gui.c */
|
||||
|
||||
void redraw(const struct gui_ctx *ctx);
|
||||
@ -129,9 +134,6 @@ struct gui_sheet *find_corresponding_sheet(struct gui_sheet *pick_from,
|
||||
struct gui_sheet *ref_in, const struct gui_sheet *ref);
|
||||
void render_sheet(struct gui_sheet *sheet);
|
||||
void render_delta(struct gui_ctx *ctx);
|
||||
void hide_history(struct gui_ctx *ctx);
|
||||
void show_history(struct gui_ctx *ctx, enum selecting sel);
|
||||
void mark_aois(struct gui_ctx *ctx, struct gui_sheet *sheet);
|
||||
|
||||
|
||||
#endif /* !GUI_COMMON_H */
|
||||
|
217
eeshow/gui/gui.c
217
eeshow/gui/gui.c
@ -209,223 +209,6 @@ void eeschema_coord(const struct gui_ctx *ctx, int x, int y, int *rx, int *ry)
|
||||
}
|
||||
|
||||
|
||||
/* ----- Revision history -------------------------------------------------- */
|
||||
|
||||
|
||||
void hide_history(struct gui_ctx *ctx)
|
||||
{
|
||||
input_pop();
|
||||
|
||||
ctx->showing_history = 0;
|
||||
do_revision_overlays(ctx);
|
||||
redraw(ctx);
|
||||
}
|
||||
|
||||
|
||||
#define RGBA(r, g, b, a) ((struct color) { (r), (g), (b), (a) })
|
||||
#define COLOR(color) RGBA(color)
|
||||
|
||||
|
||||
static void set_history_style(struct gui_hist *h, bool current)
|
||||
{
|
||||
struct gui_ctx *ctx = h->ctx;
|
||||
struct overlay_style style = overlay_style_dense;
|
||||
const struct gui_hist *new = ctx->new_hist;
|
||||
const struct gui_hist *old = ctx->old_hist;
|
||||
|
||||
/* this is in addition to showing detailed content */
|
||||
if (current)
|
||||
style.width++;
|
||||
|
||||
switch (ctx->selecting) {
|
||||
case sel_only:
|
||||
style.frame = COLOR(FRAME_SEL_ONLY);
|
||||
break;
|
||||
case sel_old:
|
||||
style.frame = COLOR(FRAME_SEL_OLD);
|
||||
break;
|
||||
case sel_new:
|
||||
style.frame = COLOR(FRAME_SEL_NEW);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
if (ctx->new_hist == h || ctx->old_hist == h) {
|
||||
style.width++;
|
||||
style.font = BOLD_FONT;
|
||||
}
|
||||
if (ctx->old_hist) {
|
||||
if (h == new)
|
||||
style.bg = COLOR(BG_NEW);
|
||||
if (h == old)
|
||||
style.bg = COLOR(BG_OLD);
|
||||
}
|
||||
|
||||
if (h->identical)
|
||||
style.fg = RGBA(0.5, 0.5, 0.5, 1);
|
||||
if (!h->sheets)
|
||||
style.fg = RGBA(0.7, 0.0, 0.0, 1);
|
||||
|
||||
overlay_style(h->over, &style);
|
||||
}
|
||||
|
||||
|
||||
static bool hover_history(void *user, bool on)
|
||||
{
|
||||
struct gui_hist *h = user;
|
||||
struct gui_ctx *ctx = h->ctx;
|
||||
char *s;
|
||||
|
||||
if (on) {
|
||||
s = vcs_git_long_for_pango(h->vcs_hist, fmt_pango);
|
||||
overlay_text_raw(h->over, s);
|
||||
free(s);
|
||||
} else {
|
||||
overlay_text(h->over, "<small>%s</small>",
|
||||
vcs_git_summary(h->vcs_hist));
|
||||
}
|
||||
set_history_style(h, on);
|
||||
redraw(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void click_history(void *user)
|
||||
{
|
||||
struct gui_hist *h = user;
|
||||
struct gui_ctx *ctx = h->ctx;
|
||||
struct gui_sheet *sheet;
|
||||
|
||||
hide_history(ctx);
|
||||
|
||||
if (!h->sheets)
|
||||
return;
|
||||
|
||||
sheet = find_corresponding_sheet(h->sheets,
|
||||
ctx->new_hist->sheets, ctx->curr_sheet);
|
||||
|
||||
switch (ctx->selecting) {
|
||||
case sel_only:
|
||||
ctx->old_hist = ctx->new_hist;
|
||||
ctx->new_hist = h;
|
||||
break;
|
||||
case sel_new:
|
||||
ctx->new_hist = h;
|
||||
break;
|
||||
case sel_old:
|
||||
ctx->old_hist = h;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
if (ctx->new_hist->age > ctx->old_hist->age) {
|
||||
swap(ctx->new_hist, ctx->old_hist);
|
||||
if (ctx->selecting == sel_old)
|
||||
go_to_sheet(ctx, sheet);
|
||||
else
|
||||
render_delta(ctx);
|
||||
} else {
|
||||
if (ctx->selecting != sel_old)
|
||||
go_to_sheet(ctx, sheet);
|
||||
else
|
||||
render_delta(ctx);
|
||||
}
|
||||
|
||||
if (ctx->old_hist == ctx->new_hist)
|
||||
ctx->old_hist = NULL;
|
||||
|
||||
do_revision_overlays(ctx);
|
||||
redraw(ctx);
|
||||
}
|
||||
|
||||
|
||||
static void ignore_click(void *user)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static struct gui_hist *skip_history(struct gui_ctx *ctx, struct gui_hist *h)
|
||||
{
|
||||
struct overlay_style style = overlay_style_dense;
|
||||
unsigned n;
|
||||
|
||||
/* don't skip the first entry */
|
||||
if (h == ctx->hist)
|
||||
return h;
|
||||
|
||||
/* need at least two entries */
|
||||
if (!h->identical || !h->next || !h->next->identical)
|
||||
return h;
|
||||
|
||||
/* don't skip the last entry */
|
||||
for (n = 0; h->next && h->identical; h = h->next)
|
||||
n++;
|
||||
|
||||
h->over = overlay_add(&ctx->hist_overlays, &ctx->aois,
|
||||
NULL, ignore_click, h);
|
||||
overlay_text(h->over, "<small>%u commits without changes</small>", n);
|
||||
|
||||
style.width = 0;
|
||||
style.pad = 0;
|
||||
style.bg = RGBA(1.0, 1.0, 1.0, 0.8);
|
||||
overlay_style(h->over, &style);
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
static const struct input_ops history_input_ops;
|
||||
|
||||
|
||||
void show_history(struct gui_ctx *ctx, enum selecting sel)
|
||||
{
|
||||
struct gui_hist *h = ctx->hist;
|
||||
|
||||
input_push(&history_input_ops, ctx);
|
||||
|
||||
ctx->showing_history = 1;
|
||||
ctx->hist_y_offset = 0;
|
||||
ctx->selecting = sel;
|
||||
overlay_remove_all(&ctx->hist_overlays);
|
||||
for (h = ctx->hist; h; h = h->next) {
|
||||
h = skip_history(ctx, h);
|
||||
h->over = overlay_add(&ctx->hist_overlays, &ctx->aois,
|
||||
hover_history, click_history, h);
|
||||
hover_history(h, 0);
|
||||
set_history_style(h, 0);
|
||||
}
|
||||
redraw(ctx);
|
||||
}
|
||||
|
||||
|
||||
/* ----- Input: history ---------------------------------------------------- */
|
||||
|
||||
|
||||
static void history_drag_move(void *user, int dx, int dy)
|
||||
{
|
||||
struct gui_ctx *ctx = user;
|
||||
|
||||
ctx->hist_y_offset += dy;
|
||||
redraw(ctx);
|
||||
}
|
||||
|
||||
|
||||
/* @@@ under construction */
|
||||
|
||||
|
||||
static const struct input_ops history_input_ops = {
|
||||
.click = sheet_click,
|
||||
.hover_begin = sheet_hover_update,
|
||||
.hover_update = sheet_hover_update,
|
||||
.hover_click = sheet_click,
|
||||
.drag_begin = input_accept,
|
||||
.drag_move = history_drag_move,
|
||||
.key = sheet_key,
|
||||
};
|
||||
|
||||
|
||||
/* ----- AoI callbacks ----------------------------------------------------- */
|
||||
|
||||
|
||||
|
240
eeshow/gui/history.c
Normal file
240
eeshow/gui/history.c
Normal file
@ -0,0 +1,240 @@
|
||||
/*
|
||||
* gui/history.c - Revision history (navigation)
|
||||
*
|
||||
* Written 2016 by Werner Almesberger
|
||||
* Copyright 2016 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "misc/util.h"
|
||||
#include "file/git-hist.h"
|
||||
#include "gui/fmt-pango.h"
|
||||
#include "gui/style.h"
|
||||
#include "gui/aoi.h"
|
||||
#include "gui/over.h"
|
||||
#include "gui/input.h"
|
||||
#include "gui/common.h"
|
||||
|
||||
|
||||
void hide_history(struct gui_ctx *ctx)
|
||||
{
|
||||
input_pop();
|
||||
|
||||
ctx->showing_history = 0;
|
||||
do_revision_overlays(ctx);
|
||||
redraw(ctx);
|
||||
}
|
||||
|
||||
|
||||
#define RGBA(r, g, b, a) ((struct color) { (r), (g), (b), (a) })
|
||||
#define COLOR(color) RGBA(color)
|
||||
|
||||
|
||||
static void set_history_style(struct gui_hist *h, bool current)
|
||||
{
|
||||
struct gui_ctx *ctx = h->ctx;
|
||||
struct overlay_style style = overlay_style_dense;
|
||||
const struct gui_hist *new = ctx->new_hist;
|
||||
const struct gui_hist *old = ctx->old_hist;
|
||||
|
||||
/* this is in addition to showing detailed content */
|
||||
if (current)
|
||||
style.width++;
|
||||
|
||||
switch (ctx->selecting) {
|
||||
case sel_only:
|
||||
style.frame = COLOR(FRAME_SEL_ONLY);
|
||||
break;
|
||||
case sel_old:
|
||||
style.frame = COLOR(FRAME_SEL_OLD);
|
||||
break;
|
||||
case sel_new:
|
||||
style.frame = COLOR(FRAME_SEL_NEW);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
if (ctx->new_hist == h || ctx->old_hist == h) {
|
||||
style.width++;
|
||||
style.font = BOLD_FONT;
|
||||
}
|
||||
if (ctx->old_hist) {
|
||||
if (h == new)
|
||||
style.bg = COLOR(BG_NEW);
|
||||
if (h == old)
|
||||
style.bg = COLOR(BG_OLD);
|
||||
}
|
||||
|
||||
if (h->identical)
|
||||
style.fg = RGBA(0.5, 0.5, 0.5, 1);
|
||||
if (!h->sheets)
|
||||
style.fg = RGBA(0.7, 0.0, 0.0, 1);
|
||||
|
||||
overlay_style(h->over, &style);
|
||||
}
|
||||
|
||||
|
||||
static bool hover_history(void *user, bool on)
|
||||
{
|
||||
struct gui_hist *h = user;
|
||||
struct gui_ctx *ctx = h->ctx;
|
||||
char *s;
|
||||
|
||||
if (on) {
|
||||
s = vcs_git_long_for_pango(h->vcs_hist, fmt_pango);
|
||||
overlay_text_raw(h->over, s);
|
||||
free(s);
|
||||
} else {
|
||||
overlay_text(h->over, "<small>%s</small>",
|
||||
vcs_git_summary(h->vcs_hist));
|
||||
}
|
||||
set_history_style(h, on);
|
||||
redraw(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void click_history(void *user)
|
||||
{
|
||||
struct gui_hist *h = user;
|
||||
struct gui_ctx *ctx = h->ctx;
|
||||
struct gui_sheet *sheet;
|
||||
|
||||
hide_history(ctx);
|
||||
|
||||
if (!h->sheets)
|
||||
return;
|
||||
|
||||
sheet = find_corresponding_sheet(h->sheets,
|
||||
ctx->new_hist->sheets, ctx->curr_sheet);
|
||||
|
||||
switch (ctx->selecting) {
|
||||
case sel_only:
|
||||
ctx->old_hist = ctx->new_hist;
|
||||
ctx->new_hist = h;
|
||||
break;
|
||||
case sel_new:
|
||||
ctx->new_hist = h;
|
||||
break;
|
||||
case sel_old:
|
||||
ctx->old_hist = h;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
if (ctx->new_hist->age > ctx->old_hist->age) {
|
||||
swap(ctx->new_hist, ctx->old_hist);
|
||||
if (ctx->selecting == sel_old)
|
||||
go_to_sheet(ctx, sheet);
|
||||
else
|
||||
render_delta(ctx);
|
||||
} else {
|
||||
if (ctx->selecting != sel_old)
|
||||
go_to_sheet(ctx, sheet);
|
||||
else
|
||||
render_delta(ctx);
|
||||
}
|
||||
|
||||
if (ctx->old_hist == ctx->new_hist)
|
||||
ctx->old_hist = NULL;
|
||||
|
||||
do_revision_overlays(ctx);
|
||||
redraw(ctx);
|
||||
}
|
||||
|
||||
|
||||
static void ignore_click(void *user)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static struct gui_hist *skip_history(struct gui_ctx *ctx, struct gui_hist *h)
|
||||
{
|
||||
struct overlay_style style = overlay_style_dense;
|
||||
unsigned n;
|
||||
|
||||
/* don't skip the first entry */
|
||||
if (h == ctx->hist)
|
||||
return h;
|
||||
|
||||
/* need at least two entries */
|
||||
if (!h->identical || !h->next || !h->next->identical)
|
||||
return h;
|
||||
|
||||
/* don't skip the last entry */
|
||||
for (n = 0; h->next && h->identical; h = h->next)
|
||||
n++;
|
||||
|
||||
h->over = overlay_add(&ctx->hist_overlays, &ctx->aois,
|
||||
NULL, ignore_click, h);
|
||||
overlay_text(h->over, "<small>%u commits without changes</small>", n);
|
||||
|
||||
style.width = 0;
|
||||
style.pad = 0;
|
||||
style.bg = RGBA(1.0, 1.0, 1.0, 0.8);
|
||||
overlay_style(h->over, &style);
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
static const struct input_ops history_input_ops;
|
||||
|
||||
|
||||
void show_history(struct gui_ctx *ctx, enum selecting sel)
|
||||
{
|
||||
struct gui_hist *h = ctx->hist;
|
||||
|
||||
input_push(&history_input_ops, ctx);
|
||||
|
||||
ctx->showing_history = 1;
|
||||
ctx->hist_y_offset = 0;
|
||||
ctx->selecting = sel;
|
||||
overlay_remove_all(&ctx->hist_overlays);
|
||||
for (h = ctx->hist; h; h = h->next) {
|
||||
h = skip_history(ctx, h);
|
||||
h->over = overlay_add(&ctx->hist_overlays, &ctx->aois,
|
||||
hover_history, click_history, h);
|
||||
hover_history(h, 0);
|
||||
set_history_style(h, 0);
|
||||
}
|
||||
redraw(ctx);
|
||||
}
|
||||
|
||||
|
||||
/* ----- Input ------------------------------------------------------------- */
|
||||
|
||||
|
||||
static void history_drag_move(void *user, int dx, int dy)
|
||||
{
|
||||
struct gui_ctx *ctx = user;
|
||||
|
||||
ctx->hist_y_offset += dy;
|
||||
redraw(ctx);
|
||||
}
|
||||
|
||||
|
||||
/* @@@ under construction */
|
||||
|
||||
|
||||
static const struct input_ops history_input_ops = {
|
||||
.click = sheet_click,
|
||||
.hover_begin = sheet_hover_update,
|
||||
.hover_update = sheet_hover_update,
|
||||
.hover_click = sheet_click,
|
||||
.drag_begin = input_accept,
|
||||
.drag_move = history_drag_move,
|
||||
.key = sheet_key,
|
||||
};
|
Loading…
Reference in New Issue
Block a user