From 61d7dc79448d7b7db712ef900b5b0ba8e92f10c5 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 11 Jun 2011 18:51:13 +0100 Subject: [PATCH] ui: hook up event log and finish work --- .../Mac/{SparkleLog.cs => SparkleEventLog.cs} | 142 ++++++++++-------- SparkleShare/Mac/SparkleShare.csproj | 2 +- SparkleShare/Mac/SparkleStatusIcon.cs | 21 +-- SparkleShare/Mac/SparkleUI.cs | 39 ++--- SparkleShare/SparkleController.cs | 18 ++- data/html/event-entry.html | 10 +- data/html/event-log.html | 8 +- data/icons/document-moved-12.png | Bin 3182 -> 3173 bytes 8 files changed, 129 insertions(+), 111 deletions(-) rename SparkleShare/Mac/{SparkleLog.cs => SparkleEventLog.cs} (66%) diff --git a/SparkleShare/Mac/SparkleLog.cs b/SparkleShare/Mac/SparkleEventLog.cs similarity index 66% rename from SparkleShare/Mac/SparkleLog.cs rename to SparkleShare/Mac/SparkleEventLog.cs index a8ca567f..c5564257 100644 --- a/SparkleShare/Mac/SparkleLog.cs +++ b/SparkleShare/Mac/SparkleEventLog.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.IO; using System.Threading; @@ -29,56 +30,46 @@ using SparkleLib; // Only used for SparkleChangeSet namespace SparkleShare { - public class SparkleLog : NSWindow { + public class SparkleEventLog : NSWindow { - public readonly string LocalPath; private WebView WebView; private NSBox Separator; private string HTML; private NSPopUpButton popup_button; private NSProgressIndicator ProgressIndicator; - private List change_sets = SparkleShare.Controller.GetLog (); + private List change_sets; + private string selected_log = null; - public SparkleLog (IntPtr handle) : base (handle) { } - - public SparkleLog (string path) : base () + public SparkleEventLog (IntPtr handle) : base (handle) { } + + public SparkleEventLog () : base () { - LocalPath = path; - - Delegate = new SparkleLogDelegate (); + Title = "Recent Events"; + Delegate = new SparkleEventsDelegate (); SetFrame (new RectangleF (0, 0, 480, 640), true); Center (); - - // Open slightly off center for each consecutive window - if (SparkleUI.OpenLogs.Count > 0) { - RectangleF offset = new RectangleF (Frame.X + (SparkleUI.OpenLogs.Count * 20), - Frame.Y - (SparkleUI.OpenLogs.Count * 20), Frame.Width, Frame.Height); - SetFrame (offset, true); - } - StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Titled); MaxSize = new SizeF (480, 640); MinSize = new SizeF (480, 640); - HasShadow = true; + HasShadow = true; BackingType = NSBackingStore.Buffered; - CreateEventLog (); - UpdateEventLog (); - + CreateEvents (); + UpdateEvents (false); + UpdateChooser (); + OrderFrontRegardless (); } - private void CreateEventLog () + private void CreateEvents () { - Title = "Recent Events"; - Separator = new NSBox (new RectangleF (0, 573, 480, 1)) { BorderColor = NSColor.LightGray, BoxType = NSBoxType.NSBoxCustom @@ -86,44 +77,77 @@ namespace SparkleShare { ContentView.AddSubview (Separator); - this.popup_button = new NSPopUpButton (new RectangleF (480 - 156 - 8, 640 - 31 - 26, 156, 26), false); - //this.popup_button. - this.popup_button.AddItem ("All Folders"); - this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem); - this.popup_button.AddItems (SparkleShare.Controller.Folders.ToArray ()); - - - this.popup_button.Activated += delegate { - Console.WriteLine (this.popup_button.SelectedItem.Title); - }; - - ContentView.AddSubview (this.popup_button); - - ProgressIndicator = new NSProgressIndicator () { - Style = NSProgressIndicatorStyle.Spinning, - Frame = new RectangleF (Frame.Width / 2 - 10, Frame.Height / 2 + 10, 20, 20) - }; - - ProgressIndicator.StartAnimation (this); - WebView = new WebView (new RectangleF (0, 0, 480, 573 ), "", ""){ PolicyDelegate = new SparkleWebPolicyDelegate () }; + ProgressIndicator = new NSProgressIndicator () { + Style = NSProgressIndicatorStyle.Spinning, + Frame = new RectangleF (WebView.Frame.Width / 2 - 10, WebView.Frame.Height / 2 + 10, 20, 20) + }; + + ProgressIndicator.StartAnimation (this); Update (); } - public void UpdateEventLog () + public void UpdateChooser () { - InvokeOnMainThread (delegate { - if (HTML == null) - ContentView.AddSubview (ProgressIndicator); - }); + if (this.popup_button != null) + this.popup_button.RemoveFromSuperview (); + + this.popup_button = new NSPopUpButton () { + Frame = new RectangleF (480 - 156 - 8, 640 - 31 - 26, 156, 26), + PullsDown = false + }; + + this.popup_button.AddItem ("All Folders"); + this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem); + this.popup_button.AddItems (SparkleShare.Controller.Folders.ToArray ()); + + this.popup_button.Activated += delegate { + if (popup_button.IndexOfSelectedItem == 0) + this.selected_log = null; + else + this.selected_log = this.popup_button.SelectedItem.Title; + + UpdateEvents (false); + }; + + ContentView.AddSubview (this.popup_button); + } + + + public void UpdateEvents () + { + UpdateEvents (true); + } + + + public void UpdateEvents (bool silent) + { + if (!silent) { + InvokeOnMainThread (delegate { + if (WebView.Superview == ContentView) + WebView.RemoveFromSuperview (); + + ContentView.AddSubview (ProgressIndicator); + }); + } Thread thread = new Thread (new ThreadStart (delegate { using (NSAutoreleasePool pool = new NSAutoreleasePool ()) { + Stopwatch watch = new Stopwatch (); + watch.Start (); + this.change_sets = SparkleShare.Controller.GetLog (this.selected_log); GenerateHTML (); + watch.Stop (); + + // A short delay is less annoying than + // a flashing window + if (watch.ElapsedMilliseconds < 300 && !silent) + Thread.Sleep (300 - (int) watch.ElapsedMilliseconds); + AddHTML (); } })); @@ -134,7 +158,7 @@ namespace SparkleShare { private void GenerateHTML () { - HTML = SparkleShare.Controller.GetHTMLLog (); + HTML = SparkleShare.Controller.GetHTMLLog (this.change_sets); HTML = HTML.Replace ("", "Lucida Grande"); HTML = HTML.Replace ("", "13.6px"); @@ -160,24 +184,22 @@ namespace SparkleShare { private void AddHTML () { InvokeOnMainThread (delegate { - if (ProgressIndicator.Superview == ContentView) - ProgressIndicator.RemoveFromSuperview (); - - WebView.MainFrame.LoadHtmlString (HTML, new NSUrl ("")); - - ContentView.AddSubview (WebView); - Update (); + if (ProgressIndicator.Superview == ContentView) + ProgressIndicator.RemoveFromSuperview (); + WebView.MainFrame.LoadHtmlString (HTML, new NSUrl ("")); + ContentView.AddSubview (WebView); + Update (); }); } } - public class SparkleLogDelegate : NSWindowDelegate { + public class SparkleEventsDelegate : NSWindowDelegate { public override bool WindowShouldClose (NSObject sender) { - (sender as SparkleLog).OrderOut (this); + (sender as SparkleEventLog).OrderOut (this); return false; } } @@ -186,7 +208,7 @@ namespace SparkleShare { public class SparkleWebPolicyDelegate : WebPolicyDelegate { public override void DecidePolicyForNavigation (WebView web_view, NSDictionary action_info, - NSUrlRequest request, WebFrame frame, NSObject decision_token) + NSUrlRequest request, WebFrame frame, NSObject decision_token) { string file_path = request.Url.ToString (); file_path = file_path.Replace ("%20", " "); diff --git a/SparkleShare/Mac/SparkleShare.csproj b/SparkleShare/Mac/SparkleShare.csproj index 31bc86d1..579e66b0 100644 --- a/SparkleShare/Mac/SparkleShare.csproj +++ b/SparkleShare/Mac/SparkleShare.csproj @@ -79,7 +79,6 @@ - @@ -90,6 +89,7 @@ + diff --git a/SparkleShare/Mac/SparkleStatusIcon.cs b/SparkleShare/Mac/SparkleStatusIcon.cs index 8c62892d..16040dee 100644 --- a/SparkleShare/Mac/SparkleStatusIcon.cs +++ b/SparkleShare/Mac/SparkleStatusIcon.cs @@ -154,27 +154,16 @@ namespace SparkleShare { Menu.AddItem (NSMenuItem.SeparatorItem); RecentEventsMenuItem = new NSMenuItem () { - Title = "Show Events" + Title = "Show Recent Events" }; RecentEventsMenuItem.Activated +=delegate { InvokeOnMainThread (delegate { - NSApplication.SharedApplication.ActivateIgnoringOtherApps (true); - string path = "test"; - SparkleLog log = SparkleUI.OpenLogs.Find (delegate (SparkleLog l) { - return l.LocalPath.Equals (path); - }); + NSApplication.SharedApplication.ActivateIgnoringOtherApps (true); - // Check whether the log is already open, create a new one if - // that's not the case or present it to the user if it is - if (log == null) { - SparkleUI.OpenLogs.Add (new SparkleLog (path)); - SparkleUI.OpenLogs [SparkleUI.OpenLogs.Count - 1].MakeKeyAndOrderFront (this); - } else { - log.OrderFrontRegardless (); - log.MakeKeyAndOrderFront (this); - } - }); + if (SparkleUI.EventLog == null) + SparkleUI.EventLog = new SparkleEventLog (); + }); }; Menu.AddItem (RecentEventsMenuItem); diff --git a/SparkleShare/Mac/SparkleUI.cs b/SparkleShare/Mac/SparkleUI.cs index 0a57636b..b888c43f 100644 --- a/SparkleShare/Mac/SparkleUI.cs +++ b/SparkleShare/Mac/SparkleUI.cs @@ -51,7 +51,7 @@ namespace SparkleShare { public class SparkleUI : AppDelegate { public static SparkleStatusIcon StatusIcon; - public static List OpenLogs; + public static SparkleEventLog EventLog; public static SparkleIntro Intro; public static SparkleAbout About; public static NSFont Font; @@ -89,18 +89,15 @@ namespace SparkleShare { Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande", NSFontTraitMask.Condensed, 0, 13); - - OpenLogs = new List (); + StatusIcon = new SparkleStatusIcon (); } SparkleShare.Controller.NotificationRaised += delegate (string user_name, string user_email, string message, string repository_path) { InvokeOnMainThread (delegate { - foreach (SparkleLog log in OpenLogs) { - if (log.LocalPath.Equals (repository_path)) - log.UpdateEventLog (); - } + if (EventLog != null) + EventLog.UpdateEvents (); if (SparkleShare.Controller.NotificationsEnabled) { if (NSApplication.SharedApplication.DockTile.BadgeLabel == null) @@ -135,20 +132,28 @@ namespace SparkleShare { SparkleShare.Controller.AvatarFetched += delegate { InvokeOnMainThread (delegate { - foreach (SparkleLog log in SparkleUI.OpenLogs) - log.UpdateEventLog (); + if (EventLog != null) + EventLog.UpdateEvents (); }); }; - SparkleShare.Controller.OnIdle += delegate { - InvokeOnMainThread (delegate { - foreach (SparkleLog log in SparkleUI.OpenLogs) - log.UpdateEventLog (); - }); - }; - - + SparkleShare.Controller.OnIdle += delegate { + InvokeOnMainThread (delegate { + if (EventLog != null) + EventLog.UpdateEvents (); + }); + }; + + + SparkleShare.Controller.FolderListChanged += delegate { + InvokeOnMainThread (delegate { + if (EventLog != null) + EventLog.UpdateChooser (); + }); + }; + + if (SparkleShare.Controller.FirstRun) { Intro = new SparkleIntro (); Intro.ShowAccountForm (); diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index 429def79..12c0e8ba 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -247,13 +247,13 @@ namespace SparkleShare { List list = new List (); foreach (SparkleRepoBase repo in Repositories) - list.AddRange (repo.GetChangeSets (30)); + list.AddRange (repo.GetChangeSets (50)); list.Sort ((x, y) => (x.Timestamp.CompareTo (y.Timestamp))); list.Reverse (); - if (list.Count > 50) - return list.GetRange (0, 50); + if (list.Count > 100) + return list.GetRange (0, 100); else return list.GetRange (0, list.Count); } @@ -261,8 +261,11 @@ namespace SparkleShare { public List GetLog (string name) { + if (name == null) + return GetLog (); + string path = Path.Combine (SparklePaths.SparklePath, name); - int log_size = 30; + int log_size = 50; foreach (SparkleRepoBase repo in Repositories) { if (repo.LocalPath.Equals (path)) @@ -278,10 +281,9 @@ namespace SparkleShare { public abstract string EventEntryHTML { get; } - public string GetHTMLLog () + public string GetHTMLLog (List change_sets) { - List change_sets = GetLog (); - List activity_days = new List (); + List activity_days = new List (); if (change_sets.Count == 0) return null; @@ -1036,7 +1038,7 @@ namespace SparkleShare { { string hash = GetMD5 (s).Substring (0, 8); string numbers = Regex.Replace (hash, "[a-z]", ""); - int number = 1 + int.Parse (numbers); + int number = 3 + int.Parse (numbers); return this.tango_palette [number % this.tango_palette.Length]; } } diff --git a/data/html/event-entry.html b/data/html/event-entry.html index f8643fac..1ede4727 100644 --- a/data/html/event-entry.html +++ b/data/html/event-entry.html @@ -1,20 +1,16 @@
-
- -
-
+

-
+
- - +
diff --git a/data/html/event-log.html b/data/html/event-log.html index f16f3573..fc3f6252 100644 --- a/data/html/event-log.html +++ b/data/html/event-log.html @@ -44,6 +44,7 @@ } .event-time { + opacity: 0.8; font-size: 80%; color: #fff; float: right; @@ -62,9 +63,12 @@ padding: 0px; padding-bottom: 6px; border: #ccc 1px solid; - -webkit-border-radius: 0 0 3px 3px; } - + + .wrapper { + float: left; + } + dl { padding : 0; margin: 0; diff --git a/data/icons/document-moved-12.png b/data/icons/document-moved-12.png index dfe29d1d923a76d561e0d9df40d286d22bda4207..50f4fb32bb8f458879fd6247b54c2cf2e2caa36d 100644 GIT binary patch delta 460 zcmV;-0W<#Y808qSqzZpE4KXg@(EtDeqe(XG=s&oleVcb7jZCCVy{GZ^KuA3At8hb;1+-dU`<3%0G_0j-+bTyjtlT#;rm=Jr-^F`Fma0vDs|EIiF3Z)93$g;#}Ca{d&LO-=))O1%MaFv1FA> z<(;akH;SU*a5#TtN~Ka9MbST{nWp(FlgX6Y?KXD1-CIRb-ZY!dfV$mowOA~EYPDJj zf&i=43diH|;?0I(pwsDKGMOL@!>{Bx4iyT8dtKKx+qPjC1{h;67MIOt!5G7EI0ONJ z<2aYsl=m%_DL4ZU6up66k?Ts{)6q~GsW0Go&&06c_Y_|vki9S*?%gl~W2@pvYe%ORakgL95B z3_(QL@AqU`77hvw!#GPM5}8V+g2iHi>2wO;_d!Ge0N?lV797BZEX!~l2cGBM2SM;< zJRU#2J~RyD6M!oK-(Am*6izkeVc3YW`ev|26n`+dx2vpd3(wA)SX&(&)6veW6H*Xv<2ncNZ4 zwQ#IJ5QOt$v53K7@HcFlX26aWluD&%+qN^S)#@8#?8Y?B003S9Yvz+~cLpqg00000 LNkvXXu0mjfySCUM