[gedit/wip/use-gsv-search: 13/15] ViewFrame: split GtkSourceSearchFlags



commit 57bb81cd6f5cc8cff43a3d04d3230ed24d65d4f6
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Jun 30 18:30:08 2013 +0200

    ViewFrame: split GtkSourceSearchFlags

 gedit/gedit-view-frame.c |  152 +++++++++++++++++-----------------------------
 1 files changed, 55 insertions(+), 97 deletions(-)
---
diff --git a/gedit/gedit-view-frame.c b/gedit/gedit-view-frame.c
index 08fadd5..745b1bb 100644
--- a/gedit/gedit-view-frame.c
+++ b/gedit/gedit-view-frame.c
@@ -56,17 +56,10 @@ struct _GeditViewFramePrivate
         */
        GtkTextMark *start_mark;
 
-       /* used to restore the search state if an
-        * incremental search is cancelled
+       /* Used to restore the search state if an incremental search is
+        * cancelled.
         */
        gchar       *old_search_text;
-       GtkSourceSearchFlags old_search_flags;
-
-       /* used to remember the state of the last
-        * incremental search (the document search
-        * state may be changed by the search dialog)
-        */
-       GtkSourceSearchFlags search_flags;
 
        GtkRevealer *slider;
        GtkEntry    *search_entry;
@@ -79,6 +72,20 @@ struct _GeditViewFramePrivate
        glong        search_entry_changed_id;
 
        guint        disable_popdown : 1;
+
+       /* 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;
+
+       /* 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;
 };
 
 enum
@@ -466,7 +473,9 @@ search_widget_key_press_event (GtkWidget      *widget,
 
                        /* 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_search_flags (buffer, frame->priv->old_search_flags);
+                       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);
                        gtk_source_buffer_set_search_text (buffer, frame->priv->old_search_text);
                }
 
@@ -523,120 +532,59 @@ update_search (GeditViewFrame *frame)
        entry_text = gtk_entry_get_text (frame->priv->search_entry);
 
        gtk_source_buffer_set_search_text (buffer, entry_text);
-       gtk_source_buffer_set_search_flags (buffer, frame->priv->search_flags);
-}
-
-static void
-wrap_around_menu_item_toggled (GtkCheckMenuItem *checkmenuitem,
-                               GeditViewFrame   *frame)
-{
-       GtkSourceBuffer *buffer;
-
-       if (gtk_check_menu_item_get_active (checkmenuitem))
-       {
-               frame->priv->search_flags |= GTK_SOURCE_SEARCH_WRAP_AROUND;
-       }
-       else
-       {
-               frame->priv->search_flags &= ~GTK_SOURCE_SEARCH_WRAP_AROUND;
-       }
-
-       buffer = GTK_SOURCE_BUFFER (gedit_view_frame_get_document (frame));
-
-       gtk_source_buffer_set_search_flags (buffer, frame->priv->search_flags);
-}
-
-static void
-match_entire_word_menu_item_toggled (GtkCheckMenuItem *checkmenuitem,
-                                     GeditViewFrame   *frame)
-{
-       GtkSourceBuffer *buffer;
-
-       if (gtk_check_menu_item_get_active (checkmenuitem))
-       {
-               frame->priv->search_flags |= GTK_SOURCE_SEARCH_AT_WORD_BOUNDARIES;
-       }
-       else
-       {
-               frame->priv->search_flags &= ~GTK_SOURCE_SEARCH_AT_WORD_BOUNDARIES;
-       }
-
-       buffer = GTK_SOURCE_BUFFER (gedit_view_frame_get_document (frame));
-
-       gtk_source_buffer_set_search_flags (buffer, frame->priv->search_flags);
-}
-
-static void
-match_case_menu_item_toggled (GtkCheckMenuItem *checkmenuitem,
-                              GeditViewFrame   *frame)
-{
-       GtkSourceBuffer *buffer;
-
-       if (gtk_check_menu_item_get_active (checkmenuitem))
-       {
-               frame->priv->search_flags |= GTK_SOURCE_SEARCH_CASE_SENSITIVE;
-       }
-       else
-       {
-               frame->priv->search_flags &= ~GTK_SOURCE_SEARCH_CASE_SENSITIVE;
-       }
-
-       buffer = GTK_SOURCE_BUFFER (gedit_view_frame_get_document (frame));
-
-       gtk_source_buffer_set_search_flags (buffer, frame->priv->search_flags);
+       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);
 }
 
 static void
 add_popup_menu_items (GtkWidget      *menu,
                       GeditViewFrame *frame)
 {
+       GeditDocument *doc;
        GtkWidget *menu_item;
-       gboolean wrap_around;
-       gboolean entire_word;
-       gboolean case_sensitive;
+
+       doc = gedit_view_frame_get_document (frame);
 
        /* create "Wrap Around" menu item. */
        menu_item = gtk_check_menu_item_new_with_mnemonic (_("_Wrap Around"));
 
-       g_signal_connect (G_OBJECT (menu_item),
-                         "toggled",
-                         G_CALLBACK (wrap_around_menu_item_toggled),
-                         frame);
-
        gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
 
-       wrap_around = (frame->priv->search_flags & GTK_SOURCE_SEARCH_WRAP_AROUND) != 0;
-       gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), wrap_around);
+       gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
+                                       frame->priv->search_wrap_around);
+
+       g_object_bind_property (menu_item, "active",
+                               doc, "search-wrap-around",
+                               G_BINDING_SYNC_CREATE);
 
        gtk_widget_show (menu_item);
 
        /* create "Match Entire Word Only" menu item. */
        menu_item = gtk_check_menu_item_new_with_mnemonic (_("Match _Entire Word Only"));
 
-       g_signal_connect (G_OBJECT (menu_item),
-                         "toggled",
-                         G_CALLBACK (match_entire_word_menu_item_toggled),
-                         frame);
-
        gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
 
-       entire_word = (frame->priv->search_flags & GTK_SOURCE_SEARCH_AT_WORD_BOUNDARIES) != 0;
-       gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), entire_word);
+       gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
+                                       frame->priv->search_at_word_boundaries);
+
+       g_object_bind_property (menu_item, "active",
+                               doc, "search-at-word-boundaries",
+                               G_BINDING_SYNC_CREATE);
 
        gtk_widget_show (menu_item);
 
        /* create "Match Case" menu item. */
        menu_item = gtk_check_menu_item_new_with_mnemonic (_("_Match Case"));
 
-       g_signal_connect (G_OBJECT (menu_item),
-                         "toggled",
-                         G_CALLBACK (match_case_menu_item_toggled),
-                         frame);
-
        gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
 
-       case_sensitive = (frame->priv->search_flags & GTK_SOURCE_SEARCH_CASE_SENSITIVE) != 0;
-       gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), case_sensitive);
+       gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
+                                       frame->priv->case_sensitive_search);
+
+       g_object_bind_property (menu_item, "active",
+                               doc, "case-sensitive-search",
+                               G_BINDING_SYNC_CREATE);
 
        gtk_widget_show (menu_item);
 }
@@ -1114,7 +1062,15 @@ init_search_entry (GeditViewFrame *frame)
                gint selection_len = 0;
 
                old_search_text = gtk_source_buffer_get_search_text (GTK_SOURCE_BUFFER (buffer));
-               frame->priv->old_search_flags = gtk_source_buffer_get_search_flags (GTK_SOURCE_BUFFER 
(buffer));
+
+               frame->priv->old_case_sensitive_search =
+                       gtk_source_buffer_get_case_sensitive_search (GTK_SOURCE_BUFFER (buffer));
+
+               frame->priv->old_search_at_word_boundaries =
+                       gtk_source_buffer_get_search_at_word_boundaries (GTK_SOURCE_BUFFER (buffer));
+
+               frame->priv->old_search_wrap_around =
+                       gtk_source_buffer_get_search_wrap_around (GTK_SOURCE_BUFFER (buffer));
 
                selection_exists = get_selected_text (buffer,
                                                      &search_text,
@@ -1273,7 +1229,9 @@ gedit_view_frame_init (GeditViewFrame *frame)
        frame->priv = GEDIT_VIEW_FRAME_GET_PRIVATE (frame);
 
        frame->priv->typeselect_flush_timeout = 0;
-       frame->priv->search_flags = GTK_SOURCE_SEARCH_WRAP_AROUND;
+       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));
 


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