diff options
author | Richard Hult <rhult@codefactory.se> | 2002-10-29 10:25:28 +0000 |
---|---|---|
committer | Richard Hult <rhult@src.gnome.org> | 2002-10-29 10:25:28 +0000 |
commit | 8a7b83d894610412f77c9aff20104aa98c14c300 (patch) | |
tree | 6f9019e84ed117dea2fefe099f3b3187c075d0ef | |
parent | 0e55eadfefad0dfc87e3de38e3e4f6c29be363ab (diff) | |
download | yelp-8a7b83d894610412f77c9aff20104aa98c14c300.tar.gz |
Use the find dialog.
2002-10-29 Richard Hult <rhult@codefactory.se>
* src/yelp-window.c (window_find_response_cb)
(window_find_delete_event_cb, window_find_cb): Use the find
dialog.
* src/yelp-html-gtkhtml2.c (yelp_html_find): Implement find
forward.
* data/ui/yelp.glade: Steal galeons find dialog.
* configure.in: Add libglade dependency.
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | configure.in | 24 | ||||
-rw-r--r-- | data/Makefile.am | 2 | ||||
-rw-r--r-- | data/ui/.cvsignore | 2 | ||||
-rw-r--r-- | data/ui/Makefile.am | 7 | ||||
-rw-r--r-- | data/ui/yelp.glade | 335 | ||||
-rw-r--r-- | src/yelp-html-gtkhtml2.c | 104 | ||||
-rw-r--r-- | src/yelp-html.h | 9 | ||||
-rw-r--r-- | src/yelp-window.c | 137 |
9 files changed, 552 insertions, 81 deletions
@@ -1,3 +1,16 @@ +2002-10-29 Richard Hult <rhult@codefactory.se> + + * src/yelp-window.c (window_find_response_cb) + (window_find_delete_event_cb, window_find_cb): Use the find + dialog. + + * src/yelp-html-gtkhtml2.c (yelp_html_find): Implement find + forward. + + * data/ui/yelp.glade: Steal galeons find dialog. + + * configure.in: Add libglade dependency. + 2002-10-27 Richard Hult <rhult@codefactory.se> * src/yelp-pregenerate.c (main): Don't create GNodes with g_new, diff --git a/configure.in b/configure.in index 648f20ae..76722220 100644 --- a/configure.in +++ b/configure.in @@ -56,15 +56,22 @@ else fi AC_DEFINE_UNQUOTED(GNOMELOCALEDIR, "$GNOMELOCALEDIR") -PKG_CHECK_MODULES(DB2HTML, glib-2.0 >= 2.0.6 \ - libxslt >= 1.0.15) +PKG_CHECK_MODULES(DB2HTML, +[ + glib-2.0 >= 2.0.6 + libxslt >= 1.0.15 +]) -PKG_CHECK_MODULES(YELP, gnome-vfs-2.0 >= 1.1 \ - libgnome-2.0 >= 2.0.2 \ - libgnomeui-2.0 >= 1.103.0 \ - libbonobo-2.0 >= 1.108.0 \ - libxslt >= 1.0.15 \ - gconf-2.0) +PKG_CHECK_MODULES(YELP, +[ + gnome-vfs-2.0 >= 1.1 + libgnome-2.0 >= 2.0.2 + libgnomeui-2.0 >= 1.103.0 + libbonobo-2.0 >= 1.108.0 + libxslt >= 1.0.15 + libglade-2.0 >= 2.0.0 + gconf-2.0 +]) CFLAGS="$YELP_CFLAGS $CFLAGS" @@ -113,5 +120,6 @@ stylesheets/docbook/catalog stylesheets/docbook/dtd/Makefile data/Makefile data/images/Makefile +data/ui/Makefile po/Makefile.in ]) diff --git a/data/Makefile.am b/data/Makefile.am index a6356772..c3f1ae2f 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1 +1 @@ -SUBDIRS = images +SUBDIRS = images ui diff --git a/data/ui/.cvsignore b/data/ui/.cvsignore new file mode 100644 index 00000000..282522db --- /dev/null +++ b/data/ui/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/data/ui/Makefile.am b/data/ui/Makefile.am new file mode 100644 index 00000000..7d8034dc --- /dev/null +++ b/data/ui/Makefile.am @@ -0,0 +1,7 @@ +uidir = $(datadir)/yelp/ui + +ui_DATA = \ + yelp.glade + +EXTRA_DIST = \ + $(ui_DATA) diff --git a/data/ui/yelp.glade b/data/ui/yelp.glade new file mode 100644 index 00000000..12d5a6ee --- /dev/null +++ b/data/ui/yelp.glade @@ -0,0 +1,335 @@ +<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> +<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> + +<glade-interface> +<requires lib="gnome"/> + +<widget class="GtkDialog" id="find_dialog"> + <property name="border_width">4</property> + <property name="title" translatable="yes">Find text...</property> + <property name="type">GTK_WINDOW_TOPLEVEL</property> + <property name="window_position">GTK_WIN_POS_NONE</property> + <property name="modal">False</property> + <property name="resizable">True</property> + <property name="destroy_with_parent">False</property> + <property name="has_separator">False</property> + + <child internal-child="vbox"> + <widget class="GtkVBox" id="dialog-vbox4"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">0</property> + + <child internal-child="action_area"> + <widget class="GtkHButtonBox" id="dialog-action_area4"> + <property name="visible">True</property> + <property name="layout_style">GTK_BUTTONBOX_END</property> + + <child> + <widget class="GtkButton" id="close_button"> + <property name="visible">True</property> + <property name="can_default">True</property> + <property name="can_focus">True</property> + <property name="label">gtk-close</property> + <property name="use_stock">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="response_id">-7</property> + <signal name="clicked" handler="find_close_button_clicked_cb"/> + </widget> + </child> + + <child> + <widget class="GtkButton" id="prev_button"> + <property name="visible">True</property> + <property name="can_default">True</property> + <property name="can_focus">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="response_id">1</property> + <signal name="clicked" handler="find_prev_button_clicked_cb"/> + + <child> + <widget class="GtkAlignment" id="alignment7"> + <property name="visible">True</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xscale">0</property> + <property name="yscale">0</property> + + <child> + <widget class="GtkHBox" id="hbox85"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">2</property> + + <child> + <widget class="GtkImage" id="image5"> + <property name="visible">True</property> + <property name="stock">gtk-go-back</property> + <property name="icon_size">4</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkLabel" id="label1222"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Previous</property> + <property name="use_underline">True</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + </widget> + </child> + </widget> + </child> + </widget> + </child> + + <child> + <widget class="GtkButton" id="next_button"> + <property name="visible">True</property> + <property name="can_default">True</property> + <property name="has_default">True</property> + <property name="can_focus">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="response_id">2</property> + <signal name="clicked" handler="find_next_button_clicked_cb"/> + + <child> + <widget class="GtkAlignment" id="alignment6"> + <property name="visible">True</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xscale">0</property> + <property name="yscale">0</property> + + <child> + <widget class="GtkHBox" id="hbox84"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">2</property> + + <child> + <widget class="GtkImage" id="image4"> + <property name="visible">True</property> + <property name="stock">gtk-go-forward</property> + <property name="icon_size">4</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkLabel" id="label1221"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Next</property> + <property name="use_underline">True</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + </widget> + </child> + </widget> + </child> + </widget> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack_type">GTK_PACK_END</property> + </packing> + </child> + + <child> + <widget class="GtkVBox" id="vbox131"> + <property name="border_width">6</property> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">0</property> + + <child> + <widget class="GtkVBox" id="vbox109"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">6</property> + + <child> + <widget class="GtkHBox" id="hbox72"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">6</property> + + <child> + <widget class="GtkLabel" id="label63"> + <property name="visible">True</property> + <property name="label" translatable="yes"><b>Find text in the document:</b></property> + <property name="use_underline">False</property> + <property name="use_markup">True</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">7.45058e-09</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GnomeEntry" id="find_gnome_entry"> + <property name="visible">True</property> + <property name="history_id">FindEntry</property> + <property name="max_saved">10</property> + + <child internal-child="entry"> + <widget class="GtkEntry" id="find_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="has_focus">True</property> + <property name="editable">True</property> + <property name="visibility">True</property> + <property name="max_length">0</property> + <property name="text" translatable="yes"></property> + <property name="has_frame">True</property> + <property name="invisible_char" translatable="yes">*</property> + <property name="activates_default">False</property> + <signal name="activate" handler="find_entry_activate_cb"/> + <signal name="changed" handler="find_entry_changed_cb"/> + </widget> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkCheckButton" id="case_check"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">_Match upper/lower case</property> + <property name="use_underline">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="active">False</property> + <property name="inconsistent">False</property> + <property name="draw_indicator">True</property> + <signal name="toggled" handler="find_check_toggled_cb" last_modification_time="Wed, 03 Apr 2002 12:46:24 GMT"/> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkCheckButton" id="word_check"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">Match _entire word</property> + <property name="use_underline">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="active">False</property> + <property name="inconsistent">False</property> + <property name="draw_indicator">True</property> + <signal name="toggled" handler="find_check_toggled_cb" last_modification_time="Wed, 03 Apr 2002 12:46:34 GMT"/> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkCheckButton" id="wrap_check"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">Automatically _wrap around</property> + <property name="use_underline">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="active">False</property> + <property name="inconsistent">False</property> + <property name="draw_indicator">True</property> + <signal name="toggled" handler="find_check_toggled_cb" last_modification_time="Wed, 03 Apr 2002 12:47:04 GMT"/> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + </widget> + <packing> + <property name="padding">2</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + </widget> + </child> +</widget> + +</glade-interface> diff --git a/src/yelp-html-gtkhtml2.c b/src/yelp-html-gtkhtml2.c index ce610a78..26e01acb 100644 --- a/src/yelp-html-gtkhtml2.c +++ b/src/yelp-html-gtkhtml2.c @@ -31,6 +31,7 @@ #include <libgtkhtml/dom/traversal/dom-nodeiterator.h> #include <libgtkhtml/dom/traversal/dom-documenttraversal.h> #include <libgtkhtml/view/htmlselection.h> +#include <libgtkhtml/layout/htmlboxtext.h> #include <string.h> #include <stdio.h> @@ -49,7 +50,6 @@ struct _YelpHtmlPriv { HtmlDocument *doc; YelpURI *base_uri; - gchar *find_string; DomNodeIterator *find_iter; DomNode *find_node; gint find_offset; @@ -73,7 +73,7 @@ static void html_link_clicked_cb (HtmlDocument *doc, static void html_title_changed_cb (HtmlDocument *doc, const gchar *new_title, YelpHtml *html); - +static void html_clear_find_data (YelpHtml *html); #define BUFFER_SIZE 16384 @@ -182,10 +182,7 @@ html_url_requested_cb (HtmlDocument *doc, priv = html->priv; /* Reset find data when we load a new page. */ - if (priv->find_iter) { - g_object_unref (priv->find_iter); - priv->find_iter = NULL; - } + html_clear_find_data (html); html_stream_set_cancel_func (stream, html_cancel_stream, html); @@ -253,12 +250,9 @@ html_link_clicked_cb (HtmlDocument *doc, const gchar *url, YelpHtml *html) } } - /* Reset find data when link is clicked. */ - if (priv->find_iter) { - g_object_unref (priv->find_iter); - priv->find_iter = NULL; - } - + /* Reset find data when we load a new page. */ + html_clear_find_data (html); + g_signal_emit (html, signals[URI_SELECTED], 0, uri, handled); yelp_uri_unref (uri); @@ -389,28 +383,48 @@ yelp_html_get_widget (YelpHtml *html) return GTK_WIDGET (html->priv->view); } -/* Experimental find stuff. */ +static void +html_clear_find_data (YelpHtml *html) +{ + YelpHtmlPriv *priv; + + priv = html->priv; + + /* Reset find data when we load a new page. */ + if (priv->find_iter) { + g_object_unref (priv->find_iter); + priv->find_iter = NULL; + } +} void -yelp_html_find_next (YelpHtml *html) +yelp_html_find (YelpHtml *html, + const gchar *find_string, + gboolean match_case, + gboolean forward) { YelpHtmlPriv *priv; DomNode *root; DomNode *node; DomNodeIterator *iter; gchar *str; - gchar *tmp; gchar *hit; gchar *haystack; + HtmlBox *box; + gchar *box_text; + gint len; + g_return_if_fail (YELP_IS_HTML (html)); + g_return_if_fail (find_string != NULL); - priv = html->priv; - - if (!priv->find_string) { - priv->find_string = g_utf8_casefold ("e", -1); + if (!forward) { + /* FIXME: Implement find backwards. */ + return; } + priv = html->priv; + if (!priv->find_iter) { iter = dom_DocumentTraversal_createNodeIterator ( DOM_DOCUMENT_TRAVERSAL (priv->doc->dom_document), @@ -424,20 +438,15 @@ yelp_html_find_next (YelpHtml *html) while ((node = dom_NodeIterator_nextNode (iter, NULL))) { if (!g_ascii_strcasecmp (dom_Node__get_nodeName (node), "body")) { root = node; - /*str = dom_Node__get_nodeName (node); - g_free (str);*/ break; } - - /*str = dom_Node__get_nodeName (node); - g_free (str);*/ } g_object_unref (iter); iter = NULL; if (!root) { - g_warning ("No body!\n"); + g_warning ("html_find(): Couldn't find html body."); return; } @@ -454,38 +463,51 @@ yelp_html_find_next (YelpHtml *html) } while (priv->find_node) { - str = dom_Node__get_nodeValue (priv->find_node, NULL); - tmp = str + priv->find_offset; - haystack = g_utf8_casefold (tmp, -1); + box = html_view_find_layout_box (priv->view, priv->find_node, FALSE); + + /* We get the text from the layout box instead from the DOM node + * directly, since the text in the box is canonicalized + * (whitespace stripped in places etc. + */ + box_text = html_box_text_get_text (HTML_BOX_TEXT (box), &len); + if (len) { + str = g_new (gchar, len + 1); + memcpy (str, box_text, sizeof (gchar) * len); + str[len] = 0; + } else { + str = g_strdup (""); + } + + if (!match_case) { + haystack = g_utf8_casefold (str + priv->find_offset, len - priv->find_offset); + } else { + haystack = g_strdup (str + priv->find_offset); + } - g_strstrip (haystack); - g_print (">>> '%s'\n", tmp); + g_free (str); - hit = strstr (haystack, priv->find_string); + hit = strstr (haystack, find_string); if (hit) { html_selection_set (priv->view, priv->find_node, hit - haystack + priv->find_offset, - strlen (priv->find_string)); + strlen (find_string)); priv->find_offset += hit - haystack; - g_print ("'%s', %d\n", hit, priv->find_offset); - html_view_scroll_to_node (priv->view, priv->find_node, HTML_VIEW_SCROLL_TO_TOP); - priv->find_offset++; - - g_free (str); - g_free (haystack); - break; + priv->find_offset += strlen (find_string); } - g_free (str); g_free (haystack); - + + if (hit) { + break; + } + priv->find_node = dom_NodeIterator_nextNode (priv->find_iter, NULL); priv->find_offset = 0; } diff --git a/src/yelp-html.h b/src/yelp-html.h index 9565cbb7..80c70d91 100644 --- a/src/yelp-html.h +++ b/src/yelp-html.h @@ -64,14 +64,17 @@ void yelp_html_clear (YelpHtml *html); void yelp_html_write (YelpHtml *html, const gchar *data, gint len); -void yelp_html_printf (YelpHtml *html, +void yelp_html_printf (YelpHtml *html, char *format, ...); void yelp_html_close (YelpHtml *html); -GtkWidget * yelp_html_get_widget (YelpHtml *html); +GtkWidget * yelp_html_get_widget (YelpHtml *html); -void yelp_html_find_next (YelpHtml *html); +void yelp_html_find (YelpHtml *html, + const gchar *str, + gboolean match_case, + gboolean forward); #endif /* __YELP_HTML_H__ */ diff --git a/src/yelp-window.c b/src/yelp-window.c index 39505a54..9df98dc6 100644 --- a/src/yelp-window.c +++ b/src/yelp-window.c @@ -33,6 +33,7 @@ #include <libgnome/gnome-i18n.h> #include <libgnome/gnome-url.h> #include <libgnome/gnome-program.h> +#include <glade/glade.h> #include <string.h> #include "yelp-error.h" #include "yelp-html.h" @@ -45,6 +46,8 @@ #include "yelp-window.h" #define d(x) +#define RESPONSE_PREV 1 +#define RESPONSE_NEXT 2 typedef enum { YELP_WINDOW_ACTION_BACK = 1, @@ -104,6 +107,11 @@ static void window_go_index_cb (gpointer data, static void window_about_cb (gpointer data, guint section, GtkWidget *widget); +static gboolean window_find_delete_event_cb (GtkWidget *widget, + gpointer user_data); +static void window_find_response_cb (GtkWidget *dialog , + gint response, + YelpWindow *window); static GtkWidget * window_create_toolbar (YelpWindow *window); static GdkPixbuf * window_load_icon (void); @@ -134,7 +142,9 @@ struct _YelpWindowPriv { YelpView *index_view; GtkWidget *find_dialog; - + GtkWidget *find_entry; + GtkWidget *case_checkbutton; + YelpHistory *history; GtkItemFactory *item_factory; @@ -145,14 +155,19 @@ struct _YelpWindowPriv { static GtkItemFactoryEntry menu_items[] = { {N_("/_File"), NULL, 0, 0, "<Branch>"}, - {N_("/File/_New window"), NULL, window_new_window_cb, 0, "<StockItem>", GTK_STOCK_NEW }, -/* {N_("/File/_Find in page..."), NULL, window_find_cb, 0, "<StockItem>", GTK_STOCK_FIND },*/ - {N_("/File/_Close window"), NULL, window_close_window_cb, 0, "<StockItem>", GTK_STOCK_CLOSE }, + {N_("/File/_New window"), NULL, window_new_window_cb, 0, "<StockItem>", GTK_STOCK_NEW }, + {N_("/File/_Close window"), NULL, window_close_window_cb, 0, "<StockItem>", GTK_STOCK_CLOSE }, + + {N_("/_Edit"), NULL, 0, 0, "<Branch>"}, + {N_("/Edit/_Find in page..."), NULL, window_find_cb, 0, "<StockItem>", GTK_STOCK_FIND }, +/* {N_("/Edit/_Find again"), NULL, window_find_again_cb, 0, "<StockItem>", GTK_STOCK_FIND },*/ + {N_("/_Go"), NULL, 0, 0, "<Branch>"}, {N_("/Go/_Back"), NULL, window_history_go_cb, YELP_WINDOW_ACTION_BACK, "<StockItem>", GTK_STOCK_GO_BACK }, {N_("/Go/_Forward"), NULL, window_history_go_cb, YELP_WINDOW_ACTION_FORWARD, "<StockItem>", GTK_STOCK_GO_FORWARD }, {N_("/Go/_Home"), NULL, window_go_home_cb, 0, "<StockItem>", GTK_STOCK_HOME }, {N_("/Go/_Index"), NULL, window_go_index_cb, 0, "<StockItem>", GTK_STOCK_INDEX }, + {N_("/_Help"), NULL, 0, 0, "<Branch>"}, {N_("/Help/_About"), NULL, window_about_cb, 0, "<StockItem>", GNOME_STOCK_ABOUT }, }; @@ -556,7 +571,7 @@ window_find_cb (gpointer data, guint section, GtkWidget *widget) { YelpWindow *window = data; YelpWindowPriv *priv; - YelpHtml *html; + GladeXML *glade; g_return_if_fail (YELP_IS_WINDOW (data)); @@ -564,33 +579,33 @@ window_find_cb (gpointer data, guint section, GtkWidget *widget) priv = window->priv; - /* To get rid of warning for now. */ - if (0) { - window_find_cb (data, section, widget); - } - - switch (gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook))) { - case PAGE_TOC_VIEW: - html = yelp_view_get_html (priv->toc_view); - break; - case PAGE_CONTENT_VIEW: - html = yelp_view_get_html (priv->content_view); - break; - case PAGE_INDEX_VIEW: - html = yelp_view_get_html (priv->index_view); - break; - default: - g_assert_not_reached (); - } - if (priv->find_dialog) { gtk_window_present (GTK_WINDOW (priv->find_dialog)); } else { - priv->find_dialog = NULL; - } + glade = glade_xml_new (DATADIR "/yelp/ui/yelp.glade", "find_dialog", NULL); + if (!glade) { + g_warning ("Couldn't find necessary glade file " DATADIR "/yelp/ui/yelp.glade"); + return; + } + + priv->find_dialog = glade_xml_get_widget (glade, "find_dialog"); + gtk_widget_show (priv->find_dialog); + + priv->find_entry = glade_xml_get_widget (glade, "find_entry"); + priv->case_checkbutton = glade_xml_get_widget (glade, "case_check"); - /* FIXME: Implement the dialog. */ - yelp_html_find_next (html); + g_signal_connect (priv->find_dialog, + "delete_event", + G_CALLBACK (window_find_delete_event_cb), + NULL); + + g_signal_connect (priv->find_dialog, + "response", + G_CALLBACK (window_find_response_cb), + window); + + g_object_unref (glade); + } } static void @@ -636,6 +651,72 @@ window_about_cb (gpointer data, guint section, GtkWidget *widget) gtk_widget_show (about); } +static gboolean +window_find_delete_event_cb (GtkWidget *widget, gpointer user_data) +{ + gtk_widget_hide (widget); + + return TRUE; +} + +static void +window_find_response_cb (GtkWidget *dialog , + gint response, + YelpWindow *window) +{ + YelpWindowPriv *priv; + YelpHtml *html; + const gchar *tmp; + gchar *str; + gboolean match_case; + + priv = window->priv; + + switch (gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook))) { + case PAGE_TOC_VIEW: + html = yelp_view_get_html (priv->toc_view); + break; + case PAGE_CONTENT_VIEW: + html = yelp_view_get_html (priv->content_view); + break; + case PAGE_INDEX_VIEW: + html = yelp_view_get_html (priv->index_view); + break; + default: + g_assert_not_reached (); + } + + switch (response) { + case GTK_RESPONSE_CLOSE: + gtk_widget_hide (dialog); + break; + + case RESPONSE_PREV: + case RESPONSE_NEXT: + tmp = gtk_entry_get_text (GTK_ENTRY (priv->find_entry)); + match_case = gtk_toggle_button_get_active ( + GTK_TOGGLE_BUTTON (priv->case_checkbutton)); + + if (!match_case) { + str = g_utf8_casefold (tmp, -1); + } else { + str = g_strdup (tmp); + } + + yelp_html_find (html, + str, + match_case, + response == RESPONSE_NEXT); + + g_free (str); + break; + + default: + break; + } + +} + static GtkWidget * window_create_toolbar (YelpWindow *window) { |