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