All pastes #728256 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-10-06 20:45 UTC
rendered paste body
Index: Note.cs
===================================================================
--- Note.cs	(revision 1587)
+++ Note.cs	(working copy)
@@ -283,6 +283,14 @@
 
 		InterruptableTimeout save_timeout;
 
+		struct ChildWidgetData
+		{
+			public Gtk.TextChildAnchor anchor;
+			public Gtk.Widget widget;
+		};
+
+		Queue <ChildWidgetData> childWidgetQueue;
+
 		[System.Diagnostics.Conditional ("DEBUG_SAVE")]
 		static void DebugSave (string format, params object[] args)
 		{
@@ -303,6 +311,8 @@
 			
 			save_timeout = new InterruptableTimeout ();
 			save_timeout.Timeout += SaveTimeout;
+
+			childWidgetQueue = new Queue <ChildWidgetData> ();
 		}
 
 		static string UrlFromPath (string filepath)
@@ -522,6 +532,31 @@
 			QueueSave (true);
 		}
 
+		public void AddChildWidget (Gtk.TextChildAnchor childAnchor, Gtk.Widget widget)
+		{
+			ChildWidgetData data = new ChildWidgetData ();
+			data.anchor = childAnchor;
+			data.widget = widget;
+
+			childWidgetQueue.Enqueue (data);
+
+			if (HasWindow)
+				ProcessChildWidgetQueue ();
+		}
+
+		private void ProcessChildWidgetQueue ()
+		{
+			// Insert widgets in the childWidgetQueue into the NoteEditor
+			if (!HasWindow)
+				return; // can't do anything without a window
+
+			foreach (ChildWidgetData data in childWidgetQueue) {
+				Window.Editor.AddChildAtAnchor (data.widget, data.anchor);
+			}
+
+			childWidgetQueue.Clear ();
+		}
+
 		public string Uri
 		{
 			get { return data.Data.Uri; }
@@ -763,7 +798,7 @@
 					Logger.Log ("Creating Buffer for '{0}'...", 
 						    data.Data.Title);
 
-					buffer = new NoteBuffer (TagTable);
+					buffer = new NoteBuffer (TagTable, this);
 					data.Buffer = buffer;
 
 					// Listen for further changed signals
@@ -800,6 +835,10 @@
 					// OnRealized causes segfaults.
 					if (Opened != null)
 						Opened (this, new EventArgs ());
+
+					// Add any child widgets if any exist now that
+					// the window is showing.
+					ProcessChildWidgetQueue ();
 				}
 				return window; 
 			}