[gtksourceview/wip/regex-search] test-search-ui: show regex error



commit 6da6236c69f09bbbc86003342da014af35df1de0
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jul 20 18:30:28 2013 +0200

    test-search-ui: show regex error

 tests/test-search-ui.c  |   37 +++++++++++++++++++++++++++++++++----
 tests/test-search-ui.ui |   40 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 68 insertions(+), 9 deletions(-)
---
diff --git a/tests/test-search-ui.c b/tests/test-search-ui.c
index b0151d6..04c6c45 100644
--- a/tests/test-search-ui.c
+++ b/tests/test-search-ui.c
@@ -50,6 +50,7 @@ struct _TestSearchUIPrivate
        GtkSourceBuffer *source_buffer;
        GtkEntry *replace_entry;
        GtkLabel *label_occurrences;
+       GtkLabel *label_regex_error;
 
        guint idle_update_label_id;
 };
@@ -92,7 +93,7 @@ open_file (TestSearchUI *search,
 }
 
 static void
-update_label (TestSearchUI *search)
+update_label_occurrences (TestSearchUI *search)
 {
        gint occurrences_count;
        GtkTextIter select_start;
@@ -127,6 +128,26 @@ update_label (TestSearchUI *search)
        g_free (text);
 }
 
+static void
+update_label_regex_error (TestSearchUI *search)
+{
+       GError *error;
+
+       error = gtk_source_buffer_get_regex_search_error (search->priv->source_buffer);
+
+       if (error == NULL)
+       {
+               gtk_label_set_text (search->priv->label_regex_error, "");
+               gtk_widget_hide (GTK_WIDGET (search->priv->label_regex_error));
+       }
+       else
+       {
+               gtk_label_set_text (search->priv->label_regex_error, error->message);
+               gtk_widget_show (GTK_WIDGET (search->priv->label_regex_error));
+               g_error_free (error);
+       }
+}
+
 /* The search entry is a GtkSearchEntry. The "changed" signal is delayed on a
  * GtkSearchEntry (but not with a simple GtkEntry). That's why the
  * "notify::text" signal is used instead.
@@ -285,7 +306,7 @@ update_label_idle_cb (TestSearchUI *search)
 {
        search->priv->idle_update_label_id = 0;
 
-       update_label (search);
+       update_label_occurrences (search);
 
        return G_SOURCE_REMOVE;
 }
@@ -374,6 +395,7 @@ test_search_ui_class_init (TestSearchUIClass *klass)
        gtk_widget_class_bind_child (widget_class, TestSearchUIPrivate, source_view);
        gtk_widget_class_bind_child (widget_class, TestSearchUIPrivate, replace_entry);
        gtk_widget_class_bind_child (widget_class, TestSearchUIPrivate, label_occurrences);
+       gtk_widget_class_bind_child (widget_class, TestSearchUIPrivate, label_regex_error);
 
        gtk_widget_class_bind_callback (widget_class, search_entry_text_notify_cb);
        gtk_widget_class_bind_callback (widget_class, button_previous_clicked_cb);
@@ -417,13 +439,20 @@ test_search_ui_init (TestSearchUI *search)
 
        g_signal_connect_swapped (search->priv->source_buffer,
                                  "notify::search-occurrences-count",
-                                 G_CALLBACK (update_label),
+                                 G_CALLBACK (update_label_occurrences),
                                  search);
 
        g_signal_connect (search->priv->source_buffer,
                          "mark-set",
                          G_CALLBACK (mark_set_cb),
                          search);
+
+       g_signal_connect_swapped (search->priv->source_buffer,
+                                 "notify::regex-search-error",
+                                 G_CALLBACK (update_label_regex_error),
+                                 search);
+
+       update_label_regex_error (search);
 }
 
 static TestSearchUI *
@@ -452,7 +481,7 @@ main (gint argc, gchar *argv[])
        search = test_search_ui_new ();
        gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (search));
 
-       gtk_widget_show_all (window);
+       gtk_widget_show (window);
 
        gtk_main ();
 
diff --git a/tests/test-search-ui.ui b/tests/test-search-ui.ui
index 9f2a39e..2c87d85 100644
--- a/tests/test-search-ui.ui
+++ b/tests/test-search-ui.ui
@@ -59,11 +59,13 @@
       <object class="GtkGrid" id="grid2">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
+        <property name="row_spacing">6</property>
         <property name="column_spacing">6</property>
         <child>
           <object class="GtkLabel" id="label1">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
+            <property name="halign">start</property>
             <property name="xalign">0</property>
             <property name="label">Search:</property>
             <attributes>
@@ -72,15 +74,17 @@
           </object>
           <packing>
             <property name="left_attach">0</property>
-            <property name="top_attach">0</property>
+            <property name="top_attach">1</property>
             <property name="width">1</property>
             <property name="height">1</property>
           </packing>
         </child>
         <child>
           <object class="GtkSearchEntry" id="search_entry">
+            <property name="width_request">200</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
+            <property name="halign">start</property>
             <property name="primary_icon_name">edit-find-symbolic</property>
             <property name="primary_icon_activatable">False</property>
             <property name="primary_icon_sensitive">False</property>
@@ -88,7 +92,7 @@
           </object>
           <packing>
             <property name="left_attach">1</property>
-            <property name="top_attach">0</property>
+            <property name="top_attach">1</property>
             <property name="width">1</property>
             <property name="height">1</property>
           </packing>
@@ -97,11 +101,12 @@
           <object class="GtkLabel" id="label_occurrences">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
+            <property name="halign">start</property>
             <property name="label">0 occurrences</property>
           </object>
           <packing>
             <property name="left_attach">4</property>
-            <property name="top_attach">0</property>
+            <property name="top_attach">1</property>
             <property name="width">1</property>
             <property name="height">1</property>
           </packing>
@@ -111,12 +116,13 @@
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">True</property>
+            <property name="halign">start</property>
             <property name="image">image1</property>
             <signal name="clicked" handler="button_previous_clicked_cb" object="TestSearchUI" swapped="yes"/>
           </object>
           <packing>
             <property name="left_attach">2</property>
-            <property name="top_attach">0</property>
+            <property name="top_attach">1</property>
             <property name="width">1</property>
             <property name="height">1</property>
           </packing>
@@ -126,16 +132,40 @@
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">True</property>
+            <property name="halign">start</property>
             <property name="image">image2</property>
             <signal name="clicked" handler="button_next_clicked_cb" object="TestSearchUI" swapped="yes"/>
           </object>
           <packing>
             <property name="left_attach">3</property>
-            <property name="top_attach">0</property>
+            <property name="top_attach">1</property>
             <property name="width">1</property>
             <property name="height">1</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkLabel" id="label_regex_error">
+            <property name="can_focus">False</property>
+            <property name="halign">start</property>
+            <property name="xalign">0</property>
+            <property name="label">Regex search error</property>
+            <property name="wrap">True</property>
+            <property name="selectable">True</property>
+            <property name="max_width_chars">72</property>
+            <attributes>
+              <attribute name="foreground" value="#cccc00000000"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">0</property>
+            <property name="width">4</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
       </object>
       <packing>
         <property name="left_attach">0</property>


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