Cancel 'typing' search when the entry loses its focus

This commit is contained in:
Christian Dywan 2009-02-22 15:36:41 +01:00
parent 0d1a1edaaa
commit 2347045245

View file

@ -1554,6 +1554,18 @@ _midori_browser_find (MidoriBrowser* browser,
midori_view_search_text (MIDORI_VIEW (view), text, case_sensitive, forward); midori_view_search_text (MIDORI_VIEW (view), text, case_sensitive, forward);
} }
static void
_midori_browser_find_done (MidoriBrowser* browser)
{
GtkWidget* view = midori_browser_get_current_tab (browser);
midori_view_unmark_text_matches (MIDORI_VIEW (view));
gtk_widget_hide (browser->find);
browser->find_typing = FALSE;
gtk_window_set_focus (GTK_WINDOW (browser),
gtk_bin_get_child (GTK_BIN (view)) ?
gtk_bin_get_child (GTK_BIN (view)) : view);
}
static void static void
_action_find_next_activate (GtkAction* action, _action_find_next_activate (GtkAction* action,
MidoriBrowser* browser) MidoriBrowser* browser)
@ -1562,13 +1574,23 @@ _action_find_next_activate (GtkAction* action,
} }
static void static void
midori_browser_find_text_changed (GtkWidget* entry, midori_browser_find_text_changed_cb (GtkWidget* entry,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
if (browser->find_typing) if (browser->find_typing)
_midori_browser_find (browser, TRUE); _midori_browser_find (browser, TRUE);
} }
static gboolean
midori_browser_find_text_focus_out_event_cb (GtkWidget* entry,
GdkEventFocus* event,
MidoriBrowser* browser)
{
if (browser->find_typing)
_midori_browser_find_done (browser);
return FALSE;
}
static void static void
_action_find_previous_activate (GtkAction* action, _action_find_previous_activate (GtkAction* action,
MidoriBrowser* browser) MidoriBrowser* browser)
@ -1595,13 +1617,7 @@ midori_browser_find_key_press_event_cb (GtkWidget* toolbar,
{ {
if (event->keyval == GDK_Escape) if (event->keyval == GDK_Escape)
{ {
GtkWidget* view = midori_browser_get_current_tab (browser); _midori_browser_find_done (browser);
midori_view_unmark_text_matches (MIDORI_VIEW (view));
gtk_widget_hide (toolbar);
browser->find_typing = FALSE;
gtk_window_set_focus (GTK_WINDOW (browser),
gtk_bin_get_child (GTK_BIN (view)) ?
gtk_bin_get_child (GTK_BIN (view)) : view);
return TRUE; return TRUE;
} }
@ -1612,14 +1628,7 @@ static void
midori_browser_find_button_close_clicked_cb (GtkWidget* widget, midori_browser_find_button_close_clicked_cb (GtkWidget* widget,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
GtkWidget* view; _midori_browser_find_done (browser);
gtk_widget_hide (browser->find);
browser->find_typing = FALSE;
view = midori_browser_get_current_tab (browser);
gtk_window_set_focus (GTK_WINDOW (browser),
gtk_bin_get_child (GTK_BIN (view)) ?
gtk_bin_get_child (GTK_BIN (view)) : view);
} }
static void static void
@ -3664,7 +3673,9 @@ midori_browser_init (MidoriBrowser* browser)
g_signal_connect (browser->find_text, "activate", g_signal_connect (browser->find_text, "activate",
G_CALLBACK (_action_find_next_activate), browser); G_CALLBACK (_action_find_next_activate), browser);
g_signal_connect (browser->find_text, "changed", g_signal_connect (browser->find_text, "changed",
G_CALLBACK (midori_browser_find_text_changed), browser); G_CALLBACK (midori_browser_find_text_changed_cb), browser);
g_signal_connect (browser->find_text, "focus-out-event",
G_CALLBACK (midori_browser_find_text_focus_out_event_cb), browser);
toolitem = gtk_tool_item_new (); toolitem = gtk_tool_item_new ();
gtk_container_add (GTK_CONTAINER (toolitem), browser->find_text); gtk_container_add (GTK_CONTAINER (toolitem), browser->find_text);
gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE); gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE);