Make event log work with its controller
This commit is contained in:
parent
1bc207cc61
commit
10ca98921a
|
@ -16,8 +16,6 @@
|
|||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
@ -27,18 +25,24 @@ using MonoMac.Foundation;
|
|||
using MonoMac.AppKit;
|
||||
using MonoMac.ObjCRuntime;
|
||||
using MonoMac.WebKit;
|
||||
using SparkleLib; // Only used for SparkleChangeSet
|
||||
|
||||
namespace SparkleShare {
|
||||
|
||||
public class SparkleEventLog : NSWindow {
|
||||
|
||||
private SparkleEventLogController controller;
|
||||
private SparkleEventLogController controller = new SparkleEventLogController ();
|
||||
|
||||
private WebView web_view = new WebView (new RectangleF (0, 0, 480, 579), "", "") {
|
||||
PolicyDelegate = new SparkleWebPolicyDelegate ()
|
||||
};
|
||||
|
||||
private NSBox Separator = new NSBox (new RectangleF (0, 579, 480, 1)) {
|
||||
BorderColor = NSColor.LightGray,
|
||||
BoxType = NSBoxType.NSBoxCustom
|
||||
};
|
||||
|
||||
private WebView WebView;
|
||||
private NSBox Separator;
|
||||
private NSPopUpButton popup_button;
|
||||
private NSProgressIndicator ProgressIndicator;
|
||||
private NSProgressIndicator progress_indicator;
|
||||
|
||||
|
||||
public SparkleEventLog (IntPtr handle) : base (handle) { }
|
||||
|
@ -60,51 +64,52 @@ namespace SparkleShare {
|
|||
HasShadow = true;
|
||||
BackingType = NSBackingStore.Buffered;
|
||||
|
||||
|
||||
Separator = new NSBox (new RectangleF (0, 579, 480, 1)) {
|
||||
BorderColor = NSColor.LightGray,
|
||||
BoxType = NSBoxType.NSBoxCustom
|
||||
};
|
||||
|
||||
ContentView.AddSubview (Separator);
|
||||
|
||||
|
||||
WebView = new WebView (new RectangleF (0, 0, 480, 579), "", "") {
|
||||
PolicyDelegate = new SparkleWebPolicyDelegate ()
|
||||
this.progress_indicator = new NSthis.progress_indicator () {
|
||||
Style = NSthis.progress_indicatorStyle.Spinning,
|
||||
Frame = new RectangleF (this.web_view.Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10, 20, 20)
|
||||
};
|
||||
|
||||
|
||||
ProgressIndicator = new NSProgressIndicator () {
|
||||
Style = NSProgressIndicatorStyle.Spinning,
|
||||
Frame = new RectangleF (WebView.Frame.Width / 2 - 10, WebView.Frame.Height / 2 + 10, 20, 20)
|
||||
};
|
||||
this.progress_indicator.StartAnimation (this);
|
||||
ContentView.AddSubview (this.progress_indicator);
|
||||
|
||||
|
||||
UpdateContent (null, false);
|
||||
UpdateChooser (this.controller.Folders);
|
||||
UpdateContent (null);
|
||||
UpdateChooser (null);
|
||||
OrderFrontRegardless ();
|
||||
|
||||
// Hook up the controller events
|
||||
this.controller = new SparkleEventLogController ();
|
||||
|
||||
// Hook up the controller events
|
||||
this.controller.UpdateChooserEvent += delegate (string [] folders) {
|
||||
InvokeOnMainThread (delegate {
|
||||
UpdateChooser (folders);
|
||||
});
|
||||
};
|
||||
|
||||
this.controller.UpdateContentEvent += delegate (string html, bool silently) {
|
||||
this.controller.UpdateContentEvent += delegate (string html) {
|
||||
InvokeOnMainThread (delegate {
|
||||
UpdateContent (html, true);
|
||||
UpdateContent (html);
|
||||
});
|
||||
};
|
||||
|
||||
this.controller.ContentLoadingEvent += delegate {
|
||||
InvokeOnMainThread (delegate {
|
||||
if (this.web_view.Superview == ContentView)
|
||||
this.web_view.RemoveFromSuperview ();
|
||||
|
||||
ContentView.AddSubview (this.progress_indicator);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void UpdateChooser (string [] folders)
|
||||
{
|
||||
if (folders == null)
|
||||
folders = this.controller.Folders;
|
||||
|
||||
if (this.popup_button != null)
|
||||
this.popup_button.RemoveFromSuperview ();
|
||||
|
||||
|
@ -132,17 +137,10 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
|
||||
public void UpdateContent (string html, bool silently)
|
||||
public void UpdateContent (string html)
|
||||
{
|
||||
if (!silently) {
|
||||
if (WebView.Superview == ContentView)
|
||||
WebView.RemoveFromSuperview ();
|
||||
|
||||
ContentView.AddSubview (ProgressIndicator);
|
||||
}
|
||||
|
||||
Thread thread = new Thread (new ThreadStart (delegate {
|
||||
using (NSAutoreleasePool pool = new NSAutoreleasePool ()) {
|
||||
using (NSAutoreleasePool pool = new NSAutoreleasePool ()) {
|
||||
Thread thread = new Thread (new ThreadStart (delegate {
|
||||
if (html == null)
|
||||
html = this.controller.HTML;
|
||||
|
||||
|
@ -166,20 +164,22 @@ namespace SparkleShare {
|
|||
"file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "document-moved-12.png"));
|
||||
|
||||
InvokeOnMainThread (delegate {
|
||||
if (ProgressIndicator.Superview == ContentView)
|
||||
ProgressIndicator.RemoveFromSuperview ();
|
||||
if (this.progress_indicator.Superview == ContentView)
|
||||
this.progress_indicator.RemoveFromSuperview ();
|
||||
|
||||
this.web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
|
||||
ContentView.AddSubview (this.web_view);
|
||||
|
||||
WebView.MainFrame.LoadHtmlString (html, new NSUrl (""));
|
||||
ContentView.AddSubview (WebView);
|
||||
Update ();
|
||||
});
|
||||
}
|
||||
}));
|
||||
}));
|
||||
|
||||
thread.Start ();
|
||||
thread.Start ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class SparkleEventsDelegate : NSWindowDelegate {
|
||||
|
||||
public override bool WindowShouldClose (NSObject sender)
|
||||
|
|
|
@ -27,11 +27,15 @@ namespace SparkleShare {
|
|||
public class SparkleEventLogController {
|
||||
|
||||
public event UpdateContentEventEventHandler UpdateContentEvent;
|
||||
public delegate void UpdateContentEventEventHandler (string html, bool silently);
|
||||
public delegate void UpdateContentEventEventHandler (string html);
|
||||
|
||||
public event UpdateChooserEventHandler UpdateChooserEvent;
|
||||
public delegate void UpdateChooserEventHandler (string [] folders);
|
||||
|
||||
public event ContentLoadingEventHandler ContentLoadingEvent;
|
||||
public delegate void ContentLoadingEventHandler ();
|
||||
|
||||
|
||||
public string SelectedFolder {
|
||||
get {
|
||||
return this.selected_folder;
|
||||
|
@ -40,27 +44,33 @@ namespace SparkleShare {
|
|||
set {
|
||||
this.selected_folder = value;
|
||||
|
||||
if (UpdateContentEvent != null)
|
||||
UpdateContentEvent (HTML, true);
|
||||
if (ContentLoadingEvent != null)
|
||||
ContentLoadingEvent ();
|
||||
|
||||
Stopwatch watch = new Stopwatch ();
|
||||
watch.Start ();
|
||||
|
||||
Thread thread = new Thread (new ThreadStart (delegate {
|
||||
string html = HTML;
|
||||
watch.Stop ();
|
||||
|
||||
// A short delay is less annoying than
|
||||
// a flashing window
|
||||
if (watch.ElapsedMilliseconds < 500)
|
||||
Thread.Sleep (500 - (int) watch.ElapsedMilliseconds);
|
||||
|
||||
if (UpdateContentEvent != null)
|
||||
UpdateContentEvent (html);
|
||||
}));
|
||||
|
||||
thread.Start ();
|
||||
}
|
||||
}
|
||||
|
||||
public string HTML {
|
||||
get {
|
||||
Stopwatch watch = new Stopwatch ();
|
||||
watch.Start ();
|
||||
|
||||
List<SparkleChangeSet> change_sets = SparkleShare.Controller.GetLog (SelectedFolder);
|
||||
string html = SparkleShare.Controller.GetHTMLLog (change_sets);
|
||||
|
||||
watch.Stop ();
|
||||
|
||||
// A short delay is less annoying than
|
||||
// a flashing window
|
||||
if (watch.ElapsedMilliseconds < 500 /* && !silent */)
|
||||
Thread.Sleep (500 - (int) watch.ElapsedMilliseconds);
|
||||
|
||||
return html;
|
||||
List<SparkleChangeSet> change_sets = SparkleShare.Controller.GetLog (this.selected_folder);
|
||||
return SparkleShare.Controller.GetHTMLLog (change_sets);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,12 +88,12 @@ namespace SparkleShare {
|
|||
{
|
||||
SparkleShare.Controller.AvatarFetched += delegate {
|
||||
if (UpdateContentEvent != null)
|
||||
UpdateContentEvent (HTML, true);
|
||||
UpdateContentEvent (HTML);
|
||||
};
|
||||
|
||||
SparkleShare.Controller.OnIdle += delegate {
|
||||
if (UpdateContentEvent != null)
|
||||
UpdateContentEvent (HTML, true);
|
||||
UpdateContentEvent (HTML);
|
||||
};
|
||||
|
||||
SparkleShare.Controller.FolderListChanged += delegate {
|
||||
|
@ -97,12 +107,12 @@ namespace SparkleShare {
|
|||
UpdateChooserEvent (Folders);
|
||||
|
||||
if (UpdateContentEvent != null)
|
||||
UpdateContentEvent (HTML, true);
|
||||
UpdateContentEvent (HTML);
|
||||
};
|
||||
|
||||
SparkleShare.Controller.NotificationRaised += delegate {
|
||||
if (UpdateContentEvent != null)
|
||||
UpdateContentEvent (HTML, true);
|
||||
UpdateContentEvent (HTML);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue