[gitg] Allow searching in the dash view



commit fb7b1e5f8bd6c5e0593f15b9f5ba9ff5cf3221a2
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Wed Mar 13 10:26:15 2013 +0100

    Allow searching in the dash view

 gitg/gitg-window.vala               |   18 ++++++++++++++-
 libgitg-gtk/gitg-gtk-dash-view.vala |   38 ++++++++++++++++++++++++++++------
 2 files changed, 47 insertions(+), 9 deletions(-)
---
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index ad7280b..2bf32dd 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -39,6 +39,8 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
        private Gd.HeaderSimpleButton d_button_dash;
        private Gd.StackSwitcher d_commit_view_switcher;
 
+       private Gd.TaggedEntry d_search_entry;
+
        private Gd.Stack d_main_stack;
 
        private Gtk.ScrolledWindow d_dash_scrolled_window;
@@ -202,13 +204,25 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable, Gtk.
 
                var search_button = builder.get_object("search-button") as Gd.HeaderToggleButton;
                var revealer = builder.get_object("search-revealer") as Gd.Revealer;
-               var entry = builder.get_object("search-entry") as Gd.TaggedEntry;
+               d_search_entry = builder.get_object("search-entry") as Gd.TaggedEntry;
 
                search_button.bind_property("active", revealer, "reveal-child");
                search_button.toggled.connect((b) => {
                        if (b.get_active())
                        {
-                               entry.grab_focus();
+                               d_search_entry.grab_focus();
+                       }
+                       else
+                       {
+                               d_search_entry.set_text("");
+                       }
+               });
+
+               d_search_entry.changed.connect((e) => {
+                       // FIXME: this is a weird way to know the dash is visible
+                       if (d_repository == null)
+                       {
+                               d_dash_view.filter_text((e as Gtk.Entry).text);
                        }
                });
 
diff --git a/libgitg-gtk/gitg-gtk-dash-view.vala b/libgitg-gtk/gitg-gtk-dash-view.vala
index 72655e9..66319cd 100644
--- a/libgitg-gtk/gitg-gtk-dash-view.vala
+++ b/libgitg-gtk/gitg-gtk-dash-view.vala
@@ -24,11 +24,13 @@ namespace GitgGtk
 {
        public class DashView : Grid
        {
+               private string? d_filter_text;
                private Egg.ListBox d_listbox;
                private class RepositoryData
                {
                        public Repository repository;
                        public Grid grid;
+                       public Label repository_label;
                        public Label branch_label;
                }
 
@@ -43,6 +45,7 @@ namespace GitgGtk
                        context.add_class("view");
                        context.add_class("content-view");
                        d_listbox.set_separator_funcs(update_separator);
+                       d_listbox.set_filter_func(null);
                        d_listbox.show();
                        add(d_listbox);
 
@@ -81,6 +84,13 @@ namespace GitgGtk
                        }
                }
 
+               private bool filter(Widget widget)
+               {
+                       var data = widget.get_data<RepositoryData>("data");
+                       var text = data.repository_label.get_text();
+                       return text.contains(d_filter_text);
+               }
+
                private void add_repository(RecentInfo info)
                {
                        File info_file = File.new_for_uri(info.get_uri());
@@ -113,15 +123,15 @@ namespace GitgGtk
                        data.grid.margin = 12;
                        data.grid.column_spacing = 10;
 
-                       var label = new Label(null);
+                       data.repository_label = new Label(null);
                        File? workdir = repo.get_workdir();
                        var label_text = (workdir != null) ? workdir.get_basename() : 
repo_file.get_basename();
-                       label.set_markup("<b>%s</b>".printf(label_text));
-                       label.ellipsize = Pango.EllipsizeMode.END;
-                       label.valign = Align.START;
-                       label.halign = Align.START;
-                       label.hexpand = true;
-                       data.grid.attach(label, 0, 0, 1, 1);
+                       data.repository_label.set_markup("<b>%s</b>".printf(label_text));
+                       data.repository_label.ellipsize = Pango.EllipsizeMode.END;
+                       data.repository_label.valign = Align.START;
+                       data.repository_label.halign = Align.START;
+                       data.repository_label.hexpand = true;
+                       data.grid.attach(data.repository_label, 0, 0, 1, 1);
 
                        data.branch_label = new Label("");
                        data.branch_label.ellipsize = Pango.EllipsizeMode.END;
@@ -166,6 +176,20 @@ namespace GitgGtk
                        data.grid.show_all();
                        d_listbox.add(data.grid);
                }
+
+               public void filter_text(string? text)
+               {
+                       d_filter_text = text;
+
+                       if (text != null && text != "")
+                       {
+                               d_listbox.set_filter_func(filter);
+                       }
+                       else
+                       {
+                               d_listbox.set_filter_func(null);
+                       }
+               }
        }
 }
 


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