Commit 63557d60 authored by Sébastien Wilmet's avatar Sébastien Wilmet

Search: use the new API for the regex replace errors

When a regex replace error occurs, the error icon with the tooltip is
added to the replace entry. The error icon is removed when the
replacement text changes. The new replacement text can still contain
errors, but it will be reported only when the user clicks again on the
replace button.

And when there is a replace error, the replace button is insensitive.
parent dcf7fb32
......@@ -404,6 +404,7 @@ do_replace (GeditReplaceDialog *dialog,
gchar *unescaped_replace_text;
GtkTextIter start;
GtkTextIter end;
GError *error = NULL;
doc = gedit_window_get_active_document (window);
......@@ -431,10 +432,17 @@ do_replace (GeditReplaceDialog *dialog,
&start,
&end,
unescaped_replace_text,
-1);
-1,
&error);
g_free (unescaped_replace_text);
if (error != NULL)
{
gedit_replace_dialog_set_replace_error (dialog, error->message);
g_error_free (error);
}
do_find (dialog, window);
}
......@@ -447,6 +455,7 @@ do_replace_all (GeditReplaceDialog *dialog,
const gchar *replace_entry_text;
gchar *unescaped_replace_text;
gint count;
GError *error = NULL;
doc = gedit_window_get_active_document (window);
......@@ -468,7 +477,10 @@ do_replace_all (GeditReplaceDialog *dialog,
unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_entry_text);
count = gtk_source_search_context_replace_all (search_context, unescaped_replace_text, -1);
count = gtk_source_search_context_replace_all (search_context,
unescaped_replace_text,
-1,
&error);
g_free (unescaped_replace_text);
......@@ -476,10 +488,16 @@ do_replace_all (GeditReplaceDialog *dialog,
{
text_found (window, count);
}
else
else if (error == NULL)
{
text_not_found (window, dialog);
}
if (error != NULL)
{
gedit_replace_dialog_set_replace_error (dialog, error->message);
g_error_free (error);
}
}
static void
......
......@@ -141,22 +141,29 @@ set_search_error (GeditReplaceDialog *dialog,
set_error (GTK_ENTRY (dialog->priv->search_text_entry), error_msg);
}
static void
set_replace_error (GeditReplaceDialog *dialog,
const gchar *error_msg)
void
gedit_replace_dialog_set_replace_error (GeditReplaceDialog *dialog,
const gchar *error_msg)
{
set_error (GTK_ENTRY (dialog->priv->replace_text_entry), error_msg);
}
static gboolean
has_replace_error (GeditReplaceDialog *dialog)
{
GIcon *icon = gtk_entry_get_icon_gicon (GTK_ENTRY (dialog->priv->replace_text_entry),
GTK_ENTRY_ICON_SECONDARY);
return icon != NULL;
}
static void
update_regex_error (GeditReplaceDialog *dialog)
{
GtkSourceSearchContext *search_context;
GError *regex_error;
GtkSourceRegexSearchState regex_state;
set_search_error (dialog, NULL);
set_replace_error (dialog, NULL);
search_context = get_search_context (dialog, dialog->priv->active_document);
......@@ -166,29 +173,12 @@ update_regex_error (GeditReplaceDialog *dialog)
}
regex_error = gtk_source_search_context_get_regex_error (search_context);
regex_state = gtk_source_search_context_get_regex_state (search_context);
if (regex_error == NULL)
if (regex_error != NULL)
{
return;
set_search_error (dialog, regex_error->message);
g_error_free (regex_error);
}
switch (regex_state)
{
case GTK_SOURCE_REGEX_SEARCH_COMPILATION_ERROR:
case GTK_SOURCE_REGEX_SEARCH_MATCHING_ERROR:
set_search_error (dialog, regex_error->message);
break;
case GTK_SOURCE_REGEX_SEARCH_REPLACE_ERROR:
set_replace_error (dialog, regex_error->message);
break;
default:
g_return_if_reached ();
}
g_error_free (regex_error);
}
static gboolean
......@@ -199,6 +189,16 @@ update_replace_response_sensitivity_cb (GeditReplaceDialog *dialog)
GtkTextIter end;
gint pos;
if (has_replace_error (dialog))
{
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
GEDIT_REPLACE_DIALOG_REPLACE_RESPONSE,
FALSE);
dialog->priv->idle_update_sensitivity_id = 0;
return G_SOURCE_REMOVE;
}
search_context = get_search_context (dialog, dialog->priv->active_document);
if (search_context == NULL)
......@@ -291,14 +291,18 @@ update_responses_sensitivity (GeditReplaceDialog *dialog)
regex_state = gtk_source_search_context_get_regex_state (search_context);
sensitive = (regex_state == GTK_SOURCE_REGEX_SEARCH_NO_ERROR ||
regex_state == GTK_SOURCE_REGEX_SEARCH_REPLACE_ERROR);
sensitive = regex_state == GTK_SOURCE_REGEX_SEARCH_NO_ERROR;
}
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
GEDIT_REPLACE_DIALOG_FIND_RESPONSE,
sensitive);
if (has_replace_error (dialog))
{
sensitive = FALSE;
}
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
GEDIT_REPLACE_DIALOG_REPLACE_ALL_RESPONSE,
sensitive);
......@@ -486,6 +490,15 @@ search_text_entry_changed (GtkEditable *editable,
update_responses_sensitivity (dialog);
}
static void
replace_text_entry_changed (GtkEditable *editable,
GeditReplaceDialog *dialog)
{
gedit_replace_dialog_set_replace_error (dialog, NULL);
update_responses_sensitivity (dialog);
}
/* TODO: move in gedit-document.c and share it with gedit-view-frame */
static gboolean
get_selected_text (GtkTextBuffer *doc,
......@@ -636,6 +649,11 @@ gedit_replace_dialog_init (GeditReplaceDialog *dlg)
G_CALLBACK (search_text_entry_changed),
dlg);
g_signal_connect (dlg->priv->replace_text_entry,
"changed",
G_CALLBACK (replace_text_entry_changed),
dlg);
dlg->priv->search_settings = gtk_source_search_settings_new ();
g_object_bind_property (dlg->priv->match_case_checkbutton, "active",
......
......@@ -97,6 +97,9 @@ const gchar *gedit_replace_dialog_get_replace_text (GeditReplaceDialog *dialog
gboolean gedit_replace_dialog_get_backwards (GeditReplaceDialog *dialog);
void gedit_replace_dialog_set_replace_error (GeditReplaceDialog *dialog,
const gchar *error_msg);
G_END_DECLS
#endif /* __GEDIT_REPLACE_DIALOG_H__ */
......
......@@ -701,7 +701,7 @@ change_all_cb (GeditSpellCheckerDialog *dlg,
gtk_source_search_context_set_highlight (search_context, FALSE);
gtk_source_search_context_replace_all (search_context, change, -1);
gtk_source_search_context_replace_all (search_context, change, -1, NULL);
update_current (doc, range->mw_start + g_utf8_strlen (change, -1));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment