[tomboy] Add Note.BufferChanged and NoteManager.NoteBufferChanged events



commit 0e6e52ed07080a832ee468412e054594d74ac28c
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date:   Mon Mar 8 10:19:55 2010 -0800

    Add Note.BufferChanged and NoteManager.NoteBufferChanged events
    
    These are fired constantly while editing, so event handlers should be
    extremely conservative in how much work they do.

 Tomboy/Note.cs        |   13 ++++++++-----
 Tomboy/NoteManager.cs |    9 +++++++++
 2 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/Tomboy/Note.cs b/Tomboy/Note.cs
index 21d6ec9..996940a 100644
--- a/Tomboy/Note.cs
+++ b/Tomboy/Note.cs
@@ -252,7 +252,7 @@ namespace Tomboy
 			}
 			set {
 				buffer = value;
-				buffer.Changed += BufferChanged;
+				buffer.Changed += OnBufferChanged;
 				buffer.TagApplied += BufferTagApplied;
 				buffer.TagRemoved += BufferTagRemoved;
 
@@ -325,7 +325,7 @@ namespace Tomboy
 
 		// Callbacks
 
-		void BufferChanged (object sender, EventArgs args)
+		void OnBufferChanged (object sender, EventArgs args)
 		{
 			InvalidateText ();
 		}
@@ -513,10 +513,12 @@ namespace Tomboy
 		// depending on the change...
 		//
 
-		void BufferChanged (object sender, EventArgs args)
+		void OnBufferChanged (object sender, EventArgs args)
 		{
-			DebugSave ("BufferChanged queueing save");
+			DebugSave ("OnBufferChanged queueing save");
 			QueueSave (ChangeType.ContentChanged);
+			if (BufferChanged != null)
+				BufferChanged (this);
 		}
 
 		void BufferTagApplied (object sender, Gtk.TagAppliedArgs args)
@@ -1070,7 +1072,7 @@ namespace Tomboy
 					data.Buffer = buffer;
 
 					// Listen for further changed signals
-					buffer.Changed += BufferChanged;
+					buffer.Changed += OnBufferChanged;
 					buffer.TagApplied += BufferTagApplied;
 					buffer.TagRemoved += BufferTagRemoved;
 					buffer.MarkSet += BufferInsertMarkSet;
@@ -1218,6 +1220,7 @@ namespace Tomboy
 		public event TagAddedHandler TagAdded;
 		public event TagRemovingHandler TagRemoving;
 		public event TagRemovedHandler TagRemoved;
+		public event Action<Note> BufferChanged;
 	}
 
 	// Singleton - allow overriding the instance for easy sensing in
diff --git a/Tomboy/NoteManager.cs b/Tomboy/NoteManager.cs
index d6b1374..be9f6d8 100644
--- a/Tomboy/NoteManager.cs
+++ b/Tomboy/NoteManager.cs
@@ -246,6 +246,12 @@ Ciao!");
 			this.notes.Sort (new CompareDates ());
 		}
 
+		void OnBufferChanged (Note note)
+		{
+			if (NoteBufferChanged != null)
+				NoteBufferChanged (note);
+		}
+
 		protected virtual void CreateStartNotes ()
 		{
 			// FIXME: Delay the creation of the start notes so the panel/tray
@@ -317,6 +323,7 @@ Ciao!");
 					if (note != null) {
 						note.Renamed += OnNoteRename;
 						note.Saved += OnNoteSave;
+						note.BufferChanged += OnBufferChanged;
 						notes.Add (note);
 					}
 				} catch (System.Xml.XmlException e) {
@@ -547,6 +554,7 @@ Ciao!");
 			new_note.XmlContent = xml_content;
 			new_note.Renamed += OnNoteRename;
 			new_note.Saved += OnNoteSave;
+			new_note.BufferChanged += OnBufferChanged;
 
 			notes.Add (new_note);
 
@@ -685,6 +693,7 @@ Ciao!");
 		public event NotesChangedHandler NoteAdded;
 		public event NoteRenameHandler NoteRenamed;
 		public event NoteSavedHandler NoteSaved;
+		public event Action<Note> NoteBufferChanged;
 	}
 
 	public class TrieController



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