[gedit/wip/search] Use the new search and replace API from GtkSourceView
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/search] Use the new search and replace API from GtkSourceView
- Date: Mon, 12 Aug 2013 22:55:32 +0000 (UTC)
commit f72d06ed3be57a17b18020398a13195553ff81ba
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Aug 8 19:30:50 2013 +0200
Use the new search and replace API from GtkSourceView
Almost compilable.
gedit/gedit-commands-search.c | 284 ++++++++++++++--------------
gedit/gedit-document.c | 213 ++++++++++++++-------
gedit/gedit-document.h | 5 +
gedit/gedit-replace-dialog.c | 190 ++++++++----------
gedit/gedit-replace-dialog.h | 33 +---
gedit/gedit-view-frame.c | 373 ++++++++++++++++++------------------
plugins/spell/gedit-spell-plugin.c | 30 ++--
7 files changed, 584 insertions(+), 544 deletions(-)
---
diff --git a/gedit/gedit-commands-search.c b/gedit/gedit-commands-search.c
index da0b9d3..36652af 100644
--- a/gedit/gedit-commands-search.c
+++ b/gedit/gedit-commands-search.c
@@ -130,20 +130,29 @@ text_found (GeditWindow *window,
}
#define MAX_MSG_LENGTH 40
+
static void
-text_not_found (GeditWindow *window,
- const gchar *text)
+text_not_found (GeditWindow *window,
+ GeditReplaceDialog *replace_dialog)
{
- gchar *searched;
+ GtkSourceSearchSettings *search_settings;
+ const gchar *search_text;
+ gchar *escaped_search_text;
+ gchar *truncated_text;
- searched = gedit_utils_str_end_truncate (text, MAX_MSG_LENGTH);
+ search_settings = gedit_replace_dialog_get_search_settings (replace_dialog);
+ search_text = gtk_source_search_settings_get_search_text (search_settings);
+ escaped_search_text = gtk_source_utils_escape_search_text (search_text);
+ truncated_text = gedit_utils_str_end_truncate (escaped_search_text, MAX_MSG_LENGTH);
gedit_statusbar_flash_message (GEDIT_STATUSBAR (window->priv->statusbar),
window->priv->generic_message_cid,
/* Translators: %s is replaced by the text
entered by the user in the search box */
- _("\"%s\" not found"), searched);
- g_free (searched);
+ _("\"%s\" not found"), truncated_text);
+
+ g_free (escaped_search_text);
+ g_free (truncated_text);
}
static void
@@ -162,8 +171,7 @@ finish_search_from_dialog (GeditWindow *window,
}
else
{
- const gchar *search_text = gedit_replace_dialog_get_search_text (replace_dialog);
- text_not_found (window, search_text);
+ text_not_found (window, replace_dialog);
}
gtk_dialog_set_response_sensitive (GTK_DIALOG (replace_dialog),
@@ -172,19 +180,22 @@ finish_search_from_dialog (GeditWindow *window,
}
static gboolean
-forward_search_finished (GtkSourceBuffer *buffer,
- GAsyncResult *result,
- GeditView *view)
+forward_search_finished (GtkSourceSearchContext *search_context,
+ GAsyncResult *result,
+ GeditView *view)
{
gboolean found;
+ GtkSourceBuffer *buffer;
GtkTextIter match_start;
GtkTextIter match_end;
- found = gtk_source_buffer_forward_search_finish (buffer,
- result,
- &match_start,
- &match_end,
- NULL);
+ found = gtk_source_search_context_forward_finish (search_context,
+ result,
+ &match_start,
+ &match_end,
+ NULL);
+
+ buffer = gtk_source_search_context_get_buffer (search_context);
if (found)
{
@@ -211,9 +222,9 @@ forward_search_finished (GtkSourceBuffer *buffer,
}
static void
-forward_search_from_dialog_finished (GtkSourceBuffer *buffer,
- GAsyncResult *result,
- GeditWindow *window)
+forward_search_from_dialog_finished (GtkSourceSearchContext *search_context,
+ GAsyncResult *result,
+ GeditWindow *window)
{
GeditView *view = gedit_window_get_active_view (window);
gboolean found;
@@ -223,7 +234,7 @@ forward_search_from_dialog_finished (GtkSourceBuffer *buffer,
return;
}
- found = forward_search_finished (buffer, result, view);
+ found = forward_search_finished (search_context, result, view);
finish_search_from_dialog (window, found);
}
@@ -235,6 +246,7 @@ run_forward_search (GeditWindow *window,
GeditView *view;
GtkTextBuffer *buffer;
GtkTextIter start_at;
+ GtkSourceSearchContext *search_context;
view = gedit_window_get_active_view (window);
@@ -245,40 +257,50 @@ run_forward_search (GeditWindow *window,
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ search_context = _gedit_document_get_search_context (GEDIT_DOCUMENT (buffer));
+
+ if (search_context == NULL)
+ {
+ return;
+ }
+
gtk_text_buffer_get_selection_bounds (buffer, NULL, &start_at);
if (from_dialog)
{
- gtk_source_buffer_forward_search_async (GTK_SOURCE_BUFFER (buffer),
- &start_at,
- NULL,
-
(GAsyncReadyCallback)forward_search_from_dialog_finished,
- window);
+ gtk_source_search_context_forward_async (search_context,
+ &start_at,
+ NULL,
+
(GAsyncReadyCallback)forward_search_from_dialog_finished,
+ window);
}
else
{
- gtk_source_buffer_forward_search_async (GTK_SOURCE_BUFFER (buffer),
- &start_at,
- NULL,
- (GAsyncReadyCallback)forward_search_finished,
- view);
+ gtk_source_search_context_forward_async (search_context,
+ &start_at,
+ NULL,
+ (GAsyncReadyCallback)forward_search_finished,
+ view);
}
}
static gboolean
-backward_search_finished (GtkSourceBuffer *buffer,
- GAsyncResult *result,
- GeditView *view)
+backward_search_finished (GtkSourceSearchContext *search_context,
+ GAsyncResult *result,
+ GeditView *view)
{
gboolean found;
GtkTextIter match_start;
GtkTextIter match_end;
+ GtkSourceBuffer *buffer;
- found = gtk_source_buffer_backward_search_finish (buffer,
- result,
- &match_start,
- &match_end,
- NULL);
+ found = gtk_source_search_context_backward_finish (search_context,
+ result,
+ &match_start,
+ &match_end,
+ NULL);
+
+ buffer = gtk_source_search_context_get_buffer (search_context);
if (found)
{
@@ -305,9 +327,9 @@ backward_search_finished (GtkSourceBuffer *buffer,
}
static void
-backward_search_from_dialog_finished (GtkSourceBuffer *buffer,
- GAsyncResult *result,
- GeditWindow *window)
+backward_search_from_dialog_finished (GtkSourceSearchContext *search_context,
+ GAsyncResult *result,
+ GeditWindow *window)
{
GeditView *view = gedit_window_get_active_view (window);
gboolean found;
@@ -317,7 +339,7 @@ backward_search_from_dialog_finished (GtkSourceBuffer *buffer,
return;
}
- found = backward_search_finished (buffer, result, view);
+ found = backward_search_finished (search_context, result, view);
finish_search_from_dialog (window, found);
}
@@ -329,6 +351,7 @@ run_backward_search (GeditWindow *window,
GeditView *view;
GtkTextBuffer *buffer;
GtkTextIter start_at;
+ GtkSourceSearchContext *search_context;
view = gedit_window_get_active_view (window);
@@ -339,71 +362,37 @@ run_backward_search (GeditWindow *window,
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ search_context = _gedit_document_get_search_context (GEDIT_DOCUMENT (buffer));
+
+ if (search_context == NULL)
+ {
+ return;
+ }
+
gtk_text_buffer_get_selection_bounds (buffer, &start_at, NULL);
if (from_dialog)
{
- gtk_source_buffer_backward_search_async (GTK_SOURCE_BUFFER (buffer),
- &start_at,
- NULL,
-
(GAsyncReadyCallback)backward_search_from_dialog_finished,
- window);
+ gtk_source_search_context_backward_async (search_context,
+ &start_at,
+ NULL,
+
(GAsyncReadyCallback)backward_search_from_dialog_finished,
+ window);
}
else
{
- gtk_source_buffer_backward_search_async (GTK_SOURCE_BUFFER (buffer),
- &start_at,
- NULL,
- (GAsyncReadyCallback)backward_search_finished,
- view);
+ gtk_source_search_context_backward_async (search_context,
+ &start_at,
+ NULL,
+ (GAsyncReadyCallback)backward_search_finished,
+ view);
}
}
static void
-set_search_state (GeditReplaceDialog *dialog,
- GtkSourceBuffer *buffer)
-{
- const gchar *search_text;
- gchar *unescaped_search_text;
- gboolean match_case;
- gboolean entire_word;
- gboolean wrap_around;
-
- search_text = gedit_replace_dialog_get_search_text (dialog);
- unescaped_search_text = gtk_source_utils_unescape_search_text (search_text);
- gtk_source_buffer_set_search_text (buffer, unescaped_search_text);
- g_free (unescaped_search_text);
-
- match_case = gedit_replace_dialog_get_match_case (dialog);
- gtk_source_buffer_set_case_sensitive_search (buffer, match_case);
-
- entire_word = gedit_replace_dialog_get_entire_word (dialog);
- gtk_source_buffer_set_search_at_word_boundaries (buffer, entire_word);
-
- wrap_around = gedit_replace_dialog_get_wrap_around (dialog);
- gtk_source_buffer_set_search_wrap_around (buffer, wrap_around);
-}
-
-static void
do_find (GeditReplaceDialog *dialog,
GeditWindow *window)
{
- GeditView *active_view;
- GtkSourceBuffer *buffer;
-
- /* TODO: make the dialog insensitive when all the tabs are closed
- * and assert here that the view is not NULL */
- active_view = gedit_window_get_active_view (window);
-
- if (active_view == NULL)
- {
- return;
- }
-
- buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
-
- set_search_state (dialog, buffer);
-
if (gedit_replace_dialog_get_backwards (dialog))
{
run_backward_search (window, TRUE);
@@ -414,7 +403,7 @@ do_find (GeditReplaceDialog *dialog,
}
}
-/* FIXME: move in gedit-document.c and share it with gedit-view */
+/* FIXME: move in gedit-document.c and share it with gedit-view-frame */
static gboolean
get_selected_text (GtkTextBuffer *doc,
gchar **selected_text,
@@ -445,20 +434,26 @@ static void
do_replace (GeditReplaceDialog *dialog,
GeditWindow *window)
{
- GtkSourceBuffer *buffer;
+ GeditDocument *doc;
+ GtkSourceSearchContext *search_context;
const gchar *replace_entry_text;
gchar *unescaped_replace_text;
GtkTextIter start;
GtkTextIter end;
- buffer = GTK_SOURCE_BUFFER (gedit_window_get_active_document (window));
+ doc = gedit_window_get_active_document (window);
- if (buffer == NULL)
+ if (doc == NULL)
{
return;
}
- set_search_state (dialog, buffer);
+ search_context = _gedit_document_get_search_context (doc);
+
+ if (search_context == NULL)
+ {
+ return;
+ }
/* replace text may be "", we just delete */
replace_entry_text = gedit_replace_dialog_get_replace_text (dialog);
@@ -466,9 +461,13 @@ do_replace (GeditReplaceDialog *dialog,
unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_entry_text);
- gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), &start, &end);
+ gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start, &end);
- gtk_source_buffer_search_replace (buffer, &start, &end, unescaped_replace_text, -1);
+ gtk_source_search_context_replace (search_context,
+ &start,
+ &end,
+ unescaped_replace_text,
+ -1);
g_free (unescaped_replace_text);
@@ -479,22 +478,25 @@ static void
do_replace_all (GeditReplaceDialog *dialog,
GeditWindow *window)
{
- GeditView *active_view;
- GtkSourceBuffer *buffer;
+ GeditDocument *doc;
+ GtkSourceSearchContext *search_context;
const gchar *replace_entry_text;
gchar *unescaped_replace_text;
gint count;
- active_view = gedit_window_get_active_view (window);
+ doc = gedit_window_get_active_document (window);
- if (active_view == NULL)
+ if (doc == NULL)
{
return;
}
- buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
+ search_context = _gedit_document_get_search_context (doc);
- set_search_state (dialog, buffer);
+ if (search_context == NULL)
+ {
+ return;
+ }
/* replace text may be "", we just delete all occurrences */
replace_entry_text = gedit_replace_dialog_get_replace_text (dialog);
@@ -502,7 +504,7 @@ do_replace_all (GeditReplaceDialog *dialog,
unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_entry_text);
- count = gtk_source_buffer_search_replace_all (buffer, unescaped_replace_text, -1);
+ count = gtk_source_search_context_replace_all (search_context, unescaped_replace_text, -1);
g_free (unescaped_replace_text);
@@ -512,8 +514,7 @@ do_replace_all (GeditReplaceDialog *dialog,
}
else
{
- const gchar *search_entry_text = gedit_replace_dialog_get_search_text (dialog);
- text_not_found (window, search_entry_text);
+ text_not_found (window, dialog);
}
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
@@ -526,8 +527,28 @@ replace_dialog_response_cb (GeditReplaceDialog *dialog,
gint response_id,
GeditWindow *window)
{
+ GeditDocument *doc;
+ GtkSourceSearchContext *search_context;
+ GtkSourceSearchSettings *search_settings;
+
gedit_debug (DEBUG_COMMANDS);
+ search_settings = gedit_replace_dialog_get_search_settings (dialog);
+
+ doc = gedit_window_get_active_document (window);
+ search_context = _gedit_document_get_search_context (doc);
+
+ if (search_context == NULL ||
+ search_settings != gtk_source_search_context_get_settings (search_context))
+ {
+ search_context = gtk_source_search_context_new (GTK_SOURCE_BUFFER (doc),
+ search_settings);
+
+ _gedit_document_set_search_context (doc, search_context);
+
+ g_object_unref (search_context);
+ }
+
switch (response_id)
{
case GEDIT_REPLACE_DIALOG_FIND_RESPONSE:
@@ -640,8 +661,11 @@ _gedit_cmd_search_replace (GtkAction *action,
if (selection_exists && find_text != NULL && sel_len < 80)
{
- gedit_replace_dialog_set_search_text (GEDIT_REPLACE_DIALOG (replace_dialog),
- find_text);
+ GtkSourceSearchSettings *search_settings;
+
+ search_settings = gedit_replace_dialog_get_search_settings (GEDIT_REPLACE_DIALOG
(replace_dialog));
+
+ gtk_source_search_settings_set_search_text (search_settings, find_text);
}
g_free (find_text);
@@ -652,43 +676,13 @@ _gedit_cmd_search_replace (GtkAction *action,
GDK_CURRENT_TIME);
}
-static void
-do_find_again (GeditWindow *window,
- gboolean backward)
-{
- GeditView *active_view;
- gpointer data;
-
- active_view = gedit_window_get_active_view (window);
- g_return_if_fail (active_view != NULL);
-
- data = g_object_get_data (G_OBJECT (window), GEDIT_REPLACE_DIALOG_KEY);
-
- if (data != NULL)
- {
- GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view));
-
- set_search_state (GEDIT_REPLACE_DIALOG (data),
- GTK_SOURCE_BUFFER (buffer));
- }
-
- if (backward)
- {
- run_backward_search (window, FALSE);
- }
- else
- {
- run_forward_search (window, FALSE);
- }
-}
-
void
_gedit_cmd_search_find_next (GtkAction *action,
GeditWindow *window)
{
gedit_debug (DEBUG_COMMANDS);
- do_find_again (window, FALSE);
+ run_forward_search (window, FALSE);
}
void
@@ -697,7 +691,7 @@ _gedit_cmd_search_find_prev (GtkAction *action,
{
gedit_debug (DEBUG_COMMANDS);
- do_find_again (window, TRUE);
+ run_backward_search (window, FALSE);
}
void
@@ -706,6 +700,7 @@ _gedit_cmd_search_clear_highlight (GtkAction *action,
{
GeditTab *active_tab;
GeditViewFrame *frame;
+ GeditDocument *doc;
gedit_debug (DEBUG_COMMANDS);
@@ -718,6 +713,9 @@ _gedit_cmd_search_clear_highlight (GtkAction *action,
frame = GEDIT_VIEW_FRAME (_gedit_tab_get_view_frame (active_tab));
gedit_view_frame_clear_search (frame);
+
+ doc = gedit_view_frame_get_document (frame);
+ _gedit_document_set_search_context (doc, NULL);
}
void
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 7527cb2..4bd7890 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -104,8 +104,12 @@ struct _GeditDocumentPrivate
GTimeVal mtime;
GTimeVal time_of_last_save_or_load;
- guint search_flags;
- gchar *search_text;
+ /* The search context for the incremental search, or the search and
+ * replace. They are mutually exclusive.
+ */
+ GtkSourceSearchContext *search_context;
+
+ GtkSourceSearchSettings *deprecated_search_settings;
GeditDocumentNewlineType newline_type;
GeditDocumentCompressionType compression_type;
@@ -293,6 +297,8 @@ gedit_document_dispose (GObject *object)
g_clear_object (&doc->priv->editor_settings);
g_clear_object (&doc->priv->metadata_info);
g_clear_object (&doc->priv->location);
+ g_clear_object (&doc->priv->search_context);
+ g_clear_object (&doc->priv->deprecated_search_settings);
doc->priv->dispose_has_run = TRUE;
@@ -312,7 +318,6 @@ gedit_document_finalize (GObject *object)
}
g_free (doc->priv->content_type);
- g_free (doc->priv->search_text);
G_OBJECT_CLASS (gedit_document_parent_class)->finalize (object);
}
@@ -351,7 +356,9 @@ gedit_document_get_property (GObject *object,
G_GNUC_END_IGNORE_DEPRECATIONS;
break;
case PROP_ENABLE_SEARCH_HIGHLIGHTING:
- g_value_set_boolean (value, gtk_source_buffer_get_highlight_search (GTK_SOURCE_BUFFER
(doc)));
+ g_value_set_boolean (value,
+ doc->priv->search_context != NULL &&
+ gtk_source_search_context_get_highlight
(doc->priv->search_context));
break;
case PROP_NEWLINE_TYPE:
g_value_set_enum (value, doc->priv->newline_type);
@@ -397,8 +404,11 @@ gedit_document_set_property (GObject *object,
g_value_get_string (value));
break;
case PROP_ENABLE_SEARCH_HIGHLIGHTING:
- gtk_source_buffer_set_highlight_search (GTK_SOURCE_BUFFER (doc),
- g_value_get_boolean (value));
+ if (doc->priv->search_context != NULL)
+ {
+ gtk_source_search_context_set_highlight (doc->priv->search_context,
+ g_value_get_boolean (value));
+ }
break;
case PROP_NEWLINE_TYPE:
set_newline_type (doc,
@@ -1005,12 +1015,6 @@ gedit_document_init (GeditDocument *doc)
"highlight-matching-brackets",
G_SETTINGS_BIND_GET);
- g_settings_bind (priv->editor_settings,
- GEDIT_SETTINGS_SEARCH_HIGHLIGHTING,
- doc,
- "highlight-search",
- G_SETTINGS_BIND_GET);
-
style_scheme = get_default_style_scheme (priv->editor_settings);
if (style_scheme != NULL)
gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc),
@@ -2062,13 +2066,33 @@ gedit_document_goto_line_offset (GeditDocument *doc,
return ret;
}
+static GtkSourceSearchContext *
+get_deprecated_search_context (GeditDocument *doc)
+{
+ GtkSourceSearchSettings *search_settings;
+
+ if (doc->priv->search_context == NULL)
+ {
+ return NULL;
+ }
+
+ search_settings = gtk_source_search_context_get_settings (doc->priv->search_context);
+
+ if (search_settings == doc->priv->deprecated_search_settings)
+ {
+ return doc->priv->search_context;
+ }
+
+ return NULL;
+}
+
/**
* gedit_document_set_search_text:
* @doc:
* @text: (allow-none):
* @flags:
*
- * Deprecated: 3.10: Use gtk_source_buffer_set_search_text() instead.
+ * Deprecated: 3.10: Use the search and replace API of GtkSourceView instead.
**/
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
@@ -2080,9 +2104,9 @@ gedit_document_set_search_text (GeditDocument *doc,
{
gchar *converted_text;
gboolean notify = FALSE;
+ GtkSourceSearchContext *search_context;
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
- g_return_if_fail ((text == NULL) || (doc->priv->search_text != text));
g_return_if_fail ((text == NULL) || g_utf8_validate (text, -1, NULL));
gedit_debug_message (DEBUG_DOCUMENT, "text = %s", text);
@@ -2100,23 +2124,32 @@ gedit_document_set_search_text (GeditDocument *doc,
notify = gedit_document_get_can_search_again (doc);
}
- g_free (doc->priv->search_text);
- doc->priv->search_text = converted_text;
+ gtk_source_search_settings_set_search_text (doc->priv->deprecated_search_settings,
+ converted_text);
+
+ g_free (converted_text);
}
if (!GEDIT_SEARCH_IS_DONT_SET_FLAGS (flags))
{
- doc->priv->search_flags = flags;
-
- gtk_source_buffer_set_case_sensitive_search (GTK_SOURCE_BUFFER (doc),
- GEDIT_SEARCH_IS_CASE_SENSITIVE (flags));
+ gtk_source_search_settings_set_case_sensitive (doc->priv->deprecated_search_settings,
+ GEDIT_SEARCH_IS_CASE_SENSITIVE (flags));
- gtk_source_buffer_set_search_at_word_boundaries (GTK_SOURCE_BUFFER (doc),
- GEDIT_SEARCH_IS_ENTIRE_WORD (flags));
+ gtk_source_search_settings_set_at_word_boundaries (doc->priv->deprecated_search_settings,
+ GEDIT_SEARCH_IS_ENTIRE_WORD (flags));
}
- gtk_source_buffer_set_search_text (GTK_SOURCE_BUFFER (doc),
- doc->priv->search_text);
+ search_context = get_deprecated_search_context (doc);
+
+ if (search_context == NULL)
+ {
+ search_context = gtk_source_search_context_new (GTK_SOURCE_BUFFER (doc),
+ doc->priv->deprecated_search_settings);
+
+ _gedit_document_set_search_context (doc, search_context);
+
+ g_object_unref (search_context);
+ }
if (notify)
{
@@ -2131,33 +2164,48 @@ G_GNUC_END_IGNORE_DEPRECATIONS;
* @doc:
* @flags: (allow-none):
*
- * Deprecated: 3.10: Use gtk_source_buffer_get_search_text() instead.
+ * Deprecated: 3.10: Use the search and replace API of GtkSourceView instead.
*/
gchar *
gedit_document_get_search_text (GeditDocument *doc,
guint *flags)
{
+ const gchar *search_text;
+
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
if (flags != NULL)
- *flags = doc->priv->search_flags;
+ {
+ *flags = 0;
- return gtk_source_utils_escape_search_text (doc->priv->search_text);
+ if (gtk_source_search_settings_get_case_sensitive (doc->priv->deprecated_search_settings))
+ {
+ *flags |= GEDIT_SEARCH_CASE_SENSITIVE;
+ }
+
+ if (gtk_source_search_settings_get_at_word_boundaries (doc->priv->deprecated_search_settings))
+ {
+ *flags |= GEDIT_SEARCH_ENTIRE_WORD;
+ }
+ }
+
+ search_text = gtk_source_search_settings_get_search_text (doc->priv->deprecated_search_settings);
+
+ return gtk_source_utils_escape_search_text (search_text);
}
/**
* gedit_document_get_can_search_again:
* @doc:
*
- * Deprecated: 3.10: Use gtk_source_buffer_get_search_text() instead. If the
- * search text is non-%NULL, it means that it can search again.
+ * Deprecated: 3.10: Use the search and replace API of GtkSourceView instead.
*/
gboolean
gedit_document_get_can_search_again (GeditDocument *doc)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
- return gtk_source_buffer_get_search_text (GTK_SOURCE_BUFFER (doc)) != NULL;
+ return gtk_source_search_settings_get_search_text (doc->priv->deprecated_search_settings) != NULL;
}
/**
@@ -2168,7 +2216,7 @@ gedit_document_get_can_search_again (GeditDocument *doc)
* @match_start: (allow-none):
* @match_end: (allow-none):
*
- * Deprecated: 3.10: Use gtk_source_buffer_forward_search_async() instead.
+ * Deprecated: 3.10: Use the search and replace API of GtkSourceView instead.
**/
gboolean
gedit_document_search_forward (GeditDocument *doc,
@@ -2177,6 +2225,7 @@ gedit_document_search_forward (GeditDocument *doc,
GtkTextIter *match_start,
GtkTextIter *match_end)
{
+ const gchar *search_text;
GtkTextIter iter;
GtkTextSearchFlags search_flags;
gboolean found = FALSE;
@@ -2189,15 +2238,12 @@ gedit_document_search_forward (GeditDocument *doc,
g_return_val_if_fail ((end == NULL) ||
(gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE);
- if (doc->priv->search_text == NULL)
+ search_text = gtk_source_search_settings_get_search_text (doc->priv->deprecated_search_settings);
+
+ if (search_text == NULL)
{
- gedit_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n");
return FALSE;
}
- else
- {
- gedit_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n",
doc->priv->search_text);
- }
if (start == NULL)
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (doc), &iter);
@@ -2206,21 +2252,22 @@ gedit_document_search_forward (GeditDocument *doc,
search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY;
- if (!GEDIT_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags))
+ if (!gtk_source_search_settings_get_case_sensitive (doc->priv->deprecated_search_settings))
{
- search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE;
+ search_flags |= GTK_TEXT_SEARCH_CASE_INSENSITIVE;
}
while (!found)
{
found = gtk_text_iter_forward_search (&iter,
- doc->priv->search_text,
+ search_text,
search_flags,
&m_start,
&m_end,
end);
- if (found && GEDIT_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags))
+ if (found &&
+ gtk_source_search_settings_get_at_word_boundaries (doc->priv->deprecated_search_settings))
{
found = gtk_text_iter_starts_word (&m_start) &&
gtk_text_iter_ends_word (&m_end);
@@ -2251,7 +2298,7 @@ gedit_document_search_forward (GeditDocument *doc,
* @match_start: (allow-none):
* @match_end: (allow-none):
*
- * Deprecated: 3.10: Use gtk_source_buffer_backward_search_async() instead.
+ * Deprecated: 3.10: Use the search and replace API of GtkSourceView instead.
**/
gboolean
gedit_document_search_backward (GeditDocument *doc,
@@ -2260,6 +2307,7 @@ gedit_document_search_backward (GeditDocument *doc,
GtkTextIter *match_start,
GtkTextIter *match_end)
{
+ const gchar *search_text;
GtkTextIter iter;
GtkTextSearchFlags search_flags;
gboolean found = FALSE;
@@ -2272,15 +2320,12 @@ gedit_document_search_backward (GeditDocument *doc,
g_return_val_if_fail ((end == NULL) ||
(gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE);
- if (doc->priv->search_text == NULL)
+ search_text = gtk_source_search_settings_get_search_text (doc->priv->deprecated_search_settings);
+
+ if (search_text == NULL)
{
- gedit_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n");
return FALSE;
}
- else
- {
- gedit_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n",
doc->priv->search_text);
- }
if (end == NULL)
gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter);
@@ -2289,21 +2334,22 @@ gedit_document_search_backward (GeditDocument *doc,
search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY;
- if (!GEDIT_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags))
+ if (!gtk_source_search_settings_get_case_sensitive (doc->priv->deprecated_search_settings))
{
- search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE;
+ search_flags |= GTK_TEXT_SEARCH_CASE_INSENSITIVE;
}
while (!found)
{
found = gtk_text_iter_backward_search (&iter,
- doc->priv->search_text,
+ search_text,
search_flags,
&m_start,
&m_end,
start);
- if (found && GEDIT_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags))
+ if (found &&
+ gtk_source_search_settings_get_at_word_boundaries (doc->priv->deprecated_search_settings))
{
found = gtk_text_iter_starts_word (&m_start) &&
gtk_text_iter_ends_word (&m_end);
@@ -2333,7 +2379,7 @@ gedit_document_search_backward (GeditDocument *doc,
* @replace:
* @flags:
*
- * Deprecated: 3.10: Use gtk_source_buffer_search_replace_all() instead.
+ * Deprecated: 3.10: Use the search and replace API of GtkSourceView instead.
*/
/* FIXME this is an issue for introspection regardning @find */
@@ -2349,21 +2395,24 @@ gedit_document_replace_all (GeditDocument *doc,
GtkTextSearchFlags search_flags = 0;
gboolean found = TRUE;
gint cont = 0;
+ const gchar *search_text_from_settings;
gchar *search_text;
gchar *replace_text;
gint replace_text_len;
GtkTextBuffer *buffer;
gboolean brackets_highlighting;
- gboolean search_highliting;
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), 0);
g_return_val_if_fail (replace != NULL, 0);
- g_return_val_if_fail ((find != NULL) || (doc->priv->search_text != NULL), 0);
+
+ search_text_from_settings = gtk_source_search_settings_get_search_text
(doc->priv->deprecated_search_settings);
+
+ g_return_val_if_fail ((find != NULL) || (search_text_from_settings != NULL), 0);
buffer = GTK_TEXT_BUFFER (doc);
if (find == NULL)
- search_text = g_strdup (doc->priv->search_text);
+ search_text = g_strdup (search_text_from_settings);
else
search_text = gtk_source_utils_unescape_search_text (find);
@@ -2390,10 +2439,6 @@ gedit_document_replace_all (GeditDocument *doc,
brackets_highlighting = gtk_source_buffer_get_highlight_matching_brackets (GTK_SOURCE_BUFFER
(buffer));
gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer), FALSE);
- /* and do search highliting later */
- search_highliting = gtk_source_buffer_get_highlight_search (GTK_SOURCE_BUFFER (buffer));
- gtk_source_buffer_set_highlight_search (GTK_SOURCE_BUFFER (buffer), FALSE);
-
gtk_text_buffer_begin_user_action (buffer);
do
@@ -2447,9 +2492,6 @@ gedit_document_replace_all (GeditDocument *doc,
gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer),
brackets_highlighting);
- gtk_source_buffer_set_highlight_search (GTK_SOURCE_BUFFER (buffer),
- search_highliting);
-
g_free (search_text);
g_free (replace_text);
@@ -2666,7 +2708,7 @@ _gedit_document_get_seconds_since_last_save_or_load (GeditDocument *doc)
* @doc:
* @enable:
*
- * Deprecated: 3.10: Use gtk_source_buffer_set_highlight_search() instead.
+ * Deprecated: 3.10: Use the search and replace API of GtkSourceView instead.
*/
void
gedit_document_set_enable_search_highlighting (GeditDocument *doc,
@@ -2674,21 +2716,30 @@ gedit_document_set_enable_search_highlighting (GeditDocument *doc,
{
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
- gtk_source_buffer_set_highlight_search (GTK_SOURCE_BUFFER (doc), enable);
+ if (doc->priv->search_context != NULL)
+ {
+ gtk_source_search_context_set_highlight (doc->priv->search_context,
+ enable);
+ }
}
/**
* gedit_document_get_enable_search_highlighting:
* @doc:
*
- * Deprecated: 3.10: Use gtk_source_buffer_get_highlight_search() instead.
+ * Deprecated: 3.10: Use the search and replace API of GtkSourceView instead.
*/
gboolean
gedit_document_get_enable_search_highlighting (GeditDocument *doc)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
- return gtk_source_buffer_get_highlight_search (GTK_SOURCE_BUFFER (doc));
+ if (doc->priv->search_context == NULL)
+ {
+ return FALSE;
+ }
+
+ return gtk_source_search_context_get_highlight (doc->priv->search_context);
}
GeditDocumentNewlineType
@@ -2939,4 +2990,32 @@ _gedit_document_apply_error_style (GeditDocument *doc,
end);
}
+void
+_gedit_document_set_search_context (GeditDocument *doc,
+ GtkSourceSearchContext *search_context)
+{
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+ g_clear_object (&doc->priv->search_context);
+ doc->priv->search_context = search_context;
+
+ if (search_context != NULL)
+ {
+ gboolean highlight = g_settings_get_boolean (doc->priv->editor_settings,
+ GEDIT_SETTINGS_SEARCH_HIGHLIGHTING);
+
+ gtk_source_search_context_set_highlight (search_context, highlight);
+
+ g_object_ref (search_context);
+ }
+}
+
+GtkSourceSearchContext *
+_gedit_document_get_search_context (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
+
+ return doc->priv->search_context;
+}
+
/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-document.h b/gedit/gedit-document.h
index 16c93fc..e5965e0 100644
--- a/gedit/gedit-document.h
+++ b/gedit/gedit-document.h
@@ -376,6 +376,11 @@ GMountOperation
*_gedit_document_create_mount_operation
(GeditDocument *doc);
+void _gedit_document_set_search_context (GeditDocument *doc,
+ GtkSourceSearchContext *search_context);
+
+GtkSourceSearchContext *_gedit_document_get_search_context (GeditDocument *doc);
+
G_END_DECLS
#endif /* __GEDIT_DOCUMENT_H__ */
diff --git a/gedit/gedit-replace-dialog.c b/gedit/gedit-replace-dialog.c
index afe70e7..41c0f72 100644
--- a/gedit/gedit-replace-dialog.c
+++ b/gedit/gedit-replace-dialog.c
@@ -3,6 +3,7 @@
* This file is part of gedit
*
* Copyright (C) 2005 Paolo Maggi
+ * Copyright (C) 2013 Sébastien Wilmet
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -48,14 +49,16 @@ struct _GeditReplaceDialogPrivate
GtkWidget *backwards_checkbutton;
GtkWidget *wrap_around_checkbutton;
- gboolean ui_error;
+ GtkSourceSearchSettings *search_settings;
+
+ gboolean ui_error;
};
G_DEFINE_TYPE_WITH_PRIVATE (GeditReplaceDialog, gedit_replace_dialog, GTK_TYPE_DIALOG)
void
gedit_replace_dialog_present_with_time (GeditReplaceDialog *dialog,
- guint32 timestamp)
+ guint32 timestamp)
{
g_return_if_fail (GEDIT_REPLACE_DIALOG (dialog));
@@ -113,11 +116,23 @@ gedit_replace_dialog_response (GtkDialog *dialog,
}
static void
+gedit_replace_dialog_dispose (GObject *object)
+{
+ GeditReplaceDialog *dialog = GEDIT_REPLACE_DIALOG (object);
+
+ g_clear_object (&dialog->priv->search_settings);
+
+ G_OBJECT_CLASS (gedit_replace_dialog_parent_class)->dispose (object);
+}
+
+static void
gedit_replace_dialog_class_init (GeditReplaceDialogClass *klass)
{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
+ gobject_class->dispose = gedit_replace_dialog_dispose;
widget_class->delete_event = gedit_replace_dialog_delete_event;
dialog_class->response = gedit_replace_dialog_response;
@@ -140,6 +155,10 @@ insert_text_handler (GtkEditable *editable,
gint *position,
gpointer data)
{
+ /* FIXME: I think we can remove this function. This was a hack in the
+ * escape_search_text() function. Now there is a bug when inserting '\'
+ * in the text entry (the '\' is escaped and becomes '\\').
+ */
static gboolean insert_text = FALSE;
gchar *escaped_text;
gint new_len;
@@ -174,6 +193,7 @@ search_text_entry_changed (GtkEditable *editable,
GeditReplaceDialog *dialog)
{
const gchar *search_string;
+ gchar *unescaped_search_string;
search_string = gtk_entry_get_text (GTK_ENTRY (editable));
g_return_if_fail (search_string != NULL);
@@ -181,19 +201,51 @@ search_text_entry_changed (GtkEditable *editable,
if (*search_string != '\0')
{
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
- GEDIT_REPLACE_DIALOG_FIND_RESPONSE, TRUE);
+ GEDIT_REPLACE_DIALOG_FIND_RESPONSE,
+ TRUE);
+
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
- GEDIT_REPLACE_DIALOG_REPLACE_ALL_RESPONSE, TRUE);
+ GEDIT_REPLACE_DIALOG_REPLACE_ALL_RESPONSE,
+ TRUE);
}
else
{
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
- GEDIT_REPLACE_DIALOG_FIND_RESPONSE, FALSE);
+ GEDIT_REPLACE_DIALOG_FIND_RESPONSE,
+ FALSE);
+
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
- GEDIT_REPLACE_DIALOG_REPLACE_RESPONSE, FALSE);
+ GEDIT_REPLACE_DIALOG_REPLACE_RESPONSE,
+ FALSE);
+
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
- GEDIT_REPLACE_DIALOG_REPLACE_ALL_RESPONSE, FALSE);
+ GEDIT_REPLACE_DIALOG_REPLACE_ALL_RESPONSE,
+ FALSE);
}
+
+ unescaped_search_string = gtk_source_utils_unescape_search_text (search_string);
+
+ gtk_source_search_settings_set_search_text (dialog->priv->search_settings,
+ unescaped_search_string);
+
+ g_free (unescaped_search_string);
+}
+
+static void
+search_text_notify_cb (GtkSourceSearchSettings *search_settings,
+ GParamSpec *pspec,
+ GeditReplaceDialog *dialog)
+{
+ const gchar *search_text;
+ gchar *escaped_search_text;
+
+ search_text = gtk_source_search_settings_get_search_text (search_settings);
+ escaped_search_text = gtk_source_utils_escape_search_text (search_text);
+
+ gtk_entry_set_text (GTK_ENTRY (dialog->priv->search_text_entry),
+ escaped_search_text);
+
+ g_free (escaped_search_text);
}
static void
@@ -249,15 +301,36 @@ gedit_replace_dialog_init (GeditReplaceDialog *dlg)
"insert_text",
G_CALLBACK (insert_text_handler),
NULL);
+
g_signal_connect (dlg->priv->replace_text_entry,
"insert_text",
G_CALLBACK (insert_text_handler),
NULL);
+
g_signal_connect (dlg->priv->search_text_entry,
"changed",
G_CALLBACK (search_text_entry_changed),
dlg);
+ dlg->priv->search_settings = gtk_source_search_settings_new ();
+
+ g_object_bind_property (dlg->priv->match_case_checkbutton, "active",
+ dlg->priv->search_settings, "case-sensitive",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (dlg->priv->entire_word_checkbutton, "active",
+ dlg->priv->search_settings, "at-word-boundaries",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_object_bind_property (dlg->priv->wrap_around_checkbutton, "active",
+ dlg->priv->search_settings, "wrap-around",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
+ g_signal_connect (dlg->priv->search_settings,
+ "notify::search-text",
+ G_CALLBACK (search_text_notify_cb),
+ dlg);
+
gtk_widget_show_all (GTK_WIDGET (dlg));
}
@@ -281,45 +354,6 @@ gedit_replace_dialog_new (GtkWindow *parent)
return GTK_WIDGET (dlg);
}
-void
-gedit_replace_dialog_set_search_text (GeditReplaceDialog *dialog,
- const gchar *text)
-{
- g_return_if_fail (GEDIT_IS_REPLACE_DIALOG (dialog));
- g_return_if_fail (text != NULL);
-
- gtk_entry_set_text (GTK_ENTRY (dialog->priv->search_text_entry),
- text);
-
- gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
- GEDIT_REPLACE_DIALOG_FIND_RESPONSE,
- (text != '\0'));
-
- gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
- GEDIT_REPLACE_DIALOG_REPLACE_ALL_RESPONSE,
- (text != '\0'));
-}
-
-/* The text must be unescaped before searching */
-const gchar *
-gedit_replace_dialog_get_search_text (GeditReplaceDialog *dialog)
-{
- g_return_val_if_fail (GEDIT_IS_REPLACE_DIALOG (dialog), NULL);
-
- return gtk_entry_get_text (GTK_ENTRY (dialog->priv->search_text_entry));
-}
-
-void
-gedit_replace_dialog_set_replace_text (GeditReplaceDialog *dialog,
- const gchar *text)
-{
- g_return_if_fail (GEDIT_IS_REPLACE_DIALOG (dialog));
- g_return_if_fail (text != NULL);
-
- gtk_entry_set_text (GTK_ENTRY (dialog->priv->replace_text_entry),
- text);
-}
-
const gchar *
gedit_replace_dialog_get_replace_text (GeditReplaceDialog *dialog)
{
@@ -328,52 +362,6 @@ gedit_replace_dialog_get_replace_text (GeditReplaceDialog *dialog)
return gtk_entry_get_text (GTK_ENTRY (dialog->priv->replace_text_entry));
}
-void
-gedit_replace_dialog_set_match_case (GeditReplaceDialog *dialog,
- gboolean match_case)
-{
- g_return_if_fail (GEDIT_IS_REPLACE_DIALOG (dialog));
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->match_case_checkbutton),
- match_case);
-}
-
-gboolean
-gedit_replace_dialog_get_match_case (GeditReplaceDialog *dialog)
-{
- g_return_val_if_fail (GEDIT_IS_REPLACE_DIALOG (dialog), FALSE);
-
- return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->match_case_checkbutton));
-}
-
-void
-gedit_replace_dialog_set_entire_word (GeditReplaceDialog *dialog,
- gboolean entire_word)
-{
- g_return_if_fail (GEDIT_IS_REPLACE_DIALOG (dialog));
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->entire_word_checkbutton),
- entire_word);
-}
-
-gboolean
-gedit_replace_dialog_get_entire_word (GeditReplaceDialog *dialog)
-{
- g_return_val_if_fail (GEDIT_IS_REPLACE_DIALOG (dialog), FALSE);
-
- return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->entire_word_checkbutton));
-}
-
-void
-gedit_replace_dialog_set_backwards (GeditReplaceDialog *dialog,
- gboolean backwards)
-{
- g_return_if_fail (GEDIT_IS_REPLACE_DIALOG (dialog));
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->backwards_checkbutton),
- backwards);
-}
-
gboolean
gedit_replace_dialog_get_backwards (GeditReplaceDialog *dialog)
{
@@ -382,22 +370,12 @@ gedit_replace_dialog_get_backwards (GeditReplaceDialog *dialog)
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->backwards_checkbutton));
}
-void
-gedit_replace_dialog_set_wrap_around (GeditReplaceDialog *dialog,
- gboolean wrap_around)
-{
- g_return_if_fail (GEDIT_IS_REPLACE_DIALOG (dialog));
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->wrap_around_checkbutton),
- wrap_around);
-}
-
-gboolean
-gedit_replace_dialog_get_wrap_around (GeditReplaceDialog *dialog)
+GtkSourceSearchSettings *
+gedit_replace_dialog_get_search_settings (GeditReplaceDialog *dialog)
{
- g_return_val_if_fail (GEDIT_IS_REPLACE_DIALOG (dialog), FALSE);
+ g_return_val_if_fail (GEDIT_IS_REPLACE_DIALOG (dialog), NULL);
- return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->wrap_around_checkbutton));
+ return dialog->priv->search_settings;
}
/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-replace-dialog.h b/gedit/gedit-replace-dialog.h
index 9eb0f40..3f7b834 100644
--- a/gedit/gedit-replace-dialog.h
+++ b/gedit/gedit-replace-dialog.h
@@ -32,6 +32,7 @@
#define __GEDIT_REPLACE_DIALOG_H__
#include <gtk/gtk.h>
+#include <gtksourceview/gtksource.h>
G_BEGIN_DECLS
@@ -82,36 +83,18 @@ enum
/*
* Public methods
*/
-GType gedit_replace_dialog_get_type (void) G_GNUC_CONST;
+GType gedit_replace_dialog_get_type (void) G_GNUC_CONST;
-GtkWidget *gedit_replace_dialog_new (GtkWindow *parent);
+GtkWidget *gedit_replace_dialog_new (GtkWindow *parent);
-void gedit_replace_dialog_present_with_time (GeditReplaceDialog *dialog,
- guint32 timestamp);
+void gedit_replace_dialog_present_with_time (GeditReplaceDialog *dialog,
+ guint32 timestamp);
-void gedit_replace_dialog_set_search_text (GeditReplaceDialog *dialog,
- const gchar *text);
-const gchar *gedit_replace_dialog_get_search_text (GeditReplaceDialog *dialog);
+const gchar *gedit_replace_dialog_get_replace_text (GeditReplaceDialog *dialog);
-void gedit_replace_dialog_set_replace_text (GeditReplaceDialog *dialog,
- const gchar *text);
-const gchar *gedit_replace_dialog_get_replace_text (GeditReplaceDialog *dialog);
+gboolean gedit_replace_dialog_get_backwards (GeditReplaceDialog *dialog);
-void gedit_replace_dialog_set_match_case (GeditReplaceDialog *dialog,
- gboolean match_case);
-gboolean gedit_replace_dialog_get_match_case (GeditReplaceDialog *dialog);
-
-void gedit_replace_dialog_set_entire_word (GeditReplaceDialog *dialog,
- gboolean entire_word);
-gboolean gedit_replace_dialog_get_entire_word (GeditReplaceDialog *dialog);
-
-void gedit_replace_dialog_set_backwards (GeditReplaceDialog *dialog,
- gboolean backwards);
-gboolean gedit_replace_dialog_get_backwards (GeditReplaceDialog *dialog);
-
-void gedit_replace_dialog_set_wrap_around (GeditReplaceDialog *dialog,
- gboolean wrap_around);
-gboolean gedit_replace_dialog_get_wrap_around (GeditReplaceDialog *dialog);
+GtkSourceSearchSettings *gedit_replace_dialog_get_search_settings (GeditReplaceDialog *dialog);
G_END_DECLS
diff --git a/gedit/gedit-view-frame.c b/gedit/gedit-view-frame.c
index fe4fc53..938c7df 100644
--- a/gedit/gedit-view-frame.c
+++ b/gedit/gedit-view-frame.c
@@ -61,11 +61,6 @@ struct _GeditViewFramePrivate
*/
GtkTextMark *start_mark;
- /* Used to restore the search state if an incremental search is
- * cancelled.
- */
- gchar *old_search_text;
-
GtkRevealer *revealer;
GdTaggedEntry *search_entry;
GdTaggedEntryTag *entry_tag;
@@ -78,19 +73,12 @@ struct _GeditViewFramePrivate
gulong search_entry_focus_out_id;
gulong search_entry_changed_id;
- /* Used to remember the state of the last incremental search (the
- * buffer search state may be changed by the search and replace dialog).
- */
- guint case_sensitive_search : 1;
- guint search_at_word_boundaries : 1;
- guint search_wrap_around : 1;
+ GtkSourceSearchSettings *search_settings;
/* Used to restore the search state if an incremental search is
* cancelled.
*/
- guint old_case_sensitive_search : 1;
- guint old_search_at_word_boundaries : 1;
- guint old_search_wrap_around : 1;
+ GtkSourceSearchSettings *old_search_settings;
};
enum
@@ -103,16 +91,6 @@ enum
G_DEFINE_TYPE_WITH_PRIVATE (GeditViewFrame, gedit_view_frame, GTK_TYPE_OVERLAY)
static void
-gedit_view_frame_finalize (GObject *object)
-{
- GeditViewFrame *frame = GEDIT_VIEW_FRAME (object);
-
- g_free (frame->priv->old_search_text);
-
- G_OBJECT_CLASS (gedit_view_frame_parent_class)->finalize (object);
-}
-
-static void
gedit_view_frame_dispose (GObject *object)
{
GeditViewFrame *frame = GEDIT_VIEW_FRAME (object);
@@ -130,6 +108,8 @@ gedit_view_frame_dispose (GObject *object)
}
g_clear_object (&frame->priv->entry_tag);
+ g_clear_object (&frame->priv->search_settings);
+ g_clear_object (&frame->priv->old_search_settings);
G_OBJECT_CLASS (gedit_view_frame_parent_class)->dispose (object);
}
@@ -226,6 +206,25 @@ renew_flush_timeout (GeditViewFrame *frame)
frame);
}
+static GtkSourceSearchContext *
+get_search_context (GeditViewFrame *frame)
+{
+ GeditDocument *doc;
+ GtkSourceSearchContext *search_context;
+ GtkSourceSearchSettings *search_settings;
+
+ doc = gedit_view_frame_get_document (frame);
+ search_context = _gedit_document_get_search_context (doc);
+ search_settings = gtk_source_search_context_get_settings (search_context);
+
+ if (search_settings == frame->priv->search_settings)
+ {
+ return search_context;
+ }
+
+ return NULL;
+}
+
static void
set_search_state (GeditViewFrame *frame,
SearchState state)
@@ -263,19 +262,22 @@ finish_search (GeditViewFrame *frame,
}
static void
-start_search_finished (GtkSourceBuffer *buffer,
- GAsyncResult *result,
- GeditViewFrame *frame)
+start_search_finished (GtkSourceSearchContext *search_context,
+ GAsyncResult *result,
+ GeditViewFrame *frame)
{
GtkTextIter match_start;
GtkTextIter match_end;
gboolean found;
+ GtkSourceBuffer *buffer;
+
+ found = gtk_source_search_context_forward_finish (search_context,
+ result,
+ &match_start,
+ &match_end,
+ NULL);
- found = gtk_source_buffer_forward_search_finish (buffer,
- result,
- &match_start,
- &match_end,
- NULL);
+ buffer = gtk_source_search_context_get_buffer (search_context);
if (found)
{
@@ -303,41 +305,51 @@ static void
start_search (GeditViewFrame *frame)
{
GtkTextIter start_at;
- GtkSourceBuffer *buffer;
+ GtkTextBuffer *buffer;
+ GtkSourceSearchContext *search_context;
g_return_if_fail (frame->priv->search_mode == SEARCH);
- buffer = GTK_SOURCE_BUFFER (gedit_view_frame_get_document (frame));
+ search_context = get_search_context (frame);
- gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer),
+ if (search_context == NULL)
+ {
+ return;
+ }
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->priv->view));
+
+ gtk_text_buffer_get_iter_at_mark (buffer,
&start_at,
frame->priv->start_mark);
- gtk_source_buffer_forward_search_async (buffer,
- &start_at,
- NULL,
- (GAsyncReadyCallback)start_search_finished,
- frame);
+ gtk_source_search_context_forward_async (search_context,
+ &start_at,
+ NULL,
+ (GAsyncReadyCallback)start_search_finished,
+ frame);
}
static void
-forward_search_finished (GtkSourceBuffer *buffer,
- GAsyncResult *result,
- GeditViewFrame *frame)
+forward_search_finished (GtkSourceSearchContext *search_context,
+ GAsyncResult *result,
+ GeditViewFrame *frame)
{
GtkTextIter match_start;
GtkTextIter match_end;
gboolean found;
- found = gtk_source_buffer_forward_search_finish (buffer,
- result,
- &match_start,
- &match_end,
- NULL);
+ found = gtk_source_search_context_forward_finish (search_context,
+ result,
+ &match_start,
+ &match_end,
+ NULL);
if (found)
{
- gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer),
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->priv->view));
+
+ gtk_text_buffer_select_range (buffer,
&match_start,
&match_end);
}
@@ -349,39 +361,48 @@ static void
forward_search (GeditViewFrame *frame)
{
GtkTextIter start_at;
- GtkSourceBuffer *buffer;
+ GtkTextBuffer *buffer;
+ GtkSourceSearchContext *search_context;
g_return_if_fail (frame->priv->search_mode == SEARCH);
+ search_context = get_search_context (frame);
+
+ if (search_context == NULL)
+ {
+ return;
+ }
+
renew_flush_timeout (frame);
- buffer = GTK_SOURCE_BUFFER (gedit_view_frame_get_document (frame));
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->priv->view));
- gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer),
- NULL,
- &start_at);
+ gtk_text_buffer_get_selection_bounds (buffer, NULL, &start_at);
- gtk_source_buffer_forward_search_async (buffer,
- &start_at,
- NULL,
- (GAsyncReadyCallback)forward_search_finished,
- frame);
+ gtk_source_search_context_forward_async (search_context,
+ &start_at,
+ NULL,
+ (GAsyncReadyCallback)forward_search_finished,
+ frame);
}
static void
-backward_search_finished (GtkSourceBuffer *buffer,
- GAsyncResult *result,
- GeditViewFrame *frame)
+backward_search_finished (GtkSourceSearchContext *search_context,
+ GAsyncResult *result,
+ GeditViewFrame *frame)
{
GtkTextIter match_start;
GtkTextIter match_end;
gboolean found;
+ GtkSourceBuffer *buffer;
- found = gtk_source_buffer_backward_search_finish (buffer,
- result,
- &match_start,
- &match_end,
- NULL);
+ found = gtk_source_search_context_backward_finish (search_context,
+ result,
+ &match_start,
+ &match_end,
+ NULL);
+
+ buffer = gtk_source_search_context_get_buffer (search_context);
if (found)
{
@@ -397,23 +418,29 @@ static void
backward_search (GeditViewFrame *frame)
{
GtkTextIter start_at;
- GtkSourceBuffer *buffer;
+ GtkTextBuffer *buffer;
+ GtkSourceSearchContext *search_context;
g_return_if_fail (frame->priv->search_mode == SEARCH);
+ search_context = get_search_context (frame);
+
+ if (search_context == NULL)
+ {
+ return;
+ }
+
renew_flush_timeout (frame);
- buffer = GTK_SOURCE_BUFFER (gedit_view_frame_get_document (frame));
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->priv->view));
- gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer),
- &start_at,
- NULL);
+ gtk_text_buffer_get_selection_bounds (buffer, &start_at, NULL);
- gtk_source_buffer_backward_search_async (buffer,
- &start_at,
- NULL,
- (GAsyncReadyCallback)backward_search_finished,
- frame);
+ gtk_source_search_context_backward_async (search_context,
+ &start_at,
+ NULL,
+ (GAsyncReadyCallback)backward_search_finished,
+ frame);
}
static gboolean
@@ -443,6 +470,36 @@ search_widget_scroll_event (GtkWidget *widget,
return GDK_EVENT_PROPAGATE;
}
+static GtkSourceSearchSettings *
+copy_search_settings (GtkSourceSearchSettings *settings)
+{
+ GtkSourceSearchSettings *new_settings = gtk_source_search_settings_new ();
+ gboolean val;
+ const gchar *text;
+
+ if (settings == NULL)
+ {
+ return new_settings;
+ }
+
+ val = gtk_source_search_settings_get_case_sensitive (settings);
+ gtk_source_search_settings_set_case_sensitive (new_settings, val);
+
+ val = gtk_source_search_settings_get_wrap_around (settings);
+ gtk_source_search_settings_set_wrap_around (new_settings, val);
+
+ val = gtk_source_search_settings_get_at_word_boundaries (settings);
+ gtk_source_search_settings_set_at_word_boundaries (new_settings, val);
+
+ val = gtk_source_search_settings_get_regex_enabled (settings);
+ gtk_source_search_settings_set_regex_enabled (new_settings, val);
+
+ text = gtk_source_search_settings_get_search_text (settings);
+ gtk_source_search_settings_set_search_text (new_settings, text);
+
+ return new_settings;
+}
+
static gboolean
search_widget_key_press_event (GtkWidget *widget,
GdkEventKey *event,
@@ -460,20 +517,16 @@ search_widget_key_press_event (GtkWidget *widget,
/* Close window and cancel the search */
if (event->keyval == GDK_KEY_Escape)
{
- if (frame->priv->search_mode == SEARCH)
+ GtkSourceSearchContext *search_context = get_search_context (frame);
+
+ if (frame->priv->search_mode == SEARCH &&
+ search_context != NULL)
{
- GtkSourceBuffer *buffer;
- gchar *unescaped_search_text;
-
- /* restore document search so that Find Next does the right thing */
- buffer = GTK_SOURCE_BUFFER (gedit_view_frame_get_document (frame));
- gtk_source_buffer_set_case_sensitive_search (buffer,
frame->priv->old_case_sensitive_search);
- gtk_source_buffer_set_search_at_word_boundaries (buffer,
frame->priv->old_search_at_word_boundaries);
- gtk_source_buffer_set_search_wrap_around (buffer,
frame->priv->old_search_wrap_around);
-
- unescaped_search_text = gtk_source_utils_unescape_search_text
(frame->priv->old_search_text);
- gtk_source_buffer_set_search_text (buffer, unescaped_search_text);
- g_free (unescaped_search_text);
+ g_clear_object (&frame->priv->search_settings);
+ frame->priv->search_settings = copy_search_settings
(frame->priv->old_search_settings);
+
+ gtk_source_search_context_set_settings (search_context,
+ frame->priv->search_settings);
}
hide_search_widget (frame, TRUE);
@@ -521,6 +574,7 @@ search_widget_key_press_event (GtkWidget *widget,
static void
update_entry_tag (GeditViewFrame *frame)
{
+ GtkSourceSearchContext *search_context;
GtkTextBuffer *buffer;
GtkTextIter select_start;
GtkTextIter select_end;
@@ -535,15 +589,21 @@ update_entry_tag (GeditViewFrame *frame)
return;
}
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->priv->view));
+ search_context = get_search_context (frame);
+
+ if (search_context == NULL)
+ {
+ return;
+ }
- count = gtk_source_buffer_get_search_occurrences_count (GTK_SOURCE_BUFFER (buffer));
+ count = gtk_source_search_context_get_occurrences_count (search_context);
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->priv->view));
gtk_text_buffer_get_selection_bounds (buffer, &select_start, &select_end);
- pos = gtk_source_buffer_get_search_occurrence_position (GTK_SOURCE_BUFFER (buffer),
- &select_start,
- &select_end);
+ pos = gtk_source_search_context_get_occurrence_position (search_context,
+ &select_start,
+ &select_end);
if (count == -1 || pos == -1)
{
@@ -600,59 +660,21 @@ install_update_entry_tag_idle (GeditViewFrame *frame)
}
static void
-update_search_settings (GeditViewFrame *frame)
+update_search_text (GeditViewFrame *frame)
{
- GtkSourceBuffer *buffer;
const gchar *entry_text;
gchar *unescaped_entry_text;
- buffer = GTK_SOURCE_BUFFER (gedit_view_frame_get_document (frame));
-
entry_text = gtk_entry_get_text (GTK_ENTRY (frame->priv->search_entry));
unescaped_entry_text = gtk_source_utils_unescape_search_text (entry_text);
- gtk_source_buffer_set_search_text (buffer, unescaped_entry_text);
- gtk_source_buffer_set_case_sensitive_search (buffer, frame->priv->case_sensitive_search);
- gtk_source_buffer_set_search_at_word_boundaries (buffer, frame->priv->search_at_word_boundaries);
- gtk_source_buffer_set_search_wrap_around (buffer, frame->priv->search_wrap_around);
+ gtk_source_search_settings_set_search_text (frame->priv->search_settings,
+ unescaped_entry_text);
g_free (unescaped_entry_text);
}
static void
-wrap_around_toggled_cb (GtkCheckMenuItem *menu_item,
- GeditViewFrame *frame)
-{
- GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (gedit_view_frame_get_document (frame));
-
- frame->priv->search_wrap_around = gtk_check_menu_item_get_active (menu_item);
-
- gtk_source_buffer_set_search_wrap_around (buffer, frame->priv->search_wrap_around);
-}
-
-static void
-entire_word_toggled_cb (GtkCheckMenuItem *menu_item,
- GeditViewFrame *frame)
-{
- GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (gedit_view_frame_get_document (frame));
-
- frame->priv->search_at_word_boundaries = gtk_check_menu_item_get_active (menu_item);
-
- gtk_source_buffer_set_search_at_word_boundaries (buffer, frame->priv->search_at_word_boundaries);
-}
-
-static void
-match_case_toggled_cb (GtkCheckMenuItem *menu_item,
- GeditViewFrame *frame)
-{
- GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (gedit_view_frame_get_document (frame));
-
- frame->priv->case_sensitive_search = gtk_check_menu_item_get_active (menu_item);
-
- gtk_source_buffer_set_case_sensitive_search (buffer, frame->priv->case_sensitive_search);
-}
-
-static void
add_popup_menu_items (GeditViewFrame *frame,
GtkWidget *menu)
{
@@ -662,46 +684,31 @@ add_popup_menu_items (GeditViewFrame *frame,
menu_item = gtk_check_menu_item_new_with_mnemonic (_("_Wrap Around"));
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
-
- g_signal_connect (menu_item,
- "toggled",
- G_CALLBACK (wrap_around_toggled_cb),
- frame);
-
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
- frame->priv->search_wrap_around);
-
gtk_widget_show (menu_item);
+ g_object_bind_property (frame->priv->search_settings, "wrap-around",
+ menu_item, "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
/* create "Match Entire Word Only" menu item. */
menu_item = gtk_check_menu_item_new_with_mnemonic (_("Match _Entire Word Only"));
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
-
- g_signal_connect (menu_item,
- "toggled",
- G_CALLBACK (entire_word_toggled_cb),
- frame);
-
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
- frame->priv->search_at_word_boundaries);
-
gtk_widget_show (menu_item);
+ g_object_bind_property (frame->priv->search_settings, "at-word-boundaries",
+ menu_item, "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
/* create "Match Case" menu item. */
menu_item = gtk_check_menu_item_new_with_mnemonic (_("_Match Case"));
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
-
- g_signal_connect (menu_item,
- "toggled",
- G_CALLBACK (match_case_toggled_cb),
- frame);
-
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
- frame->priv->case_sensitive_search);
-
gtk_widget_show (menu_item);
+
+ g_object_bind_property (frame->priv->search_settings, "case-sensitive",
+ menu_item, "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
}
static void
@@ -979,7 +986,7 @@ search_entry_changed_cb (GtkEntry *entry,
if (frame->priv->search_mode == SEARCH)
{
- update_search_settings (frame);
+ update_search_text (frame);
start_search (frame);
}
else
@@ -1077,24 +1084,32 @@ init_search_entry (GeditViewFrame *frame)
/* SEARCH mode */
gboolean selection_exists;
gchar *search_text = NULL;
- const gchar *old_search_text;
gint selection_len = 0;
+ const gchar *old_search_text;
+ GtkSourceSearchContext *search_context;
+
+ if (frame->priv->search_settings == NULL)
+ {
+ frame->priv->search_settings = gtk_source_search_settings_new ();
+ }
- old_search_text = gtk_source_buffer_get_search_text (GTK_SOURCE_BUFFER (buffer));
+ g_clear_object (&frame->priv->old_search_settings);
+ frame->priv->old_search_settings = copy_search_settings (frame->priv->search_settings);
- frame->priv->old_case_sensitive_search =
- gtk_source_buffer_get_case_sensitive_search (GTK_SOURCE_BUFFER (buffer));
+ search_context = gtk_source_search_context_new (GTK_SOURCE_BUFFER (buffer),
+ frame->priv->search_settings);
- frame->priv->old_search_at_word_boundaries =
- gtk_source_buffer_get_search_at_word_boundaries (GTK_SOURCE_BUFFER (buffer));
+ _gedit_document_set_search_context (GEDIT_DOCUMENT (buffer),
+ search_context);
- frame->priv->old_search_wrap_around =
- gtk_source_buffer_get_search_wrap_around (GTK_SOURCE_BUFFER (buffer));
+ g_object_unref (search_context);
selection_exists = get_selected_text (buffer,
&search_text,
&selection_len);
+ old_search_text = gtk_source_search_settings_get_search_text (frame->priv->search_settings);
+
if (selection_exists && (search_text != NULL) && (selection_len <= 160))
{
gchar *search_text_escaped = gtk_source_utils_escape_search_text (search_text);
@@ -1111,9 +1126,6 @@ init_search_entry (GeditViewFrame *frame)
{
gchar *old_search_text_escaped = gtk_source_utils_escape_search_text
(old_search_text);
- g_free (frame->priv->old_search_text);
- frame->priv->old_search_text = old_search_text_escaped;
-
g_signal_handler_block (frame->priv->search_entry,
frame->priv->search_entry_changed_id);
@@ -1204,7 +1216,6 @@ gedit_view_frame_class_init (GeditViewFrameClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- object_class->finalize = gedit_view_frame_finalize;
object_class->dispose = gedit_view_frame_dispose;
object_class->get_property = gedit_view_frame_get_property;
@@ -1252,10 +1263,6 @@ gedit_view_frame_init (GeditViewFrame *frame)
frame->priv = gedit_view_frame_get_instance_private (frame);
- frame->priv->case_sensitive_search = FALSE;
- frame->priv->search_at_word_boundaries = FALSE;
- frame->priv->search_wrap_around = TRUE;
-
gtk_widget_init_template (GTK_WIDGET (frame));
gtk_widget_override_background_color (GTK_WIDGET (frame), 0, &transparent);
@@ -1387,14 +1394,8 @@ gedit_view_frame_popup_goto_line (GeditViewFrame *frame)
void
gedit_view_frame_clear_search (GeditViewFrame *frame)
{
- GeditDocument *doc;
-
g_return_if_fail (GEDIT_IS_VIEW_FRAME (frame));
- doc = gedit_view_frame_get_document (frame);
-
- gtk_source_buffer_set_search_text (GTK_SOURCE_BUFFER (doc), "");
-
g_signal_handler_block (frame->priv->search_entry,
frame->priv->search_entry_changed_id);
diff --git a/plugins/spell/gedit-spell-plugin.c b/plugins/spell/gedit-spell-plugin.c
index efccae5..0bc498a 100644
--- a/plugins/spell/gedit-spell-plugin.c
+++ b/plugins/spell/gedit-spell-plugin.c
@@ -659,9 +659,8 @@ change_all_cb (GeditSpellCheckerDialog *dlg,
CheckRange *range;
gchar *w = NULL;
GtkTextIter start, end;
- gboolean case_sensitive;
- gboolean at_word_boundaries;
- gboolean highlight_search;
+ GtkSourceSearchSettings *search_settings;
+ GtkSourceSearchContext *search_context;
gedit_debug (DEBUG_PLUGINS);
@@ -692,26 +691,25 @@ change_all_cb (GeditSpellCheckerDialog *dlg,
g_free (w);
- case_sensitive = gtk_source_buffer_get_case_sensitive_search (GTK_SOURCE_BUFFER (doc));
- at_word_boundaries = gtk_source_buffer_get_search_at_word_boundaries (GTK_SOURCE_BUFFER (doc));
- highlight_search = gtk_source_buffer_get_highlight_search (GTK_SOURCE_BUFFER (doc));
+ search_settings = gtk_source_search_settings_new ();
+ gtk_source_search_settings_set_case_sensitive (search_settings, TRUE);
+ gtk_source_search_settings_set_at_word_boundaries (search_settings, TRUE);
+ gtk_source_search_settings_set_search_text (search_settings, word);
- gtk_source_buffer_set_case_sensitive_search (GTK_SOURCE_BUFFER (doc), TRUE);
- gtk_source_buffer_set_search_at_word_boundaries (GTK_SOURCE_BUFFER (doc), TRUE);
- gtk_source_buffer_set_highlight_search (GTK_SOURCE_BUFFER (doc), FALSE);
+ search_context = gtk_source_search_context_new (GTK_SOURCE_BUFFER (doc),
+ search_settings);
- gtk_source_buffer_set_search_text (GTK_SOURCE_BUFFER (doc), word);
- gtk_source_buffer_search_replace_all (GTK_SOURCE_BUFFER (doc), change, -1);
- gtk_source_buffer_set_search_text (GTK_SOURCE_BUFFER (doc), NULL);
+ gtk_source_search_context_set_highlight (search_context, FALSE);
- gtk_source_buffer_set_case_sensitive_search (GTK_SOURCE_BUFFER (doc), case_sensitive);
- gtk_source_buffer_set_search_at_word_boundaries (GTK_SOURCE_BUFFER (doc), at_word_boundaries);
- gtk_source_buffer_set_highlight_search (GTK_SOURCE_BUFFER (doc), highlight_search);
+ gtk_source_search_context_replace_all (search_context, change, -1);
update_current (doc, range->mw_start + g_utf8_strlen (change, -1));
/* go to next misspelled word */
ignore_cb (dlg, word, view);
+
+ g_object_unref (search_settings);
+ g_object_unref (search_context);
}
static void
@@ -857,8 +855,6 @@ spell_cb (GtkAction *action,
gtk_window_set_transient_for (GTK_WINDOW (dlg),
GTK_WINDOW (priv->window));
- gtk_source_buffer_set_search_text (GTK_SOURCE_BUFFER (doc), NULL);
-
g_signal_connect (dlg, "ignore", G_CALLBACK (ignore_cb), view);
g_signal_connect (dlg, "ignore_all", G_CALLBACK (ignore_cb), view);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]