]> spindle.queued.net Git - midori/commitdiff
Allow Find Next and Find Previous when the findbox is hidden.
authorChristian Dywan <christian@twotoasts.de>
Wed, 9 Jan 2008 06:39:19 +0000 (07:39 +0100)
committerChristian Dywan <christian@twotoasts.de>
Wed, 9 Jan 2008 06:39:19 +0000 (07:39 +0100)
The find text should be preserved after hiding the findbox until
it is shown again. Refactor the find code for both directions.

src/browser.c

index f56ed0f5abc9c111f96559f653f6d5fe3572c289..ce9f9a44ad022694011bacd63f92f0647149b140 100644 (file)
@@ -115,7 +115,6 @@ void on_action_find_activate(GtkAction* action, CBrowser* browser)
     {
         GtkWidget* webView = get_nth_webView(-1, browser);
         webkit_web_view_unmark_text_matches(WEBKIT_WEB_VIEW(webView));
-        gtk_entry_set_text(GTK_ENTRY(browser->findbox_text), "");
         gtk_toggle_tool_button_set_active(
          GTK_TOGGLE_TOOL_BUTTON(browser->findbox_highlight), FALSE);
         gtk_widget_hide(browser->findbox);
@@ -125,53 +124,46 @@ void on_action_find_activate(GtkAction* action, CBrowser* browser)
         GtkWidget* icon = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
         sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(browser->findbox_text)
          , SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(icon));
+        gtk_entry_set_text(GTK_ENTRY(browser->findbox_text), "");
         gtk_widget_show(browser->findbox);
         gtk_widget_grab_focus(GTK_WIDGET(browser->findbox_text));
     }
 }
 
-void on_action_find_next_activate(GtkAction* action, CBrowser* browser)
+static void findbox_find(gboolean forward, CBrowser* browser)
 {
-    if(!GTK_WIDGET_VISIBLE(browser->findbox))
-        return;
     const gchar* text = gtk_entry_get_text(GTK_ENTRY(browser->findbox_text));
     const gboolean caseSensitive = gtk_toggle_tool_button_get_active(
      GTK_TOGGLE_TOOL_BUTTON(browser->findbox_case));
     GtkWidget* webView = get_nth_webView(-1, browser);
-    GtkWidget* icon;
-    webkit_web_view_unmark_text_matches(WEBKIT_WEB_VIEW(webView));
-    if(webkit_web_view_search_text(WEBKIT_WEB_VIEW(webView), text, caseSensitive, TRUE, TRUE))
-        icon = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
-    else
-        icon = gtk_image_new_from_stock(GTK_STOCK_STOP, GTK_ICON_SIZE_MENU);
-    sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(browser->findbox_text)
-     , SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(icon));
-    webkit_web_view_mark_text_matches(WEBKIT_WEB_VIEW(webView), text, caseSensitive, 0);
-    const gboolean highlight = gtk_toggle_tool_button_get_active(
-     GTK_TOGGLE_TOOL_BUTTON(browser->findbox_highlight));
-    webkit_web_view_set_highlight_text_matches(WEBKIT_WEB_VIEW(webView), highlight);
+    if(GTK_WIDGET_VISIBLE(browser->findbox))
+        webkit_web_view_unmark_text_matches(WEBKIT_WEB_VIEW(webView));
+    gboolean found = webkit_web_view_search_text(WEBKIT_WEB_VIEW(webView)
+     , text, caseSensitive, forward, TRUE);
+    if(GTK_WIDGET_VISIBLE(browser->findbox))
+    {
+        GtkWidget* icon;
+        if(found)
+            icon = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
+        else
+            icon = gtk_image_new_from_stock(GTK_STOCK_STOP, GTK_ICON_SIZE_MENU);
+        sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(browser->findbox_text)
+         , SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(icon));
+        webkit_web_view_mark_text_matches(WEBKIT_WEB_VIEW(webView), text, caseSensitive, 0);
+        const gboolean highlight = gtk_toggle_tool_button_get_active(
+         GTK_TOGGLE_TOOL_BUTTON(browser->findbox_highlight));
+        webkit_web_view_set_highlight_text_matches(WEBKIT_WEB_VIEW(webView), highlight);
+    }
+}
+
+void on_action_find_next_activate(GtkAction* action, CBrowser* browser)
+{
+    findbox_find(TRUE, browser);
 }
 
 void on_action_find_previous_activate(GtkAction* action, CBrowser* browser)
 {
-    if(!GTK_WIDGET_VISIBLE(browser->findbox))
-        return;
-    const gchar* text = gtk_entry_get_text(GTK_ENTRY(browser->findbox_text));
-    const gboolean caseSensitive = gtk_toggle_tool_button_get_active(
-     GTK_TOGGLE_TOOL_BUTTON(browser->findbox_case));
-    GtkWidget* webView = get_nth_webView(-1, browser);
-    webkit_web_view_unmark_text_matches(WEBKIT_WEB_VIEW(webView));
-    GtkWidget* icon;
-    if(webkit_web_view_search_text(WEBKIT_WEB_VIEW(webView), text, caseSensitive, FALSE, TRUE))
-        icon = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
-    else
-        icon = gtk_image_new_from_stock(GTK_STOCK_STOP, GTK_ICON_SIZE_MENU);
-    sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(browser->findbox_text)
-     , SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(icon));
-    webkit_web_view_mark_text_matches(WEBKIT_WEB_VIEW(webView), text, caseSensitive, 0);
-    const gboolean highlight = gtk_toggle_tool_button_get_active(
-     GTK_TOGGLE_TOOL_BUTTON(browser->findbox_highlight));
-    webkit_web_view_set_highlight_text_matches(WEBKIT_WEB_VIEW(webView), highlight);
+    findbox_find(FALSE, browser);
 }
 
 void on_findbox_highlight_toggled(GtkToggleToolButton* toolitem, CBrowser* browser)
@@ -181,6 +173,11 @@ void on_findbox_highlight_toggled(GtkToggleToolButton* toolitem, CBrowser* brows
     webkit_web_view_set_highlight_text_matches(WEBKIT_WEB_VIEW(webView), highlight);
 }
 
+void on_findbox_button_close_clicked(GtkWidget* widget, CBrowser* browser)
+{
+    gtk_widget_hide(browser->findbox);
+}
+
 void on_action_preferences_activate(GtkAction* action, CBrowser* browser)
 {
     // Show the preferences dialog. Create it if necessary.
@@ -1051,11 +1048,6 @@ void on_notebook_switch_page(GtkWidget* widget, GtkNotebookPage* page
     update_search_engines(browser);
 }
 
-void on_findbox_button_close_clicked(GtkWidget* widget, CBrowser* browser)
-{
-    gtk_widget_hide(browser->findbox);
-}
-
 static void on_window_size_allocate(GtkWidget* widget, GtkAllocation* allocation
  , CBrowser* browser)
 {