[gtksourceview/wip/search] test-search-ui: unescape text + match case option



commit 1616c7e3c522d9f02d4940e74ceff86dc55c28b0
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Jun 24 16:38:26 2013 +0200

    test-search-ui: unescape text + match case option

 tests/test-search-ui.c  |   52 ++++++++++++++++++++++++++++++++++++++--------
 tests/test-search-ui.ui |   29 ++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 9 deletions(-)
---
diff --git a/tests/test-search-ui.c b/tests/test-search-ui.c
index aac5910..13ac850 100644
--- a/tests/test-search-ui.c
+++ b/tests/test-search-ui.c
@@ -50,18 +50,44 @@ on_occurrences_count_notify_cb (GtkSourceBuffer *buffer,
                                GParamSpec      *spec,
                                GtkLabel        *label)
 {
-       guint occurrences_count;
-       gchar *text;
-
-       g_object_get (buffer, "search-occurrences-count", &occurrences_count, NULL);
-
-       text = g_strdup_printf ("%u occurrences", occurrences_count);
+       guint occurrences_count = gtk_source_buffer_get_search_occurrences_count (buffer);
+       gchar *text = g_strdup_printf ("%u occurrences", occurrences_count);
 
        gtk_label_set_text (label, text);
        g_free (text);
 }
 
 static void
+on_search_entry_text_notify_cb (GtkEntry        *entry,
+                               GParamSpec      *spec,
+                               GtkSourceBuffer *buffer)
+{
+       const gchar *text = gtk_entry_get_text (entry);
+       gchar *unescaped_text = gtk_source_utils_unescape_search_text (text);
+
+       gtk_source_buffer_set_search_text (buffer, unescaped_text);
+       g_free (unescaped_text);
+}
+
+static void
+on_match_case_toggled_cb (GtkToggleButton *button,
+                         GtkSourceBuffer *buffer)
+{
+       GtkTextSearchFlags flags = gtk_source_buffer_get_search_flags (buffer);
+
+       if (gtk_toggle_button_get_active (button))
+       {
+               flags &= ~GTK_TEXT_SEARCH_CASE_INSENSITIVE;
+       }
+       else
+       {
+               flags |= GTK_TEXT_SEARCH_CASE_INSENSITIVE;
+       }
+
+       gtk_source_buffer_set_search_flags (buffer, flags);
+}
+
+static void
 create_window (void)
 {
        GtkBuilder *builder;
@@ -71,6 +97,7 @@ create_window (void)
        GtkSourceBuffer *source_buffer;
        GtkSearchEntry *search_entry;
        GtkLabel *label_occurrences_count;
+       GtkCheckButton *match_case;
        PangoFontDescription *font;
 
        builder = gtk_builder_new ();
@@ -88,6 +115,7 @@ create_window (void)
        source_view = GTK_SOURCE_VIEW (gtk_builder_get_object (builder, "source_view"));
        search_entry = GTK_SEARCH_ENTRY (gtk_builder_get_object (builder, "search_entry"));
        label_occurrences_count = GTK_LABEL (gtk_builder_get_object (builder, "label_occurrences_count"));
+       match_case = GTK_CHECK_BUTTON (gtk_builder_get_object (builder, "checkbutton_match_case"));
 
        font = pango_font_description_from_string ("Monospace 10");
        gtk_widget_override_font (GTK_WIDGET (source_view), font);
@@ -111,15 +139,21 @@ create_window (void)
                          G_CALLBACK (gtk_main_quit),
                          NULL);
 
-       g_object_bind_property (search_entry, "text",
-                               source_buffer, "search-text",
-                               G_BINDING_DEFAULT);
+       g_signal_connect (search_entry,
+                         "notify::text",
+                         G_CALLBACK (on_search_entry_text_notify_cb),
+                         source_buffer);
 
        g_signal_connect (source_buffer,
                          "notify::search-occurrences-count",
                          G_CALLBACK (on_occurrences_count_notify_cb),
                          label_occurrences_count);
 
+       g_signal_connect (match_case,
+                         "toggled",
+                         G_CALLBACK (on_match_case_toggled_cb),
+                         source_buffer);
+
        g_object_unref (builder);
 }
 
diff --git a/tests/test-search-ui.ui b/tests/test-search-ui.ui
index 3b52dab..0a43de8 100644
--- a/tests/test-search-ui.ui
+++ b/tests/test-search-ui.ui
@@ -98,6 +98,35 @@
             <property name="height">1</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkGrid" id="grid3">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkCheckButton" id="checkbutton_match_case">
+                <property name="label">Match case</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">2</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
       </object>
     </child>
   </object>


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