nemo r49 - in trunk: . broker gtk gtk-gui



Author: arj
Date: Mon Jan  7 18:13:15 2008
New Revision: 49
URL: http://svn.gnome.org/viewvc/nemo?rev=49&view=rev

Log:
Add pagination support in search popup window



Modified:
   trunk/NEWS
   trunk/broker/Xesam.cs
   trunk/gtk-gui/MainWindow.cs
   trunk/gtk-gui/gui.stetic
   trunk/gtk/MainWindow.cs
   trunk/gtk/OverlayTracker.cs
   trunk/gtk/SearchPopup.cs

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Mon Jan  7 18:13:15 2008
@@ -6,12 +6,14 @@
 - Add indexing dialog
 - Add open directory to right click menu for file
 - Add copy to clipboard to right click menu for file
+- Add pagination support in search results window
 
 Bugfixes:
 - Fix indexing so it doesn't kill the machine
 - Fix bug that caused a crash in metadata store
 - Don't do needless searching for text and handle the case of empty
   search text
+- Fix resize for search results window
 
 Other:
 - Optimize metadata store to be faster at checking for valid files

Modified: trunk/broker/Xesam.cs
==============================================================================
--- trunk/broker/Xesam.cs	(original)
+++ trunk/broker/Xesam.cs	Mon Jan  7 18:13:15 2008
@@ -261,6 +261,8 @@
 
 					string search_id = bus_search.NewSearch(session_id, xml_string);
 
+					List<Tuple<string[], File>> results = new List<Tuple<string[],File>>();
+
 					bool search_closed = false;
 
 					hits_added_callbacks.Add(search_id, new Callback(10, delegate(ref int count, UInt32 amount) {
@@ -287,8 +289,6 @@
 
 								System.Console.WriteLine("got {0} files from metadata store", files.Count);
 
-								List<Tuple<string[], File>> real_results = new List<Tuple<string[], File>>();
-
 								int nr = 0;
 
 								foreach (File file in files) {
@@ -299,15 +299,14 @@
 
 									nr++;
 
-									real_results.Add(new Tuple<string[], File>(s, file));
+									results.Add(new Tuple<string[], File>(s, file));
 								}
 
 								got_results = true;
 
-								callback(real_results);
-								
 								System.Console.WriteLine("no more results");
 								
+#if false
 								// We don't want more results
 								if (hits_added_callbacks.ContainsKey(search_id))
 									hits_added_callbacks.Remove(search_id);
@@ -317,6 +316,7 @@
 									bus_search.CloseSession(session_id);
 									search_closed = true;
 								}
+#endif								
 							}));
 						}
 					}));
@@ -333,6 +333,8 @@
 
 						if (!got_results) // no results
 							callback(new List<Tuple<string[], File>>());
+						else
+							callback(results);
 					});
 
 					bus_search.StartSearch(session_id);

Modified: trunk/gtk-gui/MainWindow.cs
==============================================================================
--- trunk/gtk-gui/MainWindow.cs	(original)
+++ trunk/gtk-gui/MainWindow.cs	Mon Jan  7 18:13:15 2008
@@ -237,14 +237,14 @@
         this.prev_button.UseUnderline = true;
         // Container child prev_button.Gtk.Container+ContainerChild
         Gtk.Alignment w22 = new Gtk.Alignment(0.5F, 0.5F, 0F, 0F);
-        // Container child GtkAlignment.Gtk.Container+ContainerChild
+        // Container child GtkAlignment1.Gtk.Container+ContainerChild
         Gtk.HBox w23 = new Gtk.HBox();
         w23.Spacing = 2;
-        // Container child GtkHBox.Gtk.Container+ContainerChild
+        // Container child GtkHBox1.Gtk.Container+ContainerChild
         Gtk.Image w24 = new Gtk.Image();
         w24.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-go-back", Gtk.IconSize.Menu, 16);
         w23.Add(w24);
-        // Container child GtkHBox.Gtk.Container+ContainerChild
+        // Container child GtkHBox1.Gtk.Container+ContainerChild
         Gtk.Label w26 = new Gtk.Label();
         w26.LabelProp = "";
         w23.Add(w26);
@@ -262,14 +262,14 @@
         this.next_button.UseUnderline = true;
         // Container child next_button.Gtk.Container+ContainerChild
         Gtk.Alignment w31 = new Gtk.Alignment(0.5F, 0.5F, 0F, 0F);
-        // Container child GtkAlignment.Gtk.Container+ContainerChild
+        // Container child GtkAlignment2.Gtk.Container+ContainerChild
         Gtk.HBox w32 = new Gtk.HBox();
         w32.Spacing = 2;
-        // Container child GtkHBox.Gtk.Container+ContainerChild
+        // Container child GtkHBox2.Gtk.Container+ContainerChild
         Gtk.Image w33 = new Gtk.Image();
         w33.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-go-forward", Gtk.IconSize.Menu, 16);
         w32.Add(w33);
-        // Container child GtkHBox.Gtk.Container+ContainerChild
+        // Container child GtkHBox2.Gtk.Container+ContainerChild
         Gtk.Label w35 = new Gtk.Label();
         w35.LabelProp = "";
         w32.Add(w35);
@@ -392,6 +392,8 @@
         this.DefaultWidth = 701;
         this.DefaultHeight = 512;
         this.Show();
+        this.FocusInEvent += new Gtk.FocusInEventHandler(this.GotFocus);
+        this.FocusOutEvent += new Gtk.FocusOutEventHandler(this.FocusLeave);
         this.all_files_button.Pressed += new System.EventHandler(this.OnAllFilesPressed);
         this.starred_button.Pressed += new System.EventHandler(this.OnStarredPressed);
         this.search_input.KeyReleaseEvent += new Gtk.KeyReleaseEventHandler(this.on_key_release);

Modified: trunk/gtk-gui/gui.stetic
==============================================================================
--- trunk/gtk-gui/gui.stetic	(original)
+++ trunk/gtk-gui/gui.stetic	Mon Jan  7 18:13:15 2008
@@ -9,6 +9,8 @@
     <property name="Title" translatable="yes">MainWindow</property>
     <property name="Icon">resource:blue_guy.png</property>
     <property name="WindowPosition">CenterOnParent</property>
+    <signal name="FocusInEvent" handler="GotFocus" />
+    <signal name="FocusOutEvent" handler="FocusLeave" />
     <child>
       <widget class="Gtk.HBox" id="main_box">
         <property name="MemberName" />

Modified: trunk/gtk/MainWindow.cs
==============================================================================
--- trunk/gtk/MainWindow.cs	(original)
+++ trunk/gtk/MainWindow.cs	Mon Jan  7 18:13:15 2008
@@ -239,8 +239,6 @@
 
 		List<ItemWrapper> items = new List<ItemWrapper>();
 
-		// must be map, dang
-
 		List<string> files = new List<string>();
 		Dictionary<string, VoidFunction<string[]>> callbacks = new Dictionary<string, VoidFunction<string[]>>(); 
 
@@ -309,33 +307,23 @@
 
 		List<Nemo.Item> items = new List<Nemo.Item>();
 
-		int height_left = calendar_event_box.Allocation.Height;
+//		int height_left = calendar_event_box.Allocation.Height;
 
 		foreach (Tuple<string[], File> result in search_results) 
 		{
 			Nemo.Item item;
 			
-			System.Console.WriteLine("number of values: {0}", result.first.Length);
+			System.Console.WriteLine("type {0}", result.first[1]);
 			
-			if (DocumentItem.is_document(result.first[0]))
-			{
+			if (DocumentItem.is_document(result.first[1]))
 				item = new DocumentItem(result.second, result.first, search_input.Text);
-				height_left -= 75;
-			} 
-			else if (PictureItem.is_image(result.first[0])) 
-			{
+			else if (PictureItem.is_image(result.first[1])) 
 				item = new PictureItem(result.second, result.first);
-				height_left -= 55; 
-			} 
 			else 
 			{
 				item = new Nemo.Item(result.second);
-				item.mime_type = result.first[0];
-				height_left -= 55; 
+				item.mime_type = result.first[1];
 			}
-
-			if (height_left <= 0)
-				break;
 			
 			item.set_file(result.second);
 
@@ -344,17 +332,22 @@
 			items.Add(item);
 		}
 
-		int root_x = 0, root_y = 0;
-		calendar_event_box.GdkWindow.GetOrigin(out root_x, out root_y);
 
-		int tmp = 0; // throw away
-		search_input.GdkWindow.GetOrigin(out root_x, out tmp); 
-
-		System.Console.WriteLine("{0} - {1} - {2} - {3}", root_x, root_y, search_input.Allocation.Width, search_input.Allocation.Height);
+//		System.Console.WriteLine("{0} - {1} - {2} - {3}", root_x, root_y, search_input.Allocation.Width, search_input.Allocation.Height);
 
 		SearchPopup popup = new SearchPopup(calendar_driver.update_view_set_next);
-		popup.set_files_and_show(items, search_text, root_x + search_input.Allocation.Width,
-							     root_y + calendar_event_box.Allocation.Height);
+		popup.get_size = delegate { return calendar_event_box.Allocation.Height; };
+		popup.calculate_start_position = delegate {
+			int root_x = 0, root_y = 0;
+			calendar_event_box.GdkWindow.GetOrigin(out root_x, out root_y);
+
+			int tmp = 0; // throw away
+			search_input.GdkWindow.GetOrigin(out root_x, out tmp);
+			
+			return new Nemo.Tuple<int, int>(root_x + search_input.Allocation.Width, root_y + calendar_event_box.Allocation.Height);
+		};
+
+		popup.set_files_and_show(items, search_text);
 
 		Singleton<OverlayTracker>.Instance.add_overlay_and_show(popup);
 	}

Modified: trunk/gtk/OverlayTracker.cs
==============================================================================
--- trunk/gtk/OverlayTracker.cs	(original)
+++ trunk/gtk/OverlayTracker.cs	Mon Jan  7 18:13:15 2008
@@ -9,6 +9,7 @@
 	{
 		public abstract void hide();
 		public abstract void show();
+		// x = vertical shift, y = horizontal shift
 		public abstract void shift(int x, int y);
 		public abstract void resize();
 	

Modified: trunk/gtk/SearchPopup.cs
==============================================================================
--- trunk/gtk/SearchPopup.cs	(original)
+++ trunk/gtk/SearchPopup.cs	Mon Jan  7 18:13:15 2008
@@ -11,6 +11,13 @@
 		Gtk.VBox elements;
 		
 		VoidFunction<CalendarDriver.View, DateTime> set_view_callback;
+		public Function<int> get_size;
+		public Function<Tuple<int, int>> calculate_start_position;
+		
+		List<Item> items;
+		string search_text;
+		int offset;
+		int last_page_size;
 		
 		public SearchPopup(VoidFunction<CalendarDriver.View, DateTime> set_view)
 		{
@@ -18,6 +25,8 @@
 			elements = null;
 			set_view_callback = set_view;
 			name = "search_popup";
+			offset = 0;
+			last_page_size = 0;
 		}
 
 		public override void hide()
@@ -30,21 +39,52 @@
 			popup.Show();
 		}
 		
-		public override void shift(int x, int y)
+		public override void shift(int shift_x, int shift_y)
 		{
+			int x = 0, y = 0;
+			popup.GdkWindow.GetPosition(out x, out y);
+			popup.Move(x + shift_x, y + shift_y);
 		}
 		
 		public override void resize()
 		{
+			add_elements();
 		}
 		
-		public void set_files_and_show(List<Item> items, string search_text, int x, int y)
+		public void set_files_and_show(List<Item> items, string search_text)
 		{
-			create_window(search_text, x, y);
+			this.items = items;
+			this.search_text = search_text;
 
-			foreach (Item item in items)
-				elements.PackStart(create_element(item, search_text, "", delegate { popup.ShowAll(); }), true, true, 5);
+			add_elements();
+		}
+
+		private void add_elements()
+		{
+			Tuple<int, int> pos = calculate_start_position();
 
+			create_window(search_text, pos.first, pos.second);
+
+			int height = get_size();
+
+			int index = 0;
+
+			foreach (Item item in items) {
+				++index;
+				if (index < offset)
+					continue;
+
+				if (item is DocumentItem)
+					height -= 75;
+				else
+					height -= 55;
+					
+				if (height <= 0)
+					break;
+
+				elements.PackStart(create_element(item, search_text, "", delegate { popup.ShowAll(); }), true, true, 5);
+			}
+			
 			if (items.Count == 0) {
 				Gtk.Alignment tmp = new Gtk.Alignment(0.5f, 1f, 1f, 1f);
 				tmp.BorderWidth = 5;
@@ -52,13 +92,44 @@
 				elements.Add(tmp);
 			}
 
-			System.Console.WriteLine("elements size {0}", items.Count);
-
 			elements.SizeAllocated += delegate(object sender, Gtk.SizeAllocatedArgs args) {
-				popup.Move(x, y - args.Allocation.Height);
+				popup.Move(pos.first, pos.second - args.Allocation.Height);
 			};
 
+			Gtk.HBox page_navigation = new Gtk.HBox();
+
+			if (offset > 0) // prev
+				add_page_link(Mono.Unix.Catalog.GetString("Prev page"), page_navigation, offset-last_page_size);
+			if (items.Count > index) // next
+				add_page_link(Mono.Unix.Catalog.GetString("Next page"), page_navigation, index);
+
+	        Gtk.Alignment alignment = new Gtk.Alignment(1F, 0.5F, 0F, 0F);
+			alignment.Add(page_navigation);
+			elements.PackStart(alignment, true, true, 5);
+
+			last_page_size = index - offset;
+			offset = index;
+
 			popup.ShowAll();
+
+			System.Console.WriteLine("elements size {0}", items.Count);
+		}
+		
+		private void add_page_link(string text, Gtk.HBox page_navigation, int offset)
+		{
+			Gtk.EventBox link_wrapper = new Gtk.EventBox();
+			Gtk.Label link = new Gtk.Label();
+			link.Markup = "<u><small>" + text + "</small></u>";
+			
+			GtkCommon.show_hand_and_tooltip(link_wrapper, text);
+			
+			link_wrapper.Add(link);
+			link_wrapper.ButtonPressEvent += delegate(object sender, Gtk.ButtonPressEventArgs args) {
+				this.offset = offset;
+				add_elements();
+			};
+			GtkCommon.set_background_color(link_wrapper, "white");
+			page_navigation.PackStart(link_wrapper, false, false, 5);
 		}
 		
 		private void create_window(string search_text, int x, int y)
@@ -79,7 +150,9 @@
 			if (name == "")
 				throw new Exception("name for an overlay cannot be empty");
 
-			image_wrapper.ButtonPressEvent += delegate(object sender, Gtk.ButtonPressEventArgs args) { Singleton<OverlayTracker>.Instance.hide_and_die(name); };
+			image_wrapper.ButtonPressEvent += delegate(object sender, Gtk.ButtonPressEventArgs args) { 
+				Singleton<OverlayTracker>.Instance.hide_and_die(name); 
+			};
 			GtkCommon.set_background_color(image_wrapper, "white");
 			alignment.Add(image_wrapper);
 			elements.Add(alignment);



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