From 1eece7806e4e883a4a7b1969df7cc1a7f40fd930 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 23 Jul 2011 22:23:14 +0100 Subject: [PATCH] Add notifications for new notes --- SparkleLib/SparkleRepoBase.cs | 24 +++++++++++++++++++++--- SparkleShare/SparkleController.cs | 10 ++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index 8421722f..9229e669 100644 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -67,9 +67,12 @@ namespace SparkleLib { public delegate void SyncStatusChangedEventHandler (SyncStatus new_status); public event SyncStatusChangedEventHandler SyncStatusChanged; - public delegate void NewChangeSetEventHandler (SparkleChangeSet change_set, string source_path); + public delegate void NewChangeSetEventHandler (SparkleChangeSet change_set); public event NewChangeSetEventHandler NewChangeSet; + public delegate void NewNoteEventHandler (string user_name, string user_email); + public event NewNoteEventHandler NewNote; + public delegate void ConflictResolvedEventHandler (); public event ConflictResolvedEventHandler ConflictResolved; @@ -441,8 +444,23 @@ namespace SparkleLib { if (SyncStatusChanged != null) SyncStatusChanged (SyncStatus.Idle); - if (NewChangeSet != null) - NewChangeSet (GetChangeSets (1) [0], LocalPath); + SparkleChangeSet change_set = GetChangeSets (1) [0]; + + bool note_added = false; + foreach (string added in change_set.Added) { + if (added.StartsWith (".notes")) { + if (NewNote != null) + NewNote (change_set.UserName, change_set.UserEmail); + + note_added = true; + break; + } + } + + if (!note_added) { + if (NewChangeSet != null) + NewChangeSet (change_set); + } // There could be changes from a // resolved conflict. Tries only once, diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index 8545a217..602c0fd5 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -594,11 +594,17 @@ namespace SparkleShare { else repo = new SparkleRepoGit (folder_path, SparkleBackend.DefaultBackend); - repo.NewChangeSet += delegate (SparkleChangeSet change_set, string repository_path) { + repo.NewChangeSet += delegate (SparkleChangeSet change_set) { string message = FormatMessage (change_set); if (NotificationRaised != null) - NotificationRaised (change_set.UserName, change_set.UserEmail, message, repository_path); + NotificationRaised (change_set.UserName, change_set.UserEmail, message, repo.LocalPath); + }; + + repo.NewNote += delegate (string user_name, string user_email) { + if (NotificationRaised != null) + NotificationRaised (user_name, user_email, + "added a note to " + Path.GetFileName (repo.LocalPath), repo.LocalPath); }; repo.ConflictResolved += delegate {