[tomboy] Make NotebookNoteAddin handle button sensitivity when untemplating



commit f79c0c7c9aacfa36b6e09d3cff1880d9ba0c3f75
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date:   Sun Jul 25 09:39:50 2010 -0700

    Make NotebookNoteAddin handle button sensitivity when untemplating
    
    Signed-off-by: Aaron Borden <adborden live com>

 Tomboy/Notebooks/NotebookNoteAddin.cs |   41 +++++++++++++++++++++++++--------
 1 files changed, 31 insertions(+), 10 deletions(-)
---
diff --git a/Tomboy/Notebooks/NotebookNoteAddin.cs b/Tomboy/Notebooks/NotebookNoteAddin.cs
index 201db5a..b066e54 100644
--- a/Tomboy/Notebooks/NotebookNoteAddin.cs
+++ b/Tomboy/Notebooks/NotebookNoteAddin.cs
@@ -11,6 +11,16 @@ namespace Tomboy.Notebooks
 		Gtk.Menu menu;
 		static Gdk.Pixbuf notebookIcon;
 		static Gdk.Pixbuf newNotebookIcon;
+		static Tag templateTag;
+
+		static Tag TemplateTag
+		{
+			get {
+				if (templateTag == null)
+					templateTag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSystemTag);
+				return templateTag;
+			}
+		}
 		
 		static Gdk.Pixbuf NotebookIcon
 		{
@@ -53,6 +63,18 @@ namespace Tomboy.Notebooks
 			
 			NotebookManager.NoteAddedToNotebook += OnNoteAddedToNotebook;
 			NotebookManager.NoteRemovedFromNotebook += OnNoteRemovedFromNotebook;
+
+
+			Note.TagAdded += delegate (Note taggedNote, Tag tag) {
+				if (taggedNote == Note && tag == TemplateTag)
+					UpdateButtonSensitivity (true);
+			};
+
+			// TODO: Make sure this is handled in NotebookNoteAddin, too
+			Note.TagRemoved += delegate (Note taggedNote, string tag) {
+				if (taggedNote == Note && tag == TemplateTag.NormalizedName)
+					UpdateButtonSensitivity (false);
+			};
 		}
 
 		public override void Shutdown ()
@@ -77,18 +99,17 @@ namespace Tomboy.Notebooks
 			
 			if (toolButton == null) {
 				InitializeToolButton ();
-
-				// Disable the notebook button if this note is a template note
-				Tag templateTag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSystemTag);
-				if (Note.ContainsTag (templateTag) == true) {
-					toolButton.Sensitive = false;
-				
-					// Also prevent notebook templates from being deleted
-					if (NotebookManager.GetNotebookFromNote (Note) != null)
-						Note.Window.DeleteButton.Sensitive = false;
-				}
+				UpdateButtonSensitivity (Note.ContainsTag (TemplateTag));
 			}
 		}
+
+		private void UpdateButtonSensitivity (bool isTemplate)
+		{
+			if (toolButton != null)
+				toolButton.Sensitive = !isTemplate;
+			if (Note.HasWindow)
+				Note.Window.DeleteButton.Sensitive = !isTemplate || NotebookManager.GetNotebookFromNote (Note) == null;
+		}
 		
 		void OnMenuShown (object sender, EventArgs args)
 		{



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