[tomboy] Fix Template syncing



commit 0d62a62d5b3a7c435678533ced2c6a2927b62e44
Author: Aaron Borden <adborden live com>
Date:   Sun Dec 11 15:54:01 2011 -0800

    Fix Template syncing
    
    https://bugzilla.gnome.org/show_bug.cgi?id=665679

 Tomboy/NoteManager.cs                 |   16 ++++++++++++++--
 Tomboy/Notebooks/Notebook.cs          |   10 ++++++++--
 Tomboy/Synchronization/SilentUI.cs    |    4 +++-
 Tomboy/Synchronization/SyncManager.cs |   10 +++++++---
 4 files changed, 32 insertions(+), 8 deletions(-)
---
diff --git a/Tomboy/NoteManager.cs b/Tomboy/NoteManager.cs
index 97fe345..034091e 100644
--- a/Tomboy/NoteManager.cs
+++ b/Tomboy/NoteManager.cs
@@ -516,10 +516,22 @@ Ciao!");
 		{
 			return CreateNewNote (title, xml_content, null);
 		}
-
+		
+		/// <summary>
+		/// Creates a new note with GUID.
+		/// </summary>
+		/// <returns>
+		/// Empty note with specified title and GUID.
+		/// </returns>
+		/// <param name='title'>
+		/// Title.
+		/// </param>
+		/// <param name='guid'>
+		/// GUID.
+		/// </param>
 		public Note CreateWithGuid (string title, string guid)
 		{
-			return CreateNewNote (title, guid);
+			return CreateNewNote (title, "", guid);
 		}
 
 		// Create a new note with the specified title from the default
diff --git a/Tomboy/Notebooks/Notebook.cs b/Tomboy/Notebooks/Notebook.cs
index c41124e..dbede33 100644
--- a/Tomboy/Notebooks/Notebook.cs
+++ b/Tomboy/Notebooks/Notebook.cs
@@ -120,9 +120,15 @@ namespace Tomboy.Notebooks
 			}
 			
 			if (template_note == null) {
+				// Check name does not exist
+				String template_name = templateNoteTitle;
+				if (noteManager.Find(template_name) != null) {
+					template_name = noteManager.GetUniqueName(template_name, 1);
+				}
+				
 				template_note =
-					noteManager.Create (templateNoteTitle,
-							NoteManager.GetNoteTemplateContent (templateNoteTitle));
+					noteManager.Create (template_name,
+							NoteManager.GetNoteTemplateContent (template_name));
 					
 				// Select the initial text
 				NoteBuffer buffer = template_note.Buffer;
diff --git a/Tomboy/Synchronization/SilentUI.cs b/Tomboy/Synchronization/SilentUI.cs
index 2f926ac..5fc4831 100644
--- a/Tomboy/Synchronization/SilentUI.cs
+++ b/Tomboy/Synchronization/SilentUI.cs
@@ -87,7 +87,9 @@ namespace Tomboy.Sync
 			// TODO: At least respect conflict prefs
 			// TODO: Implement more useful conflict handling
 			if (localConflictNote.Id != remoteNote.UUID)
-				manager.Delete (localConflictNote);
+				GuiUtils.GtkInvokeAndWait (() => {
+					manager.Delete (localConflictNote);
+				});
 			SyncManager.ResolveConflict (SyncTitleConflictResolution.OverwriteExisting);
 		}
 		#endregion
diff --git a/Tomboy/Synchronization/SyncManager.cs b/Tomboy/Synchronization/SyncManager.cs
index a175929..1bd7e1a 100644
--- a/Tomboy/Synchronization/SyncManager.cs
+++ b/Tomboy/Synchronization/SyncManager.cs
@@ -487,9 +487,10 @@ namespace Tomboy.Sync
 						existingNote = NoteMgr.Find (noteUpdate.Title);
 						if (existingNote != null) {
 							Logger.Debug ("SyncManager: Deleting auto-generated note: " + noteUpdate.Title);
-							DeleteNoteInMainThread (existingNote);
+							RecreateNoteInMainThread (existingNote, noteUpdate);
+						} else {
+							CreateNoteInMainThread (noteUpdate);
 						}
-						CreateNoteInMainThread (noteUpdate);
 					} else if (existingNote.MetadataChangeDate.CompareTo (client.LastSyncDate) <= 0 ||
 					           noteUpdate.BasicallyEqualTo (existingNote)) {
 						// Existing note hasn't been modified since last sync; simply update it from server
@@ -674,7 +675,7 @@ namespace Tomboy.Sync
 			});
 		}
 
-		private static void DeleteNoteInMainThread (Note existingNote)
+		private static void RecreateNoteInMainThread (Note existingNote, NoteUpdate noteUpdate)
 		{
 			// Note deletion may affect the GUI, so we have to use the
 			// delegate to run in the main gtk thread.
@@ -682,6 +683,9 @@ namespace Tomboy.Sync
 			// and then rethrown in the synchronization thread.
 			GuiUtils.GtkInvokeAndWait (() => {
 				NoteMgr.Delete (existingNote);
+				// Create note with existing content
+				existingNote = NoteMgr.CreateWithGuid (noteUpdate.Title, noteUpdate.UUID);
+				UpdateLocalNote (existingNote, noteUpdate, NoteSyncType.DownloadNew);
 			});
 		}
 



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