author | Lars Hjemli <hjemli@gmail.com> | 2006-12-28 01:01:49 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2006-12-28 01:01:49 (UTC) |
commit | e39d738c39d37cdef115c145027f3eec85a62272 (patch) (unidiff) | |
tree | be60a07674a0d118d42f572a35b62ada9529a6bd | |
parent | 27cd3b2a700e1cc46cd0393ddea48c07b62ee3a6 (diff) | |
download | cgit-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>
-rw-r--r-- | cgit.c | 4 | ||||
-rw-r--r-- | cgit.css | 5 | ||||
-rw-r--r-- | cgit.h | 4 | ||||
-rw-r--r-- | html.c | 10 | ||||
-rw-r--r-- | shared.c | 3 | ||||
-rw-r--r-- | ui-repolist.c | 2 | ||||
-rw-r--r-- | ui-shared.c | 28 |
7 files changed, 51 insertions, 5 deletions
@@ -17,5 +17,5 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
17 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 17 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); |
18 | cgit_print_docstart(title, item); | 18 | cgit_print_docstart(title, item); |
19 | cgit_print_pageheader(title); | 19 | cgit_print_pageheader(title, 0); |
20 | cgit_print_error(fmt("Unable to scan repository: %s", | 20 | cgit_print_error(fmt("Unable to scan repository: %s", |
21 | strerror(errno))); | 21 | strerror(errno))); |
@@ -26,5 +26,5 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
26 | char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); | 26 | char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); |
27 | cgit_print_docstart(title, item); | 27 | cgit_print_docstart(title, item); |
28 | cgit_print_pageheader(title); | 28 | cgit_print_pageheader(title, 0); |
29 | if (!cgit_query_page) { | 29 | if (!cgit_query_page) { |
30 | cgit_print_summary(); | 30 | cgit_print_summary(); |
@@ -62,4 +62,9 @@ div#header img#logo { | |||
62 | float: right; | 62 | float: right; |
63 | } | 63 | } |
64 | |||
65 | div#header input { | ||
66 | float: right; | ||
67 | margin: 0.25em 1em; | ||
68 | } | ||
64 | div#header a { | 69 | div#header a { |
65 | color: black; | 70 | color: black; |
@@ -56,4 +56,5 @@ extern char *cgit_querystring; | |||
56 | extern char *cgit_query_repo; | 56 | extern char *cgit_query_repo; |
57 | extern char *cgit_query_page; | 57 | extern char *cgit_query_page; |
58 | extern char *cgit_query_search; | ||
58 | extern char *cgit_query_head; | 59 | extern char *cgit_query_head; |
59 | extern char *cgit_query_sha1; | 60 | extern char *cgit_query_sha1; |
@@ -76,4 +77,5 @@ extern void html_txt(char *txt); | |||
76 | extern void html_ntxt(int len, char *txt); | 77 | extern void html_ntxt(int len, char *txt); |
77 | extern void html_attr(char *txt); | 78 | extern void html_attr(char *txt); |
79 | extern void html_hidden(char *name, char *value); | ||
78 | extern void html_link_open(char *url, char *title, char *class); | 80 | extern void html_link_open(char *url, char *title, char *class); |
79 | extern void html_link_close(void); | 81 | extern void html_link_close(void); |
@@ -99,5 +101,5 @@ extern void cgit_print_date(unsigned long secs); | |||
99 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 101 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
100 | extern void cgit_print_docend(); | 102 | extern void cgit_print_docend(); |
101 | extern void cgit_print_pageheader(char *title); | 103 | extern void cgit_print_pageheader(char *title, int show_search); |
102 | 104 | ||
103 | extern void cgit_print_repolist(struct cacheitem *item); | 105 | extern void cgit_print_repolist(struct cacheitem *item); |
@@ -118,4 +118,13 @@ void html_attr(char *txt) | |||
118 | } | 118 | } |
119 | 119 | ||
120 | void html_hidden(char *name, char *value) | ||
121 | { | ||
122 | html("<input type='hidden' name='"); | ||
123 | html_attr(name); | ||
124 | html("' value='"); | ||
125 | html_attr(value); | ||
126 | html("'/>"); | ||
127 | } | ||
128 | |||
120 | void html_link_open(char *url, char *title, char *class) | 129 | void html_link_open(char *url, char *title, char *class) |
121 | { | 130 | { |
@@ -156,2 +165,3 @@ void html_filemode(unsigned short mode) | |||
156 | html_fileperm(mode); | 165 | html_fileperm(mode); |
157 | } | 166 | } |
167 | |||
@@ -37,4 +37,5 @@ char *cgit_query_repo = NULL; | |||
37 | char *cgit_query_page = NULL; | 37 | char *cgit_query_page = NULL; |
38 | char *cgit_query_head = NULL; | 38 | char *cgit_query_head = NULL; |
39 | char *cgit_query_search = NULL; | ||
39 | char *cgit_query_sha1 = NULL; | 40 | char *cgit_query_sha1 = NULL; |
40 | char *cgit_query_sha2 = NULL; | 41 | char *cgit_query_sha2 = NULL; |
@@ -87,4 +88,6 @@ void cgit_querystring_cb(const char *name, const char *value) | |||
87 | } else if (!strcmp(name, "p")) { | 88 | } else if (!strcmp(name, "p")) { |
88 | cgit_query_page = xstrdup(value); | 89 | cgit_query_page = xstrdup(value); |
90 | } else if (!strcmp(name, "q")) { | ||
91 | cgit_query_search = xstrdup(value); | ||
89 | } else if (!strcmp(name, "h")) { | 92 | } else if (!strcmp(name, "h")) { |
90 | cgit_query_head = xstrdup(value); | 93 | 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) | |||
18 | chdir(cgit_root); | 18 | chdir(cgit_root); |
19 | cgit_print_docstart(cgit_root_title, item); | 19 | cgit_print_docstart(cgit_root_title, item); |
20 | cgit_print_pageheader(cgit_root_title); | 20 | cgit_print_pageheader(cgit_root_title, 0); |
21 | 21 | ||
22 | if (!(d = opendir("."))) { | 22 | 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, | |||
61 | } | 61 | } |
62 | 62 | ||
63 | char *cgit_currurl() | ||
64 | { | ||
65 | if (!cgit_virtual_root) | ||
66 | return "./cgit.cgi"; | ||
67 | else if (cgit_query_page) | ||
68 | return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); | ||
69 | else if (cgit_query_repo) | ||
70 | return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); | ||
71 | else | ||
72 | return fmt("%s/", cgit_virtual_root); | ||
73 | } | ||
74 | |||
63 | 75 | ||
64 | void cgit_print_date(unsigned long secs) | 76 | void cgit_print_date(unsigned long secs) |
@@ -99,5 +111,5 @@ void cgit_print_docend() | |||
99 | } | 111 | } |
100 | 112 | ||
101 | void cgit_print_pageheader(char *title) | 113 | void cgit_print_pageheader(char *title, int show_search) |
102 | { | 114 | { |
103 | html("<div id='header'>"); | 115 | html("<div id='header'>"); |
@@ -105,4 +117,18 @@ void cgit_print_pageheader(char *title) | |||
105 | htmlf("<img id='logo' src='%s'/>\n", cgit_logo); | 117 | htmlf("<img id='logo' src='%s'/>\n", cgit_logo); |
106 | htmlf("</a>"); | 118 | htmlf("</a>"); |
119 | if (show_search) { | ||
120 | html("<form method='get' href='"); | ||
121 | html_attr(cgit_currurl()); | ||
122 | html("'>"); | ||
123 | if (cgit_query_head) | ||
124 | html_hidden("h", cgit_query_head); | ||
125 | if (cgit_query_sha1) | ||
126 | html_hidden("id", cgit_query_sha1); | ||
127 | if (cgit_query_sha2) | ||
128 | html_hidden("id2", cgit_query_sha2); | ||
129 | html("<input type='text' name='q' value='"); | ||
130 | html_attr(cgit_query_search); | ||
131 | html("'/></form>"); | ||
132 | } | ||
107 | if (cgit_query_repo) | 133 | if (cgit_query_repo) |
108 | htmlf("<a href='%s'>", cgit_repourl(cgit_query_repo)); | 134 | htmlf("<a href='%s'>", cgit_repourl(cgit_query_repo)); |