nemo r87 - trunk/gtk



Author: arj
Date: Thu Feb 14 11:55:00 2008
New Revision: 87
URL: http://svn.gnome.org/viewvc/nemo?rev=87&view=rev

Log:
Fix another memory leak

By working around a bug in gtk#

https://bugzilla.novell.com/show_bug.cgi?id=361772



Modified:
   trunk/gtk/CalendarDrawer.cs

Modified: trunk/gtk/CalendarDrawer.cs
==============================================================================
--- trunk/gtk/CalendarDrawer.cs	(original)
+++ trunk/gtk/CalendarDrawer.cs	Thu Feb 14 11:55:00 2008
@@ -305,10 +305,21 @@
 				if (update_view_set_next == null) // sanity check
 					throw new Exception("Error: update view set next not set before calling set_dates");
 
-				header_wrapper.ButtonPressEvent += delegate { update_view_set_next(next, header_start_date); };
+				header_wrapper_handler = delegate { update_view_set_next(next, header_start_date); };
+				header_wrapper.ButtonPressEvent += header_wrapper_handler;
 			}
 		}
 
+		Gtk.ButtonPressEventHandler header_wrapper_handler;
+					
+		public void reset()
+		{
+			if (header_wrapper_handler != null) {
+				header_wrapper.ButtonPressEvent -= header_wrapper_handler;
+				header_wrapper_handler = null;
+			}
+		}
+		
 		public void set_files(List<ItemWrapper> files)
 		{
 			body.items = files;
@@ -359,15 +370,30 @@
 			return new int[] { root_x, root_y, calendar_event_box.Allocation.Width, calendar_event_box.Allocation.Height };
 		}
 
+		Gtk.Table calendar_body;
+		List<CalendarFixedElement> calendar_elements = new List<CalendarFixedElement>();
+		
 		public void draw(CalendarDriver.State state, System.DateTime centered_date, List<ItemWrapper> elements)
 		{
 			if (elements.Count > 0)
 				System.Console.WriteLine("hurray! elements");
 
+			if (calendar_body != null) {
+				System.Console.WriteLine("cleaning up body of size:{0}", calendar_body.Children.Length);
+				foreach (Widget w in calendar_body.Children)
+					w.Destroy();
+				calendar_body.Dispose();
+			}
+			
+			foreach (CalendarFixedElement element in calendar_elements)
+				element.reset(); // workaround GTK-sharp signal bug
+				
+			calendar_elements.Clear();
+
             // cleanup
             foreach (Widget w in calendar_event_box.Children)
 				w.Destroy();
-
+			
 			Gtk.VBox calendar = new Gtk.VBox();
 			Gtk.HBox calendar_middle = new Gtk.HBox(); 
 			Gtk.HBox calendar_top = new Gtk.HBox();
@@ -383,7 +409,7 @@
 			calendar_header.RowSpacing = 2;
 			calendar_header.ColumnSpacing = 2;
 
-			Gtk.Table calendar_body = new Gtk.Table(1, 1, true);
+			calendar_body = new Gtk.Table(1, 1, true);
 			calendar_body.RowSpacing = 2;
 			calendar_body.ColumnSpacing = 2;
 
@@ -538,6 +564,8 @@
 				{
 					CalendarFixedElement element = new CalendarFixedElement(false, false, 0.5, size, true, false, 
 						System.DateTime.Now.ToShortDateString() == state.start_time.AddDays(col).ToShortDateString());
+					calendar_elements.Add(element);
+					
 					element.set_update_view(update_view, update_view_set_next);
 				
 					List<ItemWrapper> filenames = new List<ItemWrapper>();
@@ -760,7 +788,9 @@
 
 					CalendarFixedElement element = new CalendarFixedElement(true, true, 0.5, size, true, header_date.Month != centered_date.Month, 
 																			System.DateTime.Now.ToShortDateString() == header_date.ToShortDateString());
-					
+			
+					calendar_elements.Add(element);
+
 					string header_string = "";
 					
 					if (end_of_week)
@@ -797,7 +827,7 @@
 							     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 
 							     	     AttachOptions.Shrink | AttachOptions.Fill | AttachOptions.Expand, 0, 0);
 
-		            col = ++col % (uint)days_in_week;
+					col = ++col % (uint)days_in_week;
 		            if (col == 0)
 		                ++row;
 
@@ -827,6 +857,8 @@
 					CalendarFixedElement element = new CalendarFixedElement(true, false, 0.5, size, true, false, 
 																			String.Format("{0:MM/yy}", System.DateTime.Now) == String.Format("{0:MM/yy}", 
 																			header_date));
+					calendar_elements.Add(element);
+
 					element.set_large_header(GtkCommon.month_name(header_date.Month), 
 											 String.Format(Mono.Unix.Catalog.GetString("Zoom to {0}, {1}"), GtkCommon.month_name(header_date.Month), 
 											 header_date.Year));



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