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.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<SparkleChangeSet> change_sets = SparkleShare.Controller.GetLog ();
private List<SparkleChangeSet> 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 ("<!-- $body-font-family -->", "Lucida Grande");
HTML = HTML.Replace ("<!-- $day-entry-header-font-size -->", "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", " ");

View file

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

View file

@ -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);

View file

@ -51,7 +51,7 @@ namespace SparkleShare {
public class SparkleUI : AppDelegate {
public static SparkleStatusIcon StatusIcon;
public static List <SparkleLog> 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 <SparkleLog> ();
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 ();

View file

@ -247,13 +247,13 @@ namespace SparkleShare {
List<SparkleChangeSet> list = new List<SparkleChangeSet> ();
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<SparkleChangeSet> 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<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)
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];
}
}

View file

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

View file

@ -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;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB