[gitg/wip/albfan/search-buttons: 2/2] Add buttons to move from search results



commit 66653c03abac17537c211558924c4a8b986fabc8
Author: Alberto Fanjul <albertofanjul gmail com>
Date:   Mon Nov 11 01:10:31 2019 +0100

    Add buttons to move from search results

 gitg/gitg-window.vala                | 52 ++++++++++++++++++++++++++++++++++++
 gitg/history/gitg-history.vala       | 10 +++++++
 gitg/resources/ui/gitg-window.ui     | 47 +++++++++++++++++++++++++++++---
 libgitg-ext/gitg-ext-searchable.vala |  2 ++
 4 files changed, 107 insertions(+), 4 deletions(-)
---
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index ca640d5b..ce8525ea 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -90,6 +90,10 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
        private Gtk.SearchBar d_search_bar;
        [GtkChild]
        private Gtk.SearchEntry d_search_entry;
+       [GtkChild]
+       private Gtk.Button d_search_up_button;
+       [GtkChild]
+       private Gtk.Button d_search_down_button;
 
        [GtkChild]
        private Gtk.Stack d_main_stack;
@@ -246,12 +250,25 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                        d_search_entry.text = searchable.search_text;
                        searchable.search_visible = true;
                        searchable.search_entry = d_search_entry;
+                       var has_text = d_search_entry.text.length > 0;
+                       d_search_up_button.set_sensitive(has_text);
+                       d_search_down_button.set_sensitive(has_text);
                }
                else
                {
                        searchable.search_visible = false;
                        searchable.search_entry = null;
+                       d_search_up_button.set_sensitive(false);
+                       d_search_down_button.set_sensitive(false);
+               }
+
+               var show_buttons = false;
+               if (current_activity is GitgExt.Searchable)
+               {
+                       show_buttons = searchable.show_buttons();
                }
+               d_search_up_button.set_visible(show_buttons);
+               d_search_down_button.set_visible(show_buttons);
        }
 
        [GtkCallback]
@@ -263,6 +280,9 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                if (ntext != searchable.search_text)
                {
                        searchable.search_text = ntext;
+                       var has_text = ntext.length > 0;
+                       d_search_up_button.set_sensitive(has_text);
+                       d_search_down_button.set_sensitive(has_text);
                }
        }
 
@@ -277,6 +297,18 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
                return ret;
        }
 
+       [GtkCallback]
+       private void search_up_clicked(Gtk.Button button)
+       {
+               search_move(true);
+       }
+
+       [GtkCallback]
+       private void search_down_clicked(Gtk.Button button)
+       {
+               search_move(false);
+       }
+
        construct
        {
                if (Gitg.PlatformSupport.use_native_window_controls())
@@ -1326,6 +1358,26 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
        {
                owned get { return d_notifications; }
        }
+
+       private void search_move(bool up)
+       {
+               if (current_activity is GitgExt.Searchable)
+               {
+                       var searchable = current_activity as GitgExt.Searchable;
+                       var key = d_search_entry.text;
+                       var result = searchable.search_move(key, up);
+                       if (up)
+                       {
+                               d_search_up_button.set_sensitive(result);
+                               d_search_down_button.set_sensitive(true);
+                       }
+                       else
+                       {
+                               d_search_up_button.set_sensitive(true);
+                               d_search_down_button.set_sensitive(result);
+                       }
+               }
+       }
 }
 
 }
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index fc5d93cb..2968d12d 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -1167,6 +1167,16 @@ namespace GitgHistory
 
                public string search_text { owned get; set; default = ""; }
                public bool search_visible { get; set; }
+
+               public override bool search_move(string key, bool up)
+               {
+                       return d_main.commit_list_view.search_move(up);
+               }
+
+               public override bool show_buttons()
+               {
+                       return true;
+               }
        }
 }
 
diff --git a/gitg/resources/ui/gitg-window.ui b/gitg/resources/ui/gitg-window.ui
index 6259dbd3..b14309a8 100644
--- a/gitg/resources/ui/gitg-window.ui
+++ b/gitg/resources/ui/gitg-window.ui
@@ -244,11 +244,50 @@
                     <property name="can_focus">False</property>
                     <property name="show-close-button">False</property>
                     <child>
-                      <object class="GtkSearchEntry" id="d_search_entry">
+                      <object class="GtkBox" id="d_search_box">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="width-request">500</property>
-                        <signal name="changed" handler="search_entry_changed" swapped="no"/>
+                        <property name="orientation">horizontal</property>
+                        <style>
+                          <class name="linked"/>
+                        </style>
+                        <child>
+                          <object class="GtkSearchEntry" id="d_search_entry">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="width-request">500</property>
+                            <signal name="changed" handler="search_entry_changed" swapped="no"/>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkButton" id="d_search_up_button">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <signal name="clicked" handler="search_up_clicked" swapped="no"/>
+                            <child>
+                              <object class="GtkImage" id="up_image">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="icon_size">1</property>
+                                <property name="icon_name">go-up-symbolic</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkButton" id="d_search_down_button">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <signal name="clicked" handler="search_down_clicked" swapped="no"/>
+                            <child>
+                              <object class="GtkImage" id="down_image">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="icon_size">1</property>
+                                <property name="icon_name">go-down-symbolic</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
                       </object>
                     </child>
                   </object>
diff --git a/libgitg-ext/gitg-ext-searchable.vala b/libgitg-ext/gitg-ext-searchable.vala
index f49d5d6b..9d6158ee 100644
--- a/libgitg-ext/gitg-ext-searchable.vala
+++ b/libgitg-ext/gitg-ext-searchable.vala
@@ -32,6 +32,8 @@ public interface Searchable : Object, Activity
        public abstract bool search_visible { get; set; }
        public abstract bool search_available { get; }
        public abstract Gtk.Entry? search_entry { set; }
+       public virtual bool search_move(string key, bool up) { return false; }
+       public virtual bool show_buttons() { return false; }
 }
 
 }


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