]> spindle.queued.net Git - midori/commitdiff
Implement a primitive find-as-you-type
authorChristian Dywan <christian@twotoasts.de>
Sun, 22 Feb 2009 00:45:22 +0000 (01:45 +0100)
committerChristian Dywan <christian@twotoasts.de>
Sun, 22 Feb 2009 00:45:22 +0000 (01:45 +0100)
midori/marshal.list
midori/midori-browser.c
midori/midori-view.c

index 53e9849d5046638c2abe500af8182b8f097fc012..c82c563942f83c5ce9df36465d2bc661e5cf1087 100644 (file)
@@ -1,4 +1,5 @@
 BOOLEAN:VOID
+VOID:BOOLEAN,STRING
 VOID:OBJECT,ENUM
 VOID:STRING,BOOLEAN
 VOID:STRING,INT,STRING
index 85c15cd07a900d4d8017f612291b94beab7578a5..cdc316521dd86b30472f0867dcbef5730f0be20b 100644 (file)
@@ -855,12 +855,22 @@ midori_view_new_view_cb (GtkWidget*     view,
 static void
 midori_view_search_text_cb (GtkWidget*     view,
                             gboolean       found,
+                            gchar*         typing,
                             MidoriBrowser* browser)
 {
     const gchar* text;
     gboolean case_sensitive;
     gboolean highlight;
 
+    if (typing)
+    {
+        gint position = -1;
+
+        gtk_widget_show (browser->find);
+        gtk_window_set_focus (GTK_WINDOW (browser), browser->find_text);
+        gtk_editable_insert_text (GTK_EDITABLE (browser->find_text), typing, -1, &position);
+        gtk_editable_set_position (GTK_EDITABLE (browser->find_text), -1);
+    }
     if (GTK_WIDGET_VISIBLE (browser->find))
     {
         gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (browser->find_text),
index d49c0374d248ad7f1f31ccbadb1d86519bf67bf0..f029583dfcc6f7a1734ca5b72445c7dc3a7c0aa5 100644 (file)
@@ -275,6 +275,18 @@ midori_view_class_init (MidoriViewClass* class)
         MIDORI_TYPE_VIEW,
         MIDORI_TYPE_NEW_VIEW);
 
+    /**
+     * MidoriView::search-text:
+     * @view: the object on which the signal is emitted
+     * @found: whether the search was successful
+     * @typing: whether the search was initiated by typing
+     *
+     * Emitted when a search is performed. Either manually
+     * invoked or automatically by typing. The value of typing
+     * is actually the text the user typed.
+     *
+     * Note that in 0.1.3 the argument @typing was introduced.
+     */
     signals[SEARCH_TEXT] = g_signal_new (
         "search-text",
         G_TYPE_FROM_CLASS (class),
@@ -282,9 +294,10 @@ midori_view_class_init (MidoriViewClass* class)
         0,
         0,
         NULL,
-        g_cclosure_marshal_VOID__BOOLEAN,
-        G_TYPE_NONE, 1,
-        G_TYPE_BOOLEAN);
+        midori_cclosure_marshal_VOID__BOOLEAN_STRING,
+        G_TYPE_NONE, 2,
+        G_TYPE_BOOLEAN,
+        G_TYPE_STRING);
 
     signals[ADD_BOOKMARK] = g_signal_new (
         "add-bookmark",
@@ -794,6 +807,27 @@ gtk_widget_button_press_event_cb (WebKitWebView*  web_view,
     return FALSE;
 }
 
+static gboolean
+gtk_widget_key_press_event_cb (WebKitWebView* web_view,
+                               GdkEventKey*   event,
+                               MidoriView*    view)
+{
+    guint character = gdk_unicode_to_keyval (event->keyval);
+
+    if (!webkit_web_view_can_cut_clipboard (web_view)
+        && !webkit_web_view_can_paste_clipboard (web_view))
+    {
+        gchar* text = g_strdup_printf ("%c", character);
+
+        g_signal_emit (view, signals[SEARCH_TEXT], 0,
+        webkit_web_view_search_text (web_view,
+            text, FALSE, TRUE, TRUE), text);
+        g_free (text);
+    }
+
+    return FALSE;
+}
+
 static gboolean
 gtk_widget_scroll_event_cb (WebKitWebView*  web_view,
                             GdkEventScroll* event,
@@ -1541,6 +1575,8 @@ midori_view_construct_web_view (MidoriView* view)
                       webkit_web_view_hovering_over_link_cb, view,
                       "signal::button-press-event",
                       gtk_widget_button_press_event_cb, view,
+                      "signal::key-press-event",
+                      gtk_widget_key_press_event_cb, view,
                       "signal::scroll-event",
                       gtk_widget_scroll_event_cb, view,
                       "signal::populate-popup",
@@ -2434,7 +2470,7 @@ midori_view_search_text (MidoriView*  view,
 
     g_signal_emit (view, signals[SEARCH_TEXT], 0,
         webkit_web_view_search_text (WEBKIT_WEB_VIEW (view->web_view),
-            text, case_sensitive, forward, TRUE));
+            text, case_sensitive, forward, TRUE), NULL);
 }
 
 /**