nemo r97 - trunk/gtk



Author: arj
Date: Tue Mar 11 12:47:12 2008
New Revision: 97
URL: http://svn.gnome.org/viewvc/nemo?rev=97&view=rev

Log:
Fix day view

- Don't small all elements at once (do navigation)
  - It's much faster 
  - Uses lots less ram
  - But you won't be able to scroll all items
- Fix a refresh bug where the day view would blink upon first enter



Modified:
   trunk/gtk/CalendarDrawer.cs

Modified: trunk/gtk/CalendarDrawer.cs
==============================================================================
--- trunk/gtk/CalendarDrawer.cs	(original)
+++ trunk/gtk/CalendarDrawer.cs	Tue Mar 11 12:47:12 2008
@@ -325,6 +325,7 @@
 			body.items = files;
 		}
 	}
+
 	public class CalendarDrawer
 	{
 		private Gtk.EventBox calendar_event_box;
@@ -360,6 +361,8 @@
 
 			cal = new System.Globalization.GregorianCalendar();
 			culture = System.Globalization.CultureInfo.CreateSpecificCulture("da");
+			
+			day_offset = 0;
 		}
 
 		int[] size()
@@ -373,8 +376,21 @@
 		Gtk.Table calendar_body;
 		List<CalendarFixedElement> calendar_elements = new List<CalendarFixedElement>();
 		
+		int day_offset;
+		int days_per_page = 30;
+		
+		List<ItemWrapper> last_elements;
+		
 		public void draw(CalendarDriver.State state, System.DateTime centered_date, List<ItemWrapper> elements)
 		{
+			if (last_elements != null) {
+				if (last_elements != elements) {
+					last_elements = elements;
+					day_offset = 0;
+				}
+			} else
+				last_elements = elements;
+			
 			if (elements.Count > 0)
 				System.Console.WriteLine("hurray! elements");
 
@@ -421,95 +437,155 @@
 			if (state.view == CalendarDriver.View.Day)
 			{
 				Gtk.Viewport viewport = new Gtk.Viewport();
-				viewport.Add(calendar_body);
 
+				Gtk.VBox viewbox = new VBox();
+				viewbox.Add(calendar_body);
+				
+				viewport.Add(viewbox);
+				
 				Gtk.ScrolledWindow scrolled = new Gtk.ScrolledWindow();
 				scrolled.Add(viewport);
-
+				
 				calendar.PackStart(scrolled, true, true, 0);
 
 				today_button.Label = "Today";
 				current_date.Markup = "<b>" + String.Format("{0:dddd} {0:dd/MM/yy}", centered_date) + "</b>";
 
 				Gdk.Rectangle last_allocation = new Gdk.Rectangle();
+				
+				foreach (Widget w in calendar_body.Children)
+					w.Destroy();
 
-				calendar_body.ExposeEvent += delegate {
-
-					if (calendar_body.Allocation.Height == last_allocation.Height && calendar_body.Allocation.Width == last_allocation.Width)
-						return;
-
-					last_allocation = calendar_body.Allocation;
-
-					foreach (Widget w in calendar_body.Children)
-						w.Destroy();
-
-					uint cols = 3;
+				uint cols = 3;
 
-					if (calendar_body.Allocation.Width >= 300)
-						cols = (uint)calendar_body.Allocation.Width/300;
+				if (calendar_event_box.Allocation.Width >= 350)
+					cols = (uint)calendar_event_box.Allocation.Width/350;
 				
-					uint rows = (uint)elements.Count/cols;
+				uint rows;
 				
-					if (elements.Count < 3)
-						rows = 1;
+				if (elements.Count >= days_per_page) {
+					int elements_in_view = days_per_page;
+					if ((day_offset+1)*days_per_page > elements.Count) // last page
+						elements_in_view = elements.Count - day_offset*days_per_page;
+					rows = (uint)Math.Ceiling((elements_in_view*1.0)/cols);
+				} else
+					rows = (uint)Math.Ceiling((elements.Count*1.0)/cols);
+
+				System.Console.WriteLine("elements: {0}, day_offset {1}", elements.Count, day_offset);
+				System.Console.WriteLine("cols {0} - rows {1}", cols, rows);
+				System.Console.WriteLine("width {0}, height {1}", calendar_event_box.Allocation.Width, calendar_event_box.Allocation.Height);
 
-					System.Console.WriteLine("cols {0} - rows {1}", cols, rows);
-					System.Console.WriteLine("width {0}, height {1}", calendar_body.Allocation.Width, calendar_body.Allocation.Height);
+				calendar_body.Resize(rows, cols);
+			
+				uint col = 0, row = 0; 
 
-					calendar_body.Resize(rows, cols);
+				int element = 0;
 				
-					uint col = 0, row = 0; 
+				// fill in elements
+				foreach (ItemWrapper wrapper in elements)
+				{
+					if (!(element >= day_offset*days_per_page && element < (day_offset+1)*days_per_page)) {
+						++element;
+						continue;
+					}
 
-					// fill in elements
-					foreach (ItemWrapper wrapper in elements)
-					{
-						uint tmp_col = col;
-						uint tmp_row = row;
-						ItemWrapper tmp_wrapper = wrapper; // oh lambda bug, we love ye
-				
-						wrapper.item.on_data_callback = delegate {
-							calendar_body.Attach(tmp_wrapper.item.Display().get_representation(), tmp_col, tmp_col+1, tmp_row, tmp_row+1, 
-									     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
-												 AttachOptions.Shrink | AttachOptions.Fill,
-												 0,0);
+					uint tmp_col = col;
+					uint tmp_row = row;
+					ItemWrapper tmp_wrapper = wrapper; // oh lambda bug, we love ye
+			
+					wrapper.item.on_data_callback = delegate {
+						calendar_body.Attach(tmp_wrapper.item.Display().get_representation(), tmp_col, tmp_col+1, tmp_row, tmp_row+1, 
+								     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
+											 AttachOptions.Shrink | AttachOptions.Fill,
+											 0,0);
+					};
+					
+					wrapper.item.on_data_callback();
+
+		            col = ++col % cols;
+		            if (col == 0)
+		                ++row;
+					
+					++element;
+				}
+
+				if (elements.Count > days_per_page)
+				{
+					Gtk.HBox page_navigation = new Gtk.HBox();
+					page_navigation.Homogeneous = true;
+					
+					if (day_offset > 0) {
+						// prev button
+						Gtk.EventBox link_wrapper = new Gtk.EventBox();
+						Gtk.Alignment alignment = new Alignment(1,1,1,1);
+						alignment.BorderWidth = 15;
+						Gtk.Label link = new Gtk.Label();
+						string text = Mono.Posix.Catalog.GetString("Previous page");
+						link.Markup = "<u>" + text + String.Format(" ({0}/{1})", day_offset, Math.Ceiling(elements.Count*1.0/days_per_page)) + "</u>";
+		
+						GtkCommon.show_hand_and_tooltip(link_wrapper, text);
+		
+						link_wrapper.Add(alignment);
+						alignment.Add(link);
+						link_wrapper.ButtonPressEvent += delegate {
+							day_offset -= 1;
+							draw(state, centered_date, elements);
 						};
 						
-						wrapper.item.on_data_callback();
-
-			            col = ++col % cols;
-			            if (col == 0)
-			                ++row;
+						GtkCommon.set_background_color(link_wrapper, "white");
+						page_navigation.PackStart(link_wrapper, false, true, 0);
 					}
 					
-					if (elements.Count == 0)
+					if ((day_offset+1)*days_per_page <= elements.Count)
 					{
-						Gtk.EventBox eventbox = new Gtk.EventBox();
-						Gtk.Alignment alignment = new Alignment(0.5f, 0.5f, 0f, 0f);
-					
-						Gtk.VBox box = new Gtk.VBox();
-					
-						Gtk.Image img = new Gtk.Image(null, "blue_guy_med.png");
-						box.PackStart(img, true, true, 10);
-						
-						Gtk.Label label = new Gtk.Label(Mono.Unix.Catalog.GetString("Sorry, no files for this day"));
-						box.PackStart(label, true, true, 10);
-						
-						alignment.Add(box);
-						eventbox.Add(alignment);
+						// next button
+						Gtk.EventBox link_wrapper = new Gtk.EventBox();
+						Gtk.Alignment alignment = new Alignment(1,1,1,1);
+						alignment.BorderWidth = 15;
+						Gtk.Label link = new Gtk.Label();
+						string text = Mono.Posix.Catalog.GetString("Next page");
+						link.Markup = "<u>" + text + String.Format(" ({0}/{1})", day_offset+2, Math.Ceiling(elements.Count*1.0/days_per_page))  + "</u>";
+		
+						GtkCommon.show_hand_and_tooltip(link_wrapper, text);
+		
+						link_wrapper.Add(alignment);
+						alignment.Add(link);
+						link_wrapper.ButtonPressEvent += delegate {
+							day_offset += 1;
+							draw(state, centered_date, elements);
+						};
 						
-						GtkCommon.set_background_color(eventbox, "white");
+						GtkCommon.set_background_color(link_wrapper, "white");
+						page_navigation.PackStart(link_wrapper, false, true, 0);
+					}
 
-						calendar_body.Resize(1, 1);
+					viewbox.Add(page_navigation);					
+				}
 					
-						calendar_body.Attach(eventbox, 0, 1, 0, 1, 
-									     	 AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
-											 AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0,0);
-					}
+				if (elements.Count == 0)
+				{
+					Gtk.EventBox eventbox = new Gtk.EventBox();
+					Gtk.Alignment alignment = new Alignment(0.5f, 0.5f, 0f, 0f);
+				
+					Gtk.VBox box = new Gtk.VBox();
+				
+					Gtk.Image img = new Gtk.Image(null, "blue_guy_med.png");
+					box.PackStart(img, true, true, 10);
 					
-					System.Console.WriteLine("showing all");
+					Gtk.Label label = new Gtk.Label(Mono.Unix.Catalog.GetString("Sorry, no files for this day"));
+					box.PackStart(label, true, true, 10);
 					
-					calendar_body.ShowAll();
-				};
+					alignment.Add(box);
+					eventbox.Add(alignment);
+					
+					GtkCommon.set_background_color(eventbox, "white");
+
+					calendar_body.Resize(1, 1);
+				
+					calendar_body.Attach(eventbox, 0, 1, 0, 1, 
+								     	 AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
+										 AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0,0);
+				}
 				
 				week_button.Active = false;
 				month_button.Active = false;				



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