[gtranslator/merge-requests/61: 6/20] Add GtrSearchBar to gtr-tab inside a GtkRevealer



commit b2bc982e1d2106ff089f27643004191bf601210e
Author: Priyanka Saggu <priyankasggu11929 gmail com>
Date:   Sun Jan 5 01:12:59 2020 +0530

    Add GtrSearchBar to gtr-tab inside a GtkRevealer

 src/gtr-tab.c  |  56 ++++++
 src/gtr-tab.ui | 582 ++++++++++++++++++++++++++++++---------------------------
 2 files changed, 359 insertions(+), 279 deletions(-)
---
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index 94b65249..d88afd5d 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -46,6 +46,7 @@
 #include "gtr-debug.h"
 #include "gtr-window.h"
 #include "gtr-progress.h"
+#include "gtr-search-bar.h"
 
 #include <glib.h>
 #include <glib-object.h>
@@ -113,6 +114,12 @@ typedef struct
 
   guint tab_realized : 1;
   guint dispose_has_run : 1;
+
+  /*Search Bar*/
+  GtkOverlay    *overlay;
+  GtkRevealer   *search_revealer;
+  GtrSearchBar *search_bar;
+  GtkSearchEntry *search;
 } GtrTabPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtrTab, gtr_tab, GTK_TYPE_BOX)
@@ -138,6 +145,49 @@ static guint signals[LAST_SIGNAL];
 
 static gboolean gtr_tab_autosave (GtrTab * tab);
 
+//---------------------------Search Bar Revealer------------------//
+
+static void
+gtr_page_stop_search (GtrTab *tab,
+                             GtrSearchBar *search_bar)
+{
+  GtrTabPrivate *priv;
+
+  priv = gtr_tab_get_instance_private (tab);
+  g_assert (GTR_IS_TAB (tab));
+  g_assert (GTR_IS_SEARCH_BAR (priv->search_bar));
+
+  gtk_revealer_set_reveal_child (priv->search_revealer, FALSE);
+
+}
+
+static void
+gtr_page_notify_child_revealed (GtrTab *tab,
+                                       GParamSpec    *pspec,
+                                       GtkRevealer   *revealer)
+{
+  GtrTabPrivate *priv;
+
+  priv = gtr_tab_get_instance_private (tab);
+  g_assert (GTR_IS_TAB (tab));
+  g_assert (GTK_IS_REVEALER (revealer));
+
+  if (gtk_revealer_get_child_revealed (revealer))
+    {
+      GtkWidget *toplevel = gtk_widget_get_ancestor (GTK_WIDGET (revealer), GTK_TYPE_WINDOW);
+      GtkWidget *focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
+
+      /* Only focus the search bar if it doesn't already have focus,
+       * as it can reselect the search text.
+       */
+      if (focus == NULL || !gtk_widget_is_ancestor (focus, GTK_WIDGET (revealer)))
+        gtk_widget_grab_focus (GTK_WIDGET (priv->search_bar));
+    }
+}
+
+//----------------------------------------------------------------//
+
+
 static gboolean
 show_hide_revealer (GtkWidget *widget, GdkEvent *ev, GtrTab *tab)
 {
@@ -867,10 +917,16 @@ gtr_tab_class_init (GtrTabClass * klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtrTab, progress_fuzzy);
   gtk_widget_class_bind_template_child_private (widget_class, GtrTab, progress_untrans);
   gtk_widget_class_bind_template_child_private (widget_class, GtrTab, progress_percentage);
+  gtk_widget_class_bind_template_child_private (widget_class, GtrTab, overlay);
+  gtk_widget_class_bind_template_child_private (widget_class, GtrTab, search_bar);
+  gtk_widget_class_bind_template_child_private (widget_class, GtrTab, search_revealer);
+  gtk_widget_class_bind_template_callback (widget_class, gtr_page_notify_child_revealed);
+  gtk_widget_class_bind_template_callback (widget_class, gtr_page_stop_search);
 
   g_type_ensure (gtr_view_get_type ());
   g_type_ensure (gtr_context_panel_get_type ());
   g_type_ensure (gtr_message_table_get_type ());
+  g_type_ensure (gtr_search_bar_get_type ());
 }
 
 /***************************** Public funcs ***********************************/
diff --git a/src/gtr-tab.ui b/src/gtr-tab.ui
index b40ba37c..bf3b1767 100644
--- a/src/gtr-tab.ui
+++ b/src/gtr-tab.ui
@@ -1,301 +1,325 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- Generated with glade 3.15.3 on Wed Sep  4 22:17:30 2013 -->
 <interface>
-  <!-- interface-requires gtk+ 3.10 -->
-  <template class="GtrTab" parent="GtkBox">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="orientation">vertical</property>
+   <!-- interface-requires gtk+ 3.10 -->
+   <template class="GtrTab" parent="GtkBox">
+      <property name="visible">True</property>
+      <property name="can_focus">False</property>
+      <property name="orientation">vertical</property>
 
-    <child>
-      <object class="GtkEventBox" id="progress_eventbox">
-        <property name="visible">True</property>
-        <child>
-          <object class="GtkBox" id="progress_box">
+      <child>
+         <object class="GtkEventBox" id="progress_eventbox">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="orientation">vertical</property>
             <child>
-
-              <object class="GtkRevealer" id="progress_revealer">
-                <property name="visible">True</property>
-                <property name="reveal_child">True</property>
-                <child>
-                  <object class="GtkBox">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="margin_left">6</property>
-                    <property name="margin_right">6</property>
-                    <property name="margin_top">6</property>
-                    <property name="margin_bottom">6</property>
-                    <property name="orientation">horizontal</property>
-                    <property name="homogeneous">True</property>
-                    <child>
-                      <object class="GtkLabel" id="progress_percentage">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label">translated: 0.00%</property>
-                        <property name="xalign">0.5</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="progress_trans">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label">Translated: 0</property>
-                        <property name="xalign">0.5</property>
-                        <style>
-                          <class name="progress_trans"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="progress_fuzzy">
+               <object class="GtkBox" id="progress_box">
+                  <property name="visible">True</property>
+                  <property name="can_focus">False</property>
+                  <property name="orientation">vertical</property>
+                  <child>
+                     <object class="GtkRevealer" id="progress_revealer">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label">fuzzy: 0</property>
-                        <property name="xalign">0.5</property>
-                        <style>
-                          <class name="progress_fuzzy"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">2</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="progress_untrans">
+                        <property name="reveal_child">True</property>
+                        <child>
+                           <object class="GtkBox">
+                              <property name="visible">True</property>
+                              <property name="can_focus">False</property>
+                              <property name="margin_left">6</property>
+                              <property name="margin_right">6</property>
+                              <property name="margin_top">6</property>
+                              <property name="margin_bottom">6</property>
+                              <property name="orientation">horizontal</property>
+                              <property name="homogeneous">True</property>
+                              <child>
+                                 <object class="GtkLabel" id="progress_percentage">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label">translated: 0.00%</property>
+                                    <property name="xalign">0.5</property>
+                                 </object>
+                                 <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                 </packing>
+                              </child>
+                              <child>
+                                 <object class="GtkLabel" id="progress_trans">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label">Translated: 0</property>
+                                    <property name="xalign">0.5</property>
+                                    <style>
+                                       <class name="progress_trans"/>
+                                    </style>
+                                 </object>
+                                 <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                 </packing>
+                              </child>
+                              <child>
+                                 <object class="GtkLabel" id="progress_fuzzy">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label">fuzzy: 0</property>
+                                    <property name="xalign">0.5</property>
+                                    <style>
+                                       <class name="progress_fuzzy"/>
+                                    </style>
+                                 </object>
+                                 <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">2</property>
+                                 </packing>
+                              </child>
+                              <child>
+                                 <object class="GtkLabel" id="progress_untrans">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label">untranslated: 0</property>
+                                    <property name="xalign">0.5</property>
+                                    <style>
+                                       <class name="progress_untranslated"/>
+                                    </style>
+                                 </object>
+                                 <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">3</property>
+                                 </packing>
+                              </child>
+                           </object>
+                        </child>
+                     </object>
+                  </child>
+               </object>
+            </child>
+         </object>
+         <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+         </packing>
+      </child>
+      <child>
+         <object class="GtkOverlay" id="overlay">
+            <property name="visible">True</property>
+           <property name="expand">True</property>
+            <child type="overlay">
+               <object class="GtkRevealer" id="search_revealer">
+                  <property name="width-request">525</property>
+                  <property name="halign">end</property>
+                  <property name="valign">start</property>
+                  <property name="margin-right">12</property>
+                  <property name="reveal-child">True</property>
+                  <property name="visible">True</property>
+                  <child>
+                     <object class="GtrSearchBar" id="search_bar">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label">untranslated: 0</property>
-                        <property name="xalign">0.5</property>
-                        <style>
-                          <class name="progress_untranslated"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">3</property>
-                      </packing>
-                    </child>
-                  </object>
-                </child>
-              </object>
-
+                        <!--<signal name="stop-search" handler="gtr_page_stop_search" swapped="true" 
object="IdeEditorPage"/>-->
+                     </object>
+                  </child>
+               </object>
+               <packing>
+                  <property name="expand">True</property>
+                  <property name="fill">False</property>
+                  <property name="position">2</property>
+               </packing>
             </child>
-          </object>
-        </child>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="fill">false</property>
-        <property name="position">1</property>
-      </packing>
-    </child>
-
-    <child>
-      <object class="GtkPaned" id="hbox">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="wide_handle">True</property>
-        <child>
-          <object class="GtkPaned" id="vertical_box">
+         </object>
+      </child>
+      <child>
+         <object class="GtkPaned" id="hbox">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="orientation">vertical</property>
-            <property name="width_request">450</property>
             <property name="wide_handle">True</property>
             <child>
-              <object class="GtrMessageTable" id="message_table">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="tab">GtrTab</property>
-                <property name="height_request">350</property>
-              </object>
-              <packing>
-                <property name="resize">True</property>
-                <property name="shrink">False</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkBox" id="translation_box">
-                <property name="visible">True</property>
-                <property name="orientation">vertical</property>
-                <child>
-                  <object class="GtkBox" id="text_vbox">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="orientation">vertical</property>
-                    <child>
-                      <object class="GtkBox" id="text_hbox">
+               <object class="GtkPaned" id="vertical_box">
+                  <property name="visible">True</property>
+                  <property name="can_focus">False</property>
+                  <property name="orientation">vertical</property>
+                  <property name="width_request">450</property>
+                  <property name="wide_handle">True</property>
+                  <child>
+                     <object class="GtrMessageTable" id="message_table">
                         <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="orientation">horizontal</property>
-                        <child>
-                          <object class="GtkLabel" id="msgid_label">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="xalign">0</property>
-                            <property name="ypad">5</property>
-                            <property name="label" translatable="yes">_Original Message</property>
-                            <property name="use_underline">True</property>
-                            <attributes>
-                              <attribute name="weight" value="bold"/>
-                            </attributes>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="msgid_ctxt">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="no"></property>
-                            <property name="use_underline">True</property>
-                            <property name="ellipsize">end</property>
-                            <style>
-                              <class name="msgcontext"/>
-                            </style>
-                          </object>
-                        </child>
+                        <property name="can_focus">True</property>
+                        <property name="tab">GtrTab</property>
+                        <property name="height_request">350</property>
+                     </object>
+                     <packing>
+                        <property name="resize">True</property>
+                        <property name="shrink">False</property>
+                     </packing>
+                  </child>
+                  <child>
+                     <object class="GtkBox" id="translation_box">
+                        <property name="visible">True</property>
+                        <property name="orientation">vertical</property>
                         <child>
-                          <object class="GtkLabel" id="msgid_tags">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="xalign">0</property>
-                            <property name="label"></property>
-                            <attributes>
-                              <attribute name="weight" value="bold"/>
-                            </attributes>
-                            <style>
-                              <class name="msgtags"/>
-                            </style>
-                          </object>
+                           <object class="GtkBox" id="text_vbox">
+                              <property name="visible">True</property>
+                              <property name="can_focus">False</property>
+                              <property name="orientation">vertical</property>
+                              <child>
+                                 <object class="GtkBox" id="text_hbox">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="orientation">horizontal</property>
+                                    <child>
+                                       <object class="GtkLabel" id="msgid_label">
+                                          <property name="visible">True</property>
+                                          <property name="can_focus">False</property>
+                                          <property name="xalign">0</property>
+                                          <property name="ypad">5</property>
+                                          <property name="label" translatable="yes">_Original 
Message</property>
+                                          <property name="use_underline">True</property>
+                                          <attributes>
+                                             <attribute name="weight" value="bold"/>
+                                          </attributes>
+                                       </object>
+                                    </child>
+                                    <child>
+                                       <object class="GtkLabel" id="msgid_ctxt">
+                                          <property name="visible">True</property>
+                                          <property name="can_focus">False</property>
+                                          <property name="xalign">0</property>
+                                          <property name="label" translatable="no"></property>
+                                          <property name="use_underline">True</property>
+                                          <property name="ellipsize">end</property>
+                                          <style>
+                                             <class name="msgcontext"/>
+                                          </style>
+                                       </object>
+                                    </child>
+                                    <child>
+                                       <object class="GtkLabel" id="msgid_tags">
+                                          <property name="visible">True</property>
+                                          <property name="can_focus">False</property>
+                                          <property name="xalign">0</property>
+                                          <property name="label"></property>
+                                          <attributes>
+                                             <attribute name="weight" value="bold"/>
+                                          </attributes>
+                                          <style>
+                                             <class name="msgtags"/>
+                                          </style>
+                                       </object>
+                                    </child>
+                                 </object>
+                                 <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">0</property>
+                                 </packing>
+                              </child>
+                              <child>
+                                 <object class="GtkScrolledWindow" id="text_msgid_scroll">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="shadow_type">in</property>
+                                    <child>
+                                       <object class="GtrView" id="text_msgid">
+                                          <property name="visible">True</property>
+                                          <property name="can_focus">True</property>
+                                          <property name="editable">False</property>
+                                       </object>
+                                    </child>
+                                 </object>
+                                 <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                 </packing>
+                              </child>
+                              <child>
+                                 <object class="GtkScrolledWindow" id="text_plural_scroll">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="shadow_type">in</property>
+                                    <child>
+                                       <object class="GtrView" id="text_msgid_plural">
+                                          <property name="visible">True</property>
+                                          <property name="can_focus">True</property>
+                                          <property name="editable">False</property>
+                                       </object>
+                                    </child>
+                                 </object>
+                                 <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">2</property>
+                                 </packing>
+                              </child>
+                           </object>
+                           <packing>
+                              <property name="expand">True</property>
+                              <property name="fill">True</property>
+                              <property name="position">1</property>
+                           </packing>
                         </child>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkScrolledWindow" id="text_msgid_scroll">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="shadow_type">in</property>
                         <child>
-                          <object class="GtrView" id="text_msgid">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="editable">False</property>
-                          </object>
+                           <object class="GtkLabel" id="msgstr_label">
+                              <property name="visible">True</property>
+                              <property name="can_focus">False</property>
+                              <property name="xalign">0</property>
+                              <property name="ypad">5</property>
+                              <property name="label" translatable="yes">Translate_d Text</property>
+                              <property name="use_underline">True</property>
+                              <attributes>
+                                 <attribute name="weight" value="bold"/>
+                              </attributes>
+                           </object>
+                           <packing>
+                              <property name="expand">False</property>
+                              <property name="fill">False</property>
+                              <property name="position">2</property>
+                           </packing>
                         </child>
-                      </object>
-                      <packing>
-                        <property name="expand">True</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkScrolledWindow" id="text_plural_scroll">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="shadow_type">in</property>
                         <child>
-                          <object class="GtrView" id="text_msgid_plural">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="editable">False</property>
-                          </object>
+                           <object class="GtkNotebook" id="trans_notebook">
+                              <property name="visible">True</property>
+                              <property name="can_focus">True</property>
+                              <property name="show_border">False</property>
+                           </object>
+                           <packing>
+                              <property name="expand">True</property>
+                              <property name="fill">True</property>
+                              <property name="position">3</property>
+                           </packing>
                         </child>
-                      </object>
-                      <packing>
-                        <property name="expand">True</property>
-                        <property name="fill">True</property>
-                        <property name="position">2</property>
-                      </packing>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="msgstr_label">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="xalign">0</property>
-                    <property name="ypad">5</property>
-                    <property name="label" translatable="yes">Translate_d Text</property>
-                    <property name="use_underline">True</property>
-                    <attributes>
-                      <attribute name="weight" value="bold"/>
-                    </attributes>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="position">2</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkNotebook" id="trans_notebook">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="show_border">False</property>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">3</property>
-                  </packing>
-                </child>
-              </object>
-              <packing>
-                <property name="resize">False</property>
-                <property name="shrink">False</property>
-              </packing>
+                     </object>
+                     <packing>
+                        <property name="resize">False</property>
+                        <property name="shrink">False</property>
+                     </packing>
+                  </child>
+               </object>
+               <packing>
+                  <property name="resize">True</property>
+                  <property name="shrink">False</property>
+               </packing>
             </child>
-          </object>
-          <packing>
-            <property name="resize">True</property>
-            <property name="shrink">False</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtrContextPanel" id="context">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="tab">GtrTab</property>
-            <property name="width_request">150</property>
-          </object>
-          <packing>
-            <property name="resize">False</property>
-            <property name="shrink">False</property>
-          </packing>
-        </child>
-      </object>
-      <packing>
-        <property name="expand">True</property>
-        <property name="fill">True</property>
-        <property name="position">0</property>
-      </packing>
-    </child>
-  </template>
+            <child>
+               <object class="GtrContextPanel" id="context">
+                  <property name="visible">True</property>
+                  <property name="can_focus">True</property>
+                  <property name="tab">GtrTab</property>
+                  <property name="width_request">150</property>
+               </object>
+               <packing>
+                  <property name="resize">False</property>
+                  <property name="shrink">False</property>
+               </packing>
+            </child>
+         </object>
+         <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+         </packing>
+      </child>
+   </template>
 </interface>


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