diff options
author | Elliot Lee <sopwith@src.gnome.org> | 2000-03-06 23:35:38 +0000 |
---|---|---|
committer | Elliot Lee <sopwith@src.gnome.org> | 2000-03-06 23:35:38 +0000 |
commit | ed306ab6668ccd1708d699e74cdc5ee511f707e4 (patch) | |
tree | 29b68077c533a9c21be6588b70e950e9fd1a2c03 /components | |
parent | 6da20678f62fab9d6dfef8b1e66ddc9aa57aa753 (diff) | |
download | nautilus-ed306ab6668ccd1708d699e74cdc5ee511f707e4.tar.gz |
Use help search instead of help index. Initial implementation completed.
* src/ntl-prefs.c: Use help search instead of help index.
* components/help/hyperbola-nav-search.c: Initial implementation completed.
Diffstat (limited to 'components')
-rw-r--r-- | components/help/Makefile.am | 3 | ||||
-rw-r--r-- | components/help/hyperbola-main.c | 4 | ||||
-rw-r--r-- | components/help/hyperbola-nav-search.c | 180 | ||||
-rw-r--r-- | components/help/hyperbola.goad | 6 |
4 files changed, 192 insertions, 1 deletions
diff --git a/components/help/Makefile.am b/components/help/Makefile.am index 85155af31..03e80cf90 100644 --- a/components/help/Makefile.am +++ b/components/help/Makefile.am @@ -12,7 +12,8 @@ hyperbola_SOURCES= \ hyperbola-main.c \ hyperbola-filefmt.c \ hyperbola-filefmt.h \ - hyperbola-nav-index.c + hyperbola-nav-index.c \ + hyperbola-nav-search.c EXTRA_DIST=pages.map hyperbola.goad diff --git a/components/help/hyperbola-main.c b/components/help/hyperbola-main.c index 248755715..19b88933f 100644 --- a/components/help/hyperbola-main.c +++ b/components/help/hyperbola-main.c @@ -7,6 +7,8 @@ extern BonoboObject *hyperbola_navigation_tree_new(void); /* in hyperbola-nav-index.c */ extern BonoboObject *hyperbola_navigation_index_new(void); +/* in hyperbola-nav-search.c */ +extern BonoboObject *hyperbola_navigation_search_new(void); static int object_count = 0; @@ -28,6 +30,8 @@ make_obj(BonoboGenericFactory *Factory, const char *goad_id, void *closure) retval = hyperbola_navigation_tree_new(); else if(!strcmp(goad_id, "hyperbola_navigation_index")) retval = hyperbola_navigation_index_new(); + else if(!strcmp(goad_id, "hyperbola_navigation_search")) + retval = hyperbola_navigation_search_new(); if(retval) { diff --git a/components/help/hyperbola-nav-search.c b/components/help/hyperbola-nav-search.c new file mode 100644 index 000000000..69d42db8f --- /dev/null +++ b/components/help/hyperbola-nav-search.c @@ -0,0 +1,180 @@ +#include <libnautilus/libnautilus.h> +#include <gnome.h> +#include "hyperbola-filefmt.h" +#include <gtk/gtk.h> +#include <string.h> +#include <limits.h> +#include <gnome-xml/parser.h> +#include <dirent.h> +#include <ctype.h> + +typedef struct { + NautilusViewFrame *view_frame; + + GtkWidget *clist, *ent; + + gint8 notify_count; +} HyperbolaNavigationSearch; + +static void +hyperbola_navigation_search_ent_changed(GtkWidget *ent, HyperbolaNavigationSearch *hns) +{ +} + +static void +hyperbola_navigation_search_ent_activate(GtkWidget *ent, HyperbolaNavigationSearch *hns) +{ + GString *query; + FILE *fh; + char *dir; + char *ctmp, *line; + + query = g_string_new(NULL); + + gtk_clist_freeze(GTK_CLIST(hns->clist)); + gtk_clist_clear(GTK_CLIST(hns->clist)); + + dir = gnome_datadir_file("gnome/help"); + g_string_sprintf(query, "sgrep -l '"); + + line = gtk_entry_get_text(GTK_ENTRY(hns->ent)); + while((ctmp = strtok(line, " \t"))) + { + g_string_sprintfa(query, "%sword(\"%s\")", line?"":" and ", ctmp); + line = NULL; + } + g_string_sprintfa(query, "' %s/*/*/*.sgml", dir); + g_free(dir); + + fh = popen(query->str, "r"); + g_string_free(query, TRUE); + + if(fh) + { + char aline[LINE_MAX]; + char uri[512], *uriptr; + GHashTable *uri_hash; + + uri_hash = g_hash_table_new(g_str_hash, g_str_equal); + + while(fgets(aline, sizeof(aline), fh)) + { + char *filename, *ctmp; + int len, rownum; + + if(strncmp(aline, "---", 3) != 0) /* Skip non match-info lines */ + continue; + + g_strstrip(aline); + filename = strtok(aline, " \t"); + if(!filename) + continue; + filename = strtok(NULL, " \t"); + if(!filename) + continue; + filename = strtok(NULL, " \t"); + if(!filename) + continue; + + len = strlen(filename); + if(filename[len-1] == ':') + filename[len-1] = '\0'; + + /* XXX lame! Should use gnome_file_locate eventually to figure out all possible prefixes. */ + ctmp = strstr(filename, "/help/"); + if(ctmp) + { + char **pieces; + + ctmp += strlen("/help/"); + + pieces = g_strsplit(ctmp, "/", -1); + + if(!pieces || !pieces[0] || !pieces[1] || !pieces[2] || pieces[3]) + ctmp = NULL; + else + { + ctmp = strrchr(pieces[2], '.'); + if(ctmp && !strcmp(ctmp, ".sgml")) + *ctmp = '\0'; + + g_snprintf(uri, sizeof(uri), "help:%s/%s", pieces[0], pieces[2]); + } + + g_strfreev(pieces); + } + + if(!ctmp) + g_snprintf(uri, sizeof(uri), "file://%s", filename); + + uriptr = g_hash_table_lookup(uri_hash, uri); + if(uriptr) + continue; + + uriptr = uri; + rownum = gtk_clist_append(GTK_CLIST(hns->clist), &uriptr); + if(gtk_clist_get_text(GTK_CLIST(hns->clist), rownum, 0, &uriptr)) + g_hash_table_insert(uri_hash, uriptr, uriptr); + } + + pclose(fh); + g_hash_table_destroy(uri_hash); + } + + gtk_clist_thaw(GTK_CLIST(hns->clist)); +} + +static void +hyperbola_navigation_search_select_row(GtkWidget *clist, gint row, gint column, GdkEvent *event, HyperbolaNavigationSearch *hns) +{ + Nautilus_NavigationRequestInfo loc; + char *uri; + + if(!event || event->type != GDK_2BUTTON_PRESS) /* we only care if the user has double-clicked on an item...? */ + return; + + if(gtk_clist_get_text(GTK_CLIST(clist), row, 0, &uri)) + return; + + memset(&loc, 0, sizeof(loc)); + loc.requested_uri = uri; + loc.new_window_default = loc.new_window_suggested = loc.new_window_enforced = Nautilus_V_UNKNOWN; + nautilus_view_frame_request_location_change(NAUTILUS_VIEW_FRAME(hns->view_frame), &loc); +} + +BonoboObject *hyperbola_navigation_search_new(void) +{ + HyperbolaNavigationSearch *hns; + GtkWidget *wtmp, *vbox; + + hns = g_new0(HyperbolaNavigationSearch, 1); + + vbox = gtk_vbox_new(FALSE, GNOME_PAD); + + hns->ent = gtk_entry_new(); + gtk_signal_connect(GTK_OBJECT(hns->ent), "changed", hyperbola_navigation_search_ent_changed, hns); + gtk_signal_connect(GTK_OBJECT(hns->ent), "activate", hyperbola_navigation_search_ent_activate, hns); + gtk_container_add(GTK_CONTAINER(vbox), hns->ent); + + hns->clist = gtk_clist_new(1); + gtk_clist_freeze(GTK_CLIST(hns->clist)); + gtk_clist_set_selection_mode(GTK_CLIST(hns->clist), GTK_SELECTION_BROWSE); + gtk_clist_set_column_widget(GTK_CLIST(hns->clist), 0, hns->ent); + gtk_signal_connect(GTK_OBJECT(hns->clist), "select_row", hyperbola_navigation_search_select_row, hns); + + wtmp = gtk_scrolled_window_new(gtk_clist_get_hadjustment(GTK_CLIST(hns->clist)), + gtk_clist_get_vadjustment(GTK_CLIST(hns->clist))); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(wtmp), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + + gtk_container_add(GTK_CONTAINER(wtmp), hns->clist); + gtk_container_add(GTK_CONTAINER(vbox), wtmp); + + gtk_clist_columns_autosize(GTK_CLIST(hns->clist)); + gtk_clist_thaw(GTK_CLIST(hns->clist)); + gtk_widget_show_all(vbox); + + hns->view_frame = NAUTILUS_VIEW_FRAME (nautilus_meta_view_frame_new (vbox)); + nautilus_meta_view_frame_set_label(NAUTILUS_META_VIEW_FRAME(hns->view_frame), _("Help Search")); + + return BONOBO_OBJECT (hns->view_frame); +} diff --git a/components/help/hyperbola.goad b/components/help/hyperbola.goad index aa6f4be18..cc58a860e 100644 --- a/components/help/hyperbola.goad +++ b/components/help/hyperbola.goad @@ -15,3 +15,9 @@ location_info=hyperbola_factory type=factory description=Help Index repo_ids=IDL:GNOME/Control:1.0 IDL:Nautilus/MetaView:1.0 IDL:Nautilus/View:1.0 + +[hyperbola_navigation_search] +location_info=hyperbola_factory +type=factory +description=Help Search +repo_ids=IDL:GNOME/Control:1.0 IDL:Nautilus/MetaView:1.0 IDL:Nautilus/View:1.0 |