Add a event log controller

This commit is contained in:
Hylke Bons 2011-07-03 18:43:22 +01:00
parent 51e001ec15
commit 66b7f0c58d
5 changed files with 174 additions and 116 deletions

View file

@ -33,13 +33,12 @@ namespace SparkleShare {
public class SparkleEventLog : NSWindow {
private SparkleEventLogController controller;
private WebView WebView;
private NSBox Separator;
private string HTML;
private NSPopUpButton popup_button;
private NSProgressIndicator ProgressIndicator;
private List<SparkleChangeSet> change_sets;
private string selected_log = null;
public SparkleEventLog (IntPtr handle) : base (handle) { }
@ -61,16 +60,7 @@ namespace SparkleShare {
HasShadow = true;
BackingType = NSBackingStore.Buffered;
CreateEvents ();
UpdateEvents (false);
UpdateChooser ();
OrderFrontRegardless ();
}
private void CreateEvents ()
{
Separator = new NSBox (new RectangleF (0, 579, 480, 1)) {
BorderColor = NSColor.LightGray,
BoxType = NSBoxType.NSBoxCustom
@ -78,21 +68,42 @@ namespace SparkleShare {
ContentView.AddSubview (Separator);
WebView = new WebView (new RectangleF (0, 0, 480, 579), "", "") {
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 ();
UpdateContent (null, false);
UpdateChooser (this.controller.Folders);
OrderFrontRegardless ();
// Hook up the controller events
this.controller = new SparkleEventLogController ();
this.controller.UpdateChooserEvent += delegate (string [] folders) {
InvokeOnMainThread (delegate {
UpdateChooser (folders);
});
};
this.controller.UpdateContentEvent += delegate (string html, bool silently) {
InvokeOnMainThread (delegate {
UpdateContent (html, true);
});
};
}
public void UpdateChooser ()
public void UpdateChooser (string [] folders)
{
if (this.popup_button != null)
this.popup_button.RemoveFromSuperview ();
@ -104,108 +115,71 @@ namespace SparkleShare {
this.popup_button.Cell.ControlSize = NSControlSize.Small;
this.popup_button.Font = NSFontManager.SharedFontManager.FontWithFamily
("Lucida Grande", NSFontTraitMask.Condensed, 0, NSFont.SmallSystemFontSize);
("Lucida Grande", NSFontTraitMask.Condensed, 0, NSFont.SmallSystemFontSize);
this.popup_button.AddItem ("All Folders");
this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem);
this.popup_button.AddItems (SparkleShare.Controller.Folders.ToArray ());
if (this.selected_log != null &&
!SparkleShare.Controller.Folders.Contains (this.selected_log)) {
this.selected_log = null;
}
this.popup_button.AddItems (folders);
this.popup_button.Activated += delegate {
if (this.popup_button.IndexOfSelectedItem == 0)
this.selected_log = null;
this.controller.SelectedFolder = null;
else
this.selected_log = this.popup_button.SelectedItem.Title;
UpdateEvents (false);
this.controller.SelectedFolder = this.popup_button.SelectedItem.Title;
};
ContentView.AddSubview (this.popup_button);
}
public void UpdateEvents ()
public void UpdateContent (string html, bool silently)
{
UpdateEvents (true);
}
if (!silently) {
if (WebView.Superview == ContentView)
WebView.RemoveFromSuperview ();
public void UpdateEvents (bool silent)
{
if (!silent) {
InvokeOnMainThread (delegate {
if (WebView.Superview == ContentView)
WebView.RemoveFromSuperview ();
ContentView.AddSubview (ProgressIndicator);
});
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 ();
if (html == null)
html = this.controller.HTML;
// A short delay is less annoying than
// a flashing window
if (watch.ElapsedMilliseconds < 500 && !silent)
Thread.Sleep (500 - (int) watch.ElapsedMilliseconds);
html = html.Replace ("<!-- $body-font-family -->", "Lucida Grande");
html = html.Replace ("<!-- $day-entry-header-font-size -->", "13.6px");
html = html.Replace ("<!-- $body-font-size -->", "13.4px");
html = html.Replace ("<!-- $secondary-font-color -->", "#bbb");
html = html.Replace ("<!-- $small-color -->", "#ddd");
html = html.Replace ("<!-- $day-entry-header-background-color -->", "#f5f5f5");
html = html.Replace ("<!-- $a-color -->", "#0085cf");
html = html.Replace ("<!-- $a-hover-color -->", "#009ff8");
html = html.Replace ("<!-- $no-buddy-icon-background-image -->",
"file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "avatar-default.png"));
html = html.Replace ("<!-- $document-added-background-image -->",
"file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "document-added-12.png"));
html = html.Replace ("<!-- $document-deleted-background-image -->",
"file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "document-deleted-12.png"));
html = html.Replace ("<!-- $document-edited-background-image -->",
"file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "document-edited-12.png"));
html = html.Replace ("<!-- $document-moved-background-image -->",
"file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "document-moved-12.png"));
AddHTML ();
InvokeOnMainThread (delegate {
if (ProgressIndicator.Superview == ContentView)
ProgressIndicator.RemoveFromSuperview ();
WebView.MainFrame.LoadHtmlString (html, new NSUrl (""));
ContentView.AddSubview (WebView);
Update ();
});
}
}));
thread.Start ();
}
private void GenerateHTML ()
{
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");
HTML = HTML.Replace ("<!-- $body-font-size -->", "13.4px");
HTML = HTML.Replace ("<!-- $secondary-font-color -->", "#bbb");
HTML = HTML.Replace ("<!-- $small-color -->", "#ddd");
HTML = HTML.Replace ("<!-- $day-entry-header-background-color -->", "#f5f5f5");
HTML = HTML.Replace ("<!-- $a-color -->", "#0085cf");
HTML = HTML.Replace ("<!-- $a-hover-color -->", "#009ff8");
HTML = HTML.Replace ("<!-- $no-buddy-icon-background-image -->",
"file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "avatar-default.png"));
HTML = HTML.Replace ("<!-- $document-added-background-image -->",
"file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "document-added-12.png"));
HTML = HTML.Replace ("<!-- $document-deleted-background-image -->",
"file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "document-deleted-12.png"));
HTML = HTML.Replace ("<!-- $document-edited-background-image -->",
"file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "document-edited-12.png"));
HTML = HTML.Replace ("<!-- $document-moved-background-image -->",
"file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "document-moved-12.png"));
}
private void AddHTML ()
{
InvokeOnMainThread (delegate {
if (ProgressIndicator.Superview == ContentView)
ProgressIndicator.RemoveFromSuperview ();
WebView.MainFrame.LoadHtmlString (HTML, new NSUrl (""));
ContentView.AddSubview (WebView);
Update ();
});
}
}
public class SparkleEventsDelegate : NSWindowDelegate {
public override bool WindowShouldClose (NSObject sender)

View file

@ -0,0 +1,109 @@
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using SparkleLib;
namespace SparkleShare {
public class SparkleEventLogController {
public event UpdateContentEventEventHandler UpdateContentEvent;
public delegate void UpdateContentEventEventHandler (string html, bool silently);
public event UpdateChooserEventHandler UpdateChooserEvent;
public delegate void UpdateChooserEventHandler (string [] folders);
public string SelectedFolder {
get {
return this.selected_folder;
}
set {
this.selected_folder = value;
if (UpdateContentEvent != null)
UpdateContentEvent (HTML, true);
}
}
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;
}
}
public string [] Folders {
get {
return SparkleShare.Controller.Folders.ToArray ();
}
}
private string selected_folder;
public SparkleEventLogController ()
{
SparkleShare.Controller.AvatarFetched += delegate {
if (UpdateContentEvent != null)
UpdateContentEvent (HTML, true);
};
SparkleShare.Controller.OnIdle += delegate {
if (UpdateContentEvent != null)
UpdateContentEvent (HTML, true);
};
SparkleShare.Controller.FolderListChanged += delegate {
if (this.selected_folder != null &&
!SparkleShare.Controller.Folders.Contains (this.selected_folder)) {
this.selected_folder = null;
}
if (UpdateChooserEvent != null)
UpdateChooserEvent (Folders);
if (UpdateContentEvent != null)
UpdateContentEvent (HTML, true);
};
SparkleShare.Controller.NotificationRaised += delegate {
if (UpdateContentEvent != null)
UpdateContentEvent (HTML, true);
};
}
}
}

View file

@ -62,7 +62,7 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\bin\Meebey.SmartIrc4net.dll</HintPath>
</Reference>
<Reference Include="SparkleLib, Version=0.2.3.0, Culture=neutral, PublicKeyToken=null">
<Reference Include="SparkleLib, Version=0.2.4.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\bin\SparkleLib.dll</HintPath>
</Reference>
@ -91,6 +91,7 @@
<Compile Include="SparkleMacWatcher.cs" />
<Compile Include="SparkleEventLog.cs" />
<Compile Include="SparkleBadger.cs" />
<Compile Include="SparkleEventLogController.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="MainMenu.xib" />

View file

@ -96,8 +96,6 @@ namespace SparkleShare {
SparkleShare.Controller.NotificationRaised += delegate (string user_name, string user_email,
string message, string repository_path) {
InvokeOnMainThread (delegate {
if (EventLog != null)
EventLog.UpdateEvents ();
if (SparkleShare.Controller.NotificationsEnabled) {
if (NSApplication.SharedApplication.DockTile.BadgeLabel == null)
@ -130,30 +128,7 @@ namespace SparkleShare {
};
SparkleShare.Controller.AvatarFetched += delegate {
InvokeOnMainThread (delegate {
if (EventLog != null)
EventLog.UpdateEvents ();
});
};
SparkleShare.Controller.OnIdle += delegate {
InvokeOnMainThread (delegate {
if (EventLog != null)
EventLog.UpdateEvents ();
});
};
SparkleShare.Controller.FolderListChanged += delegate {
InvokeOnMainThread (delegate {
if (EventLog != null) {
EventLog.UpdateChooser ();
EventLog.UpdateEvents ();
}
});
};
if (SparkleShare.Controller.FirstRun) {

View file

@ -1006,7 +1006,6 @@ namespace SparkleShare {
fetcher.Failed += delegate {
if (FolderFetchError != null)
FolderFetchError ();