[log] remove 'IsFileDump' workaround and move message code to controller

This commit is contained in:
Hylke Bons 2011-03-20 14:59:35 +00:00
parent 8119b76e6b
commit e2e51624c9
5 changed files with 86 additions and 87 deletions

View file

@ -1046,38 +1046,30 @@ namespace SparkleLib {
int.Parse (match.Groups [9].Value));
string [] entry_lines = log_entry.Split ("\n".ToCharArray ());
if (entry_lines.Length > 60) {
commit.IsFileDump = true;
} else {
foreach (string entry_line in entry_lines) {
if (entry_line.StartsWith (":")) {
string change_type = entry_line [37].ToString ();
string file_path = entry_line.Substring (39);
foreach (string entry_line in entry_lines) {
if (entry_line.StartsWith (":")) {
string change_type = entry_line [37].ToString ();
string file_path = entry_line.Substring (39);
if (change_type.Equals ("A")) {
if (change_type.Equals ("A")) {
commit.Added.Add (file_path);
} else if (change_type.Equals ("M")) {
commit.Added.Add (file_path);
commit.Edited.Add (file_path);
} else if (change_type.Equals ("D")) {
commit.Deleted.Add (file_path);
}
} else if (change_type.Equals ("M")) {
commit.Edited.Add (file_path);
} else if (change_type.Equals ("D")) {
commit.Deleted.Add (file_path);
}
}
}
commits.Add (commit);

View file

@ -74,7 +74,8 @@ namespace SparkleShare {
public delegate void ConflictNotificationRaisedEventHandler ();
public event NotificationRaisedEventHandler NotificationRaised;
public delegate void NotificationRaisedEventHandler (SparkleCommit commit, string repository_path);
public delegate void NotificationRaisedEventHandler (string user_name, string user_email,
string message, string repository_path);
// Short alias for the translations
@ -301,10 +302,6 @@ namespace SparkleShare {
if (change_set.IsMerge) {
event_entry += "<dt>Merged a branch</dt>";
} else if (change_set.IsFileDump) {
event_entry += "<dt>Dumped a lot of files</dt>";
} else {
@ -535,8 +532,10 @@ namespace SparkleShare {
repo.NewCommit += delegate (SparkleCommit commit, string repository_path) {
string message = FormatMessage (commit);
if (NotificationRaised != null)
NotificationRaised (commit, repository_path);
NotificationRaised (commit.UserName, commit.UserEmail, message, repository_path);
};
@ -680,6 +679,57 @@ namespace SparkleShare {
}
private string FormatMessage (SparkleCommit commit)
{
string file_name = "";
string message = null;
if (commit.Added.Count > 0) {
foreach (string added in commit.Added) {
file_name = added;
break;
}
message = String.Format (_("added {0}"), file_name);
}
if (commit.Edited.Count > 0) {
foreach (string modified in commit.Edited) {
file_name = modified;
break;
}
message = String.Format (_("edited {0}"), file_name);
}
if (commit.Deleted.Count > 0) {
foreach (string removed in commit.Deleted) {
file_name = removed;
break;
}
message = String.Format (_("deleted {0}"), file_name);
}
int changes_count = (commit.Added.Count +
commit.Edited.Count +
commit.Deleted.Count) - 1;
if (changes_count > 0)
message += "" + String.Format ("and {0} more", changes_count);
return message;
}
// Recursively gets a folder's size in bytes
private double CalculateFolderSize (DirectoryInfo parent)
{

View file

@ -354,10 +354,7 @@ namespace SparkleShare {
string canonical_name = System.IO.Path.GetFileNameWithoutExtension (name);
Deletable = false;
ShowSyncingPage (canonical_name);
SparkleShare.Controller.FolderFetched += delegate {
@ -614,6 +611,8 @@ namespace SparkleShare {
Reset ();
Deletable = false;
VBox layout_vertical = new VBox (false, 0);
Label header = new Label ("<span size='large'><b>" +

View file

@ -157,7 +157,7 @@ namespace SparkleShare {
public void UpdateEventLog ()
{
if (HTML == null) {
if (HTML == null) { // TODO: there may be a race condition here
LayoutVertical.Remove (ScrolledWindow);
Spinner = new SparkleSpinner (22);
@ -203,10 +203,11 @@ namespace SparkleShare {
Application.Invoke (delegate {
if (Spinner.Active) {
Spinner.Stop ();
if (Spinner.Parent == LayoutVertical) {
LayoutVertical.Remove (Spinner);
Spinner.Stop ();
} else {
@ -227,7 +228,7 @@ namespace SparkleShare {
WebView.LoadString (HTML, null, null, "file://");
LayoutVertical.ShowAll ();
ShowAll ();
});

View file

@ -79,7 +79,8 @@ namespace SparkleShare {
};
// Show a bubble when there are new changes
SparkleShare.Controller.NotificationRaised += delegate (SparkleCommit commit, string repository_path) {
SparkleShare.Controller.NotificationRaised += delegate (string user_name, string user_email,
string message, string repository_path) {
foreach (SparkleLog log in OpenLogs) {
if (log.LocalPath.Equals (repository_path)) {
@ -94,55 +95,11 @@ namespace SparkleShare {
if (!SparkleShare.Controller.NotificationsEnabled)
return;
string file_name = "";
string message = null;
if (commit.Added.Count > 0) {
foreach (string added in commit.Added) {
file_name = added;
break;
}
message = String.Format (_("added {0}"), file_name);
}
if (commit.Edited.Count > 0) {
foreach (string modified in commit.Edited) {
file_name = modified;
break;
}
message = String.Format (_("edited {0}"), file_name);
}
if (commit.Deleted.Count > 0) {
foreach (string removed in commit.Deleted) {
file_name = removed;
break;
}
message = String.Format (_("deleted {0}"), file_name);
}
int changes_count = (commit.Added.Count +
commit.Edited.Count +
commit.Deleted.Count);
if (changes_count > 1)
message += " + " + (changes_count - 1);
Application.Invoke (delegate {
SparkleBubble bubble = new SparkleBubble (commit.UserName, message);
SparkleBubble bubble = new SparkleBubble (user_name, message);
string avatar_file_path = SparkleUIHelpers.GetAvatar (commit.UserEmail, 32);
string avatar_file_path = SparkleUIHelpers.GetAvatar (user_email, 32);
if (avatar_file_path != null)
bubble.Icon = new Gdk.Pixbuf (avatar_file_path);