[gtranslator/merge-requests/61: 8/20] Enable search-options in src/gtr-search-bar.c and src/gtr-tab.ui



commit 07b470366df48ba9ab617d5f78f8e3b6a4d2a54f
Author: Priyanka Saggu <priyankasggu11929 gmail com>
Date:   Wed Jan 8 19:21:28 2020 +0530

    Enable search-options in src/gtr-search-bar.c and src/gtr-tab.ui

 src/gtr-search-bar.c | 187 ++++++++++++++++++++++++++++++++++++++++++++-------
 src/gtr-tab.ui       |   3 +-
 2 files changed, 166 insertions(+), 24 deletions(-)
---
diff --git a/src/gtr-search-bar.c b/src/gtr-search-bar.c
index 0f6ad4df..142c5328 100644
--- a/src/gtr-search-bar.c
+++ b/src/gtr-search-bar.c
@@ -103,6 +103,156 @@ gtr_search_bar_real_stop_search (GtrSearchBar *self)
   g_assert (GTR_IS_SEARCH_BAR (self));
 }
 
+static gboolean
+pacify_null_text (GBinding     *binding,
+                  const GValue *from_value,
+                  GValue       *to_value,
+                  gpointer      user_data)
+{
+  g_assert (from_value != NULL);
+  g_assert (to_value != NULL);
+  g_assert (G_VALUE_HOLDS_STRING (from_value));
+  g_assert (G_VALUE_HOLDS_STRING (to_value));
+
+  if (g_value_get_string (from_value) == NULL)
+    g_value_set_static_string (to_value, "");
+  else
+    g_value_copy (from_value, to_value);
+
+  return TRUE;
+}
+
+
+static gboolean
+maybe_escape_regex (GBinding     *binding,
+                    const GValue *from_value,
+                    GValue       *to_value,
+                    gpointer      user_data)
+{
+  GtrSearchBar *self = user_data;
+  const gchar *entry_text;
+
+  g_assert (GTR_IS_SEARCH_BAR (self));
+  g_assert (from_value != NULL);
+  g_assert (to_value != NULL);
+
+  entry_text = g_value_get_string (from_value);
+
+  if (entry_text == NULL)
+    {
+      g_value_set_static_string (to_value, "");
+    }
+  else
+    {
+      g_autofree gchar *unescaped = NULL;
+
+      if (self->search != NULL //&& !ide_editor_search_get_regex_enabled (self->search)
+          )
+        entry_text = unescaped = gtk_source_utils_unescape_search_text (entry_text);
+
+      g_value_set_string (to_value, entry_text);
+    }
+
+  return TRUE;
+}
+
+gboolean
+gtr_search_bar_get_show_options (GtrSearchBar *self)
+{
+  g_return_val_if_fail (GTR_IS_SEARCH_BAR (self), FALSE);
+
+  return self->show_options;
+}
+
+gboolean
+gtr_search_bar_get_replace_mode (GtrSearchBar *self)
+{
+  g_return_val_if_fail (GTK_IS_SEARCH_BAR (self), FALSE);
+
+  return self->replace_mode;
+}
+
+static void
+gtr_search_bar_get_property (GObject    *object,
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
+{
+  GtrSearchBar *self = GTR_SEARCH_BAR (object);
+
+  switch (prop_id)
+    {
+    case PROP_REPLACE_MODE:
+      g_value_set_boolean (value, gtr_search_bar_get_replace_mode (self));
+      break;
+
+    case PROP_SHOW_OPTIONS:
+      g_value_set_boolean (value, gtr_search_bar_get_show_options (self));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+void
+gtr_search_bar_set_replace_mode (GtrSearchBar *self,
+                                        gboolean            replace_mode)
+{
+    g_return_if_fail (GTR_IS_SEARCH_BAR (self));
+
+  replace_mode = !!replace_mode;
+
+  if (replace_mode != self->replace_mode)
+    {
+      self->replace_mode = replace_mode;
+      gtk_widget_set_visible (GTK_WIDGET (self->replace_entry), replace_mode);
+      gtk_widget_set_visible (GTK_WIDGET (self->replace_button), replace_mode);
+      gtk_widget_set_visible (GTK_WIDGET (self->replace_all_button), replace_mode);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_REPLACE_MODE]);
+    }
+}
+
+
+void
+gtr_search_bar_set_show_options (GtrSearchBar *self,
+                                        gboolean            show_options)
+{
+  g_return_if_fail (GTR_IS_SEARCH_BAR (self));
+
+  show_options = !!show_options;
+
+  if (self->show_options != show_options)
+    {
+      self->show_options = show_options;
+      gtk_widget_set_visible (GTK_WIDGET (self->search_options), show_options);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SHOW_OPTIONS]);
+    }
+}
+
+
+static void
+gtr_search_bar_set_property (GObject      *object,
+                                    guint         prop_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
+{
+  GtrSearchBar *self = GTR_SEARCH_BAR (object);
+
+  switch (prop_id)
+    {
+    case PROP_REPLACE_MODE:
+      gtr_search_bar_set_replace_mode (self, g_value_get_boolean (value));
+      break;
+
+    case PROP_SHOW_OPTIONS:
+      gtr_search_bar_set_show_options (self, g_value_get_boolean (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
 
 static void
 gtr_search_bar_class_init (GtrSearchBarClass *klass)
@@ -110,6 +260,9 @@ gtr_search_bar_class_init (GtrSearchBarClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
+  object_class->get_property = gtr_search_bar_get_property;
+  object_class->set_property = gtr_search_bar_set_property;
+
    properties [PROP_REPLACE_MODE] =
     g_param_spec_boolean ("replace-mode", NULL, NULL, FALSE,
                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
@@ -153,6 +306,16 @@ gtr_search_bar_init (GtrSearchBar *self)
 
   self->search_bindings = dzl_binding_group_new ();
 
+   dzl_binding_group_bind_full (self->search_bindings, "search-text",
+                               self->search_entry, "text",
+                               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL,
+                               maybe_escape_regex, pacify_null_text, self, NULL);
+
+  dzl_binding_group_bind_full (self->search_bindings, "replacement-text",
+                               self->replace_entry, "text",
+                               G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL,
+                               pacify_null_text, pacify_null_text, NULL, NULL);
+
   dzl_binding_group_bind (self->search_bindings, "regex-enabled",
                           self->use_regex, "active",
                           G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
@@ -165,6 +328,7 @@ gtr_search_bar_init (GtrSearchBar *self)
                           self->whole_word, "active",
                           G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
 
+
   g_signal_connect_swapped (self->search_entry,
                             "populate-popup",
                             G_CALLBACK (search_entry_populate_popup),
@@ -172,29 +336,6 @@ gtr_search_bar_init (GtrSearchBar *self)
 
 }
 
-gboolean
-gtr_search_bar_get_show_options (GtrSearchBar *self)
-{
-  g_return_val_if_fail (GTR_IS_SEARCH_BAR (self), FALSE);
-
-  return self->show_options;
-}
-
-void
-gtr_search_bar_set_show_options (GtrSearchBar *self,
-                                        gboolean            show_options)
-{
-  g_return_if_fail (GTR_IS_SEARCH_BAR (self));
-
-  show_options = !!show_options;
-
-  if (self->show_options != show_options)
-    {
-      self->show_options = show_options;
-      gtk_widget_set_visible (GTK_WIDGET (self->search_options), show_options);
-      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SHOW_OPTIONS]);
-    }
-}
 
 GtkSearchEntry *
 gtr_search_bar_get_search (GtrSearchBar *self)
diff --git a/src/gtr-tab.ui b/src/gtr-tab.ui
index bf3b1767..b037ecfd 100644
--- a/src/gtr-tab.ui
+++ b/src/gtr-tab.ui
@@ -115,10 +115,11 @@
                   <property name="margin-right">12</property>
                   <property name="reveal-child">True</property>
                   <property name="visible">True</property>
+                  <signal name="notify::child-revealed" handler="gtr_page_notify_child_revealed" 
swapped="true" object="GtrTab"/>
                   <child>
                      <object class="GtrSearchBar" id="search_bar">
                         <property name="visible">True</property>
-                        <!--<signal name="stop-search" handler="gtr_page_stop_search" swapped="true" 
object="IdeEditorPage"/>-->
+                        <signal name="stop-search" handler="gtr_page_stop_search" swapped="true" 
object="GtrTab"/>
                      </object>
                   </child>
                </object>


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