[tomboy] Save selection per note



commit 72699901d3559bd5fde4a92d72abe1fac0d4a42f
Author: Aaron Borden <adborden live com>
Date:   Fri Apr 15 07:36:47 2011 -0700

    Save selection per note
    
    New property selection-bound-position which stores the position of the text
    buffer's selection mark.

 Tomboy/Note.cs |   44 ++++++++++++++++++++++++++++++++++++--------
 1 files changed, 36 insertions(+), 8 deletions(-)
---
diff --git a/Tomboy/Note.cs b/Tomboy/Note.cs
index 724ba96..0504d1d 100644
--- a/Tomboy/Note.cs
+++ b/Tomboy/Note.cs
@@ -31,7 +31,7 @@ namespace Tomboy
 		DateTime change_date;
 		DateTime metadata_change_date;
 
-		int cursor_pos;
+		int cursor_pos, selection_bound_pos;
 		int width, height;
 		int x, y;
 		bool open_on_startup;
@@ -46,6 +46,7 @@ namespace Tomboy
 			this.text = "";
 			x = noPosition;
 			y = noPosition;
+			selection_bound_pos = noPosition;
 
 			tags = new Dictionary<string, Tag> ();
 
@@ -121,7 +122,7 @@ namespace Tomboy
 		}
 		
 
-		// FIXME: the next five attributes don't belong here (the data
+		// FIXME: the next six attributes don't belong here (the data
 		// model), but belong into the view; for now they are kept here
 		// for backwards compatibility
 
@@ -134,6 +135,16 @@ namespace Tomboy
 				cursor_pos = value;
 			}
 		}
+		
+		public int SelectionBoundPosition
+		{
+			get {
+				return selection_bound_pos;
+			}
+			set {
+				selection_bound_pos = value;
+			}
+		}
 
 		public int Width
 		{
@@ -317,6 +328,13 @@ namespace Tomboy
 					cursor = buffer.GetIterAtLine (2);
 				}
 				buffer.PlaceCursor (cursor);
+				
+				if (data.SelectionBoundPosition >= 0) {
+					// Move selection bound to last-saved position
+					Gtk.TextIter selection_bound;
+					selection_bound = buffer.GetIterAtOffset (data.SelectionBoundPosition);
+					buffer.MoveMark (buffer.SelectionBound.Name, selection_bound);
+				}
 
 				// New events should create Undo actions
 				buffer.Undoer.ThawUndo ();
@@ -547,14 +565,16 @@ namespace Tomboy
 			}
 		}
 
-		void BufferInsertMarkSet (object sender, Gtk.MarkSetArgs args)
+		void OnBufferMarkSet (object sender, Gtk.MarkSetArgs args)
 		{
-			if (args.Mark != buffer.InsertMark)
+			if (args.Mark == buffer.InsertMark)
+				data.Data.CursorPosition = args.Location.Offset;
+			else if (args.Mark == buffer.SelectionBound)
+				data.Data.SelectionBoundPosition = args.Location.Offset;
+			else
 				return;
 
-			data.Data.CursorPosition = args.Location.Offset;
-
-			DebugSave ("BufferInsertSetMark queueing save");
+			DebugSave ("OnBufferSetMark queueing save");
 			QueueSave (ChangeType.NoChange);
 		}
 
@@ -1082,7 +1102,7 @@ namespace Tomboy
 					buffer.Changed += OnBufferChanged;
 					buffer.TagApplied += BufferTagApplied;
 					buffer.TagRemoved += BufferTagRemoved;
-					buffer.MarkSet += BufferInsertMarkSet;
+					buffer.MarkSet += OnBufferMarkSet;
 				}
 				return buffer;
 			}
@@ -1340,6 +1360,10 @@ namespace Tomboy
 						if (int.TryParse (xml.ReadString (), out num))
 							note.CursorPosition = num;
 						break;
+					case "selection-bound-position":
+						if (int.TryParse (xml.ReadString (), out num))
+							note.SelectionBoundPosition = num;
+						break;
 					case "width":
 						if (int.TryParse (xml.ReadString (), out num))
 							note.Width = num;
@@ -1475,6 +1499,10 @@ namespace Tomboy
 			xml.WriteStartElement (null, "cursor-position", null);
 			xml.WriteString (note.CursorPosition.ToString ());
 			xml.WriteEndElement ();
+			
+			xml.WriteStartElement (null, "selection-bound-position", null);
+			xml.WriteString (note.SelectionBoundPosition.ToString ());
+			xml.WriteEndElement ();
 
 			xml.WriteStartElement (null, "width", null);
 			xml.WriteString (note.Width.ToString ());



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