Tomboy.NoteRecentChanges.CompareSearchHits C# (CSharp) Method

CompareSearchHits() private method

private CompareSearchHits ( Gtk model, Gtk a, Gtk b ) : int
model Gtk
a Gtk
b Gtk
return int
		int CompareSearchHits (Gtk.TreeModel model, Gtk.TreeIter a, Gtk.TreeIter b)
		{
			Note note_a = model.GetValue (a, 3 /* note */) as Note;
			Note note_b = model.GetValue (b, 3 /* note */) as Note;

			if (note_a == null || note_b == null) {
				return -1;
			}

			int matches_a;
			int matches_b;
			bool has_matches_a = current_matches.TryGetValue (note_a.Uri, out matches_a);
			bool has_matches_b = current_matches.TryGetValue (note_b.Uri, out matches_b);

			if (!has_matches_a || !has_matches_b) {
				if (has_matches_a)
					return 1;

				return -1;
			}

			int result = matches_a - matches_b;
			if (result == 0) {
				// Do a secondary sort by note title in alphabetical order
				result = CompareTitles (model, a, b);

				// Make sure to always sort alphabetically
				if (result != 0) {
					int sort_col_id;
					Gtk.SortType sort_type;
					if (store_sort.GetSortColumnId (out sort_col_id,
									out sort_type)) {
						if (sort_type == Gtk.SortType.Descending)
							result = result * -1; // reverse sign
					}
				}

				return result;
			}

			return result;
		}