From c96ca660331751c1951e7a8f6ae0223350e6b5e2 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 18 Nov 2012 11:18:23 +0000 Subject: [PATCH] statusicon: rearrange and keep references to all NSObjects on mac --- SparkleShare/Linux/SparkleStatusIcon.cs | 20 +---- SparkleShare/Mac/SparkleSetupWindow.cs | 2 +- SparkleShare/Mac/SparkleStatusIcon.cs | 96 +++++++-------------- SparkleShare/SparkleStatusIconController.cs | 16 ++++ SparkleShare/Windows/SparkleStatusIcon.cs | 42 ++------- 5 files changed, 57 insertions(+), 119 deletions(-) diff --git a/SparkleShare/Linux/SparkleStatusIcon.cs b/SparkleShare/Linux/SparkleStatusIcon.cs index e25485c4..ecc42d7e 100644 --- a/SparkleShare/Linux/SparkleStatusIcon.cs +++ b/SparkleShare/Linux/SparkleStatusIcon.cs @@ -173,7 +173,7 @@ namespace SparkleShare { }; MenuItem try_again_item = new MenuItem ("Try Again"); - try_again_item.Activated += TryAgainDelegate (folder_name); + try_again_item.Activated += Controller.TryAgainDelegate (folder_name); (item.Submenu as Menu).Add (error_item); (item.Submenu as Menu).Add (new SeparatorMenuItem (); @@ -186,7 +186,7 @@ namespace SparkleShare { item.Image = new Image (folder_icon); (item.Child as Label).UseUnderline = false; - item.Activated += OpenFolderDelegate (folder_name); + item.Activated += Controller.OpenFolderDelegate (folder_name); this.menu.Add (item); i++; @@ -263,22 +263,6 @@ namespace SparkleShare { this.indicator.Menu = this.menu; #endif } - - - private EventHandler OpenFolderDelegate (string name) - { - return delegate { - Controller.SubfolderClicked (name); - }; - } - - - private EventHandler TryAgainDelegate (string name) - { - return delegate { - Controller.TryAgainClicked (name); - }; - } #if !HAVE_APP_INDICATOR diff --git a/SparkleShare/Mac/SparkleSetupWindow.cs b/SparkleShare/Mac/SparkleSetupWindow.cs index 9bdf033c..364501a0 100755 --- a/SparkleShare/Mac/SparkleSetupWindow.cs +++ b/SparkleShare/Mac/SparkleSetupWindow.cs @@ -70,7 +70,7 @@ namespace SparkleShare { Font = NSFontManager.SharedFontManager.FontWithFamily ( "Lucida Grande", NSFontTraitMask.Bold, 0, 15), }; - + this.header_text_field.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; this.description_text_field = new NSTextField () { diff --git a/SparkleShare/Mac/SparkleStatusIcon.cs b/SparkleShare/Mac/SparkleStatusIcon.cs index 9cf4dd8c..a003ef55 100755 --- a/SparkleShare/Mac/SparkleStatusIcon.cs +++ b/SparkleShare/Mac/SparkleStatusIcon.cs @@ -31,66 +31,46 @@ namespace SparkleShare { private NSMenu menu; - private NSStatusItem status_item; + private NSStatusItem status_item = NSStatusBar.SystemStatusBar.CreateStatusItem (28); private NSMenuItem state_item; private NSMenuItem folder_item; - + private NSMenuItem [] folder_menu_items; + private NSMenuItem [] error_menu_items; + private NSMenuItem [] try_again_menu_items; private NSMenuItem add_item; private NSMenuItem about_item; private NSMenuItem recent_events_item; private NSMenuItem quit_item; - private NSImage syncing_idle_image; - private NSImage syncing_up_image; - private NSImage syncing_down_image; - private NSImage syncing_image; - private NSImage syncing_error_image; - - private NSImage syncing_idle_image_active; - private NSImage syncing_up_image_active; - private NSImage syncing_down_image_active; - private NSImage syncing_image_active; - private NSImage syncing_error_image_active; - - private NSImage folder_image; - private NSImage caution_image; - private NSImage sparkleshare_image; + private NSImage syncing_idle_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-idle.png")); + private NSImage syncing_up_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-up.png")); + private NSImage syncing_down_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-down.png")); + private NSImage syncing_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing.png")); + private NSImage syncing_error_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-error.png")); - private EventHandler [] folder_tasks; - private EventHandler [] try_again_tasks; + private NSImage syncing_idle_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-idle-active.png")); + private NSImage syncing_up_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-up-active.png")); + private NSImage syncing_down_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-down-active.png")); + private NSImage syncing_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-active.png")); + private NSImage syncing_error_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-error-active.png")); + + private NSImage folder_image = NSImage.ImageNamed ("NSFolder"); + private NSImage caution_image = NSImage.ImageNamed ("NSCaution"); + private NSImage sparkleshare_image = NSImage.ImageNamed ("sparkleshare-folder"); public SparkleStatusIcon () : base () { using (var a = new NSAutoreleasePool ()) { - this.status_item = NSStatusBar.SystemStatusBar.CreateStatusItem (28); - this.status_item.HighlightMode = true; - - this.syncing_idle_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-idle.png")); - this.syncing_up_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-up.png")); - this.syncing_down_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-down.png")); - this.syncing_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing.png")); - this.syncing_error_image = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-error.png")); - - this.syncing_idle_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-idle-active.png")); - this.syncing_up_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-up-active.png")); - this.syncing_down_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-down-active.png")); - this.syncing_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-active.png")); - this.syncing_error_image_active = new NSImage (Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-error-active.png")); - - this.status_item.Image = this.syncing_idle_image; - this.status_item.Image.Size = new SizeF (16, 16); - + this.status_item.HighlightMode = true; + this.status_item.Image = this.syncing_idle_image; this.status_item.AlternateImage = this.syncing_idle_image_active; + this.status_item.Image.Size = new SizeF (16, 16); this.status_item.AlternateImage.Size = new SizeF (16, 16); - this.folder_image = NSImage.ImageNamed ("NSFolder"); - this.caution_image = NSImage.ImageNamed ("NSCaution"); - this.sparkleshare_image = NSImage.ImageNamed ("sparkleshare-folder"); - CreateMenu (); } @@ -228,10 +208,10 @@ namespace SparkleShare { this.menu.AddItem (this.folder_item); this.folder_menu_items = new NSMenuItem [Controller.Folders.Length]; + this.error_menu_items = new NSMenuItem [Controller.Folders.Length]; + this.try_again_menu_items = new NSMenuItem [Controller.Folders.Length]; if (Controller.Folders.Length > 0) { - this.folder_tasks = new EventHandler [Controller.Folders.Length]; - this.try_again_tasks = new EventHandler [Controller.Folders.Length]; int i = 0; foreach (string folder_name in Controller.Folders) { @@ -242,30 +222,28 @@ namespace SparkleShare { item.Image = this.caution_image; item.Submenu = new NSMenu (); - NSMenuItem error_item = new NSMenuItem () { + this.error_menu_items [i] = new NSMenuItem () { Title = Controller.FolderErrors [i] }; - NSMenuItem try_again_item = new NSMenuItem () { + this.try_again_menu_items [i] = new NSMenuItem () { // TODO: retain Title = "Try Again" }; - this.try_again_tasks [i] = TryAgainDelegate (folder_name); - try_again_item.Activated += this.try_again_tasks [i]; + this.try_again_menu_items [i].Activated += Controller.TryAgainDelegate (folder_name);; - item.Submenu.AddItem (error_item); + item.Submenu.AddItem (this.error_menu_items [i]); item.Submenu.AddItem (NSMenuItem.SeparatorItem); - item.Submenu.AddItem (try_again_item); + item.Submenu.AddItem (this.try_again_menu_items [i]); } else { item.Image = this.folder_image; } item.Image.Size = new SizeF (16, 16); - this.folder_tasks [i] = OpenFolderDelegate (folder_name); this.folder_menu_items [i] = item; - this.folder_menu_items [i].Activated += this.folder_tasks [i]; + this.folder_menu_items [i].Activated += Controller.OpenFolderDelegate (folder_name); i++; }; @@ -287,22 +265,6 @@ namespace SparkleShare { this.status_item.Menu = this.menu; } } - - - private EventHandler OpenFolderDelegate (string name) - { - return delegate { - Controller.SubfolderClicked (name); - }; - } - - - private EventHandler TryAgainDelegate (string name) - { - return delegate { - Controller.TryAgainClicked (name); - }; - } } diff --git a/SparkleShare/SparkleStatusIconController.cs b/SparkleShare/SparkleStatusIconController.cs index 69dd48aa..7792ac4d 100755 --- a/SparkleShare/SparkleStatusIconController.cs +++ b/SparkleShare/SparkleStatusIconController.cs @@ -244,6 +244,22 @@ namespace SparkleShare { } + public EventHandler OpenFolderDelegate (string subfolder) + { + return delegate { + SubfolderClicked (subfolder); + }; + } + + + public EventHandler TryAgainDelegate (string subfolder) + { + return delegate { + TryAgainClicked (subfolder); + }; + } + + private void UpdateFolders () { Folders = Program.Controller.Folders.ToArray (); diff --git a/SparkleShare/Windows/SparkleStatusIcon.cs b/SparkleShare/Windows/SparkleStatusIcon.cs index 39e59c7b..6f22534e 100644 --- a/SparkleShare/Windows/SparkleStatusIcon.cs +++ b/SparkleShare/Windows/SparkleStatusIcon.cs @@ -33,15 +33,14 @@ namespace SparkleShare { public SparkleStatusIconController Controller = new SparkleStatusIconController(); - private Drawing.Bitmap syncing_idle_image; - private Drawing.Bitmap syncing_up_image; - private Drawing.Bitmap syncing_down_image; - private Drawing.Bitmap syncing_image; - private Drawing.Bitmap syncing_error_image; + private Drawing.Bitmap syncing_idle_image = SparkleUIHelpers.GetBitmap ("process-syncing-idle"); + private Drawing.Bitmap syncing_up_image = SparkleUIHelpers.GetBitmap ("process-syncing-up"); + private Drawing.Bitmap syncing_down_image = SparkleUIHelpers.GetBitmap ("process-syncing-down"); + private Drawing.Bitmap syncing_image = SparkleUIHelpers.GetBitmap ("process-syncing"); + private Drawing.Bitmap syncing_error_image = SparkleUIHelpers.GetBitmap ("process-syncing-error"); private ContextMenu context_menu; - private SparkleMenuItem log_item; private SparkleMenuItem state_item; private SparkleMenuItem exit_item; @@ -51,14 +50,8 @@ namespace SparkleShare { public SparkleStatusIcon () { - this.syncing_idle_image = SparkleUIHelpers.GetBitmap ("process-syncing-idle"); - this.syncing_up_image = SparkleUIHelpers.GetBitmap ("process-syncing-up"); - this.syncing_down_image = SparkleUIHelpers.GetBitmap ("process-syncing-down"); - this.syncing_image = SparkleUIHelpers.GetBitmap ("process-syncing"); - this.syncing_error_image = SparkleUIHelpers.GetBitmap ("process-syncing-error"); - - this.notify_icon.Icon = this.syncing_idle_image; this.notify_icon.HeaderText = "SparkleShare"; + this.notify_icon.Icon = this.syncing_idle_image; CreateMenu (); @@ -206,7 +199,7 @@ namespace SparkleShare { Header = folder_name.Replace ("_", "__") }; - subfolder_item.Click += OpenFolderDelegate (folder_name); + subfolder_item.Click += Controller.OpenFolderDelegate (folder_name); Image subfolder_image = new Image () { Source = SparkleUIHelpers.GetImageSource ("folder"), @@ -218,8 +211,7 @@ namespace SparkleShare { subfolder_item.Icon = new Image () { Source = (BitmapSource) Imaging.CreateBitmapSourceFromHIcon ( System.Drawing.SystemIcons.Exclamation.Handle, Int32Rect.Empty, - BitmapSizeOptions.FromWidthAndHeight (16,16) - ) + BitmapSizeOptions.FromWidthAndHeight (16,16)) }; SparkleMenuItem error_item = new SparkleMenuItem () { @@ -231,7 +223,7 @@ namespace SparkleShare { Header = "Try again" }; - try_again_item.Click += TryAgainDelegate (folder_name); + try_again_item.Click += Controller.TryAgainDelegate (folder_name); subfolder_item.Items.Add (error_item); subfolder_item.Items.Add (new Separator ()); @@ -271,22 +263,6 @@ namespace SparkleShare { { this.notify_icon.Dispose (); } - - - private RoutedEventHandler OpenFolderDelegate (string folder_name) - { - return delegate { - Controller.SubfolderClicked (folder_name); - }; - } - - - private EventHandler TryAgainDelegate (string name) - { - return delegate { - Controller.TryAgainClicked (name); - }; - } }