[gedit/wip/search-fixes] Search and replace: create directly the SearchContext



commit 6d9df6f35232d8859b215ce886c4f177f0203ed4
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Aug 24 17:35:33 2013 +0200

    Search and replace: create directly the SearchContext
    
    As soon as the search and replace dialog is shown, we create the
    SearchContext. Before, the SearchContext was created only when a dialog
    button (find, replace, ...) was pressed.
    
    When the document tab changes, we also create the SearchContext
    directly.
    
    Once the SearchContext is created, changing the search text or the other
    search settings have a direct effect on the buffer. The highlighting is
    updated, etc. So it is a bit like the incremental search, except that
    the current match is not updated and selected when the search settings
    change.
    
    With the search and replace API from GtkSourceView, we have this
    behavior almost for free. If we wanted the old behavior, it would be
    more complicated.

 gedit/gedit-commands-search.c |   48 +++++++++++++++++++++++++++++------------
 1 files changed, 34 insertions(+), 14 deletions(-)
---
diff --git a/gedit/gedit-commands-search.c b/gedit/gedit-commands-search.c
index 0f80439..7e528ea 100644
--- a/gedit/gedit-commands-search.c
+++ b/gedit/gedit-commands-search.c
@@ -576,11 +576,21 @@ search_context_finalized_cb (GeditReplaceDialog *dialog,
 }
 
 static void
-create_search_context (GeditReplaceDialog      *dialog,
-                      GeditDocument           *doc,
-                      GtkSourceSearchSettings *search_settings)
+create_search_context (GeditReplaceDialog *dialog,
+                      GeditDocument      *doc)
 {
        GtkSourceSearchContext *search_context;
+       GtkSourceSearchSettings *search_settings;
+
+       search_settings = gedit_replace_dialog_get_search_settings (dialog);
+
+       search_context = _gedit_document_get_search_context (doc);
+
+       if (search_context != NULL &&
+           search_settings == gtk_source_search_context_get_settings (search_context))
+       {
+               return;
+       }
 
        search_context = gtk_source_search_context_new (GTK_SOURCE_BUFFER (doc),
                                                        search_settings);
@@ -608,21 +618,11 @@ replace_dialog_response_cb (GeditReplaceDialog *dialog,
                            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))
-       {
-               create_search_context (dialog, doc, search_settings);
-       }
+       create_search_context (dialog, doc);
 
        switch (response_id)
        {
@@ -658,6 +658,18 @@ replace_dialog_destroyed (GeditWindow        *window,
                           NULL);
 }
 
+static void
+active_tab_changed_cb (GeditWindow        *window,
+                      GeditTab           *tab,
+                      GeditReplaceDialog *replace_dialog)
+{
+       if (tab != NULL)
+       {
+               GeditDocument *doc = gedit_tab_get_document (tab);
+               create_search_context (replace_dialog, doc);
+       }
+}
+
 static GtkWidget *
 create_dialog (GeditWindow *window)
 {
@@ -678,6 +690,12 @@ create_dialog (GeditWindow *window)
                           (GWeakNotify) replace_dialog_destroyed,
                           window);
 
+       g_signal_connect_object (window,
+                                "active-tab-changed",
+                                G_CALLBACK (active_tab_changed_cb),
+                                dialog,
+                                0);
+
        return dialog;
 }
 
@@ -730,6 +748,8 @@ _gedit_cmd_search_replace (GtkAction   *action,
        doc = gedit_window_get_active_document (window);
        g_return_if_fail (doc != NULL);
 
+       create_search_context (GEDIT_REPLACE_DIALOG (replace_dialog), doc);
+
        selection_exists = get_selected_text (GTK_TEXT_BUFFER (doc),
                                              &find_text,
                                              &sel_len);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]