[gitg] Improve search
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Improve search
- Date: Mon, 5 Jan 2015 20:10:55 +0000 (UTC)
commit 5651fc9483ab920bc2ecac98cccc8a75ff579ee3
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Mon Jan 5 21:09:03 2015 +0100
Improve search
Searching now matches partially (not only prefixes) and
will match on hashes.
gitg/history/gitg-history.vala | 48 ++++++++++++++++++++++++++++++++++-----
1 files changed, 41 insertions(+), 7 deletions(-)
---
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 0814216..386cee0 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -499,6 +499,8 @@ namespace GitgHistory
d_main,
"selectable-mode",
BindingFlags.BIDIRECTIONAL);
+
+ d_main.commit_list_view.set_search_equal_func(search_filter_func);
}
private Gtk.Menu? popup_on_ref(Gdk.EventButton? event)
@@ -852,21 +854,53 @@ namespace GitgHistory
}
}
+ private string normalize(string s)
+ {
+ return s.normalize(-1, NormalizeMode.ALL).casefold();
+ }
+
+ private bool search_filter_func(Gtk.TreeModel model, int column, string key, Gtk.TreeIter
iter)
+ {
+ var c = d_commit_list_model.commit_from_iter(iter);
+
+ if (c.get_id().has_prefix(key))
+ {
+ return false;
+ }
+
+ var nkey = normalize(key);
+ var subject = normalize(c.get_subject());
+
+ if (subject.contains(nkey))
+ {
+ return false;
+ }
+
+ var message = normalize(c.get_message());
+
+ if (message.contains(nkey))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
public Gtk.Entry? search_entry
{
set
{
- int column = -1;
+ d_main.commit_list_view.set_search_entry(value);
+ d_main.commit_list_view.set_enable_search(value != null);
if (value != null)
{
- column = (int)Gitg.CommitModelColumns.MESSAGE;
+ d_main.commit_list_view.set_search_column(0);
+ }
+ else
+ {
+ d_main.commit_list_view.set_search_column(-1);
}
-
- d_main.commit_list_view.set_search_entry(value);
- d_main.commit_list_view.set_enable_search(value != null);
-
- d_main.commit_list_view.set_search_column(column);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]