]> granicus.if.org Git - cgit/commitdiff
Add generic support for search box in page header
authorLars Hjemli <hjemli@gmail.com>
Thu, 28 Dec 2006 01:01:49 +0000 (02:01 +0100)
committerLars Hjemli <hjemli@gmail.com>
Thu, 28 Dec 2006 01:01:49 +0000 (02:01 +0100)
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>
cgit.c
cgit.css
cgit.h
html.c
shared.c
ui-repolist.c
ui-shared.c

diff --git a/cgit.c b/cgit.c
index ac434410a484d9f06c4bec3cf96c0af352c0a4eb..277b849465044815e9c023faa4dbc093861b1d1f 100644 (file)
--- 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")) {
index 459dca7472fb348cc269a6439252f17b0e812382..9112bfe23f75a9ab9f0ac167f88dca4833d613d2 100644 (file)
--- 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 362b43514a40f1befbcf781159ed1d02ddec032c..e114a50d6d569ad0303ecd33628c3ccdd85368ce 100644 (file)
--- 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 3a5d28d9f7a255320b05755f2e42bc5aec7e520d..c0b2ed48317957c6ce9c337542ac89c89ea88206 100644 (file)
--- 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("<input type='hidden' name='");
+       html_attr(name);
+       html("' value='");
+       html_attr(value);
+       html("'/>");
+}
+
 void html_link_open(char *url, char *title, char *class)
 {
        html("<a href='");
@@ -155,3 +164,4 @@ void html_filemode(unsigned short mode)
        html_fileperm(mode >> 3);
        html_fileperm(mode);
 }
+
index 18b795b6cdec641b6e429bf9ba4ca6a274567488..7def51a997beb49f5b302477beba9aee80aebfb2 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -36,6 +36,7 @@ char *cgit_querystring  = NULL;
 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;
 int   cgit_query_ofs    = 0;
@@ -86,6 +87,8 @@ void cgit_querystring_cb(const char *name, const char *value)
                cgit_query_repo = xstrdup(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);
                cgit_query_has_symref = 1;
index 7090c127c46b7edcaaaf04404cb464a34295f9ad..9f12b181b1982126ef8f72f3a971d96d646d565d 100644 (file)
@@ -17,7 +17,7 @@ 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("."))) {
                cgit_print_error(fmt("Unable to scan repository directory: %s",
index 9ec4be8661928e7412df78595e4048642c747f74..b9c124393741bb290de02a79f91292dd7a23bf3e 100644 (file)
@@ -60,6 +60,18 @@ 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)
 {
@@ -98,12 +110,26 @@ void cgit_print_docend()
        html("</body>\n</html>\n");
 }
 
-void cgit_print_pageheader(char *title)
+void cgit_print_pageheader(char *title, int show_search)
 {
        html("<div id='header'>");
        htmlf("<a href='%s'>", cgit_logo_link);
        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));
        html_txt(title);