diff --git a/SparkleShare/Mac/SparkleAbout.cs b/SparkleShare/Mac/SparkleAbout.cs index d8be9b46..d8572210 100755 --- a/SparkleShare/Mac/SparkleAbout.cs +++ b/SparkleShare/Mac/SparkleAbout.cs @@ -31,14 +31,9 @@ namespace SparkleShare { private NSImage about_image; private NSImageView about_image_view; - private NSTextField version_text_field; - private NSTextField updates_text_field; - private NSTextField credits_text_field; + private NSTextField version_text_field, updates_text_field, credits_text_field; private NSButton hidden_close_button; - private SparkleLink website_link; - private SparkleLink credits_link; - private SparkleLink report_problem_link; - private SparkleLink debug_log_link; + private SparkleLink website_link, credits_link, report_problem_link, debug_log_link; public SparkleAbout (IntPtr handle) : base (handle) { } diff --git a/SparkleShare/Mac/SparkleBubbles.cs b/SparkleShare/Mac/SparkleBubbles.cs index fc3dd19b..971e7e22 100755 --- a/SparkleShare/Mac/SparkleBubbles.cs +++ b/SparkleShare/Mac/SparkleBubbles.cs @@ -16,7 +16,6 @@ using System; -using System.IO; using MonoMac.AppKit; using MonoMac.Foundation; @@ -44,10 +43,7 @@ namespace SparkleShare { NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter; center.ShouldPresentNotification = delegate { return true; }; - - center.DidActivateNotification += delegate { - Controller.BubbleClicked (); - }; + center.DidActivateNotification += delegate { Controller.BubbleClicked (); }; center.ScheduleNotification (notification); }); diff --git a/SparkleShare/Mac/SparkleEventLog.cs b/SparkleShare/Mac/SparkleEventLog.cs index 8161677a..da61d8a6 100755 --- a/SparkleShare/Mac/SparkleEventLog.cs +++ b/SparkleShare/Mac/SparkleEventLog.cs @@ -36,10 +36,7 @@ namespace SparkleShare { private NSBox background; private NSPopUpButton popup_button; private NSProgressIndicator progress_indicator; - private NSTextField size_label; - private NSTextField size_label_value; - private NSTextField history_label; - private NSTextField history_label_value; + private NSTextField size_label, size_label_value, history_label, history_label_value; private NSButton hidden_close_button; @@ -174,9 +171,7 @@ namespace SparkleShare { ContentView.AddSubview (this.hidden_close_button); (Delegate as SparkleEventsDelegate).WindowResized += delegate (SizeF new_window_size) { - Program.Controller.Invoke (() => { - Relayout (new_window_size); - }); + Program.Controller.Invoke (() => Relayout (new_window_size)); }; @@ -254,37 +249,31 @@ namespace SparkleShare { this.size_label.Frame = new RectangleF ( new PointF (this.size_label.Frame.X, new_window_size.Height - TitlebarHeight - 30), - this.size_label.Frame.Size - ); + this.size_label.Frame.Size); this.size_label_value.Frame = new RectangleF ( new PointF (this.size_label_value.Frame.X, new_window_size.Height - TitlebarHeight - 30), - this.size_label_value.Frame.Size - ); + this.size_label_value.Frame.Size); this.history_label.Frame = new RectangleF ( new PointF (this.history_label.Frame.X, new_window_size.Height - TitlebarHeight - 30), - this.history_label.Frame.Size - ); + this.history_label.Frame.Size); this.history_label_value.Frame = new RectangleF ( new PointF (this.history_label_value.Frame.X, new_window_size.Height - TitlebarHeight - 30), - this.history_label_value.Frame.Size - ); + this.history_label_value.Frame.Size); + + this.progress_indicator.Frame = new RectangleF ( + new PointF (new_window_size.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10), + this.progress_indicator.Frame.Size); this.popup_button.RemoveFromSuperview (); // Needed to prevent redraw glitches this.popup_button.Frame = new RectangleF ( new PointF (new_window_size.Width - this.popup_button.Frame.Width - 12, new_window_size.Height - TitlebarHeight - 33), - this.popup_button.Frame.Size - ); + this.popup_button.Frame.Size); ContentView.AddSubview (this.popup_button); - - this.progress_indicator.Frame = new RectangleF ( - new PointF (new_window_size.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10), - this.progress_indicator.Frame.Size - ); } diff --git a/SparkleShare/Mac/SparkleSetupWindow.cs b/SparkleShare/Mac/SparkleSetupWindow.cs index 0b396131..95e66ea6 100755 --- a/SparkleShare/Mac/SparkleSetupWindow.cs +++ b/SparkleShare/Mac/SparkleSetupWindow.cs @@ -34,8 +34,7 @@ namespace SparkleShare { private NSImage side_splash; private NSImageView side_splash_view; - private NSTextField header_text_field; - private NSTextField description_text_field; + private NSTextField header_text_field, description_text_field; public SparkleSetupWindow () : base () diff --git a/SparkleShare/Mac/SparkleStatusIcon.cs b/SparkleShare/Mac/SparkleStatusIcon.cs index d7380d3c..46ebeebd 100755 --- a/SparkleShare/Mac/SparkleStatusIcon.cs +++ b/SparkleShare/Mac/SparkleStatusIcon.cs @@ -21,25 +21,18 @@ using System.IO; using MonoMac.Foundation; using MonoMac.AppKit; -using MonoMac.ObjCRuntime; namespace SparkleShare { - public class SparkleStatusIcon : NSObject { + public class SparkleStatusIcon { public SparkleStatusIconController Controller = new SparkleStatusIconController (); private NSStatusItem status_item = NSStatusBar.SystemStatusBar.CreateStatusItem (28); + private NSMenu menu, submenu; - private NSMenu menu; - private NSMenu submenu; - - private NSMenuItem state_item; - private NSMenuItem folder_item; - private NSMenuItem add_item; - private NSMenuItem about_item; - private NSMenuItem recent_events_item; - private NSMenuItem quit_item; + private NSMenuItem state_item, folder_item, add_item, about_item, recent_events_item, quit_item; + private NSMenuItem [] folder_menu_items, error_menu_items, try_again_menu_items; 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")); @@ -52,17 +45,13 @@ namespace SparkleShare { 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"); - private NSMenuItem [] folder_menu_items; - private NSMenuItem [] error_menu_items; - private NSMenuItem [] try_again_menu_items; - - public SparkleStatusIcon () : base () + public SparkleStatusIcon () { this.status_item.HighlightMode = true; this.status_item.Image = this.syncing_idle_image; @@ -102,7 +91,7 @@ namespace SparkleShare { } } - this.status_item.Image.Size = new SizeF (16, 16); + this.status_item.Image.Size = new SizeF (16, 16); this.status_item.AlternateImage.Size = new SizeF (16, 16); }); }; @@ -123,98 +112,78 @@ namespace SparkleShare { public void CreateMenu () { - this.menu = new NSMenu (); - this.menu.AutoEnablesItems = false; + this.menu = new NSMenu () { AutoEnablesItems = false }; + this.state_item = new NSMenuItem () { Title = Controller.StateText, Enabled = false }; + this.folder_item = new NSMenuItem () { - Title = "SparkleShare", - Enabled = true + Title = "SparkleShare", + Enabled = true }; this.folder_item.Image = this.sparkleshare_image; this.folder_item.Image.Size = new SizeF (16, 16); + this.add_item = new NSMenuItem () { Title = "Add Hosted Project…", Enabled = true }; - this.add_item.Activated += delegate { - Controller.AddHostedProjectClicked (); - }; + this.add_item.Activated += Controller.AddHostedProjectClicked; + this.recent_events_item = new NSMenuItem () { Title = "Recent Changes…", Enabled = Controller.RecentEventsItemEnabled }; - if (Controller.Folders.Length > 0) { - this.recent_events_item.Activated += delegate { - Controller.RecentEventsClicked (); - }; - } + if (Controller.RecentEventsItemEnabled) + this.recent_events_item.Activated += Controller.RecentEventsClicked; + this.about_item = new NSMenuItem () { Title = "About SparkleShare", Enabled = true }; - this.about_item.Activated += delegate { - Controller.AboutClicked (); - }; + this.about_item.Activated += Controller.AboutClicked; + this.quit_item = new NSMenuItem () { Title = "Quit", Enabled = Controller.QuitItemEnabled }; - this.quit_item.Activated += delegate { - Controller.QuitClicked (); - }; + this.quit_item.Activated += Controller.QuitClicked; - this.menu.AddItem (this.state_item); - this.menu.AddItem (NSMenuItem.SeparatorItem); - this.menu.AddItem (this.folder_item); - - this.submenu = new NSMenu (); - - this.submenu.AddItem (this.recent_events_item); - this.submenu.AddItem (this.add_item); - this.submenu.AddItem (NSMenuItem.SeparatorItem); - this.submenu.AddItem (this.about_item); - - this.folder_item.Submenu = this.submenu; - - this.folder_menu_items = new NSMenuItem [Controller.Folders.Length]; - this.error_menu_items = new NSMenuItem [Controller.Folders.Length]; + 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) { int i = 0; foreach (string folder_name in Controller.Folders) { - NSMenuItem item = new NSMenuItem (); - item.Title = folder_name; + NSMenuItem item = new NSMenuItem () { Title = folder_name }; this.folder_menu_items [i] = item; if (!string.IsNullOrEmpty (Controller.FolderErrors [i])) { item.Image = this.caution_image; item.Submenu = new NSMenu (); - this.error_menu_items [i] = new NSMenuItem () { - Title = Controller.FolderErrors [i] - }; - - this.try_again_menu_items [i] = new NSMenuItem (); - this.try_again_menu_items [i].Title = "Try Again"; + this.error_menu_items [i] = new NSMenuItem (); + this.error_menu_items [i].Title = Controller.FolderErrors [i]; + this.try_again_menu_items [i] = new NSMenuItem (); + this.try_again_menu_items [i].Title = "Try Again"; this.try_again_menu_items [i].Activated += Controller.TryAgainDelegate (folder_name);; - + item.Submenu.AddItem (this.error_menu_items [i]); item.Submenu.AddItem (NSMenuItem.SeparatorItem); item.Submenu.AddItem (this.try_again_menu_items [i]); @@ -225,37 +194,31 @@ namespace SparkleShare { } item.Image.Size = new SizeF (16, 16); - i++; }; } + + this.menu.AddItem (this.state_item); + this.menu.AddItem (NSMenuItem.SeparatorItem); + this.menu.AddItem (this.folder_item); + + this.submenu = new NSMenu (); + + this.submenu.AddItem (this.recent_events_item); + this.submenu.AddItem (this.add_item); + this.submenu.AddItem (NSMenuItem.SeparatorItem); + this.submenu.AddItem (this.about_item); + + this.folder_item.Submenu = this.submenu; + foreach (NSMenuItem item in this.folder_menu_items) this.menu.AddItem (item); this.menu.AddItem (NSMenuItem.SeparatorItem); this.menu.AddItem (this.quit_item); - this.menu.Delegate = new SparkleStatusIconMenuDelegate (); this.status_item.Menu = this.menu; } } - - - public class SparkleStatusIconMenuDelegate : NSMenuDelegate { - - public SparkleStatusIconMenuDelegate () - { - } - - - public SparkleStatusIconMenuDelegate (IntPtr handle) : base (handle) - { - } - - - public override void MenuWillHighlightItem (NSMenu menu, NSMenuItem item) - { - } - } } diff --git a/SparkleShare/Mac/SparkleUI.cs b/SparkleShare/Mac/SparkleUI.cs index b435b9f6..24ae0701 100755 --- a/SparkleShare/Mac/SparkleUI.cs +++ b/SparkleShare/Mac/SparkleUI.cs @@ -48,11 +48,11 @@ namespace SparkleShare { NSApplication.SharedApplication.ApplicationIconImage = NSImage.ImageNamed ("sparkleshare-app.icns"); - Setup = new SparkleSetup (); - EventLog = new SparkleEventLog (); - About = new SparkleAbout (); - Bubbles = new SparkleBubbles (); - StatusIcon = new SparkleStatusIcon (); + Setup = new SparkleSetup (); + EventLog = new SparkleEventLog (); + About = new SparkleAbout (); + Bubbles = new SparkleBubbles (); + StatusIcon = new SparkleStatusIcon (); }); Program.Controller.UIHasLoaded (); diff --git a/SparkleShare/SparkleStatusIconController.cs b/SparkleShare/SparkleStatusIconController.cs index e208cc0d..a97e5a2f 100755 --- a/SparkleShare/SparkleStatusIconController.cs +++ b/SparkleShare/SparkleStatusIconController.cs @@ -46,7 +46,7 @@ namespace SparkleShare { public delegate void UpdateQuitItemEventHandler (bool quit_item_enabled); public IconState CurrentState = IconState.Idle; - public string StateText = "Welcome to SparkleShare!"; + public string StateText = "Welcome to SparkleShare!"; public string [] Folders; public string [] FolderErrors; @@ -201,20 +201,13 @@ namespace SparkleShare { public void TryAgainClicked (string subfolder) { - foreach (SparkleRepoBase repo in Program.Controller.Repositories) { + foreach (SparkleRepoBase repo in Program.Controller.Repositories) if (repo.Name.Equals (subfolder)) new Thread (() => repo.ForceRetry ()).Start (); - } } - public void AddHostedProjectClicked () - { - new Thread (() => Program.Controller.ShowSetupWindow (PageType.Add)).Start (); - } - - - public void RecentEventsClicked () + public void RecentEventsClicked (object sender, EventArgs args) { new Thread (() => { while (!Program.Controller.RepositoriesLoaded) @@ -226,13 +219,19 @@ namespace SparkleShare { } - public void AboutClicked () + public void AddHostedProjectClicked (object sender, EventArgs args) + { + new Thread (() => Program.Controller.ShowSetupWindow (PageType.Add)).Start (); + } + + + public void AboutClicked (object sender, EventArgs args) { Program.Controller.ShowAboutWindow (); } - public void QuitClicked () + public void QuitClicked (object sender, EventArgs args) { Program.Controller.Quit (); } @@ -240,17 +239,13 @@ namespace SparkleShare { public EventHandler OpenFolderDelegate (string subfolder) { - return delegate { - SubfolderClicked (subfolder); - }; + return delegate { SubfolderClicked (subfolder); }; } public EventHandler TryAgainDelegate (string subfolder) { - return delegate { - TryAgainClicked (subfolder); - }; + return delegate { TryAgainClicked (subfolder); }; }