[tomboy] Better idle handling, since Note.Saved will never be fired while editing



commit 28eadd123cc4c7d89d1abc8cf7e02e49c569e6a5
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date:   Mon Mar 8 10:20:47 2010 -0800

    Better idle handling, since Note.Saved will never be fired while editing

 Tomboy/Synchronization/SyncManager.cs |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/Tomboy/Synchronization/SyncManager.cs b/Tomboy/Synchronization/SyncManager.cs
index e2a29df..13e43b8 100644
--- a/Tomboy/Synchronization/SyncManager.cs
+++ b/Tomboy/Synchronization/SyncManager.cs
@@ -194,7 +194,7 @@ namespace Tomboy.Sync
 			}
 
 			Preferences.SettingChanged += Preferences_SettingChanged;
-			Tomboy.DefaultNoteManager.NoteSaved += HandleNoteSaved;
+			NoteMgr.NoteSaved += HandleNoteSaved;
 
 			// Update sync item based on configuration.
 			UpdateSyncAction ();
@@ -212,10 +212,33 @@ namespace Tomboy.Sync
 					currentAutosyncTimeoutMinutes = 1;
 					autosyncTimer.Change (currentAutosyncTimeoutMinutes * 60000,
 					                      autosyncTimeoutPrefMinutes * 60000);
+					NoteMgr.NoteBufferChanged -= HandleNoteBufferChanged;
+					NoteMgr.NoteBufferChanged += HandleNoteBufferChanged;
 				}
+			} else if (syncThread == null && autosyncTimer == null && autosyncTimeoutPrefMinutes > 0) {
+				lastBackgroundCheck = DateTime.Now;
+				 // Perform a sync one minute after setting change
+				currentAutosyncTimeoutMinutes = 1;
+				autosyncTimer = new Timer ((o) => BackgroundSyncChecker (),
+				                           null,
+				                           currentAutosyncTimeoutMinutes * 60000,
+				                           autosyncTimeoutPrefMinutes * 60000);
+				NoteMgr.NoteBufferChanged -= HandleNoteBufferChanged;
+				NoteMgr.NoteBufferChanged += HandleNoteBufferChanged;
 			}
 		}
 
+		static void HandleNoteBufferChanged (Note note)
+		{
+			// If note text changes, kill the timer.  It will
+			// automatically be resurrected once a Save occurs.
+			if (syncThread == null && autosyncTimer != null) {
+				autosyncTimer.Dispose ();
+				autosyncTimer = null;
+			}
+			NoteMgr.NoteBufferChanged -= HandleNoteBufferChanged;
+		}
+
 		static void Preferences_SettingChanged (object sender, EventArgs args)
 		{
 			// Update sync item based on configuration.
@@ -250,6 +273,8 @@ namespace Tomboy.Sync
 					                           null,
 					                           currentAutosyncTimeoutMinutes * 60000,
 					                           autosyncTimeoutPrefMinutes * 60000);
+					NoteMgr.NoteBufferChanged -= HandleNoteBufferChanged;
+					NoteMgr.NoteBufferChanged += HandleNoteBufferChanged;
 				}
 			}
 		}



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