ui: hook up event log and finish work

This commit is contained in:
Hylke Bons 2011-06-11 18:51:13 +01:00
parent f46a7969b0
commit 61d7dc7944
8 changed files with 129 additions and 111 deletions

View file

@ -17,6 +17,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
@ -29,56 +30,46 @@ using SparkleLib; // Only used for SparkleChangeSet
namespace SparkleShare { namespace SparkleShare {
public class SparkleLog : NSWindow { public class SparkleEventLog : NSWindow {
public readonly string LocalPath;
private WebView WebView; private WebView WebView;
private NSBox Separator; private NSBox Separator;
private string HTML; private string HTML;
private NSPopUpButton popup_button; private NSPopUpButton popup_button;
private NSProgressIndicator ProgressIndicator; private NSProgressIndicator ProgressIndicator;
private List<SparkleChangeSet> change_sets = SparkleShare.Controller.GetLog (); private List<SparkleChangeSet> change_sets;
private string selected_log = null;
public SparkleLog (IntPtr handle) : base (handle) { } public SparkleEventLog (IntPtr handle) : base (handle) { }
public SparkleLog (string path) : base () public SparkleEventLog () : base ()
{ {
LocalPath = path; Title = "Recent Events";
Delegate = new SparkleEventsDelegate ();
Delegate = new SparkleLogDelegate ();
SetFrame (new RectangleF (0, 0, 480, 640), true); SetFrame (new RectangleF (0, 0, 480, 640), true);
Center (); 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 | StyleMask = (NSWindowStyle.Closable |
NSWindowStyle.Miniaturizable | NSWindowStyle.Miniaturizable |
NSWindowStyle.Titled); NSWindowStyle.Titled);
MaxSize = new SizeF (480, 640); MaxSize = new SizeF (480, 640);
MinSize = new SizeF (480, 640); MinSize = new SizeF (480, 640);
HasShadow = true; HasShadow = true;
BackingType = NSBackingStore.Buffered; BackingType = NSBackingStore.Buffered;
CreateEventLog (); CreateEvents ();
UpdateEventLog (); UpdateEvents (false);
UpdateChooser ();
OrderFrontRegardless (); OrderFrontRegardless ();
} }
private void CreateEventLog () private void CreateEvents ()
{ {
Title = "Recent Events";
Separator = new NSBox (new RectangleF (0, 573, 480, 1)) { Separator = new NSBox (new RectangleF (0, 573, 480, 1)) {
BorderColor = NSColor.LightGray, BorderColor = NSColor.LightGray,
BoxType = NSBoxType.NSBoxCustom BoxType = NSBoxType.NSBoxCustom
@ -86,44 +77,77 @@ namespace SparkleShare {
ContentView.AddSubview (Separator); 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 ), "", ""){ WebView = new WebView (new RectangleF (0, 0, 480, 573 ), "", ""){
PolicyDelegate = new SparkleWebPolicyDelegate () 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 (); Update ();
} }
public void UpdateEventLog () public void UpdateChooser ()
{ {
InvokeOnMainThread (delegate { if (this.popup_button != null)
if (HTML == null) this.popup_button.RemoveFromSuperview ();
ContentView.AddSubview (ProgressIndicator);
}); 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 { Thread thread = new Thread (new ThreadStart (delegate {
using (NSAutoreleasePool pool = new NSAutoreleasePool ()) { using (NSAutoreleasePool pool = new NSAutoreleasePool ()) {
Stopwatch watch = new Stopwatch ();
watch.Start ();
this.change_sets = SparkleShare.Controller.GetLog (this.selected_log);
GenerateHTML (); 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 (); AddHTML ();
} }
})); }));
@ -134,7 +158,7 @@ namespace SparkleShare {
private void GenerateHTML () private void GenerateHTML ()
{ {
HTML = SparkleShare.Controller.GetHTMLLog (); HTML = SparkleShare.Controller.GetHTMLLog (this.change_sets);
HTML = HTML.Replace ("<!-- $body-font-family -->", "Lucida Grande"); HTML = HTML.Replace ("<!-- $body-font-family -->", "Lucida Grande");
HTML = HTML.Replace ("<!-- $day-entry-header-font-size -->", "13.6px"); HTML = HTML.Replace ("<!-- $day-entry-header-font-size -->", "13.6px");
@ -160,24 +184,22 @@ namespace SparkleShare {
private void AddHTML () private void AddHTML ()
{ {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
if (ProgressIndicator.Superview == ContentView) if (ProgressIndicator.Superview == ContentView)
ProgressIndicator.RemoveFromSuperview (); ProgressIndicator.RemoveFromSuperview ();
WebView.MainFrame.LoadHtmlString (HTML, new NSUrl (""));
ContentView.AddSubview (WebView);
Update ();
WebView.MainFrame.LoadHtmlString (HTML, new NSUrl (""));
ContentView.AddSubview (WebView);
Update ();
}); });
} }
} }
public class SparkleLogDelegate : NSWindowDelegate { public class SparkleEventsDelegate : NSWindowDelegate {
public override bool WindowShouldClose (NSObject sender) public override bool WindowShouldClose (NSObject sender)
{ {
(sender as SparkleLog).OrderOut (this); (sender as SparkleEventLog).OrderOut (this);
return false; return false;
} }
} }
@ -186,7 +208,7 @@ namespace SparkleShare {
public class SparkleWebPolicyDelegate : WebPolicyDelegate { public class SparkleWebPolicyDelegate : WebPolicyDelegate {
public override void DecidePolicyForNavigation (WebView web_view, NSDictionary action_info, 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 (); string file_path = request.Url.ToString ();
file_path = file_path.Replace ("%20", " "); file_path = file_path.Replace ("%20", " ");

View file

@ -79,7 +79,6 @@
</Compile> </Compile>
<Compile Include="SparkleWindow.cs" /> <Compile Include="SparkleWindow.cs" />
<Compile Include="SparkleIntro.cs" /> <Compile Include="SparkleIntro.cs" />
<Compile Include="SparkleLog.cs" />
<Compile Include="SparkleMacController.cs" /> <Compile Include="SparkleMacController.cs" />
<Compile Include="SparkleStatusIcon.cs" /> <Compile Include="SparkleStatusIcon.cs" />
<Compile Include="SparkleUI.cs" /> <Compile Include="SparkleUI.cs" />
@ -90,6 +89,7 @@
<Compile Include="SparkleAlert.cs" /> <Compile Include="SparkleAlert.cs" />
<Compile Include="SparkleBubble.cs" /> <Compile Include="SparkleBubble.cs" />
<Compile Include="SparkleMacWatcher.cs" /> <Compile Include="SparkleMacWatcher.cs" />
<Compile Include="SparkleEventLog.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Include="MainMenu.xib" /> <Page Include="MainMenu.xib" />

View file

@ -154,27 +154,16 @@ namespace SparkleShare {
Menu.AddItem (NSMenuItem.SeparatorItem); Menu.AddItem (NSMenuItem.SeparatorItem);
RecentEventsMenuItem = new NSMenuItem () { RecentEventsMenuItem = new NSMenuItem () {
Title = "Show Events" Title = "Show Recent Events"
}; };
RecentEventsMenuItem.Activated +=delegate { RecentEventsMenuItem.Activated +=delegate {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true); NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
string path = "test";
SparkleLog log = SparkleUI.OpenLogs.Find (delegate (SparkleLog l) {
return l.LocalPath.Equals (path);
});
// Check whether the log is already open, create a new one if if (SparkleUI.EventLog == null)
// that's not the case or present it to the user if it is SparkleUI.EventLog = new SparkleEventLog ();
if (log == null) { });
SparkleUI.OpenLogs.Add (new SparkleLog (path));
SparkleUI.OpenLogs [SparkleUI.OpenLogs.Count - 1].MakeKeyAndOrderFront (this);
} else {
log.OrderFrontRegardless ();
log.MakeKeyAndOrderFront (this);
}
});
}; };
Menu.AddItem (RecentEventsMenuItem); Menu.AddItem (RecentEventsMenuItem);

View file

@ -51,7 +51,7 @@ namespace SparkleShare {
public class SparkleUI : AppDelegate { public class SparkleUI : AppDelegate {
public static SparkleStatusIcon StatusIcon; public static SparkleStatusIcon StatusIcon;
public static List <SparkleLog> OpenLogs; public static SparkleEventLog EventLog;
public static SparkleIntro Intro; public static SparkleIntro Intro;
public static SparkleAbout About; public static SparkleAbout About;
public static NSFont Font; public static NSFont Font;
@ -89,18 +89,15 @@ namespace SparkleShare {
Font = NSFontManager.SharedFontManager.FontWithFamily Font = NSFontManager.SharedFontManager.FontWithFamily
("Lucida Grande", NSFontTraitMask.Condensed, 0, 13); ("Lucida Grande", NSFontTraitMask.Condensed, 0, 13);
OpenLogs = new List <SparkleLog> ();
StatusIcon = new SparkleStatusIcon (); StatusIcon = new SparkleStatusIcon ();
} }
SparkleShare.Controller.NotificationRaised += delegate (string user_name, string user_email, SparkleShare.Controller.NotificationRaised += delegate (string user_name, string user_email,
string message, string repository_path) { string message, string repository_path) {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
foreach (SparkleLog log in OpenLogs) { if (EventLog != null)
if (log.LocalPath.Equals (repository_path)) EventLog.UpdateEvents ();
log.UpdateEventLog ();
}
if (SparkleShare.Controller.NotificationsEnabled) { if (SparkleShare.Controller.NotificationsEnabled) {
if (NSApplication.SharedApplication.DockTile.BadgeLabel == null) if (NSApplication.SharedApplication.DockTile.BadgeLabel == null)
@ -135,20 +132,28 @@ namespace SparkleShare {
SparkleShare.Controller.AvatarFetched += delegate { SparkleShare.Controller.AvatarFetched += delegate {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
foreach (SparkleLog log in SparkleUI.OpenLogs) if (EventLog != null)
log.UpdateEventLog (); EventLog.UpdateEvents ();
}); });
}; };
SparkleShare.Controller.OnIdle += delegate { SparkleShare.Controller.OnIdle += delegate {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
foreach (SparkleLog log in SparkleUI.OpenLogs) if (EventLog != null)
log.UpdateEventLog (); EventLog.UpdateEvents ();
}); });
}; };
SparkleShare.Controller.FolderListChanged += delegate {
InvokeOnMainThread (delegate {
if (EventLog != null)
EventLog.UpdateChooser ();
});
};
if (SparkleShare.Controller.FirstRun) { if (SparkleShare.Controller.FirstRun) {
Intro = new SparkleIntro (); Intro = new SparkleIntro ();
Intro.ShowAccountForm (); Intro.ShowAccountForm ();

View file

@ -247,13 +247,13 @@ namespace SparkleShare {
List<SparkleChangeSet> list = new List<SparkleChangeSet> (); List<SparkleChangeSet> list = new List<SparkleChangeSet> ();
foreach (SparkleRepoBase repo in Repositories) 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.Sort ((x, y) => (x.Timestamp.CompareTo (y.Timestamp)));
list.Reverse (); list.Reverse ();
if (list.Count > 50) if (list.Count > 100)
return list.GetRange (0, 50); return list.GetRange (0, 100);
else else
return list.GetRange (0, list.Count); return list.GetRange (0, list.Count);
} }
@ -261,8 +261,11 @@ namespace SparkleShare {
public List<SparkleChangeSet> GetLog (string name) public List<SparkleChangeSet> GetLog (string name)
{ {
if (name == null)
return GetLog ();
string path = Path.Combine (SparklePaths.SparklePath, name); string path = Path.Combine (SparklePaths.SparklePath, name);
int log_size = 30; int log_size = 50;
foreach (SparkleRepoBase repo in Repositories) { foreach (SparkleRepoBase repo in Repositories) {
if (repo.LocalPath.Equals (path)) if (repo.LocalPath.Equals (path))
@ -278,10 +281,9 @@ namespace SparkleShare {
public abstract string EventEntryHTML { get; } public abstract string EventEntryHTML { get; }
public string GetHTMLLog () public string GetHTMLLog (List<SparkleChangeSet> change_sets)
{ {
List <SparkleChangeSet> change_sets = GetLog (); List <ActivityDay> activity_days = new List <ActivityDay> ();
List <ActivityDay> activity_days = new List <ActivityDay> ();
if (change_sets.Count == 0) if (change_sets.Count == 0)
return null; return null;
@ -1036,7 +1038,7 @@ namespace SparkleShare {
{ {
string hash = GetMD5 (s).Substring (0, 8); string hash = GetMD5 (s).Substring (0, 8);
string numbers = Regex.Replace (hash, "[a-z]", ""); 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]; return this.tango_palette [number % this.tango_palette.Length];
} }
} }

View file

@ -1,20 +1,16 @@
<div class='event-entry'> <div class='event-entry'>
<div class='event-entry-content'> <div class='event-entry-content'>
<div class='event-info'> <div class='event-info'>
<div style="float:left;"> <div class='wrapper'>
<div class='no-buddy-icon'> <div class='no-buddy-icon'>
<div class='buddy-icon' style='background-image: url("<!-- $event-avatar-url -->");'></div> <div class='buddy-icon' style='background-image: url("<!-- $event-avatar-url -->");'></div>
</div> </div>
<b><!-- $event-user-name --></b><br/> <b><!-- $event-user-name --></b><br/>
<small><!-- $event-time --></small> <small><!-- $event-time --></small>
</div> </div>
<div class='event-time' style='opacity: 0.8;background-color: <!-- $event-folder-color -->'><!-- $event-folder --></div> <div class='event-time' style='background-color: <!-- $event-folder-color -->'><!-- $event-folder --></div>
</div> </div>
<!-- $event-entry-content --> <!-- $event-entry-content -->
<div style='clear: both'></div> <div style='clear: both'></div>
</div> </div>
</div> </div>

View file

@ -44,6 +44,7 @@
} }
.event-time { .event-time {
opacity: 0.8;
font-size: 80%; font-size: 80%;
color: #fff; color: #fff;
float: right; float: right;
@ -62,9 +63,12 @@
padding: 0px; padding: 0px;
padding-bottom: 6px; padding-bottom: 6px;
border: #ccc 1px solid; border: #ccc 1px solid;
-webkit-border-radius: 0 0 3px 3px;
} }
.wrapper {
float: left;
}
dl { dl {
padding : 0; padding : 0;
margin: 0; margin: 0;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB