mac: remove a lot of boilerplate
This commit is contained in:
parent
60f5ec1208
commit
3ac2fa214d
|
@ -44,8 +44,6 @@ namespace SparkleShare {
|
|||
public SparkleAbout (IntPtr handle) : base (handle) { }
|
||||
|
||||
public SparkleAbout () : base ()
|
||||
{
|
||||
using (var a = new NSAutoreleasePool ())
|
||||
{
|
||||
SetFrame (new RectangleF (0, 0, 640, 281), true);
|
||||
Center ();
|
||||
|
@ -95,58 +93,36 @@ namespace SparkleShare {
|
|||
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 {
|
||||
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 {
|
||||
Program.Controller.Invoke (() => {
|
||||
this.updates_text_field.StringValue = "You are running the latest version.";
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Controller.CheckingForNewVersionEvent += delegate {
|
||||
using (var a = new NSAutoreleasePool ())
|
||||
{
|
||||
InvokeOnMainThread (delegate {
|
||||
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");
|
||||
|
||||
|
@ -202,7 +178,6 @@ namespace SparkleShare {
|
|||
ContentView.AddSubview (this.updates_text_field);
|
||||
ContentView.AddSubview (this.credits_text_field);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void OrderFrontRegardless ()
|
||||
|
|
|
@ -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 ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,6 @@ namespace SparkleShare {
|
|||
|
||||
|
||||
public SparkleEventLog () : base ()
|
||||
{
|
||||
using (var a = new NSAutoreleasePool ())
|
||||
{
|
||||
Title = "Recent Changes";
|
||||
Delegate = new SparkleEventsDelegate ();
|
||||
|
@ -175,85 +173,57 @@ namespace SparkleShare {
|
|||
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 {
|
||||
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 {
|
||||
Program.Controller.Invoke (() => {
|
||||
this.progress_indicator.Hidden = true;
|
||||
UpdateContent (html);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Controller.ContentLoadingEvent += delegate {
|
||||
using (var a = new NSAutoreleasePool ())
|
||||
{
|
||||
InvokeOnMainThread (delegate {
|
||||
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 {
|
||||
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
|
||||
Program.Controller.Invoke (() => {
|
||||
NSSavePanel panel = new NSSavePanel () {
|
||||
DirectoryUrl = new NSUrl (target_folder_path, true),
|
||||
NameFieldStringValue = file_name,
|
||||
|
@ -263,23 +233,19 @@ namespace SparkleShare {
|
|||
};
|
||||
|
||||
if ((NSPanelButtonType) panel.RunModal () == NSPanelButtonType.Ok) {
|
||||
string target_file_path = Path.Combine (panel.DirectoryUrl.RelativePath,
|
||||
panel.NameFieldStringValue);
|
||||
|
||||
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));
|
||||
|
||||
|
@ -319,13 +285,10 @@ namespace SparkleShare {
|
|||
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;
|
||||
|
@ -352,23 +315,17 @@ namespace SparkleShare {
|
|||
this.popup_button.AddItems (folders);
|
||||
|
||||
this.popup_button.Activated += delegate {
|
||||
using (var b = new NSAutoreleasePool ())
|
||||
{
|
||||
InvokeOnMainThread (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");
|
||||
|
||||
|
@ -388,8 +345,7 @@ namespace SparkleShare {
|
|||
html = html.Replace ("<!-- $document-moved-background-image -->", 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))
|
||||
Frame = new RectangleF (new PointF (0, 0), new SizeF (ContentView.Frame.Width, ContentView.Frame.Height - 39))
|
||||
};
|
||||
|
||||
this.web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
|
||||
|
@ -397,8 +353,7 @@ namespace SparkleShare {
|
|||
this.web_view.PolicyDelegate = new SparkleWebPolicyDelegate ();
|
||||
ContentView.AddSubview (this.web_view);
|
||||
|
||||
(this.web_view.PolicyDelegate as SparkleWebPolicyDelegate).LinkClicked +=
|
||||
delegate (string href) {
|
||||
(this.web_view.PolicyDelegate as SparkleWebPolicyDelegate).LinkClicked += delegate (string href) {
|
||||
if (href.StartsWith ("file:///"))
|
||||
href = href.Substring (7);
|
||||
|
||||
|
@ -407,7 +362,6 @@ namespace SparkleShare {
|
|||
|
||||
this.progress_indicator.Hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void OrderFrontRegardless ()
|
||||
|
|
|
@ -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 {
|
||||
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;
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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,10 +57,12 @@ 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;
|
||||
|
@ -73,13 +71,9 @@ namespace SparkleShare {
|
|||
this.status_item.AlternateImage.Size = new SizeF (16, 16);
|
||||
|
||||
CreateMenu ();
|
||||
}
|
||||
|
||||
|
||||
Controller.UpdateIconEvent += delegate (IconState state) {
|
||||
using (var a = new NSAutoreleasePool ())
|
||||
{
|
||||
InvokeOnMainThread (delegate {
|
||||
Program.Controller.Invoke (() => {
|
||||
switch (state) {
|
||||
case IconState.Idle: {
|
||||
this.status_item.Image = this.syncing_idle_image;
|
||||
|
@ -111,39 +105,23 @@ namespace SparkleShare {
|
|||
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;
|
||||
|
@ -262,7 +240,6 @@ namespace SparkleShare {
|
|||
this.status_item.Menu = this.menu;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class SparkleStatusIconMenuDelegate : NSMenuDelegate {
|
||||
|
|
|
@ -42,22 +42,21 @@ 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);
|
||||
|
||||
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 ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Run ()
|
||||
|
|
Loading…
Reference in a new issue