[gtranslator/merge-requests/61: 3/20] Create gtr-search-bar widget c, header and UI files



commit 1b622562efa8617355dba7903938ed6a240779ca
Author: Priyanka Saggu <priyankasggu11929 gmail com>
Date:   Sun Jan 5 00:37:59 2020 +0530

    Create gtr-search-bar widget c, header and UI files

 src/gtr-search-bar.c  | 220 ++++++++++++++++++++++++++++++++++++++++++
 src/gtr-search-bar.h  |  25 +++++
 src/gtr-search-bar.ui | 261 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 506 insertions(+)
---
diff --git a/src/gtr-search-bar.c b/src/gtr-search-bar.c
new file mode 100644
index 00000000..0f6ad4df
--- /dev/null
+++ b/src/gtr-search-bar.c
@@ -0,0 +1,220 @@
+#define G_LOG_DOMAIN "gtr-search-bar"
+
+#include "config.h"
+
+#include <dazzle.h>
+#include <glib/gi18n.h>
+
+#include "gtr-search-bar.h"
+
+struct _GtrSearchBar
+{
+  DzlBin                   parent_instance;
+
+  DzlSignalGroup          *search_signals;
+  DzlBindingGroup         *search_bindings;
+  GtkSearchEntry          *search;
+
+  GObject                 *search_entry_tag;
+
+  GtkCheckButton          *case_sensitive;
+  GtkButton               *replace_all_button;
+  GtkButton               *replace_button;
+  GtkSearchEntry          *replace_entry;
+  GtkEntry                *search_entry;
+  GtkGrid                 *search_options;
+  GtkCheckButton          *use_regex;
+  GtkCheckButton          *whole_word;
+  GtkLabel                *search_text_error;
+
+  guint                    match_source;
+
+  guint                    show_options : 1;
+  guint                    replace_mode : 1;
+};
+
+enum {
+  PROP_0,
+  PROP_REPLACE_MODE,
+  PROP_SHOW_OPTIONS,
+  N_PROPS
+};
+
+enum {
+  STOP_SEARCH,
+  N_SIGNALS
+};
+
+G_DEFINE_TYPE (GtrSearchBar, gtr_search_bar, DZL_TYPE_BIN)
+
+static GParamSpec *properties [N_PROPS];
+static guint signals [N_SIGNALS];
+
+
+static void
+search_entry_populate_popup (GtrSearchBar *self,
+                             GtkWidget          *widget,
+                             GtkEntry     *entry)
+{
+  g_assert (GTR_IS_SEARCH_BAR (self));
+  g_assert (GTK_IS_MENU (widget));
+  g_assert (GTK_IS_ENTRY (entry));
+
+  if (GTK_IS_MENU (widget))
+    {
+      g_autoptr(DzlPropertiesGroup) group = NULL;
+
+      GtkWidget *item;
+      GtkWidget *sep;
+      guint pos = 0;
+
+      item = gtk_check_menu_item_new_with_label (_("Regular "));
+      gtk_actionable_set_action_name (GTK_ACTIONABLE (item), "search-settings.regex-enabled");
+      gtk_menu_shell_insert (GTK_MENU_SHELL (widget), item, pos++);
+      gtk_widget_show (item);
+
+      item = gtk_check_menu_item_new_with_label (_("Case sensitive"));
+      gtk_actionable_set_action_name (GTK_ACTIONABLE (item), "search-settings.case-sensitive");
+      gtk_menu_shell_insert (GTK_MENU_SHELL (widget), item, pos++);
+      gtk_widget_show (item);
+
+      item = gtk_check_menu_item_new_with_label (_("Match whole word only"));
+      gtk_actionable_set_action_name (GTK_ACTIONABLE (item), "search-settings.at-word-boundaries");
+      gtk_menu_shell_insert (GTK_MENU_SHELL (widget), item, pos++);
+      gtk_widget_show (item);
+
+      sep = gtk_separator_menu_item_new ();
+      gtk_menu_shell_insert (GTK_MENU_SHELL (widget), sep, pos++);
+      gtk_widget_show (sep);
+
+      if (self->search != NULL)
+        {
+          group = dzl_properties_group_new (G_OBJECT (self->search));
+          dzl_properties_group_add_all_properties (group);
+        }
+
+      gtk_widget_insert_action_group (widget, "search-settings", G_ACTION_GROUP (group));
+    }
+}
+
+static void
+gtr_search_bar_real_stop_search (GtrSearchBar *self)
+{
+  g_assert (GTR_IS_SEARCH_BAR (self));
+}
+
+
+static void
+gtr_search_bar_class_init (GtrSearchBarClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+   properties [PROP_REPLACE_MODE] =
+    g_param_spec_boolean ("replace-mode", NULL, NULL, FALSE,
+                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+  properties [PROP_SHOW_OPTIONS] =
+    g_param_spec_boolean ("show-options", NULL, NULL, FALSE,
+                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  signals [STOP_SEARCH] =
+    g_signal_new_class_handler ("stop-search",
+                                G_TYPE_FROM_CLASS (klass),
+                                G_SIGNAL_RUN_LAST,
+                                G_CALLBACK (gtr_search_bar_real_stop_search),
+                                NULL, NULL,
+                                g_cclosure_marshal_VOID__VOID,
+                                G_TYPE_NONE, 0);
+
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/translator/gtr-search-bar.ui");
+  gtk_widget_class_bind_template_child (widget_class, GtrSearchBar, case_sensitive);
+  gtk_widget_class_bind_template_child (widget_class, GtrSearchBar, replace_all_button);
+  gtk_widget_class_bind_template_child (widget_class, GtrSearchBar, replace_button);
+  gtk_widget_class_bind_template_child (widget_class, GtrSearchBar, replace_entry);
+  gtk_widget_class_bind_template_child (widget_class, GtrSearchBar, search_entry);
+  gtk_widget_class_bind_template_child (widget_class, GtrSearchBar, search_options);
+  gtk_widget_class_bind_template_child (widget_class, GtrSearchBar, search_text_error);
+  gtk_widget_class_bind_template_child (widget_class, GtrSearchBar, use_regex);
+  gtk_widget_class_bind_template_child (widget_class, GtrSearchBar, whole_word);
+
+   gtk_widget_class_set_css_name (widget_class, "gtrsearchbar");
+}
+
+static void
+gtr_search_bar_init (GtrSearchBar *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  self->search_signals = dzl_signal_group_new (GTK_TYPE_SEARCH_ENTRY);
+
+  self->search_bindings = dzl_binding_group_new ();
+
+  dzl_binding_group_bind (self->search_bindings, "regex-enabled",
+                          self->use_regex, "active",
+                          G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+
+  dzl_binding_group_bind (self->search_bindings, "case-sensitive",
+                          self->case_sensitive, "active",
+                          G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+
+  dzl_binding_group_bind (self->search_bindings, "at-word-boundaries",
+                          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),
+                            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)
+{
+  g_return_val_if_fail (GTR_IS_SEARCH_BAR (self), NULL);
+
+  return self->search;
+}
+
+void
+gtr_search_bar_set_search (GtrSearchBar *self,
+                                  GtkSearchEntry    *search)
+{
+  g_return_if_fail (GTR_IS_SEARCH_BAR (self));
+
+  if (g_set_object (&self->search, search))
+    {
+      dzl_signal_group_set_target (self->search_signals, search);
+      dzl_binding_group_set_source (self->search_bindings, search);
+    }
+}
+
+
diff --git a/src/gtr-search-bar.h b/src/gtr-search-bar.h
new file mode 100644
index 00000000..2a62d766
--- /dev/null
+++ b/src/gtr-search-bar.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <dazzle.h>
+#include <gtksourceview/gtksource.h>
+
+G_BEGIN_DECLS
+
+#define GTR_TYPE_SEARCH_BAR (gtr_search_bar_get_type())
+
+
+G_DECLARE_FINAL_TYPE (GtrSearchBar, gtr_search_bar, GTR, SEARCH_BAR, DzlBin)
+
+
+GtkSearchEntry  *gtr_search_bar_get_search       (GtrSearchBar *self);
+void             gtr_search_bar_set_search       (GtrSearchBar *self,
+                                                         GtkSearchEntry    *search);
+gboolean         gtr_search_bar_get_show_options (GtrSearchBar *self);
+void             gtr_search_bar_set_show_options (GtrSearchBar *self,
+                                                         gboolean            show_options);
+gboolean         gtr_search_bar_get_replace_mode (GtrSearchBar *self);
+void             gtr_search_bar_set_replace_mode (GtrSearchBar *self,
+                                                         gboolean            replace_mode);
+
+G_END_DECLS
+
diff --git a/src/gtr-search-bar.ui b/src/gtr-search-bar.ui
new file mode 100644
index 00000000..4fedfa19
--- /dev/null
+++ b/src/gtr-search-bar.ui
@@ -0,0 +1,261 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GtrSearchBar" parent="DzlBin">
+    <style>
+      <class name="search-frame"/>
+    </style>
+    <child>
+      <object class="GtkBox">
+        <property name="visible">true</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">7</property>
+        <child>
+          <object class="GtkGrid">
+            <property name="visible">true</property>
+            <property name="can-focus">false</property>
+            <property name="row_spacing">8</property>
+            <property name="column_spacing">8</property>
+            <child>
+              <object class="GtkEntry" id="search_entry">
+                <property name="visible">true</property>
+                <property name="can-focus">true</property>
+                <property name="hexpand">true</property>
+                <property name="primary_icon_name">edit-find-symbolic</property>
+                <property name="primary_icon_activatable">false</property>
+                <property name="primary_icon_sensitive">false</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="search_text_error">
+                <property name="visible">false</property>
+                <property name="xalign">0.0</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+                <attributes>
+                  <attribute name="scale" value="0.8333"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="width">3</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSearchEntry" id="replace_entry">
+                <property name="visible">false</property>
+                <property name="can-focus">true</property>
+                <property name="width-chars">20</property>
+                <property name="max-width-chars">30</property>
+                <property name="primary_icon_name">edit-find-replace-symbolic</property>
+                <property name="primary_icon_activatable">false</property>
+                <property name="primary_icon_sensitive">false</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox">
+                <property name="homogeneous">true</property>
+                <property name="visible">true</property>
+                <property name="can-focus">false</property>
+                <property name="valign">center</property>
+                <style>
+                  <class name="linked"/>
+                </style>
+                <child>
+                  <object class="GtkButton">
+                    <property name="action-name">editor-search.move-previous</property>
+                    <property name="visible">true</property>
+                    <property name="can-focus">false</property>
+                    <child>
+                      <object class="GtkImage">
+                        <property name="visible">true</property>
+                        <property name="can-focus">false</property>
+                        <property name="icon_name">go-up-symbolic</property>
+                        <property name="icon_size">1</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">false</property>
+                    <property name="fill">true</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton">
+                    <property name="action-name">editor-search.move-next</property>
+                    <property name="visible">true</property>
+                    <property name="can-focus">false</property>
+                    <child>
+                      <object class="GtkImage">
+                        <property name="visible">true</property>
+                        <property name="can-focus">false</property>
+                        <property name="icon_name">go-down-symbolic</property>
+                        <property name="icon_size">1</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">false</property>
+                    <property name="fill">true</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="replace_button">
+                <property name="label" translatable="yes">Replace</property>
+                <property name="action-name">editor-search.replace</property>
+                <property name="visible">false</property>
+                <property name="can-focus">true</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="replace_all_button">
+                <property name="label" translatable="yes">Replace All</property>
+                <property name="action-name">editor-search.replace-all</property>
+                <property name="visible">false</property>
+                <property name="can-focus">true</property>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox">
+                <property name="homogeneous">true</property>
+                <property name="visible">true</property>
+                <property name="can-focus">false</property>
+                <property name="valign">center</property>
+                <property name="spacing">8</property>
+                <child>
+                  <object class="GtkToggleButton">
+                    <property name="active" bind-source="GtrSearchBar" bind-property="replace-mode" 
bind-flags="sync-create|bidirectional"/>
+                    <property name="tooltip-text" translatable="yes">Switch between Search and 
Search-and-Replace</property>
+                    <property name="visible">true</property>
+                    <property name="can-focus">true</property>
+                    <property name="image_position">right</property>
+                    <child>
+                      <object class="GtkImage">
+                        <property name="visible">true</property>
+                        <property name="can-focus">false</property>
+                        <property name="icon_name">edit-find-replace-symbolic</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">false</property>
+                    <property name="fill">true</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkToggleButton" id="show_options">
+                    <property name="tooltip-text" translatable="yes">Show or hide search options such as 
case sensitivity</property>
+                    <property name="focus-on-click">false</property>
+                    <property name="visible">true</property>
+                    <property name="can-focus">true</property>
+                    <property name="active" bind-source="GtrSearchBar" bind-property="show-options" 
bind-flags="sync-create|bidirectional"/>
+                    <child>
+                      <object class="GtkImage">
+                        <property name="visible">true</property>
+                        <property name="can-focus">false</property>
+                        <property name="icon_name">emblem-system-symbolic</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">false</property>
+                    <property name="fill">true</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">false</property>
+            <property name="fill">true</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="search_options">
+            <property name="visible">false</property>
+            <property name="can-focus">false</property>
+            <property name="column_spacing">8</property>
+            <child>
+              <object class="GtkCheckButton" id="use_regex">
+                <property name="label" translatable="yes">Regular expressions</property>
+                <property name="visible">true</property>
+                <property name="can-focus">false</property>
+                <property name="focus-on-click">false</property>
+                <property name="xalign">0</property>
+                <property name="draw-indicator">true</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="case_sensitive">
+                <property name="label" translatable="yes">Case sensitive</property>
+                <property name="visible">true</property>
+                <property name="can-focus">false</property>
+                <property name="xalign">0</property>
+                <property name="draw-indicator">true</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="whole_word">
+                <property name="label" translatable="yes">Match whole word only</property>
+                <property name="visible">true</property>
+                <property name="can-focus">false</property>
+                <property name="xalign">0</property>
+                <property name="draw-indicator">true</property>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">false</property>
+            <property name="fill">true</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
+


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