Tomboy UI/String Change: New Note Template



The following strings have been added to the project (see complete
details in the attached patch file):

    "New Note Template"
    "Use the new note template to specify the text that should be used
when creating a new note."
    "_Open New Note Template..."

Also, the circled part in the attached screenshot is a UI addition
(along with the New Note Template note).

Thanks,

Boyd

Attachment: screenshot2.png
Description: PNG image

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 1687)
+++ ChangeLog	(working copy)
@@ -1,5 +1,14 @@
 2007-12-18  Boyd Timothy <btimothy gmail com> 
 
+	* Tomboy/PreferencesDialog.cs: Added a section on the editing page for
+	  "New Note Template".
+	* Tomboy/NoteManager.cs: Added GetOrCreateTemplateNote() to allow the
+	  new note template note to be created/accessed.  Also modified
+	  CreateNewNote() to use the content of the new note template if it
+	  exists.
+
+2007-12-18  Boyd Timothy <btimothy gmail com> 
+
 	* Tomboy/NoteWindow.cs: Restored the FindBar at the bottom of the note
 	  so the find functionality stays the same as previously stable-released
 	  versions.  Also adjusted whitespace issues.
Index: Tomboy/PreferencesDialog.cs
===================================================================
--- Tomboy/PreferencesDialog.cs	(revision 1687)
+++ Tomboy/PreferencesDialog.cs	(working copy)
@@ -192,7 +192,28 @@ namespace Tomboy
 			align.Add (font_button);
 
 			font_peditor.AddGuard (font_button);
+			
+			// New Note Template
+			
+			label = MakeLabel (Catalog.GetString ("New Note Template"));
+			options_list.PackStart (label, false, false, 0);
 
+			label = MakeTipLabel (
+				Catalog.GetString ("Use the new note template to specify the text " +
+								   "that should be used when creating a new note."));
+			options_list.PackStart (label, false, false, 0);
+			
+			align = new Gtk.Alignment (0.5f, 0.5f, 0.4f, 1.0f);
+			align.Show ();
+			options_list.PackStart (align, false, false, 0);
+
+			Gtk.Button open_template_button;
+			open_template_button = new Gtk.Button (
+			        Catalog.GetString ("_Open New Note Template..."));
+			open_template_button.UseUnderline = true;
+			open_template_button.Clicked += OpenTemplateButtonClicked;
+			open_template_button.Show ();
+			align.Add (open_template_button);
 
 			return options_list;
 		}
@@ -1168,6 +1189,15 @@ namespace Tomboy
 				dialog.Destroy ();
 			}
 		}
+
+		void OpenTemplateButtonClicked (object sender, EventArgs args)
+		{
+			NoteManager manager = Tomboy.DefaultNoteManager;
+			Note template_note = manager.GetOrCreateTemplateNote ();
+
+			// Open the template note
+			template_note.Window.Show ();
+		}
 	}
 
 	// TODO: Figure out how to use Mono.Addins.Gui.AddinInfoDialog here instead.
Index: Tomboy/NoteManager.cs
===================================================================
--- Tomboy/NoteManager.cs	(revision 1687)
+++ Tomboy/NoteManager.cs	(working copy)
@@ -17,6 +17,8 @@ namespace Tomboy
 		AddinManager addin_mgr;
 		TrieController trie_controller;
 
+		public static string NoteTemplateTitle = Catalog.GetString ("New Note Template");
+
 		static string start_note_uri = String.Empty;
 
 		static NoteManager ()
@@ -363,7 +365,9 @@ public NoteManager (string directory) :
 		}
 
 		// Create a new note with the specified title, and a simple
-		// "Describe..." body which will be selected for easy overwrite.
+		// "Describe..." body or the body from the "New Note Template"
+		// note if it exists.  If the "New Note Template" body is found
+		// the text will not automatically be highlighted.
 		private Note CreateNewNote (string title, string guid)
 		{
 			string body = null;
@@ -371,9 +375,18 @@ public NoteManager (string directory) :
 			title = SplitTitleFromContent (title, out body);
 			if (title == null)
 				return null;
-
-			if (body == null)
-				body = Catalog.GetString ("Describe your new note here.");
+			
+			Note note_template = Find (NoteTemplateTitle);
+			if (note_template != null) {
+				// Use the body from the "New Note Template" note
+				string xml_content =
+					note_template.XmlContent.Replace (NoteTemplateTitle, title);
+				return CreateNewNote (title, xml_content, guid);
+			}
+			
+			// Use a simple "Describe..." body and highlight
+			// it so it can be easily overwritten
+			body = Catalog.GetString ("Describe your new note here.");
 
 			string header = title + "\n\n";
 			string content =
@@ -423,6 +436,46 @@ public NoteManager (string directory) :
 
 			return new_note;
 		}
+		
+		/// <summary>
+		/// Get the existing template note or create a new one
+		/// if it doesn't already exist.
+		/// </summary>
+		/// <returns>
+		/// A <see cref="Note"/>
+		/// </returns>
+		public Note GetOrCreateTemplateNote ()
+		{
+			Note template_note = Find (NoteTemplateTitle);
+			if (template_note == null) {
+				template_note =
+					Create (NoteTemplateTitle,
+							GetNoteTemplateContent (NoteTemplateTitle));
+					
+				// Select the initial text
+				NoteBuffer buffer = template_note.Buffer;
+				Gtk.TextIter iter = buffer.GetIterAtLineOffset (2, 0);
+				buffer.MoveMark (buffer.SelectionBound, iter);
+				buffer.MoveMark (buffer.InsertMark, buffer.EndIter);
+
+				template_note.QueueSave (true);
+			}
+			
+			return template_note;
+		}
+		
+		private string GetNoteTemplateContent (string title)
+		{
+			const string base_xml =
+			        "<note-content>" +
+			        "<note-title>{0}</note-title>\n\n" +
+			        "{1}" +
+			        "</note-content>";
+
+			return string.Format (base_xml,
+			                      title,
+			                      Catalog.GetString ("Describe your new note here."));
+		}
 
 		public Note Find (string linked_title)
 		{


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