event log, bubbles: move more logic to controllers

This commit is contained in:
Hylke Bons 2012-02-18 01:01:24 +01:00
parent 1980a81204
commit aa610c818e
10 changed files with 83 additions and 43 deletions

View file

@ -192,7 +192,7 @@ namespace SparkleShare {
public override bool WindowShouldClose (NSObject sender)
{
(sender as SparkleAbout).Controller.HideWindow ();
(sender as SparkleAbout).Controller.WindowClosed ();
return false;
}
}

View file

@ -26,12 +26,12 @@ namespace SparkleShare {
public class SparkleBubbles : NSObject {
private SparkleBubblesController controller = new SparkleBubblesController ();
public SparkleBubblesController Controller = new SparkleBubblesController ();
public SparkleBubbles ()
{
this.controller.ShowBubbleEvent += delegate (string title, string subtext, string image_path) {
Controller.ShowBubbleEvent += delegate (string title, string subtext, string image_path) {
InvokeOnMainThread (delegate {
if (!GrowlApplicationBridge.IsGrowlRunning ()) {
NSApplication.SharedApplication.RequestUserAttention (
@ -68,17 +68,7 @@ namespace SparkleShare {
[Export("growlNotificationWasClicked")]
public override void GrowlNotificationWasClicked (NSObject o)
{
InvokeOnMainThread (delegate {
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
if (SparkleUI.EventLog == null)
SparkleUI.EventLog = new SparkleEventLog ();
SparkleUI.EventLog.Controller.SelectedFolder = null;
SparkleUI.EventLog.OrderFrontRegardless ();
SparkleUI.EventLog.MakeKeyAndOrderFront (this);
});
SparkleUI.Bubbles.Controller.BubbleClicked ();
}
}
}

View file

@ -149,13 +149,22 @@ namespace SparkleShare {
};
UpdateContent (null);
UpdateChooser (null);
OrderFrontRegardless ();
Program.UI.UpdateDockIconVisibility ();
// Hook up the controller events
Controller.HideWindowEvent += delegate {
InvokeOnMainThread (delegate {
PerformClose (this);
});
};
Controller.ShowWindowEvent += delegate {
InvokeOnMainThread (delegate {
OrderFrontRegardless ();
UpdateContent (null);
UpdateChooser (null);
});
};
Controller.UpdateChooserEvent += delegate (string [] folders) {
InvokeOnMainThread (delegate {
UpdateChooser (folders);
@ -265,6 +274,29 @@ namespace SparkleShare {
thread.Start ();
}
}
public override void OrderFrontRegardless ()
{
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
MakeKeyAndOrderFront (this);
if (Program.UI != null)
Program.UI.UpdateDockIconVisibility ();
base.OrderFrontRegardless ();
}
public override void PerformClose (NSObject sender)
{
base.OrderOut (this);
if (Program.UI != null)
Program.UI.UpdateDockIconVisibility ();
return;
}
}
@ -272,9 +304,7 @@ namespace SparkleShare {
public override bool WindowShouldClose (NSObject sender)
{
(sender as SparkleEventLog).OrderOut (this);
Program.UI.UpdateDockIconVisibility ();
(sender as SparkleEventLog).Controller.WindowClosed ();
return false;
}
}

View file

@ -249,18 +249,8 @@ namespace SparkleShare {
};
if (Controller.Folders.Length > 0) {
// TODO: move this logic
RecentEventsMenuItem.Activated += delegate {
// Controller.OpenRecentEventsClicked ()
InvokeOnMainThread (delegate {
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
if (SparkleUI.EventLog == null)
SparkleUI.EventLog = new SparkleEventLog ();
SparkleUI.EventLog.OrderFrontRegardless ();
SparkleUI.EventLog.MakeKeyAndOrderFront (this);
});
Controller.OpenRecentEventsClicked ();
};
}

View file

@ -63,14 +63,14 @@ namespace SparkleShare {
BoldFont = NSFontManager.SharedFontManager.FontWithFamily
("Lucida Grande", NSFontTraitMask.Bold, 0, 13);
StatusIcon = new SparkleStatusIcon ();
Bubbles = new SparkleBubbles ();
Setup = new SparkleSetup ();
EventLog = new SparkleEventLog ();
About = new SparkleAbout ();
Bubbles = new SparkleBubbles ();
StatusIcon = new SparkleStatusIcon ();
if (Program.Controller.FirstRun)
Program.Controller.ShowSetupWindow (PageType.Setup);
}
}

View file

@ -60,7 +60,7 @@ namespace SparkleShare {
}
public void HideWindow ()
public void WindowClosed ()
{
if (HideWindowEvent != null)
HideWindowEvent ();

View file

@ -51,6 +51,12 @@ namespace SparkleShare {
}
public void BubbleClicked ()
{
Program.Controller.ShowEventLogWindow ();
}
private string FormatMessage (SparkleChangeSet change_set)
{
string file_name = "";

View file

@ -47,8 +47,8 @@ namespace SparkleShare {
public event ShowAboutWindowEventHandler ShowAboutWindowEvent;
public delegate void ShowAboutWindowEventHandler ();
public event ShowEventsWindowEventHandler ShowEventsWindowEvent;
public delegate void ShowEventsWindowEventHandler ();
public event ShowEventLogWindowEventHandler ShowEventLogWindowEvent;
public delegate void ShowEventLogWindowEventHandler ();
public event FolderFetchedEventHandler FolderFetched;
@ -224,10 +224,10 @@ namespace SparkleShare {
}
public void ShowEventsWindow ()
public void ShowEventLogWindow ()
{
if (ShowEventsWindowEvent != null)
ShowEventsWindowEvent ();
if (ShowEventLogWindowEvent != null)
ShowEventLogWindowEvent ();
}

View file

@ -28,6 +28,12 @@ namespace SparkleShare {
public class SparkleEventLogController {
public event ShowWindowEventHandler ShowWindowEvent;
public delegate void ShowWindowEventHandler ();
public event HideWindowEventHandler HideWindowEvent;
public delegate void HideWindowEventHandler ();
public event UpdateContentEventEventHandler UpdateContentEvent;
public delegate void UpdateContentEventEventHandler (string html);
@ -146,6 +152,11 @@ namespace SparkleShare {
public SparkleEventLogController ()
{
Program.Controller.ShowEventLogWindowEvent += delegate {
if (ShowWindowEvent != null)
ShowWindowEvent ();
};
Program.Controller.AvatarFetched += delegate {
if (UpdateContentEvent != null)
UpdateContentEvent (HTML);
@ -178,6 +189,13 @@ namespace SparkleShare {
}
public void WindowClosed ()
{
if (HideWindowEvent != null)
HideWindowEvent ();
}
public void LinkClicked (string url)
{
if (url.StartsWith (Path.VolumeSeparatorChar.ToString ())) {

View file

@ -141,5 +141,11 @@ namespace SparkleShare {
{
Program.Controller.ShowAboutWindow ();
}
public void OpenRecentEventsClicked ()
{
Program.Controller.ShowEventLogWindow ();
}
}
}