[gtksourceview/wip/search] Add gtk_source_buffer_replace_search_match()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/search] Add gtk_source_buffer_replace_search_match()
- Date: Mon, 1 Jul 2013 15:15:24 +0000 (UTC)
commit 6dc84ed8337e9a07e2e4f89882a8ec6c6ff97a8a
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Jul 1 16:28:58 2013 +0200
Add gtk_source_buffer_replace_search_match()
gtksourceview/gtksourcebuffer.c | 33 ++++++++++++++++++++++
gtksourceview/gtksourcebuffer.h | 6 ++++
gtksourceview/gtksourcesearch.c | 58 +++++++++++++++++++++++++++++++++++++++
gtksourceview/gtksourcesearch.h | 7 +++++
4 files changed, 104 insertions(+), 0 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index aa42dd5..ef1889f 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -2887,3 +2887,36 @@ gtk_source_buffer_backward_search_finish (GtkSourceBuffer *buffer,
match_end,
error);
}
+
+/**
+ * gtk_source_buffer_replace_search_match:
+ * @buffer: a #GtkSourceBuffer.
+ * @match_start: the start of the match to replace, or %NULL.
+ * @match_end: the end of the match to replace, or %NULL.
+ * @replace: the replacement text.
+ * @replace_length: the length of @replace in bytes, or -1.
+ *
+ * Replaces a search match by another text. If @match_start and @match_end
+ * doesn't correspond to a search match, %FALSE is returned.
+ *
+ * If you pass %NULL to @match_start and @match_end, the selection bounds will
+ * be taken.
+ *
+ * Returns: whether the match has been replaced.
+ * Since: 3.10
+ */
+gboolean
+gtk_source_buffer_replace_search_match (GtkSourceBuffer *buffer,
+ const GtkTextIter *match_start,
+ const GtkTextIter *match_end,
+ const gchar *replace,
+ gint replace_length)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
+
+ return _gtk_source_search_replace (buffer->priv->search,
+ match_start,
+ match_end,
+ replace,
+ replace_length);
+}
diff --git a/gtksourceview/gtksourcebuffer.h b/gtksourceview/gtksourcebuffer.h
index 1589d38..c9a39a7 100644
--- a/gtksourceview/gtksourcebuffer.h
+++ b/gtksourceview/gtksourcebuffer.h
@@ -232,6 +232,12 @@ gboolean gtk_source_buffer_backward_search_finish
GtkTextIter *match_end,
GError **error);
+gboolean gtk_source_buffer_replace_search_match (GtkSourceBuffer *buffer,
+ const GtkTextIter *match_start,
+ const GtkTextIter *match_end,
+ const gchar *replace,
+ gint replace_length);
+
/* private */
void _gtk_source_buffer_update_highlight (GtkSourceBuffer *buffer,
const GtkTextIter *start,
diff --git a/gtksourceview/gtksourcesearch.c b/gtksourceview/gtksourcesearch.c
index e91fffe..d4c1393 100644
--- a/gtksourceview/gtksourcesearch.c
+++ b/gtksourceview/gtksourcesearch.c
@@ -1880,3 +1880,61 @@ _gtk_source_search_backward_finish (GtkSourceSearch *search,
match_end,
error);
}
+
+gboolean
+_gtk_source_search_replace (GtkSourceSearch *search,
+ const GtkTextIter *match_start,
+ const GtkTextIter *match_end,
+ const gchar *replace,
+ gint replace_length)
+{
+ GtkTextIter start;
+ GtkTextIter end;
+ GtkTextIter check_match_start;
+ GtkTextIter check_match_end;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_SEARCH (search), FALSE);
+
+ if (match_start != NULL)
+ {
+ start = *match_start;
+ }
+ else
+ {
+ gtk_text_buffer_get_selection_bounds (search->priv->buffer,
+ &start,
+ NULL);
+ }
+
+ if (match_end != NULL)
+ {
+ end = *match_end;
+ }
+ else
+ {
+ gtk_text_buffer_get_selection_bounds (search->priv->buffer,
+ NULL,
+ &end);
+ }
+
+ basic_forward_search (search,
+ &start,
+ &check_match_start,
+ &check_match_end,
+ &end);
+
+ if (!gtk_text_iter_equal (&start, &check_match_start) ||
+ !gtk_text_iter_equal (&end, &check_match_end))
+ {
+ return FALSE;
+ }
+
+ gtk_text_buffer_begin_user_action (search->priv->buffer);
+
+ gtk_text_buffer_delete (search->priv->buffer, &start, &end);
+ gtk_text_buffer_insert (search->priv->buffer, &start, replace, replace_length);
+
+ gtk_text_buffer_end_user_action (search->priv->buffer);
+
+ return TRUE;
+}
diff --git a/gtksourceview/gtksourcesearch.h b/gtksourceview/gtksourcesearch.h
index c23bc68..0ccfe05 100644
--- a/gtksourceview/gtksourcesearch.h
+++ b/gtksourceview/gtksourcesearch.h
@@ -134,6 +134,13 @@ gboolean _gtk_source_search_backward_finish (GtkSourceSearch
*search,
GtkTextIter *match_end,
GError **error);
+G_GNUC_INTERNAL
+gboolean _gtk_source_search_replace (GtkSourceSearch *search,
+ const GtkTextIter *match_start,
+ const GtkTextIter *match_end,
+ const gchar *replace,
+ gint
replace_length);
+
G_END_DECLS
#endif /* __GTK_SOURCE_SEARCH_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]