From e39d738c39d37cdef115c145027f3eec85a62272 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Thu, 28 Dec 2006 02:01:49 +0100 Subject: Add generic support for search box in page header This adds the ability to show a search box in any pageheader with correct href and hidden form data, but does not enable the box on any pages. Signed-off-by: Lars Hjemli --- cgit.c | 4 ++-- cgit.css | 5 +++++ cgit.h | 4 +++- html.c | 10 ++++++++++ shared.c | 3 +++ ui-repolist.c | 2 +- ui-shared.c | 28 +++++++++++++++++++++++++++- 7 files changed, 51 insertions(+), 5 deletions(-) diff --git a/cgit.c b/cgit.c index ac43441..277b849 100644 --- a/cgit.c +++ b/cgit.c @@ -16,7 +16,7 @@ static void cgit_print_repo_page(struct cacheitem *item) cgit_read_config("info/cgit", cgit_repo_config_cb)) { char *title = fmt("%s - %s", cgit_root_title, "Bad request"); cgit_print_docstart(title, item); - cgit_print_pageheader(title); + cgit_print_pageheader(title, 0); cgit_print_error(fmt("Unable to scan repository: %s", strerror(errno))); cgit_print_docend(); @@ -25,7 +25,7 @@ static void cgit_print_repo_page(struct cacheitem *item) setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); cgit_print_docstart(title, item); - cgit_print_pageheader(title); + cgit_print_pageheader(title, 0); if (!cgit_query_page) { cgit_print_summary(); } else if (!strcmp(cgit_query_page, "log")) { diff --git a/cgit.css b/cgit.css index 459dca7..9112bfe 100644 --- a/cgit.css +++ b/cgit.css @@ -61,6 +61,11 @@ div#header { div#header img#logo { float: right; } + +div#header input { + float: right; + margin: 0.25em 1em; +} div#header a { color: black; } diff --git a/cgit.h b/cgit.h index 362b435..e114a50 100644 --- a/cgit.h +++ b/cgit.h @@ -55,6 +55,7 @@ extern int cgit_query_has_sha1; extern char *cgit_querystring; extern char *cgit_query_repo; extern char *cgit_query_page; +extern char *cgit_query_search; extern char *cgit_query_head; extern char *cgit_query_sha1; extern char *cgit_query_sha2; @@ -75,6 +76,7 @@ extern void htmlf(const char *format,...); extern void html_txt(char *txt); extern void html_ntxt(int len, char *txt); extern void html_attr(char *txt); +extern void html_hidden(char *name, char *value); extern void html_link_open(char *url, char *title, char *class); extern void html_link_close(void); extern void html_filemode(unsigned short mode); @@ -98,7 +100,7 @@ extern void cgit_print_error(char *msg); extern void cgit_print_date(unsigned long secs); extern void cgit_print_docstart(char *title, struct cacheitem *item); extern void cgit_print_docend(); -extern void cgit_print_pageheader(char *title); +extern void cgit_print_pageheader(char *title, int show_search); extern void cgit_print_repolist(struct cacheitem *item); extern void cgit_print_summary(); diff --git a/html.c b/html.c index 3a5d28d..c0b2ed4 100644 --- a/html.c +++ b/html.c @@ -117,6 +117,15 @@ void html_attr(char *txt) html(txt); } +void html_hidden(char *name, char *value) +{ + html(""); +} + void html_link_open(char *url, char *title, char *class) { html(""); htmlf("", cgit_logo_link); htmlf("\n", cgit_logo); htmlf(""); + if (show_search) { + html("
"); + if (cgit_query_head) + html_hidden("h", cgit_query_head); + if (cgit_query_sha1) + html_hidden("id", cgit_query_sha1); + if (cgit_query_sha2) + html_hidden("id2", cgit_query_sha2); + html("
"); + } if (cgit_query_repo) htmlf("", cgit_repourl(cgit_query_repo)); html_txt(title); -- cgit v1.2.3-57-g22cb