mac statusicon: fix more whitespace

This commit is contained in:
Hylke Bons 2011-05-13 01:22:03 +01:00
parent 7b63ef389c
commit 5ef01566b0

View file

@ -27,326 +27,326 @@ using MonoMac.ObjCRuntime;
namespace SparkleShare { namespace SparkleShare {
// The statusicon that stays in the // The statusicon that stays in the
// user's notification area // user's notification area
public class SparkleStatusIcon : NSObject { public class SparkleStatusIcon : NSObject {
private Timer Animation; private Timer Animation;
private int FrameNumber; private int FrameNumber;
private string StateText; private string StateText;
private NSStatusItem StatusItem; private NSStatusItem StatusItem;
private NSMenu Menu; private NSMenu Menu;
private NSMenuItem StateMenuItem; private NSMenuItem StateMenuItem;
private NSMenuItem FolderMenuItem; private NSMenuItem FolderMenuItem;
private NSMenuItem [] FolderMenuItems; private NSMenuItem [] FolderMenuItems;
private NSMenuItem SyncMenuItem; private NSMenuItem SyncMenuItem;
private NSMenuItem NotificationsMenuItem; private NSMenuItem NotificationsMenuItem;
private delegate void Task (); private delegate void Task ();
private EventHandler [] Tasks; private EventHandler [] Tasks;
// Short alias for the translations // Short alias for the translations
public static string _ (string s) public static string _ (string s)
{ {
return Catalog.GetString (s); return Catalog.GetString (s);
} }
public SparkleStatusIcon () : base () public SparkleStatusIcon () : base ()
{ {
Animation = CreateAnimation (); Animation = CreateAnimation ();
StatusItem = NSStatusBar.SystemStatusBar.CreateStatusItem (28); StatusItem = NSStatusBar.SystemStatusBar.CreateStatusItem (28);
StatusItem.HighlightMode = true; StatusItem.HighlightMode = true;
SetNormalState (); SetNormalState ();
CreateMenu (); CreateMenu ();
Menu.Delegate = new SparkleStatusIconMenuDelegate (); Menu.Delegate = new SparkleStatusIconMenuDelegate ();
SparkleShare.Controller.FolderSizeChanged += delegate { SparkleShare.Controller.FolderSizeChanged += delegate {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
if (!Animation.Enabled) if (!Animation.Enabled)
SetNormalState (); SetNormalState ();
UpdateMenu (); UpdateMenu ();
}); });
}; };
SparkleShare.Controller.FolderListChanged += delegate { SparkleShare.Controller.FolderListChanged += delegate {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
SetNormalState (); SetNormalState ();
CreateMenu (); CreateMenu ();
}); });
}; };
SparkleShare.Controller.OnIdle += delegate { SparkleShare.Controller.OnIdle += delegate {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
SetNormalState (); SetNormalState ();
UpdateMenu (); UpdateMenu ();
}); });
}; };
SparkleShare.Controller.OnSyncing += delegate { SparkleShare.Controller.OnSyncing += delegate {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
SetAnimationState (); SetAnimationState ();
UpdateMenu (); UpdateMenu ();
}); });
}; };
SparkleShare.Controller.OnError += delegate { SparkleShare.Controller.OnError += delegate {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
SetNormalState (true); SetNormalState (true);
UpdateMenu (); UpdateMenu ();
}); });
}; };
} }
// Creates the Animation that handles the syncing animation // Creates the Animation that handles the syncing animation
private Timer CreateAnimation () private Timer CreateAnimation ()
{ {
FrameNumber = 0; FrameNumber = 0;
Timer Animation = new Timer () { Timer Animation = new Timer () {
Interval = 35 Interval = 35
}; };
Animation.Elapsed += delegate { Animation.Elapsed += delegate {
if (FrameNumber < 4) if (FrameNumber < 4)
FrameNumber++; FrameNumber++;
else else
FrameNumber = 0; FrameNumber = 0;
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
string image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, string image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
"Pixmaps", "idle" + FrameNumber + ".png"); "Pixmaps", "idle" + FrameNumber + ".png");
string alternate_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, string alternate_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
"Pixmaps", "idle" + FrameNumber + "-active.png"); "Pixmaps", "idle" + FrameNumber + "-active.png");
StatusItem.Image = new NSImage (image_path); StatusItem.Image = new NSImage (image_path);
StatusItem.AlternateImage = new NSImage (alternate_image_path); StatusItem.AlternateImage = new NSImage (alternate_image_path);
StatusItem.Image.Size = new SizeF (16, 16); StatusItem.Image.Size = new SizeF (16, 16);
StatusItem.AlternateImage.Size = new SizeF (16, 16); StatusItem.AlternateImage.Size = new SizeF (16, 16);
}); });
}; };
return Animation; return Animation;
} }
// Creates the menu that is popped up when the // Creates the menu that is popped up when the
// user clicks the status icon // user clicks the status icon
public void CreateMenu () public void CreateMenu ()
{ {
Menu = new NSMenu (); Menu = new NSMenu ();
StateMenuItem = new NSMenuItem () { StateMenuItem = new NSMenuItem () {
Title = StateText Title = StateText
}; };
Menu.AddItem (StateMenuItem); Menu.AddItem (StateMenuItem);
Menu.AddItem (NSMenuItem.SeparatorItem); Menu.AddItem (NSMenuItem.SeparatorItem);
FolderMenuItem = new NSMenuItem () { FolderMenuItem = new NSMenuItem () {
Title = "SparkleShare" Title = "SparkleShare"
}; };
FolderMenuItem.Activated += delegate { FolderMenuItem.Activated += delegate {
SparkleShare.Controller.OpenSparkleShareFolder (); SparkleShare.Controller.OpenSparkleShareFolder ();
}; };
string folder_icon_path = Path.Combine (NSBundle.MainBundle.ResourcePath, string folder_icon_path = Path.Combine (NSBundle.MainBundle.ResourcePath,
"sparkleshare-mac.icns"); "sparkleshare-mac.icns");
FolderMenuItem.Image = new NSImage (folder_icon_path); FolderMenuItem.Image = new NSImage (folder_icon_path);
FolderMenuItem.Image.Size = new SizeF (16, 16); FolderMenuItem.Image.Size = new SizeF (16, 16);
Menu.AddItem (FolderMenuItem); Menu.AddItem (FolderMenuItem);
if (SparkleShare.Controller.Folders.Count > 0) { if (SparkleShare.Controller.Folders.Count > 0) {
FolderMenuItems = new NSMenuItem [SparkleShare.Controller.Folders.Count]; FolderMenuItems = new NSMenuItem [SparkleShare.Controller.Folders.Count];
Tasks = new EventHandler [SparkleShare.Controller.Folders.Count]; Tasks = new EventHandler [SparkleShare.Controller.Folders.Count];
int i = 0; int i = 0;
foreach (string path in SparkleShare.Controller.Folders) { foreach (string path in SparkleShare.Controller.Folders) {
/* TODO /* TODO
if (repo.HasUnsyncedChanges) if (repo.HasUnsyncedChanges)
folder_action.IconName = "dialog-error"; */ folder_action.IconName = "dialog-error"; */
NSMenuItem item = new NSMenuItem (); NSMenuItem item = new NSMenuItem ();
item.Title = System.IO.Path.GetFileName (path); item.Title = System.IO.Path.GetFileName (path);
item.Image = NSImage.ImageNamed ("NSFolder"); item.Image = NSImage.ImageNamed ("NSFolder");
item.Image.Size = new SizeF (16, 16); item.Image.Size = new SizeF (16, 16);
Tasks [i] = OpenEventLogDelegate (path); Tasks [i] = OpenEventLogDelegate (path);
FolderMenuItems [i] = item; FolderMenuItems [i] = item;
FolderMenuItems [i].Activated += Tasks [i]; FolderMenuItems [i].Activated += Tasks [i];
Menu.AddItem (FolderMenuItems [i]); Menu.AddItem (FolderMenuItems [i]);
i++; i++;
}; };
} else { } else {
FolderMenuItems = new NSMenuItem [1]; FolderMenuItems = new NSMenuItem [1];
FolderMenuItems [0] = new NSMenuItem () { FolderMenuItems [0] = new NSMenuItem () {
Title = "No Remote Folders Yet" Title = "No Remote Folders Yet"
}; };
Menu.AddItem (FolderMenuItems [0]); Menu.AddItem (FolderMenuItems [0]);
} }
Menu.AddItem (NSMenuItem.SeparatorItem); Menu.AddItem (NSMenuItem.SeparatorItem);
SyncMenuItem = new NSMenuItem () { SyncMenuItem = new NSMenuItem () {
Title = "Add Remote Folder…" Title = "Add Remote Folder…"
}; };
if (!SparkleShare.Controller.FirstRun) { if (!SparkleShare.Controller.FirstRun) {
SyncMenuItem.Activated += delegate { SyncMenuItem.Activated += delegate {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true); NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
if (SparkleUI.Intro == null) { if (SparkleUI.Intro == null) {
SparkleUI.Intro = new SparkleIntro (); SparkleUI.Intro = new SparkleIntro ();
SparkleUI.Intro.ShowServerForm (true); SparkleUI.Intro.ShowServerForm (true);
} }
if (!SparkleUI.Intro.IsVisible) if (!SparkleUI.Intro.IsVisible)
SparkleUI.Intro.ShowServerForm (true); SparkleUI.Intro.ShowServerForm (true);
SparkleUI.Intro.OrderFrontRegardless (); SparkleUI.Intro.OrderFrontRegardless ();
SparkleUI.Intro.MakeKeyAndOrderFront (this); SparkleUI.Intro.MakeKeyAndOrderFront (this);
}); });
}; };
} }
Menu.AddItem (SyncMenuItem); Menu.AddItem (SyncMenuItem);
Menu.AddItem (NSMenuItem.SeparatorItem); Menu.AddItem (NSMenuItem.SeparatorItem);
NotificationsMenuItem = new NSMenuItem (); NotificationsMenuItem = new NSMenuItem ();
if (SparkleShare.Controller.NotificationsEnabled) if (SparkleShare.Controller.NotificationsEnabled)
NotificationsMenuItem.Title = "Turn Notifications Off"; NotificationsMenuItem.Title = "Turn Notifications Off";
else else
NotificationsMenuItem.Title = "Turn Notifications On"; NotificationsMenuItem.Title = "Turn Notifications On";
NotificationsMenuItem.Activated += delegate { NotificationsMenuItem.Activated += delegate {
SparkleShare.Controller.ToggleNotifications (); SparkleShare.Controller.ToggleNotifications ();
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
if (SparkleShare.Controller.NotificationsEnabled) if (SparkleShare.Controller.NotificationsEnabled)
NotificationsMenuItem.Title = "Turn Notifications Off"; NotificationsMenuItem.Title = "Turn Notifications Off";
else else
NotificationsMenuItem.Title = "Turn Notifications On"; NotificationsMenuItem.Title = "Turn Notifications On";
}); });
}; };
Menu.AddItem (NotificationsMenuItem); Menu.AddItem (NotificationsMenuItem);
StatusItem.Menu = Menu; StatusItem.Menu = Menu;
StatusItem.Menu.Update (); StatusItem.Menu.Update ();
} }
// A method reference that makes sure that opening the // A method reference that makes sure that opening the
// event log for each repository works correctly // event log for each repository works correctly
private EventHandler OpenEventLogDelegate (string path) private EventHandler OpenEventLogDelegate (string path)
{ {
return delegate { return delegate {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
NSApplication.SharedApplication.ActivateIgnoringOtherApps (true); NSApplication.SharedApplication.ActivateIgnoringOtherApps (true);
SparkleLog log = SparkleUI.OpenLogs.Find (delegate (SparkleLog l) { SparkleLog log = SparkleUI.OpenLogs.Find (delegate (SparkleLog l) {
return l.LocalPath.Equals (path); return l.LocalPath.Equals (path);
}); });
// Check whether the log is already open, create a new one if // 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 // that's not the case or present it to the user if it is
if (log == null) { if (log == null) {
SparkleUI.OpenLogs.Add (new SparkleLog (path)); SparkleUI.OpenLogs.Add (new SparkleLog (path));
SparkleUI.OpenLogs [SparkleUI.OpenLogs.Count - 1].MakeKeyAndOrderFront (this); SparkleUI.OpenLogs [SparkleUI.OpenLogs.Count - 1].MakeKeyAndOrderFront (this);
} else { } else {
log.OrderFrontRegardless (); log.OrderFrontRegardless ();
log.MakeKeyAndOrderFront (this); log.MakeKeyAndOrderFront (this);
} }
}); });
}; };
} }
public void UpdateMenu () public void UpdateMenu ()
{ {
StateMenuItem.Title = StateText; StateMenuItem.Title = StateText;
} }
// The state when there's nothing going on // The state when there's nothing going on
private void SetNormalState () private void SetNormalState ()
{ {
SetNormalState (false); SetNormalState (false);
} }
// The state when there's nothing going on // The state when there's nothing going on
private void SetNormalState (bool error) private void SetNormalState (bool error)
{ {
Animation.Stop (); Animation.Stop ();
if (SparkleShare.Controller.Folders.Count == 0) { if (SparkleShare.Controller.Folders.Count == 0) {
StateText = _("Welcome to SparkleShare!"); StateText = _("Welcome to SparkleShare!");
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
StatusItem.Image = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle0.png"); StatusItem.Image = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle0.png");
StatusItem.Image.Size = new SizeF (16, 16); StatusItem.Image.Size = new SizeF (16, 16);
StatusItem.AlternateImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle0-active.png"); StatusItem.AlternateImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle0-active.png");
StatusItem.AlternateImage.Size = new SizeF (16, 16); StatusItem.AlternateImage.Size = new SizeF (16, 16);
}); });
} else { } else {
if (error) { if (error) {
StateText = _("Not everything is synced"); StateText = _("Not everything is synced");
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
// TODO: Pixbuf = SparkleUIHelpers.GetIcon ("sparkleshare-syncing-error", 24); // TODO: Pixbuf = SparkleUIHelpers.GetIcon ("sparkleshare-syncing-error", 24);
}); });
} else { } else {
StateText = _("Up to date") + " (" + SparkleShare.Controller.FolderSize + ")"; StateText = _("Up to date") + " (" + SparkleShare.Controller.FolderSize + ")";
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
StatusItem.Image = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle0.png"); StatusItem.Image = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle0.png");
StatusItem.AlternateImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle0-active.png"); StatusItem.AlternateImage = new NSImage (NSBundle.MainBundle.ResourcePath + "/Pixmaps/idle0-active.png");
StatusItem.Image.Size = new SizeF (16, 16); StatusItem.Image.Size = new SizeF (16, 16);
StatusItem.AlternateImage.Size = new SizeF (16, 16); StatusItem.AlternateImage.Size = new SizeF (16, 16);
}); });
} }
} }
} }
// The state when animating // The state when animating
private void SetAnimationState () private void SetAnimationState ()
{ {
StateText = _("Syncing…"); StateText = _("Syncing…");
if (!Animation.Enabled) if (!Animation.Enabled)
Animation.Start (); Animation.Start ();
} }
} }
public class SparkleStatusIconMenuDelegate : NSMenuDelegate { public class SparkleStatusIconMenuDelegate : NSMenuDelegate {
public override void MenuWillHighlightItem (NSMenu menu, NSMenuItem item) { } public override void MenuWillHighlightItem (NSMenu menu, NSMenuItem item) { }
public override void MenuWillOpen (NSMenu menu) public override void MenuWillOpen (NSMenu menu)
{ {
InvokeOnMainThread (delegate { InvokeOnMainThread (delegate {
NSApplication.SharedApplication.DockTile.BadgeLabel = null; NSApplication.SharedApplication.DockTile.BadgeLabel = null;
}); });
} }
} }
} }