summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2006-12-28 01:01:49 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2006-12-28 01:01:49 (UTC)
commite39d738c39d37cdef115c145027f3eec85a62272 (patch) (side-by-side diff)
treebe60a07674a0d118d42f572a35b62ada9529a6bd
parent27cd3b2a700e1cc46cd0393ddea48c07b62ee3a6 (diff)
downloadcgit-e39d738c39d37cdef115c145027f3eec85a62272.zip
cgit-e39d738c39d37cdef115c145027f3eec85a62272.tar.gz
cgit-e39d738c39d37cdef115c145027f3eec85a62272.tar.bz2
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 <hjemli@gmail.com>
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--cgit.c4
-rw-r--r--cgit.css5
-rw-r--r--cgit.h4
-rw-r--r--html.c10
-rw-r--r--shared.c3
-rw-r--r--ui-repolist.c2
-rw-r--r--ui-shared.c28
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
@@ -17,5 +17,5 @@ static void cgit_print_repo_page(struct cacheitem *item)
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)));
@@ -26,5 +26,5 @@ static void cgit_print_repo_page(struct cacheitem *item)
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();
diff --git a/cgit.css b/cgit.css
index 459dca7..9112bfe 100644
--- a/cgit.css
+++ b/cgit.css
@@ -62,4 +62,9 @@ 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
@@ -56,4 +56,5 @@ 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;
@@ -76,4 +77,5 @@ 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);
@@ -99,5 +101,5 @@ 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);
diff --git a/html.c b/html.c
index 3a5d28d..c0b2ed4 100644
--- a/html.c
+++ b/html.c
@@ -118,4 +118,13 @@ void html_attr(char *txt)
}
+void html_hidden(char *name, char *value)
+{
+ html("<input type='hidden' name='");
+ html_attr(name);
+ html("' value='");
+ html_attr(value);
+ html("'/>");
+}
+
void html_link_open(char *url, char *title, char *class)
{
@@ -156,2 +165,3 @@ void html_filemode(unsigned short mode)
html_fileperm(mode);
}
+
diff --git a/shared.c b/shared.c
index 18b795b..7def51a 100644
--- a/shared.c
+++ b/shared.c
@@ -37,4 +37,5 @@ char *cgit_query_repo = NULL;
char *cgit_query_page = NULL;
char *cgit_query_head = NULL;
+char *cgit_query_search = NULL;
char *cgit_query_sha1 = NULL;
char *cgit_query_sha2 = NULL;
@@ -87,4 +88,6 @@ void cgit_querystring_cb(const char *name, const char *value)
} else if (!strcmp(name, "p")) {
cgit_query_page = xstrdup(value);
+ } else if (!strcmp(name, "q")) {
+ cgit_query_search = xstrdup(value);
} else if (!strcmp(name, "h")) {
cgit_query_head = xstrdup(value);
diff --git a/ui-repolist.c b/ui-repolist.c
index 7090c12..9f12b18 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -18,5 +18,5 @@ void cgit_print_repolist(struct cacheitem *item)
chdir(cgit_root);
cgit_print_docstart(cgit_root_title, item);
- cgit_print_pageheader(cgit_root_title);
+ cgit_print_pageheader(cgit_root_title, 0);
if (!(d = opendir("."))) {
diff --git a/ui-shared.c b/ui-shared.c
index 9ec4be8..b9c1243 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -61,4 +61,16 @@ char *cgit_pageurl(const char *reponame, const char *pagename,
}
+char *cgit_currurl()
+{
+ if (!cgit_virtual_root)
+ return "./cgit.cgi";
+ else if (cgit_query_page)
+ return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page);
+ else if (cgit_query_repo)
+ return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo);
+ else
+ return fmt("%s/", cgit_virtual_root);
+}
+
void cgit_print_date(unsigned long secs)
@@ -99,5 +111,5 @@ void cgit_print_docend()
}
-void cgit_print_pageheader(char *title)
+void cgit_print_pageheader(char *title, int show_search)
{
html("<div id='header'>");
@@ -105,4 +117,18 @@ void cgit_print_pageheader(char *title)
htmlf("<img id='logo' src='%s'/>\n", cgit_logo);
htmlf("</a>");
+ if (show_search) {
+ html("<form method='get' href='");
+ html_attr(cgit_currurl());
+ 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("<input type='text' name='q' value='");
+ html_attr(cgit_query_search);
+ html("'/></form>");
+ }
if (cgit_query_repo)
htmlf("<a href='%s'>", cgit_repourl(cgit_query_repo));