tomboy r1746 - in trunk: . Tomboy Tomboy/Notebooks



Author: btimothy
Date: Mon Jan  7 18:29:46 2008
New Revision: 1746
URL: http://svn.gnome.org/viewvc/tomboy?rev=1746&view=rev

Log:
2008-01-07  Boyd Timothy <btimothy gmail com> 

        * Tomboy/Search.cs: Added selected_notebook on the SearchNotes
          method so that the search count is accurate and notes not
          belonging to a notebook can be skipped.

        * Tomboy/RecentChanges.cs: Adjusted the status text so it will
          show "Total: {0} note/s" or "Matches: {0} note/s" depending
          on whether there's a current search or not.  This helps with
          simplicity and also allows the count for searching with a
          notebook selected to have proper counts.

        * Tomboy/RemoteControl.cs: Pass null in for selected_noteboook
          when calling SearchNotes.

        * Tomboy/Notebooks/Notebook.cs:  Use the new Note.ContainsTag ()
          for Notebook.ContainsNote () instead of iterating through all
          a note's tags.  This changes this operation to O(1) time.



Modified:
   trunk/ChangeLog
   trunk/Tomboy/Notebooks/Notebook.cs
   trunk/Tomboy/RecentChanges.cs
   trunk/Tomboy/RemoteControl.cs
   trunk/Tomboy/Search.cs

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	(original)
+++ trunk/ChangeLog	Mon Jan  7 18:29:46 2008
@@ -1,5 +1,24 @@
 2008-01-07  Boyd Timothy <btimothy gmail com> 
 
+	* Tomboy/Search.cs: Added selected_notebook on the SearchNotes
+	  method so that the search count is accurate and notes not
+	  belonging to a notebook can be skipped.
+
+	* Tomboy/RecentChanges.cs: Adjusted the status text so it will
+	  show "Total: {0} note/s" or "Matches: {0} note/s" depending
+	  on whether there's a current search or not.  This helps with
+	  simplicity and also allows the count for searching with a
+	  notebook selected to have proper counts.
+
+	* Tomboy/RemoteControl.cs: Pass null in for selected_noteboook
+	  when calling SearchNotes.
+
+	* Tomboy/Notebooks/Notebook.cs:  Use the new Note.ContainsTag ()
+	  for Notebook.ContainsNote () instead of iterating through all
+	  a note's tags.  This changes this operation to O(1) time.
+
+2008-01-07  Boyd Timothy <btimothy gmail com> 
+
 	* Tomboy/Note.cs: Added a boolean to track when we're
 	  deleting a note.  Use this boolean in the Save ()
 	  method from preventing any other condition from

Modified: trunk/Tomboy/Notebooks/Notebook.cs
==============================================================================
--- trunk/Tomboy/Notebooks/Notebook.cs	(original)
+++ trunk/Tomboy/Notebooks/Notebook.cs	Mon Jan  7 18:29:46 2008
@@ -148,13 +148,7 @@
 		/// </returns>
 		public bool ContainsNote (Note note)
 		{
-			// Check the specified note to see if it contains the notebook tag
-			foreach (Tag noteTag in note.Tags) {
-				if (noteTag == tag)
-					return true;
-			}
-			
-			return false;
+			return note.ContainsTag (tag);
 		}
 		#endregion // Public Methods
 		

Modified: trunk/Tomboy/RecentChanges.cs
==============================================================================
--- trunk/Tomboy/RecentChanges.cs	(original)
+++ trunk/Tomboy/RecentChanges.cs	Mon Jan  7 18:29:46 2008
@@ -376,12 +376,6 @@
 
                         tree.Model = store_sort;
 
-                        note_count.Text = string.Format (
-                                                  Catalog.GetPluralString("Total: {0} note",
-                                                                          "Total: {0} notes",
-                                                                          cnt),
-                                                  cnt);
-
                         PerformSearch ();
 
                         if (sort_column >= 0) {
@@ -424,7 +418,7 @@
 			if (text == null) {
 				current_matches.Clear ();
 				store_filter.Refilter ();
-				UpdateNoteCount (store.IterNChildren (), -1);
+				UpdateTotalNoteCount (store_sort.IterNChildren ());
 				if (tree.IsRealized)
 					tree.ScrollToPoint (0, 0);
 				return;
@@ -433,17 +427,22 @@
 				text = text.ToLower ();
 
 			current_matches.Clear ();
-
+			
+			// Search using the currently selected notebook
+			Notebooks.Notebook selected_notebook = GetSelectedNotebook ();
+			if (selected_notebook is Notebooks.AllNotesNotebook)
+				selected_notebook = null;
+			
 			IDictionary<Note,int> results =
-				search.SearchNotes(text, case_sensitive.Active);
+				search.SearchNotes(text, case_sensitive.Active, selected_notebook);
 			foreach (Note note in results.Keys){
 				current_matches.Add(note.Uri, results[note]);
 			}
 			
-			UpdateNoteCount (store.IterNChildren (), current_matches.Count);
 			AddMatchesColumn ();
 			store_filter.Refilter ();
 			tree.ScrollToPoint (0, 0);
+			UpdateMatchNoteCount (current_matches.Count);
 		}
 
                 void AddMatchesColumn ()
@@ -514,24 +513,27 @@
 
                         crt.Text = match_str;
                 }
-
-                void UpdateNoteCount (int total, int matches)
+                
+                void UpdateTotalNoteCount (int total)
                 {
-                        string cnt = string.Format (
-                                             Catalog.GetPluralString("Total: {0} note",
-                                                                     "Total: {0} notes",
-                                                                     total),
-                                             total);
-                        if (matches >= 0) {
-                                cnt += ", " + string.Format (
-                                               Catalog.GetPluralString ("{0} match",
-                                                                        "{0} matches",
-                                                                        matches),
-                                               matches);
-                        }
-                        note_count.Text = cnt;
+                	string status = string.Format (
+                			Catalog.GetPluralString ("Total: {0} note",
+                									 "Total: {0} notes",
+                									 total),
+                			total);
+                	note_count.Text = status;
+                }
+                
+                void UpdateMatchNoteCount (int matches)
+                {
+                	string status = string.Format (
+                			Catalog.GetPluralString ("Matches: {0} note",
+                									 "Matches: {0} notes",
+                									 matches),
+                			matches);
+                	note_count.Text = status;
                 }
-
+                
                 /// <summary>
                 /// Filter out notes based on the current search string
                 /// and selected tags.  Also prevent template notes from

Modified: trunk/Tomboy/RemoteControl.cs
==============================================================================
--- trunk/Tomboy/RemoteControl.cs	(original)
+++ trunk/Tomboy/RemoteControl.cs	Mon Jan  7 18:29:46 2008
@@ -307,7 +307,7 @@
 			Search search =  new Search(note_manager);
 			List<string> list = new List<string>();
 			IDictionary<Note,int> results =
-				search.SearchNotes(query, case_sensitive);
+				search.SearchNotes(query, case_sensitive, null);
 			foreach (Note note in results.Keys) {
 				list.Add (note.Uri);
 			}

Modified: trunk/Tomboy/Search.cs
==============================================================================
--- trunk/Tomboy/Search.cs	(original)
+++ trunk/Tomboy/Search.cs	Mon Jan  7 18:29:46 2008
@@ -14,8 +14,28 @@
 		{
 			this.manager = manager;
 		}
-
-		public IDictionary<Note,int> SearchNotes (string query, bool case_sensitive)
+		
+		/// <summary>
+		/// Search the notes!
+		/// </summary>
+		/// <param name="query">
+		/// A <see cref="System.String"/>
+		/// </param>
+		/// <param name="case_sensitive">
+		/// A <see cref="System.Boolean"/>
+		/// </param>
+		/// <param name="selected_notebook">
+		/// A <see cref="Notebooks.Notebook"/>.  If this is not
+		/// null, only the notes of the specified notebook will
+		/// be searched.
+		/// </param>
+		/// <returns>
+		/// A <see cref="IDictionary`2"/>
+		/// </returns>
+		public IDictionary<Note,int> SearchNotes (
+				string query,
+				bool case_sensitive,
+				Notebooks.Notebook selected_notebook)
 		{
 			string text = query;
 			string [] words = text.Split (' ', '\t', '\n');
@@ -23,8 +43,21 @@
 			// Used for matching in the raw note XML
                         string [] encoded_words = XmlEncoder.Encode (text).Split (' ', '\t', '\n');
 			Dictionary<Note,int> temp_matches = new Dictionary<Note,int>();
+			
+			// Skip over notes that are template notes
+			Tag template_tag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSystemTag);
 
 			foreach (Note note in manager.Notes) {
+				// Skip template notes
+				if (note.ContainsTag (template_tag))
+					continue;
+				
+				// Skip notes that are not in the
+				// selected notebook
+				if (selected_notebook != null
+						&& selected_notebook.ContainsNote (note) == false)
+					continue;
+				
 				// Check the note's raw XML for at least one
 				// match, to avoid deserializing Buffers
 				// unnecessarily.



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