From 24fd7e54c82294efa68ecae5dd9cb8a8986c04bf Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Thu, 10 Jun 2010 01:09:29 +0200 Subject: ui-shared: Teach "breadcrumb" navigation to path limit display beneath tab bar When a path limit is in effect, and displayed directly beneath the tab bar, it should offer breadcrumb navigation (like what the 'tree' page does), to allow changing the path limit easily. Implementing this requires a robust way to link back to the current page with a changed ctx->qry.path, but without losing track of the other query arguments. This is solved by adding the new cgit_self_link() function, which is then invoked repeatedly by the new cgit_print_path_crumbs() function while manipulating ctx->qry.path. Signed-off-by: Johan Herland Signed-off-by: Lars Hjemli --- ui-shared.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- ui-shared.h | 2 ++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index bc14e70..4fa506f 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -399,6 +399,64 @@ void cgit_stats_link(const char *name, const char *title, const char *class, reporevlink("stats", name, title, class, head, NULL, path); } +void cgit_self_link(char *name, const char *title, const char *class, + struct cgit_context *ctx) +{ + if (!strcmp(ctx->qry.page, "repolist")) + return cgit_index_link(name, title, class, ctx->qry.search, + ctx->qry.ofs); + else if (!strcmp(ctx->qry.page, "summary")) + return cgit_summary_link(name, title, class, ctx->qry.head); + else if (!strcmp(ctx->qry.page, "tag")) + return cgit_tag_link(name, title, class, ctx->qry.head, + ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); + else if (!strcmp(ctx->qry.page, "tree")) + return cgit_tree_link(name, title, class, ctx->qry.head, + ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, + ctx->qry.path); + else if (!strcmp(ctx->qry.page, "plain")) + return cgit_plain_link(name, title, class, ctx->qry.head, + ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, + ctx->qry.path); + else if (!strcmp(ctx->qry.page, "log")) + return cgit_log_link(name, title, class, ctx->qry.head, + ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, + ctx->qry.path, ctx->qry.ofs, + ctx->qry.grep, ctx->qry.search, + ctx->qry.showmsg); + else if (!strcmp(ctx->qry.page, "commit")) + return cgit_commit_link(name, title, class, ctx->qry.head, + ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, + ctx->qry.path, 0); + else if (!strcmp(ctx->qry.page, "patch")) + return cgit_patch_link(name, title, class, ctx->qry.head, + ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, + ctx->qry.path); + else if (!strcmp(ctx->qry.page, "refs")) + return cgit_refs_link(name, title, class, ctx->qry.head, + ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, + ctx->qry.path); + else if (!strcmp(ctx->qry.page, "snapshot")) + return cgit_snapshot_link(name, title, class, ctx->qry.head, + ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, + ctx->qry.path); + else if (!strcmp(ctx->qry.page, "diff")) + return cgit_diff_link(name, title, class, ctx->qry.head, + ctx->qry.sha1, ctx->qry.sha2, + ctx->qry.path, 0); + else if (!strcmp(ctx->qry.page, "stats")) + return cgit_stats_link(name, title, class, ctx->qry.head, + ctx->qry.path); + + /* Don't known how to make link for this page */ + repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path); + html(">"); + html_txt(name); + html(""); +} + void cgit_object_link(struct object *obj) { char *page, *shortrev, *fullrev, *name; @@ -650,6 +708,27 @@ static const char *hc(struct cgit_context *ctx, const char *page) return strcmp(ctx->qry.page, page) ? NULL : "active"; } +static void cgit_print_path_crumbs(struct cgit_context *ctx, char *path) +{ + char *old_path = ctx->qry.path; + char *p = path, *q, *end = path + strlen(path); + + ctx->qry.path = NULL; + cgit_self_link("root", NULL, NULL, ctx); + ctx->qry.path = p = path; + while (p < end) { + if (!(q = strchr(p, '/'))) + q = end; + *q = '\0'; + html_txt("/"); + cgit_self_link(p, NULL, NULL, ctx); + if (q < end) + *q = '/'; + p = q + 1; + } + ctx->qry.path = old_path; +} + static void print_header(struct cgit_context *ctx) { html("\n"); @@ -760,7 +839,7 @@ void cgit_print_pageheader(struct cgit_context *ctx) if (ctx->qry.vpath) { html("
"); html("path: "); - html_txt(ctx->qry.vpath); + cgit_print_path_crumbs(ctx, ctx->qry.vpath); html("
"); } html("
"); diff --git a/ui-shared.h b/ui-shared.h index 308c982..3df5464 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -46,6 +46,8 @@ extern void cgit_diff_link(const char *name, const char *title, extern void cgit_stats_link(const char *name, const char *title, const char *class, const char *head, const char *path); +extern void cgit_self_link(char *name, const char *title, + const char *class, struct cgit_context *ctx); extern void cgit_object_link(struct object *obj); extern void cgit_print_error(const char *msg); -- cgit