diff --git a/SparkleShare/Mac/SparkleAbout.cs b/SparkleShare/Mac/SparkleAbout.cs index ba0dbcab..d8be9b46 100755 --- a/SparkleShare/Mac/SparkleAbout.cs +++ b/SparkleShare/Mac/SparkleAbout.cs @@ -45,163 +45,138 @@ namespace SparkleShare { public SparkleAbout () : base () { - using (var a = new NSAutoreleasePool ()) - { - SetFrame (new RectangleF (0, 0, 640, 281), true); - Center (); + SetFrame (new RectangleF (0, 0, 640, 281), true); + Center (); - Delegate = new SparkleAboutDelegate (); - StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Titled); - Title = "About SparkleShare"; - MaxSize = new SizeF (640, 281); - MinSize = new SizeF (640, 281); - HasShadow = true; - BackingType = NSBackingStore.Buffered; + Delegate = new SparkleAboutDelegate (); + StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Titled); + Title = "About SparkleShare"; + MaxSize = new SizeF (640, 281); + MinSize = new SizeF (640, 281); + HasShadow = true; + BackingType = NSBackingStore.Buffered; - this.website_link = new SparkleLink ("Website", Controller.WebsiteLinkAddress); - this.website_link.Frame = new RectangleF (new PointF (295, 25), this.website_link.Frame.Size); + this.website_link = new SparkleLink ("Website", Controller.WebsiteLinkAddress); + this.website_link.Frame = new RectangleF (new PointF (295, 25), this.website_link.Frame.Size); - this.credits_link = new SparkleLink ("Credits", Controller.CreditsLinkAddress); - this.credits_link.Frame = new RectangleF ( - new PointF (this.website_link.Frame.X + this.website_link.Frame.Width + 10, 25), - this.credits_link.Frame.Size); + this.credits_link = new SparkleLink ("Credits", Controller.CreditsLinkAddress); + this.credits_link.Frame = new RectangleF ( + new PointF (this.website_link.Frame.X + this.website_link.Frame.Width + 10, 25), + this.credits_link.Frame.Size); - this.report_problem_link = new SparkleLink ("Report a problem", Controller.ReportProblemLinkAddress); - this.report_problem_link.Frame = new RectangleF ( - new PointF (this.credits_link.Frame.X + this.credits_link.Frame.Width + 10, 25), - this.report_problem_link.Frame.Size); + this.report_problem_link = new SparkleLink ("Report a problem", Controller.ReportProblemLinkAddress); + this.report_problem_link.Frame = new RectangleF ( + new PointF (this.credits_link.Frame.X + this.credits_link.Frame.Width + 10, 25), + this.report_problem_link.Frame.Size); - this.debug_log_link = new SparkleLink ("Debug log", Controller.DebugLogLinkAddress); - this.debug_log_link.Frame = new RectangleF ( - new PointF (this.report_problem_link.Frame.X + this.report_problem_link.Frame.Width + 10, 25), - this.debug_log_link.Frame.Size); + this.debug_log_link = new SparkleLink ("Debug log", Controller.DebugLogLinkAddress); + this.debug_log_link.Frame = new RectangleF ( + new PointF (this.report_problem_link.Frame.X + this.report_problem_link.Frame.Width + 10, 25), + this.debug_log_link.Frame.Size); - this.hidden_close_button = new NSButton () { - Frame = new RectangleF (0, 0, 0, 0), - KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask, - KeyEquivalent = "w" - }; + this.hidden_close_button = new NSButton () { + Frame = new RectangleF (0, 0, 0, 0), + KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask, + KeyEquivalent = "w" + }; - this.hidden_close_button.Activated += delegate { - Controller.WindowClosed (); - }; + this.hidden_close_button.Activated += delegate { + Controller.WindowClosed (); + }; - ContentView.AddSubview (this.hidden_close_button); + ContentView.AddSubview (this.hidden_close_button); - CreateAbout (); + CreateAbout (); - ContentView.AddSubview (this.website_link); - ContentView.AddSubview (this.credits_link); - ContentView.AddSubview (this.report_problem_link); - ContentView.AddSubview (this.debug_log_link); - } + ContentView.AddSubview (this.website_link); + ContentView.AddSubview (this.credits_link); + ContentView.AddSubview (this.report_problem_link); + ContentView.AddSubview (this.debug_log_link); Controller.HideWindowEvent += delegate { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - PerformClose (this); - }); - } + Program.Controller.Invoke (() => PerformClose (this)); }; Controller.ShowWindowEvent += delegate { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - OrderFrontRegardless (); - }); - } + Program.Controller.Invoke (() => OrderFrontRegardless ()); }; Controller.NewVersionEvent += delegate (string new_version) { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - this.updates_text_field.StringValue = "A newer version (" + new_version + ") is available!"; - }); - } + Program.Controller.Invoke (() => { + this.updates_text_field.StringValue = "A newer version (" + new_version + ") is available!"; + }); }; Controller.VersionUpToDateEvent += delegate { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - this.updates_text_field.StringValue = "You are running the latest version."; - }); - } + Program.Controller.Invoke (() => { + this.updates_text_field.StringValue = "You are running the latest version."; + }); }; Controller.CheckingForNewVersionEvent += delegate { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - this.updates_text_field.StringValue = "Checking for updates..."; - }); - } + Program.Controller.Invoke (() => { + this.updates_text_field.StringValue = "Checking for updates..."; + }); }; } private void CreateAbout () { - using (var a = new NSAutoreleasePool ()) - { - string about_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "about.png"); + string about_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "about.png"); - this.about_image = new NSImage (about_image_path); - this.about_image.Size = new SizeF (640, 260); + this.about_image = new NSImage (about_image_path); + this.about_image.Size = new SizeF (640, 260); - this.about_image_view = new NSImageView () { - Image = this.about_image, - Frame = new RectangleF (0, 0, 640, 260) - }; + this.about_image_view = new NSImageView () { + Image = this.about_image, + Frame = new RectangleF (0, 0, 640, 260) + }; - this.version_text_field = new NSTextField () { - StringValue = "version " + Controller.RunningVersion, - Frame = new RectangleF (295, 140, 318, 22), - BackgroundColor = NSColor.White, - Bordered = false, - Editable = false, - DrawsBackground = false, - TextColor = NSColor.White, - Font = NSFontManager.SharedFontManager.FontWithFamily - ("Lucida Grande", NSFontTraitMask.Unbold, 0, 11) - }; + this.version_text_field = new NSTextField () { + StringValue = "version " + Controller.RunningVersion, + Frame = new RectangleF (295, 140, 318, 22), + BackgroundColor = NSColor.White, + Bordered = false, + Editable = false, + DrawsBackground = false, + TextColor = NSColor.White, + Font = NSFontManager.SharedFontManager.FontWithFamily + ("Lucida Grande", NSFontTraitMask.Unbold, 0, 11) + }; - this.updates_text_field = new NSTextField () { - StringValue = "Checking for updates...", - Frame = new RectangleF (295, Frame.Height - 232, 318, 98), - Bordered = false, - Editable = false, - DrawsBackground = false, - Font = NSFontManager.SharedFontManager.FontWithFamily - ("Lucida Grande", NSFontTraitMask.Unbold, 0, 11), - TextColor = NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f) // Tango Sky Blue #1 - }; + this.updates_text_field = new NSTextField () { + StringValue = "Checking for updates...", + Frame = new RectangleF (295, Frame.Height - 232, 318, 98), + Bordered = false, + Editable = false, + DrawsBackground = false, + Font = NSFontManager.SharedFontManager.FontWithFamily + ("Lucida Grande", NSFontTraitMask.Unbold, 0, 11), + TextColor = NSColor.FromCalibratedRgba (0.45f, 0.62f, 0.81f, 1.0f) // Tango Sky Blue #1 + }; - this.credits_text_field = new NSTextField () { - StringValue = @"Copyright © 2010–" + DateTime.Now.Year + " Hylke Bons and others." + - "\n" + - "\n" + - "SparkleShare is Open Source software. You are free to use, modify, and redistribute it " + - "under the GNU General Public License version 3 or later.", - Frame = new RectangleF (295, Frame.Height - 260, 318, 98), - TextColor = NSColor.White, - DrawsBackground = false, - Bordered = false, - Editable = false, - Font = NSFontManager.SharedFontManager.FontWithFamily ( - "Lucida Grande", NSFontTraitMask.Unbold, 0, 11), - }; + this.credits_text_field = new NSTextField () { + StringValue = @"Copyright © 2010–" + DateTime.Now.Year + " Hylke Bons and others." + + "\n" + + "\n" + + "SparkleShare is Open Source software. You are free to use, modify, and redistribute it " + + "under the GNU General Public License version 3 or later.", + Frame = new RectangleF (295, Frame.Height - 260, 318, 98), + TextColor = NSColor.White, + DrawsBackground = false, + Bordered = false, + Editable = false, + Font = NSFontManager.SharedFontManager.FontWithFamily ( + "Lucida Grande", NSFontTraitMask.Unbold, 0, 11), + }; - ContentView.AddSubview (this.about_image_view); - ContentView.AddSubview (this.version_text_field); - ContentView.AddSubview (this.updates_text_field); - ContentView.AddSubview (this.credits_text_field); - } + ContentView.AddSubview (this.about_image_view); + ContentView.AddSubview (this.version_text_field); + ContentView.AddSubview (this.updates_text_field); + ContentView.AddSubview (this.credits_text_field); } diff --git a/SparkleShare/Mac/SparkleController.cs b/SparkleShare/Mac/SparkleController.cs index 56ce4b61..3fc3a319 100755 --- a/SparkleShare/Mac/SparkleController.cs +++ b/SparkleShare/Mac/SparkleController.cs @@ -227,5 +227,17 @@ namespace SparkleShare { return this.event_entry_html; } } + + + public delegate void Code (); + private NSObject obj = new NSObject (); + + public void Invoke (Code code) + { + using (var a = new NSAutoreleasePool ()) + { + obj.InvokeOnMainThread (() => code ()); + } + } } } diff --git a/SparkleShare/Mac/SparkleEventLog.cs b/SparkleShare/Mac/SparkleEventLog.cs index 03d6a8a0..8161677a 100755 --- a/SparkleShare/Mac/SparkleEventLog.cs +++ b/SparkleShare/Mac/SparkleEventLog.cs @@ -50,363 +50,317 @@ namespace SparkleShare { public SparkleEventLog () : base () { - using (var a = new NSAutoreleasePool ()) - { - Title = "Recent Changes"; - Delegate = new SparkleEventsDelegate (); + Title = "Recent Changes"; + Delegate = new SparkleEventsDelegate (); - int min_width = 480; - int min_height = 640; - float x = (float) (NSScreen.MainScreen.Frame.Width * 0.61); - float y = (float) (NSScreen.MainScreen.Frame.Height * 0.5 - (min_height * 0.5)); + int min_width = 480; + int min_height = 640; + float x = (float) (NSScreen.MainScreen.Frame.Width * 0.61); + float y = (float) (NSScreen.MainScreen.Frame.Height * 0.5 - (min_height * 0.5)); - SetFrame ( - new RectangleF ( - new PointF (x, y), - new SizeF (min_width, (int) (NSScreen.MainScreen.Frame.Height * 0.85))), - true); + SetFrame ( + new RectangleF ( + new PointF (x, y), + new SizeF (min_width, (int) (NSScreen.MainScreen.Frame.Height * 0.85))), + true); - StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | - NSWindowStyle.Titled | NSWindowStyle.Resizable); + StyleMask = (NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | + NSWindowStyle.Titled | NSWindowStyle.Resizable); - MinSize = new SizeF (min_width, min_height); - HasShadow = true; - BackingType = NSBackingStore.Buffered; - TitlebarHeight = Frame.Height - ContentView.Frame.Height; + MinSize = new SizeF (min_width, min_height); + HasShadow = true; + BackingType = NSBackingStore.Buffered; + TitlebarHeight = Frame.Height - ContentView.Frame.Height; - this.web_view = new WebView (new RectangleF (0, 0, 481, 579), "", "") { - Frame = new RectangleF (new PointF (0, 0), - new SizeF (ContentView.Frame.Width, ContentView.Frame.Height - 39)) - }; + this.web_view = new WebView (new RectangleF (0, 0, 481, 579), "", "") { + Frame = new RectangleF (new PointF (0, 0), + new SizeF (ContentView.Frame.Width, ContentView.Frame.Height - 39)) + }; - this.hidden_close_button = new NSButton () { - KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask, - KeyEquivalent = "w" - }; + this.hidden_close_button = new NSButton () { + KeyEquivalentModifierMask = NSEventModifierMask.CommandKeyMask, + KeyEquivalent = "w" + }; - this.hidden_close_button.Activated += delegate { - Controller.WindowClosed (); - }; + this.hidden_close_button.Activated += delegate { + Controller.WindowClosed (); + }; - this.size_label = new NSTextField () { - Alignment = NSTextAlignment.Right, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF ( - new PointF (0, ContentView.Frame.Height - 30), - new SizeF (60, 20)), - StringValue = "Size:", - Font = SparkleUI.BoldFont - }; + this.size_label = new NSTextField () { + Alignment = NSTextAlignment.Right, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF ( + new PointF (0, ContentView.Frame.Height - 30), + new SizeF (60, 20)), + StringValue = "Size:", + Font = SparkleUI.BoldFont + }; - this.size_label_value = new NSTextField () { - Alignment = NSTextAlignment.Left, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF ( - new PointF (60, ContentView.Frame.Height - 30), - new SizeF (60, 20)), - StringValue = "…", - Font = SparkleUI.Font - }; + this.size_label_value = new NSTextField () { + Alignment = NSTextAlignment.Left, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF ( + new PointF (60, ContentView.Frame.Height - 30), + new SizeF (60, 20)), + StringValue = "…", + Font = SparkleUI.Font + }; - this.history_label = new NSTextField () { - Alignment = NSTextAlignment.Right, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF ( - new PointF (130, ContentView.Frame.Height - 30), - new SizeF (60, 20)), - StringValue = "History:", - Font = SparkleUI.BoldFont - }; + this.history_label = new NSTextField () { + Alignment = NSTextAlignment.Right, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF ( + new PointF (130, ContentView.Frame.Height - 30), + new SizeF (60, 20)), + StringValue = "History:", + Font = SparkleUI.BoldFont + }; - this.history_label_value = new NSTextField () { - Alignment = NSTextAlignment.Left, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF ( - new PointF (190, ContentView.Frame.Height - 30), - new SizeF (60, 20) - ), - StringValue = "…", - Font = SparkleUI.Font - }; + this.history_label_value = new NSTextField () { + Alignment = NSTextAlignment.Left, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF ( + new PointF (190, ContentView.Frame.Height - 30), + new SizeF (60, 20) + ), + StringValue = "…", + Font = SparkleUI.Font + }; - this.popup_button = new NSPopUpButton () { - Frame = new RectangleF ( - new PointF (ContentView.Frame.Width - 156 - 12, ContentView.Frame.Height - 33), - new SizeF (156, 26)), - PullsDown = false - }; + this.popup_button = new NSPopUpButton () { + Frame = new RectangleF ( + new PointF (ContentView.Frame.Width - 156 - 12, ContentView.Frame.Height - 33), + new SizeF (156, 26)), + PullsDown = false + }; - this.background = new NSBox () { - Frame = new RectangleF ( - new PointF (-1, -1), - new SizeF (Frame.Width + 2, this.web_view.Frame.Height + 2)), - FillColor = NSColor.White, - BorderColor = NSColor.LightGray, - BoxType = NSBoxType.NSBoxCustom - }; + this.background = new NSBox () { + Frame = new RectangleF ( + new PointF (-1, -1), + new SizeF (Frame.Width + 2, this.web_view.Frame.Height + 2)), + FillColor = NSColor.White, + BorderColor = NSColor.LightGray, + BoxType = NSBoxType.NSBoxCustom + }; - this.progress_indicator = new NSProgressIndicator () { - Frame = new RectangleF ( - new PointF (Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10), - new SizeF (20, 20)), - Style = NSProgressIndicatorStyle.Spinning - }; + this.progress_indicator = new NSProgressIndicator () { + Frame = new RectangleF ( + new PointF (Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10), + new SizeF (20, 20)), + Style = NSProgressIndicatorStyle.Spinning + }; - this.progress_indicator.StartAnimation (this); + this.progress_indicator.StartAnimation (this); - ContentView.AddSubview (this.size_label); - ContentView.AddSubview (this.size_label_value); - ContentView.AddSubview (this.history_label); - ContentView.AddSubview (this.history_label_value); - ContentView.AddSubview (this.popup_button); - ContentView.AddSubview (this.progress_indicator); - ContentView.AddSubview (this.background); - ContentView.AddSubview (this.hidden_close_button); + ContentView.AddSubview (this.size_label); + ContentView.AddSubview (this.size_label_value); + ContentView.AddSubview (this.history_label); + ContentView.AddSubview (this.history_label_value); + ContentView.AddSubview (this.popup_button); + ContentView.AddSubview (this.progress_indicator); + ContentView.AddSubview (this.background); + ContentView.AddSubview (this.hidden_close_button); - (Delegate as SparkleEventsDelegate).WindowResized += Relayout; - } + (Delegate as SparkleEventsDelegate).WindowResized += delegate (SizeF new_window_size) { + Program.Controller.Invoke (() => { + Relayout (new_window_size); + }); + }; // Hook up the controller events Controller.HideWindowEvent += delegate { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - this.progress_indicator.Hidden = true; - PerformClose (this); - }); - } + Program.Controller.Invoke (() => { + this.progress_indicator.Hidden = true; + PerformClose (this); + }); }; Controller.ShowWindowEvent += delegate { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - OrderFrontRegardless (); - }); - } + Program.Controller.Invoke (() => OrderFrontRegardless ()); }; Controller.UpdateChooserEvent += delegate (string [] folders) { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - UpdateChooser (folders); - }); - } + Program.Controller.Invoke (() => UpdateChooser (folders)); }; Controller.UpdateChooserEnablementEvent += delegate (bool enabled) { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - this.popup_button.Enabled = enabled; - }); - } + Program.Controller.Invoke (() => { this.popup_button.Enabled = enabled; }); }; Controller.UpdateContentEvent += delegate (string html) { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - this.progress_indicator.Hidden = true; - UpdateContent (html); - }); - } + Program.Controller.Invoke (() => { + this.progress_indicator.Hidden = true; + UpdateContent (html); + }); }; Controller.ContentLoadingEvent += delegate { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - this.web_view.RemoveFromSuperview (); - this.progress_indicator.Hidden = false; - - this.progress_indicator.StartAnimation (this); - }); - } + Program.Controller.Invoke (() => { + this.web_view.RemoveFromSuperview (); + this.progress_indicator.Hidden = false; + this.progress_indicator.StartAnimation (this); + }); }; Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - this.size_label_value.StringValue = size; - this.history_label_value.StringValue = history_size; - }); - } + Program.Controller.Invoke (() => { + this.size_label_value.StringValue = size; + this.history_label_value.StringValue = history_size; + }); }; Controller.ShowSaveDialogEvent += delegate (string file_name, string target_folder_path) { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (() => { - // TODO: Make this a sheet - NSSavePanel panel = new NSSavePanel () { - DirectoryUrl = new NSUrl (target_folder_path, true), - NameFieldStringValue = file_name, - ParentWindow = this, - Title = "Restore from History", - PreventsApplicationTerminationWhenModal = false - }; + Program.Controller.Invoke (() => { + NSSavePanel panel = new NSSavePanel () { + DirectoryUrl = new NSUrl (target_folder_path, true), + NameFieldStringValue = file_name, + ParentWindow = this, + Title = "Restore from History", + PreventsApplicationTerminationWhenModal = false + }; - if ((NSPanelButtonType) panel.RunModal () == NSPanelButtonType.Ok) { - string target_file_path = Path.Combine (panel.DirectoryUrl.RelativePath, - panel.NameFieldStringValue); - - Controller.SaveDialogCompleted (target_file_path); - - } else { - Controller.SaveDialogCancelled (); - } - }); - } + if ((NSPanelButtonType) panel.RunModal () == NSPanelButtonType.Ok) { + string target_file_path = Path.Combine (panel.DirectoryUrl.RelativePath, panel.NameFieldStringValue); + Controller.SaveDialogCompleted (target_file_path); + + } else { + Controller.SaveDialogCancelled (); + } + }); }; } public void Relayout (SizeF new_window_size) { - InvokeOnMainThread (delegate { - this.web_view.Frame = new RectangleF (this.web_view.Frame.Location, - new SizeF (new_window_size.Width, new_window_size.Height - TitlebarHeight - 39)); + this.web_view.Frame = new RectangleF (this.web_view.Frame.Location, + new SizeF (new_window_size.Width, new_window_size.Height - TitlebarHeight - 39)); - this.background.Frame = new RectangleF (this.background.Frame.Location, - new SizeF (new_window_size.Width, new_window_size.Height - TitlebarHeight - 37)); + this.background.Frame = new RectangleF (this.background.Frame.Location, + new SizeF (new_window_size.Width, new_window_size.Height - TitlebarHeight - 37)); - 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 = new RectangleF ( + new PointF (this.size_label.Frame.X, new_window_size.Height - TitlebarHeight - 30), + 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 = new RectangleF ( + new PointF (this.size_label_value.Frame.X, new_window_size.Height - TitlebarHeight - 30), + 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 = new RectangleF ( + new PointF (this.history_label.Frame.X, new_window_size.Height - TitlebarHeight - 30), + 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 = new RectangleF ( + new PointF (this.history_label_value.Frame.X, new_window_size.Height - TitlebarHeight - 30), + this.history_label_value.Frame.Size + ); - this.popup_button.RemoveFromSuperview (); // Needed to prevent redraw glitches + 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 = 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 + ); - ContentView.AddSubview (this.popup_button); + 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 - ); - }); + 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 + ); } public void UpdateChooser (string [] folders) { - using (var a = new NSAutoreleasePool ()) - { - if (folders == null) - folders = Controller.Folders; + if (folders == null) + folders = Controller.Folders; - this.popup_button.Cell.ControlSize = NSControlSize.Small; - this.popup_button.Font = NSFontManager.SharedFontManager.FontWithFamily - ("Lucida Grande", NSFontTraitMask.Condensed, 0, NSFont.SmallSystemFontSize); + this.popup_button.Cell.ControlSize = NSControlSize.Small; + this.popup_button.Font = NSFontManager.SharedFontManager.FontWithFamily + ("Lucida Grande", NSFontTraitMask.Condensed, 0, NSFont.SmallSystemFontSize); - this.popup_button.RemoveAllItems (); - - this.popup_button.AddItem ("Summary"); - this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem); + this.popup_button.RemoveAllItems (); + + this.popup_button.AddItem ("Summary"); + this.popup_button.Menu.AddItem (NSMenuItem.SeparatorItem); + + int row = 2; + foreach (string folder in folders) { + this.popup_button.AddItem (folder); - int row = 2; - foreach (string folder in folders) { - this.popup_button.AddItem (folder); - - if (folder.Equals (Controller.SelectedFolder)) - this.popup_button.SelectItem (row); - - row++; - } + if (folder.Equals (Controller.SelectedFolder)) + this.popup_button.SelectItem (row); - this.popup_button.AddItems (folders); - - this.popup_button.Activated += delegate { - using (var b = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - if (this.popup_button.IndexOfSelectedItem == 0) - Controller.SelectedFolder = null; - else - Controller.SelectedFolder = this.popup_button.SelectedItem.Title; - }); - } - }; - } + row++; + } + + this.popup_button.AddItems (folders); + + this.popup_button.Activated += delegate { + Program.Controller.Invoke (() => { + if (this.popup_button.IndexOfSelectedItem == 0) + Controller.SelectedFolder = null; + else + Controller.SelectedFolder = this.popup_button.SelectedItem.Title; + }); + }; } public void UpdateContent (string html) { - using (var a = new NSAutoreleasePool ()) - { - string pixmaps_path = "file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps"); - - html = html.Replace ("", "Lucida Grande"); - html = html.Replace ("", "13.6px"); - html = html.Replace ("", "13.4px"); - html = html.Replace ("", "#bbb"); - html = html.Replace ("", "#ddd"); - html = html.Replace ("", "10px"); - html = html.Replace ("", "#f5f5f5"); - html = html.Replace ("", "#0085cf"); - html = html.Replace ("", "#009ff8"); - html = html.Replace ("", pixmaps_path); - html = html.Replace ("", pixmaps_path + "/document-added-12.png"); - html = html.Replace ("", pixmaps_path + "/document-deleted-12.png"); - html = html.Replace ("", pixmaps_path + "/document-edited-12.png"); - html = html.Replace ("", pixmaps_path + "/document-moved-12.png"); - - this.web_view = new WebView (new RectangleF (0, 0, 481, 579), "", "") { - Frame = new RectangleF (new PointF (0, 0), - new SizeF (ContentView.Frame.Width, ContentView.Frame.Height - 39)) - }; + string pixmaps_path = "file://" + Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps"); + + html = html.Replace ("", "Lucida Grande"); + html = html.Replace ("", "13.6px"); + html = html.Replace ("", "13.4px"); + html = html.Replace ("", "#bbb"); + html = html.Replace ("", "#ddd"); + html = html.Replace ("", "10px"); + html = html.Replace ("", "#f5f5f5"); + html = html.Replace ("", "#0085cf"); + html = html.Replace ("", "#009ff8"); + html = html.Replace ("", pixmaps_path); + html = html.Replace ("", pixmaps_path + "/document-added-12.png"); + html = html.Replace ("", pixmaps_path + "/document-deleted-12.png"); + html = html.Replace ("", pixmaps_path + "/document-edited-12.png"); + html = html.Replace ("", pixmaps_path + "/document-moved-12.png"); + + this.web_view = new WebView (new RectangleF (0, 0, 481, 579), "", "") { + Frame = new RectangleF (new PointF (0, 0), new SizeF (ContentView.Frame.Width, ContentView.Frame.Height - 39)) + }; - this.web_view.MainFrame.LoadHtmlString (html, new NSUrl ("")); + this.web_view.MainFrame.LoadHtmlString (html, new NSUrl ("")); - this.web_view.PolicyDelegate = new SparkleWebPolicyDelegate (); - ContentView.AddSubview (this.web_view); + this.web_view.PolicyDelegate = new SparkleWebPolicyDelegate (); + ContentView.AddSubview (this.web_view); - (this.web_view.PolicyDelegate as SparkleWebPolicyDelegate).LinkClicked += - delegate (string href) { - if (href.StartsWith ("file:///")) - href = href.Substring (7); + (this.web_view.PolicyDelegate as SparkleWebPolicyDelegate).LinkClicked += delegate (string href) { + if (href.StartsWith ("file:///")) + href = href.Substring (7); - Controller.LinkClicked (href); - }; + Controller.LinkClicked (href); + }; - this.progress_indicator.Hidden = true; - } + this.progress_indicator.Hidden = true; } diff --git a/SparkleShare/Mac/SparkleSetup.cs b/SparkleShare/Mac/SparkleSetup.cs index c08b2fbc..7fe6022a 100755 --- a/SparkleShare/Mac/SparkleSetup.cs +++ b/SparkleShare/Mac/SparkleSetup.cs @@ -33,68 +33,43 @@ namespace SparkleShare { public SparkleSetupController Controller = new SparkleSetupController (); - private NSButton ContinueButton; - private NSButton AddButton; - private NSButton CopyButton; - private NSButton TryAgainButton; - private NSButton CancelButton; - private NSButton SkipTutorialButton; - private NSButton StartupCheckButton; - private NSButton HistoryCheckButton; - private NSButton ShowPasswordCheckButton; - private NSButton ShowFilesButton; - private NSButton FinishButton; - private NSImage SlideImage; - private NSImageView SlideImageView; + private NSButton ContinueButton, AddButton, CopyButton, TryAgainButton, CancelButton, + SkipTutorialButton, FinishButton, ShowFilesButton; + + private NSTextField FullNameTextField, FullNameLabel, EmailLabel, EmailTextField, EmailHelpLabel, + LinkCodeTextField, AddressTextField, AddressLabel, AddressHelpLabel, PathTextField, PathLabel, + PathHelpLabel, PasswordTextField, VisiblePasswordTextField, PasswordLabel, WarningTextField; + + private NSButton StartupCheckButton, HistoryCheckButton, ShowPasswordCheckButton; private NSProgressIndicator ProgressIndicator; - private NSTextField EmailLabel; - private NSTextField EmailTextField; - private NSTextField EmailHelpLabel; - private NSTextField FullNameTextField; - private NSTextField FullNameLabel; - private NSTextField LinkCodeTextField; - private NSTextField AddressTextField; - private NSTextField AddressLabel; - private NSTextField AddressHelpLabel; - private NSTextField PathTextField; - private NSTextField PathLabel; - private NSTextField PathHelpLabel; - private NSTextField PasswordTextField; - private NSTextField VisiblePasswordTextField; - private NSTextField PasswordLabel; - private NSTextField WarningTextField; - private NSImage WarningImage; - private NSImageView WarningImageView; + private NSImage WarningImage, SlideImage; + private NSImageView WarningImageView, SlideImageView; + private NSTableColumn IconColumn, DescriptionColumn; private NSTableView TableView; private NSScrollView ScrollView; - private NSTableColumn IconColumn; - private NSTableColumn DescriptionColumn; private SparkleDataSource DataSource; public SparkleSetup () : base () { Controller.HideWindowEvent += delegate { - InvokeOnMainThread (delegate { + Program.Controller.Invoke (() => { PerformClose (this); }); }; Controller.ShowWindowEvent += delegate { - InvokeOnMainThread (delegate { + Program.Controller.Invoke (() => { OrderFrontRegardless (); }); }; Controller.ChangePageEvent += delegate (PageType type, string [] warnings) { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - Reset (); - ShowPage (type, warnings); - ShowAll (); - }); - } + Program.Controller.Invoke (() => { + Reset (); + ShowPage (type, warnings); + ShowAll (); + }); }; } @@ -180,7 +155,7 @@ namespace SparkleShare { }; Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) { - InvokeOnMainThread (delegate { + Program.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; }); }; @@ -399,7 +374,7 @@ namespace SparkleShare { Controller.ChangeAddressFieldEvent += delegate (string text, string example_text, FieldState state) { - InvokeOnMainThread (delegate { + Program.Controller.Invoke (() => { AddressTextField.StringValue = text; AddressTextField.Enabled = (state == FieldState.Enabled); AddressHelpLabel.StringValue = example_text; @@ -409,7 +384,7 @@ namespace SparkleShare { Controller.ChangePathFieldEvent += delegate (string text, string example_text, FieldState state) { - InvokeOnMainThread (delegate { + Program.Controller.Invoke (() => { PathTextField.StringValue = text; PathTextField.Enabled = (state == FieldState.Enabled); PathHelpLabel.StringValue = example_text; @@ -445,7 +420,7 @@ namespace SparkleShare { }; Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) { - InvokeOnMainThread (delegate { + Program.Controller.Invoke (() => { AddButton.Enabled = button_enabled; }); }; @@ -493,7 +468,7 @@ namespace SparkleShare { Controller.UpdateProgressBarEvent += delegate (double percentage) { - InvokeOnMainThread (() => { + Program.Controller.Invoke (() => { ProgressIndicator.DoubleValue = percentage; }); }; @@ -664,7 +639,7 @@ namespace SparkleShare { Controller.UpdateCryptoSetupContinueButtonEvent += delegate (bool button_enabled) { - InvokeOnMainThread (() => { + Program.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; }); }; @@ -733,7 +708,7 @@ namespace SparkleShare { Controller.UpdateCryptoPasswordContinueButtonEvent += delegate (bool button_enabled) { - InvokeOnMainThread (() => { + Program.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; }); }; diff --git a/SparkleShare/Mac/SparkleStatusIcon.cs b/SparkleShare/Mac/SparkleStatusIcon.cs index 96924fe3..d7380d3c 100755 --- a/SparkleShare/Mac/SparkleStatusIcon.cs +++ b/SparkleShare/Mac/SparkleStatusIcon.cs @@ -29,17 +29,13 @@ namespace SparkleShare { public SparkleStatusIconController Controller = new SparkleStatusIconController (); + private NSStatusItem status_item = NSStatusBar.SystemStatusBar.CreateStatusItem (28); + private NSMenu menu; private NSMenu submenu; - 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; @@ -61,26 +57,24 @@ namespace SparkleShare { 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 () { - using (var a = new NSAutoreleasePool ()) - { - 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.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); - CreateMenu (); - } - + CreateMenu (); Controller.UpdateIconEvent += delegate (IconState state) { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - switch (state) { + Program.Controller.Invoke (() => { + switch (state) { case IconState.Idle: { this.status_item.Image = this.syncing_idle_image; this.status_item.AlternateImage = this.syncing_idle_image_active; @@ -106,161 +100,144 @@ namespace SparkleShare { this.status_item.AlternateImage = this.syncing_error_image_active; break; } - } + } - this.status_item.Image.Size = new SizeF (16, 16); - this.status_item.AlternateImage.Size = new SizeF (16, 16); - }); - } + this.status_item.Image.Size = new SizeF (16, 16); + this.status_item.AlternateImage.Size = new SizeF (16, 16); + }); }; - + Controller.UpdateStatusItemEvent += delegate (string state_text) { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - this.state_item.Title = state_text; - }); - } + Program.Controller.Invoke (() => { this.state_item.Title = state_text; }); }; Controller.UpdateMenuEvent += delegate { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (() => CreateMenu ()); - } + Program.Controller.Invoke (() => CreateMenu ()); }; Controller.UpdateQuitItemEvent += delegate (bool quit_item_enabled) { - using (var a = new NSAutoreleasePool ()) - { - InvokeOnMainThread (delegate { - this.quit_item.Enabled = quit_item_enabled; - }); - } + Program.Controller.Invoke (() => { this.quit_item.Enabled = quit_item_enabled; }); }; } public void CreateMenu () { - using (NSAutoreleasePool a = new NSAutoreleasePool ()) - { - this.menu = new NSMenu (); - this.menu.AutoEnablesItems = false; + this.menu = new NSMenu (); + this.menu.AutoEnablesItems = false; - this.state_item = new NSMenuItem () { - Title = Controller.StateText, - Enabled = false + this.state_item = new NSMenuItem () { + Title = Controller.StateText, + Enabled = false + }; + + this.folder_item = new NSMenuItem () { + 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.recent_events_item = new NSMenuItem () { + Title = "Recent Changes…", + Enabled = Controller.RecentEventsItemEnabled + }; + + if (Controller.Folders.Length > 0) { + this.recent_events_item.Activated += delegate { + Controller.RecentEventsClicked (); }; - - this.folder_item = new NSMenuItem () { - 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.recent_events_item = new NSMenuItem () { - Title = "Recent Changes…", - Enabled = Controller.RecentEventsItemEnabled - }; - - if (Controller.Folders.Length > 0) { - this.recent_events_item.Activated += delegate { - Controller.RecentEventsClicked (); - }; - } - - this.about_item = new NSMenuItem () { - Title = "About SparkleShare", - Enabled = true - }; - - this.about_item.Activated += delegate { - Controller.AboutClicked (); - }; - - this.quit_item = new NSMenuItem () { - Title = "Quit", - Enabled = Controller.QuitItemEnabled - }; - - this.quit_item.Activated += delegate { - 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.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; - 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.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]); - - } else { - item.Image = this.folder_image; - this.folder_menu_items [i].Activated += Controller.OpenFolderDelegate (folder_name); - } - - item.Image.Size = new SizeF (16, 16); - - i++; - }; - } - - 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; } + + this.about_item = new NSMenuItem () { + Title = "About SparkleShare", + Enabled = true + }; + + this.about_item.Activated += delegate { + Controller.AboutClicked (); + }; + + this.quit_item = new NSMenuItem () { + Title = "Quit", + Enabled = Controller.QuitItemEnabled + }; + + this.quit_item.Activated += delegate { + 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.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; + 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.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]); + + } else { + item.Image = this.folder_image; + this.folder_menu_items [i].Activated += Controller.OpenFolderDelegate (folder_name); + } + + item.Image.Size = new SizeF (16, 16); + + i++; + }; + } + + 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; } } diff --git a/SparkleShare/Mac/SparkleUI.cs b/SparkleShare/Mac/SparkleUI.cs index 97d75be6..b435b9f6 100755 --- a/SparkleShare/Mac/SparkleUI.cs +++ b/SparkleShare/Mac/SparkleUI.cs @@ -42,21 +42,20 @@ namespace SparkleShare { public SparkleUI () { - using (var a = new NSAutoreleasePool ()) - { - NSApplication.SharedApplication.ApplicationIconImage = NSImage.ImageNamed ("sparkleshare-app.icns"); - + Program.Controller.Invoke (() => { NSWorkspace.SharedWorkspace.SetIconforFile (NSImage.ImageNamed ("sparkleshare-folder.icns"), Program.Controller.FoldersPath, 0); - - Setup = new SparkleSetup (); - EventLog = new SparkleEventLog (); - About = new SparkleAbout (); - Bubbles = new SparkleBubbles (); - StatusIcon = new SparkleStatusIcon (); - Program.Controller.UIHasLoaded (); - } + NSApplication.SharedApplication.ApplicationIconImage = NSImage.ImageNamed ("sparkleshare-app.icns"); + + Setup = new SparkleSetup (); + EventLog = new SparkleEventLog (); + About = new SparkleAbout (); + Bubbles = new SparkleBubbles (); + StatusIcon = new SparkleStatusIcon (); + }); + + Program.Controller.UIHasLoaded (); }