[tracker/needle: 40/41] tracker-needle: Add combobox and remember searches for local session



commit 6260ec32b442867ea5f875c19ab6937e528390b5
Author: Martyn Russell <martyn lanedo com>
Date:   Mon Sep 20 23:08:35 2010 +0100

    tracker-needle: Add combobox and remember searches for local session

 src/tracker-needle/tracker-needle.ui   |   14 +++++++--
 src/tracker-needle/tracker-needle.vala |   47 ++++++++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 5 deletions(-)
---
diff --git a/src/tracker-needle/tracker-needle.ui b/src/tracker-needle/tracker-needle.ui
index 3cf7ca4..b654273 100644
--- a/src/tracker-needle/tracker-needle.ui
+++ b/src/tracker-needle/tracker-needle.ui
@@ -126,14 +126,16 @@
                 <child>
                   <object class="GtkAlignment" id="alignment1">
                     <property name="visible">True</property>
+                    <property name="yscale">0</property>
                     <property name="left_padding">4</property>
                     <property name="right_padding">4</property>
                     <child>
-                      <object class="GtkEntry" id="entry_search">
+                      <object class="GtkComboBoxEntry" id="comboboxentry_search">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
-                        <property name="invisible_char">&#x25CF;</property>
-                        <property name="activates_default">True</property>
+                        <property name="has_focus">True</property>
+                        <property name="model">liststore_search</property>
+                        <property name="text_column">0</property>
                       </object>
                     </child>
                   </object>
@@ -197,4 +199,10 @@
       </object>
     </child>
   </object>
+  <object class="GtkListStore" id="liststore_search">
+    <columns>
+      <!-- column-name text -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
 </interface>
diff --git a/src/tracker-needle/tracker-needle.vala b/src/tracker-needle/tracker-needle.vala
index 366859c..88a66ef 100644
--- a/src/tracker-needle/tracker-needle.vala
+++ b/src/tracker-needle/tracker-needle.vala
@@ -36,6 +36,7 @@ public class TrackerNeedle {
 	private SeparatorToolItem separator_secondary;
 	private ToggleToolButton find_in_contents;
 	private ToggleToolButton find_in_titles;
+	private ComboBoxEntry search_list;
 	private Entry search;
 	private Spinner spinner;
 	private ToolItem spinner_shell;
@@ -106,7 +107,8 @@ public class TrackerNeedle {
 		find_in_titles = builder.get_object ("toolbutton_find_in_titles") as ToggleToolButton;
 		find_in_titles.toggled.connect (find_in_toggled);
 
-		search = builder.get_object ("entry_search") as Entry;
+		search_list = builder.get_object ("comboboxentry_search") as ComboBoxEntry;
+		search = search_list.get_child () as Entry;
 		search.changed.connect (search_changed);
 
 		spinner = new Spinner ();
@@ -466,10 +468,49 @@ public class TrackerNeedle {
 		spinner_shell.hide ();
 	}
 
+	private TreeIter? search_ran_before (string criteria, bool? add_to_model = false) {
+		if (criteria.length < 1) {
+			return null;
+		}
+
+		ComboBox combo = search_list as ComboBox;
+		TreeModel model = combo.get_model ();
+		string criteria_folded = criteria.casefold ();
+
+		TreeIter iter;
+		bool valid = model.iter_children (out iter, null);
+
+		while (valid) {
+			string text;
+
+			model.get (iter, 0, out text, -1);
+
+			string text_folded = text.casefold ();
+
+			if (text_folded == criteria_folded) {
+				return iter;
+			}
+
+			valid = model.iter_next (ref iter);
+		}
+
+		if (add_to_model) {
+			TreeIter new_iter;
+			
+			ListStore store = (ListStore) model;
+			store.prepend (out new_iter);
+			store.set (new_iter, 0, criteria, -1);
+		}
+
+		return null;
+	}
+
 	private bool search_run () {
 		last_search_id = 0;
 
-		if (search.get_text ().length < 1) {
+		string criteria = search.get_text ();
+
+		if (criteria.length < 1) {
 			// Show no results window
 			sw_noresults.show ();
 			sw_iconview.hide ();
@@ -480,6 +521,8 @@ public class TrackerNeedle {
 			return false;
 		}
 
+		search_ran_before (criteria, true);
+
 		// Show correct window
 		bool rows = view_list.active || view_details.active;
 		



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