Make Find work again, and disable it for source tabs

This commit is contained in:
Christian Dywan 2008-09-28 16:29:41 +02:00
parent 213ae2f74a
commit b41c13b8fa
3 changed files with 203 additions and 67 deletions

View file

@ -225,6 +225,8 @@ _midori_browser_update_interface (MidoriBrowser* browser)
midori_view_can_find (MIDORI_VIEW (view))); midori_view_can_find (MIDORI_VIEW (view)));
/* _action_set_sensitive (browser, "FindQuick", /* _action_set_sensitive (browser, "FindQuick",
midori_view_can_find (MIDORI_VIEW (view))); */ midori_view_can_find (MIDORI_VIEW (view))); */
gtk_widget_set_sensitive (GTK_WIDGET (browser->find_highlight),
midori_view_can_find (MIDORI_VIEW (view)));
action = gtk_action_group_get_action (browser->action_group, "ReloadStop"); action = gtk_action_group_get_action (browser->action_group, "ReloadStop");
if (!loading) if (!loading)
@ -632,6 +634,29 @@ midori_view_new_window_cb (GtkWidget* view,
g_signal_emit (browser, signals[NEW_WINDOW], 0, uri); g_signal_emit (browser, signals[NEW_WINDOW], 0, uri);
} }
static void
midori_view_search_text_cb (GtkWidget* view,
gboolean found,
MidoriBrowser* browser)
{
const gchar* text;
gboolean case_sensitive;
gboolean highlight;
if (GTK_WIDGET_VISIBLE (browser->find))
{
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (browser->find_text),
GTK_ICON_ENTRY_PRIMARY, (found) ? GTK_STOCK_FIND : GTK_STOCK_STOP);
text = gtk_entry_get_text (GTK_ENTRY (browser->find_text));
case_sensitive = gtk_toggle_tool_button_get_active (
GTK_TOGGLE_TOOL_BUTTON (browser->find_case));
midori_view_mark_text_matches (MIDORI_VIEW (view), text, case_sensitive);
highlight = gtk_toggle_tool_button_get_active (
GTK_TOGGLE_TOOL_BUTTON (browser->find_highlight));
midori_view_set_highlight_text_matches (MIDORI_VIEW (view), highlight);
}
}
static gboolean static gboolean
midori_browser_tab_destroy_cb (GtkWidget* widget, midori_browser_tab_destroy_cb (GtkWidget* widget,
MidoriBrowser* browser) MidoriBrowser* browser)
@ -723,6 +748,8 @@ _midori_browser_add_tab (MidoriBrowser* browser,
midori_view_new_tab_cb, browser, midori_view_new_tab_cb, browser,
"signal::new-window", "signal::new-window",
midori_view_new_window_cb, browser, midori_view_new_window_cb, browser,
"signal::search-text",
midori_view_search_text_cb, browser,
"signal::add-bookmark", "signal::add-bookmark",
midori_view_add_bookmark_cb, browser, midori_view_add_bookmark_cb, browser,
NULL); NULL);
@ -1235,56 +1262,16 @@ _action_select_all_activate (GtkAction* action,
} }
} }
static void
_midori_browser_tab_unmark_text_matches (MidoriBrowser* browser,
GtkWidget* widget)
{
if (WEBKIT_IS_WEB_VIEW (widget))
webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW (widget));
}
static gboolean
_midori_browser_tab_search_text (MidoriBrowser* browser,
GtkWidget* widget,
const gchar* text,
gboolean case_sensitive,
gboolean forward)
{
if (WEBKIT_IS_WEB_VIEW (widget))
return webkit_web_view_search_text (WEBKIT_WEB_VIEW (widget),
text, case_sensitive, forward, TRUE);
return FALSE;
}
static void
_midori_browser_tab_mark_text_matches (MidoriBrowser* browser,
GtkWidget* widget,
const gchar* text,
gboolean case_sensitive)
{
if (WEBKIT_IS_WEB_VIEW (widget))
webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (widget),
text, case_sensitive, 0);
}
static void
_midori_browser_tab_set_highlight_text_matches (MidoriBrowser* browser,
GtkWidget* widget,
gboolean highlight)
{
if (WEBKIT_IS_WEB_VIEW (widget))
webkit_web_view_set_highlight_text_matches (
WEBKIT_WEB_VIEW (widget), highlight);
}
static void static void
_action_find_activate (GtkAction* action, _action_find_activate (GtkAction* action,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
GtkWidget* view;
if (GTK_WIDGET_VISIBLE (browser->find)) if (GTK_WIDGET_VISIBLE (browser->find))
{ {
GtkWidget* widget = midori_browser_get_current_tab (browser); view = midori_browser_get_current_tab (browser);
_midori_browser_tab_unmark_text_matches (browser, widget); midori_view_unmark_text_matches (MIDORI_VIEW (view));
gtk_toggle_tool_button_set_active ( gtk_toggle_tool_button_set_active (
GTK_TOGGLE_TOOL_BUTTON (browser->find_highlight), FALSE); GTK_TOGGLE_TOOL_BUTTON (browser->find_highlight), FALSE);
gtk_widget_hide (browser->find); gtk_widget_hide (browser->find);
@ -1303,26 +1290,18 @@ static void
_midori_browser_find (MidoriBrowser* browser, _midori_browser_find (MidoriBrowser* browser,
gboolean forward) gboolean forward)
{ {
const gchar* text = gtk_entry_get_text (GTK_ENTRY (browser->find_text)); const gchar* text;
const gboolean case_sensitive = gtk_toggle_tool_button_get_active ( gboolean case_sensitive;
GtkWidget* view;
text = gtk_entry_get_text (GTK_ENTRY (browser->find_text));
case_sensitive = gtk_toggle_tool_button_get_active (
GTK_TOGGLE_TOOL_BUTTON (browser->find_case)); GTK_TOGGLE_TOOL_BUTTON (browser->find_case));
GtkWidget* widget = midori_browser_get_current_tab (browser); view = midori_browser_get_current_tab (browser);
if (GTK_WIDGET_VISIBLE (browser->find)) if (GTK_WIDGET_VISIBLE (browser->find))
_midori_browser_tab_unmark_text_matches (browser, widget); midori_view_unmark_text_matches (MIDORI_VIEW (view));
gboolean found = _midori_browser_tab_search_text (browser, widget, midori_view_search_text (MIDORI_VIEW (view), text, case_sensitive, forward);
text, case_sensitive, forward);
if (GTK_WIDGET_VISIBLE (browser->find))
{
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (browser->find_text),
GTK_ICON_ENTRY_PRIMARY,
(found) ? GTK_STOCK_FIND : GTK_STOCK_STOP);
_midori_browser_tab_mark_text_matches (browser, widget,
text, case_sensitive);
const gboolean highlight = gtk_toggle_tool_button_get_active (
GTK_TOGGLE_TOOL_BUTTON (browser->find_highlight));
_midori_browser_tab_set_highlight_text_matches (browser, widget,
highlight);
}
} }
static void static void
@ -1343,10 +1322,12 @@ static void
_find_highlight_toggled (GtkToggleToolButton* toolitem, _find_highlight_toggled (GtkToggleToolButton* toolitem,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
GtkWidget* widget = midori_browser_get_current_tab (browser); GtkWidget* view;
const gboolean highlight = gtk_toggle_tool_button_get_active (toolitem); gboolean highlight;
_midori_browser_tab_set_highlight_text_matches (browser, widget,
highlight); view = midori_browser_get_current_tab (browser);
highlight = gtk_toggle_tool_button_get_active (toolitem);
midori_view_set_highlight_text_matches (MIDORI_VIEW (view), highlight);
} }
static void static void

View file

@ -119,6 +119,7 @@ enum {
CONSOLE_MESSAGE, CONSOLE_MESSAGE,
NEW_TAB, NEW_TAB,
NEW_WINDOW, NEW_WINDOW,
SEARCH_TEXT,
ADD_BOOKMARK, ADD_BOOKMARK,
LAST_SIGNAL LAST_SIGNAL
@ -231,6 +232,17 @@ midori_view_class_init (MidoriViewClass* class)
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_STRING); G_TYPE_STRING);
signals[SEARCH_TEXT] = g_signal_new (
"search-text",
G_TYPE_FROM_CLASS (class),
(GSignalFlags)(G_SIGNAL_RUN_LAST),
0,
0,
NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
signals[ADD_BOOKMARK] = g_signal_new ( signals[ADD_BOOKMARK] = g_signal_new (
"add-bookmark", "add-bookmark",
G_TYPE_FROM_CLASS (class), G_TYPE_FROM_CLASS (class),
@ -385,7 +397,6 @@ float_to_str (gfloat in)
return out; return out;
} }
static void static void
send_command (MidoriView* view, send_command (MidoriView* view,
const gchar* command, const gchar* command,
@ -642,6 +653,16 @@ midori_view_new_window_cb (MidoriView* view,
send_command (view, "new-window", uri); send_command (view, "new-window", uri);
} }
static void
midori_view_search_text_cb (MidoriView* view,
gboolean found)
{
if (!midori_view_is_plug (view))
return;
send_command (view, "search-text", int_to_str (found));
}
static void static void
midori_view_add_bookmark_cb (MidoriView* view, midori_view_add_bookmark_cb (MidoriView* view,
const gchar* uri) const gchar* uri)
@ -708,6 +729,10 @@ receive_status (MidoriView* view,
{ {
g_signal_emit (view, signals[NEW_WINDOW], 0, &command[11]); g_signal_emit (view, signals[NEW_WINDOW], 0, &command[11]);
} }
else if (!strncmp (command, "search-text ", 12))
{
g_signal_emit (view, signals[SEARCH_TEXT], 0, atoi (&command[12]));
}
else if (!strncmp (command, "add-bookmark ", 13)) else if (!strncmp (command, "add-bookmark ", 13))
{ {
g_signal_emit (view, signals[ADD_BOOKMARK], 0, &command[13]); g_signal_emit (view, signals[ADD_BOOKMARK], 0, &command[13]);
@ -749,6 +774,18 @@ receive_command (MidoriView* view,
midori_view_go_forward (view); midori_view_go_forward (view);
else if (!strncmp (command, "print", 5)) else if (!strncmp (command, "print", 5))
midori_view_print (view); midori_view_print (view);
else if (!strncmp (command, "unmark-matches", 14))
midori_view_unmark_text_matches (view);
else if (!strncmp (command, "search-text ", 12))
/* (forward, case_sensitive, text) => (text, case_sensitive, forward) */
midori_view_search_text (view, &command[16],
atoi (&command[14]), atoi (&command[12]));
else if (!strncmp (command, "mark-matches ", 13))
/* (case_sensitive, text) => (text, case_sensitive) */
midori_view_mark_text_matches (view, &command[17],
atoi (&command[15]));
else if (!strncmp (command, "hl-matches ", 11))
midori_view_set_highlight_text_matches (view, atoi (&command[11]));
else if (!strncmp (command, "download-manager ", 17)) else if (!strncmp (command, "download-manager ", 17))
{ {
katze_assign (view->download_manager, g_strdup (&command[17])); katze_assign (view->download_manager, g_strdup (&command[17]));
@ -1520,6 +1557,8 @@ midori_view_init (MidoriView* view)
midori_view_new_tab_cb, NULL, midori_view_new_tab_cb, NULL,
"signal::new-window", "signal::new-window",
midori_view_new_window_cb, NULL, midori_view_new_window_cb, NULL,
"signal::search-text",
midori_view_search_text_cb, NULL,
"signal::add-bookmark", "signal::add-bookmark",
midori_view_add_bookmark_cb, NULL, midori_view_add_bookmark_cb, NULL,
NULL); NULL);
@ -2498,3 +2537,101 @@ midori_view_print (MidoriView* view)
webkit_web_view_execute_script ( webkit_web_view_execute_script (
WEBKIT_WEB_VIEW (view->web_view), "print();"); WEBKIT_WEB_VIEW (view->web_view), "print();");
} }
/**
* midori_view_unmark_text_matches
* @view: a #MidoriView
*
* Unmarks the text matches in the view.
**/
void
midori_view_unmark_text_matches (MidoriView* view)
{
g_return_if_fail (MIDORI_IS_VIEW (view));
if (midori_view_is_socket (view))
send_command (view, "unmark-matches", NULL);
else
webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW (view->web_view));
}
/**
* midori_view_search_text
* @view: a #MidoriView
* @text: a string
* @case_sensitive: case sensitivity
* @forward: whether to search forward
*
* Searches a text within the view.
**/
void
midori_view_search_text (MidoriView* view,
const gchar* text,
gboolean case_sensitive,
gboolean forward)
{
gchar* data;
g_return_if_fail (MIDORI_IS_VIEW (view));
if (midori_view_is_socket (view))
{
/* (text, case_sensitive, forward) => (forward, case_sensitive, text) */
data = g_strdup_printf ("%d %d %s", forward, case_sensitive, text);
send_command (view, "search-text", data);
g_free (data);
}
else
g_signal_emit (view, signals[SEARCH_TEXT], 0,
webkit_web_view_search_text (WEBKIT_WEB_VIEW (view->web_view),
text, case_sensitive, forward, TRUE));
}
/**
* midori_view_mark_text_matches
* @view: a #MidoriView
* @text: a string
* @case_sensitive: case sensitivity
*
* Marks all text matches within the view.
**/
void
midori_view_mark_text_matches (MidoriView* view,
const gchar* text,
gboolean case_sensitive)
{
gchar* data;
g_return_if_fail (MIDORI_IS_VIEW (view));
if (midori_view_is_socket (view))
{
/* (text, case_sensitive) => (case_sensitive, text) */
data = g_strdup_printf ("%d %s", case_sensitive, text);
send_command (view, "mark-matches", data);
g_free (data);
}
else
webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (view->web_view),
text, case_sensitive, 0);
}
/**
* midori_view_set_highlight_text_matches
* @view: a #MidoriView
* @highlight: whether to highlight matches
*
* Whether to highlight all matches within the view.
**/
void
midori_view_set_highlight_text_matches (MidoriView* view,
gboolean highlight)
{
g_return_if_fail (MIDORI_IS_VIEW (view));
if (midori_view_is_socket (view))
send_command (view, "hl-matches", int_to_str (highlight));
else
webkit_web_view_set_highlight_text_matches (
WEBKIT_WEB_VIEW (view->web_view), highlight);
}

View file

@ -156,6 +156,24 @@ midori_view_can_view_source (MidoriView* view);
gboolean gboolean
midori_view_can_find (MidoriView* view); midori_view_can_find (MidoriView* view);
void
midori_view_unmark_text_matches (MidoriView* view);
void
midori_view_search_text (MidoriView* view,
const gchar* text,
gboolean case_sensitive,
gboolean forward);
void
midori_view_mark_text_matches (MidoriView* view,
const gchar* text,
gboolean case_sensitive);
void
midori_view_set_highlight_text_matches (MidoriView* view,
gboolean highlight);
G_END_DECLS G_END_DECLS
#endif /* __MIDORI_VIEW_H__ */ #endif /* __MIDORI_VIEW_H__ */