[tomboy] Template bar functionality for size and cursor pos



commit 0a0115c4f079d64cd9b8c6e69283e214c2fc11c9
Author: Aaron Borden <adborden live com>
Date:   Tue Apr 12 19:08:54 2011 -0700

    Template bar functionality for size and cursor pos
    
    The template bar allows saving the note's size and text selection. When these
    options are selected, new notes based on the template will be created with the
    same size and cursor position as the template.

 Tomboy/NoteManager.cs |   21 +++++++++++++++++++++
 Tomboy/NoteWindow.cs  |    6 +++---
 Tomboy/TagManager.cs  |    2 ++
 3 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/Tomboy/NoteManager.cs b/Tomboy/NoteManager.cs
index 9df6bb3..e1aab2b 100644
--- a/Tomboy/NoteManager.cs
+++ b/Tomboy/NoteManager.cs
@@ -712,6 +712,27 @@ Ciao!");
 			xml_content = SanitizeXmlContent (xml_content);
 
 			Note new_note = CreateNewNote (title, xml_content, guid);
+			
+			// Copy template note's properties
+			Tag template_save_size = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSaveSizeSystemTag);
+			if (template_note.Data.HasExtent () && template_note.ContainsTag (template_save_size)) {
+				new_note.Data.Height = template_note.Data.Height;
+				new_note.Data.Width = template_note.Data.Width;
+			}
+			
+			Tag template_save_selection = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSaveSelectionSystemTag);
+			if (template_note.Data.CursorPosition > 0 && template_note.ContainsTag (template_save_selection)) {
+				// Because the titles will be different between template and
+				// new note, we can't just drop the cursor at template's
+				// CursorPosition. Whitespace after the title makes this more
+				// complicated so let's just start counting from the line after the title.
+				int template_cursor_offset_normalized = template_note.Data.CursorPosition - template_note.Buffer.GetIterAtLine (1).Offset;
+				
+				Gtk.TextBuffer buffer = new_note.Buffer;
+				Gtk.TextIter cursor = buffer.GetIterAtOffset (buffer.GetIterAtLine (1).Offset + template_cursor_offset_normalized);
+				buffer.PlaceCursor(cursor);
+			}
+			
 			return new_note;
 		}
 		
diff --git a/Tomboy/NoteWindow.cs b/Tomboy/NoteWindow.cs
index 617c5b5..b0fc217 100644
--- a/Tomboy/NoteWindow.cs
+++ b/Tomboy/NoteWindow.cs
@@ -556,8 +556,8 @@ namespace Tomboy
 		{
 			// TODO: Move these to static area
 			Tag template_tag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSystemTag);
-			Tag template_save_size_tag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSystemTag + ":save-size");
-			Tag template_save_selection_tag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSystemTag + ":save-selection");
+			Tag template_save_size_tag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSaveSizeSystemTag);
+			Tag template_save_selection_tag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSaveSelectionSystemTag);
 
 			var bar = new Gtk.VBox ();
 
@@ -583,7 +583,7 @@ namespace Tomboy
 
 			var saveSelectionCheckbutton = new Gtk.CheckButton (Catalog.GetString ("Save Se_lection"));
 			saveSelectionCheckbutton.Active = note.ContainsTag (template_save_selection_tag);
-			saveSizeCheckbutton.Toggled += (o, e) => {
+			saveSelectionCheckbutton.Toggled += (o, e) => {
 				if (saveSelectionCheckbutton.Active)
 					note.AddTag (template_save_selection_tag);
 				else
diff --git a/Tomboy/TagManager.cs b/Tomboy/TagManager.cs
index 0063ded..43ddf3a 100644
--- a/Tomboy/TagManager.cs
+++ b/Tomboy/TagManager.cs
@@ -25,6 +25,8 @@ namespace Tomboy
 		/// certain places such as, Search All Notes Window, Main Menu, etc.
 		/// </summary>
 		public static string TemplateNoteSystemTag = "template";
+		public static string TemplateNoteSaveSizeSystemTag = TemplateNoteSystemTag + ":save-size";
+		public static string TemplateNoteSaveSelectionSystemTag = TemplateNoteSystemTag + ":save-selection";
 		
 		#region Constructors
 		static TagManager ()



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