From f2d6daeda25ac6d2241dc0d62dec23bca42104cb Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 1 Mar 2012 21:02:18 +0000 Subject: [PATCH] mac: open event log when dock icon with badge is clicked --- SparkleShare/Mac/SparkleBubbles.cs | 1 + SparkleShare/Mac/SparkleSetup.cs | 1307 +++++++++++++------------ SparkleShare/Mac/SparkleStatusIcon.cs | 25 +- SparkleShare/Mac/SparkleUI.cs | 14 +- 4 files changed, 678 insertions(+), 669 deletions(-) diff --git a/SparkleShare/Mac/SparkleBubbles.cs b/SparkleShare/Mac/SparkleBubbles.cs index a36443f7..a2a5ff11 100755 --- a/SparkleShare/Mac/SparkleBubbles.cs +++ b/SparkleShare/Mac/SparkleBubbles.cs @@ -68,6 +68,7 @@ namespace SparkleShare { [Export("growlNotificationWasClicked")] public override void GrowlNotificationWasClicked (NSObject o) { + NSApplication.SharedApplication.DockTile.BadgeLabel = null; SparkleUI.Bubbles.Controller.BubbleClicked (); } } diff --git a/SparkleShare/Mac/SparkleSetup.cs b/SparkleShare/Mac/SparkleSetup.cs index 675a37b8..d8717e20 100755 --- a/SparkleShare/Mac/SparkleSetup.cs +++ b/SparkleShare/Mac/SparkleSetup.cs @@ -78,698 +78,701 @@ namespace SparkleShare { }; Controller.ChangePageEvent += delegate (PageType type, string [] warnings) { - InvokeOnMainThread (delegate { - Reset (); - - switch (type) { - case PageType.Setup: { - - Header = "Welcome to SparkleShare!"; - Description = "Before we get started, what's your name and email? " + - "Don't worry, this information will only visible to your team members."; - - - FullNameLabel = new NSTextField () { - Alignment = NSTextAlignment.Right, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF (165, Frame.Height - 234, 160, 17), - StringValue = "Full Name:", - Font = SparkleUI.Font - }; - - FullNameTextField = new NSTextField () { - Frame = new RectangleF (330, Frame.Height - 238, 196, 22), - StringValue = Controller.GuessedUserName, - Delegate = new SparkleTextFieldDelegate () - }; - - EmailLabel = new NSTextField () { - Alignment = NSTextAlignment.Right, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF (165, Frame.Height - 264, 160, 17), - StringValue = "Email:", - Font = SparkleUI.Font - }; - - EmailTextField = new NSTextField () { - Frame = new RectangleF (330, Frame.Height - 268, 196, 22), - StringValue = Controller.GuessedUserEmail, - Delegate = new SparkleTextFieldDelegate () - }; - - - (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { - Controller.CheckSetupPage ( - FullNameTextField.StringValue, - EmailTextField.StringValue - ); - }; - - (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { - Controller.CheckSetupPage ( - FullNameTextField.StringValue, - EmailTextField.StringValue - ); - }; - - - ContinueButton = new NSButton () { - Title = "Continue", - Enabled = false - }; - - ContinueButton.Activated += delegate { - string full_name = FullNameTextField.StringValue.Trim (); - string email = EmailTextField.StringValue.Trim (); - - Controller.SetupPageCompleted (full_name, email); - }; - - Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) { - InvokeOnMainThread (delegate { - ContinueButton.Enabled = button_enabled; - }); - }; - - - ContentView.AddSubview (FullNameLabel); - ContentView.AddSubview (FullNameTextField); - ContentView.AddSubview (EmailLabel); - ContentView.AddSubview (EmailTextField); - - Buttons.Add (ContinueButton); - - Controller.CheckSetupPage ( - FullNameTextField.StringValue, - EmailTextField.StringValue - ); - - break; - } - - case PageType.Invite: { - - Header = "You've received an invite!"; - Description = "Do you want to add this project to SparkleShare?"; - - - AddressLabel = new NSTextField () { - Alignment = NSTextAlignment.Right, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF (165, Frame.Height - 240, 160, 17), - StringValue = "Address:", - Font = SparkleUI.Font - }; - - PathLabel = new NSTextField () { - Alignment = NSTextAlignment.Right, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF (165, Frame.Height - 264, 160, 17), - StringValue = "Remote Path:", - Font = SparkleUI.Font - }; - - AddressTextField = new NSTextField () { - Alignment = NSTextAlignment.Left, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF (330, Frame.Height - 240, 260, 17), - StringValue = Controller.PendingInvite.Address, - Font = SparkleUI.BoldFont - }; - - PathTextField = new NSTextField () { - Alignment = NSTextAlignment.Left, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF (330, Frame.Height - 264, 260, 17), - StringValue = Controller.PendingInvite.RemotePath, - Font = SparkleUI.BoldFont - }; - - - ContentView.AddSubview (AddressLabel); - ContentView.AddSubview (PathLabel); - ContentView.AddSubview (AddressTextField); - ContentView.AddSubview (PathTextField); - - - CancelButton = new NSButton () { - Title = "Cancel" - }; - - CancelButton.Activated += delegate { - Controller.PageCancelled (); - }; - - AddButton = new NSButton () { - Title = "Add" - }; - - AddButton.Activated += delegate { - Controller.InvitePageCompleted (); - }; - - Buttons.Add (AddButton); - Buttons.Add (CancelButton); - - break; - } - - case PageType.Add: { - - Header = "Where's your project hosted?"; - Description = ""; - - AddressLabel = new NSTextField () { - Alignment = NSTextAlignment.Left, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF (190, Frame.Height - 308, 160, 17), - StringValue = "Address:", - Font = SparkleUI.BoldFont - }; - - AddressTextField = new NSTextField () { - Frame = new RectangleF (190, Frame.Height - 336, 196, 22), - Font = SparkleUI.Font, - StringValue = Controller.PreviousAddress, - Enabled = (Controller.SelectedPlugin.Address == null), - Delegate = new SparkleTextFieldDelegate () - }; - - - PathLabel = new NSTextField () { - Alignment = NSTextAlignment.Left, - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - Editable = false, - Frame = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17), - StringValue = "Remote Path:", - Font = SparkleUI.BoldFont - }; - - PathTextField = new NSTextField () { - Frame = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22), - StringValue = Controller.PreviousPath, - Enabled = (Controller.SelectedPlugin.Path == null), - Delegate = new SparkleTextFieldDelegate () - }; - - - AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; - PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; - - - PathHelpLabel = new NSTextField () { - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - TextColor = NSColor.DisabledControlText, - Editable = false, - Frame = new RectangleF (190 + 196 + 16, Frame.Height - 355, 204, 17), - StringValue = "", - Font = NSFontManager.SharedFontManager.FontWithFamily - ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11) - }; - - AddressHelpLabel = new NSTextField () { - BackgroundColor = NSColor.WindowBackground, - Bordered = false, - TextColor = NSColor.DisabledControlText, - Editable = false, - Frame = new RectangleF (190, Frame.Height - 355, 204, 17), - StringValue = "", - Font = NSFontManager.SharedFontManager.FontWithFamily - ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11) - }; - - - TableView = new NSTableView () { - Frame = new RectangleF (0, 0, 0, 0), - RowHeight = 30, - IntercellSpacing = new SizeF (0, 12), - HeaderView = null, - Delegate = new SparkleTableViewDelegate () - }; - - ScrollView = new NSScrollView () { - Frame = new RectangleF (190, Frame.Height - 280, 408, 175), - DocumentView = TableView, - HasVerticalScroller = true, - BorderType = NSBorderType.BezelBorder - }; - - IconColumn = new NSTableColumn (new NSImage ()) { - Width = 42, - HeaderToolTip = "Icon", - DataCell = new NSImageCell () - }; - - DescriptionColumn = new NSTableColumn () { - Width = 350, - HeaderToolTip = "Description", - Editable = false - }; - - DescriptionColumn.DataCell.Font = - NSFontManager.SharedFontManager.FontWithFamily ( - "Lucida Grande", NSFontTraitMask.Condensed, 0, 11); - - TableView.AddColumn (IconColumn); - TableView.AddColumn (DescriptionColumn); - - DataSource = new SparkleDataSource (); - - foreach (SparklePlugin plugin in Controller.Plugins) - DataSource.Items.Add (plugin); - - TableView.DataSource = DataSource; - TableView.ReloadData (); - - - Controller.ChangeAddressFieldEvent += delegate (string text, - string example_text, FieldState state) { - - InvokeOnMainThread (delegate { - AddressTextField.StringValue = text; - AddressTextField.Enabled = (state == FieldState.Enabled); - AddressHelpLabel.StringValue = example_text; - }); - }; - - - Controller.ChangePathFieldEvent += delegate (string text, - string example_text, FieldState state) { - - InvokeOnMainThread (delegate { - PathTextField.StringValue = text; - PathTextField.Enabled = (state == FieldState.Enabled); - PathHelpLabel.StringValue = example_text; - }); - }; - - - TableView.SelectRow (Controller.SelectedPluginIndex, false); - - - (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { - Controller.CheckAddPage ( - AddressTextField.StringValue, - PathTextField.StringValue, - TableView.SelectedRow - ); - }; - - (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { - Controller.CheckAddPage ( - AddressTextField.StringValue, - PathTextField.StringValue, - TableView.SelectedRow - ); - }; - - (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate { - Controller.SelectedPluginChanged (TableView.SelectedRow); - - Controller.CheckAddPage ( - AddressTextField.StringValue, - PathTextField.StringValue, - TableView.SelectedRow - ); - }; - - - Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) { - InvokeOnMainThread (delegate { - AddButton.Enabled = button_enabled; - }); - }; - - - ContentView.AddSubview (ScrollView); - ContentView.AddSubview (AddressLabel); - ContentView.AddSubview (AddressTextField); - ContentView.AddSubview (AddressHelpLabel); - ContentView.AddSubview (PathLabel); - ContentView.AddSubview (PathTextField); - ContentView.AddSubview (PathHelpLabel); - - AddButton = new NSButton () { - Title = "Add", - Enabled = false - }; - - AddButton.Activated += delegate { - Controller.AddPageCompleted ( - AddressTextField.StringValue, - PathTextField.StringValue - ); - }; - - Buttons.Add (AddButton); - - CancelButton = new NSButton () { - Title = "Cancel" - }; - - CancelButton.Activated += delegate { - Controller.PageCancelled (); - }; - - Buttons.Add (CancelButton); - - Controller.CheckAddPage ( - AddressTextField.StringValue, - PathTextField.StringValue, - TableView.SelectedRow - ); - - - break; - } - - case PageType.Syncing: { - - Header = "Adding project ‘" + Controller.SyncingFolder + "’…"; - Description = "This may take a while.\n" + - "Are you sure it’s not coffee o'clock?"; - - ProgressIndicator = new NSProgressIndicator () { - Frame = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20), - Style = NSProgressIndicatorStyle.Bar, - MinValue = 0.0, - MaxValue = 100.0, - Indeterminate = false, - DoubleValue = 1.0 - }; - - ProgressIndicator.StartAnimation (this); - - Controller.UpdateProgressBarEvent += delegate (double percentage) { - InvokeOnMainThread (delegate { - ProgressIndicator.DoubleValue = percentage; - }); - }; - - ContentView.AddSubview (ProgressIndicator); - - FinishButton = new NSButton () { - Title = "Finish", - Enabled = false - }; - - CancelButton = new NSButton () { - Title = "Cancel" - }; - - CancelButton.Activated += delegate { - Controller.SyncingCancelled (); - }; - - Buttons.Add (FinishButton); - Buttons.Add (CancelButton); - - break; - } - - case PageType.Error: { - - Header = "Something went wrong…"; - Description = "Please check the following:"; - - // Displaying marked up text with Cocoa is - // a pain, so we just use a webview instead - WebView web_view = new WebView (); - web_view.Frame = new RectangleF (190, Frame.Height - 525, 375, 400); - - string html = "" + - ""; - - web_view.MainFrame.LoadHtmlString (html, new NSUrl ("")); - web_view.DrawsBackground = false; - - ContentView.AddSubview (web_view); - - TryAgainButton = new NSButton () { - Title = "Try again…" - }; - - TryAgainButton.Activated += delegate { - Controller.ErrorPageCompleted (); - }; - - Buttons.Add (TryAgainButton); - - break; - } - - case PageType.Finished: { - - Header = "Project ‘" + Path.GetFileName (Controller.PreviousPath) + - "’ succesfully added!"; - Description = "Access the files from your SparkleShare folder."; - - if (warnings != null) { - WarningImage = NSImage.ImageNamed ("NSCaution"); - WarningImage.Size = new SizeF (24, 24); - - WarningImageView = new NSImageView () { - Image = WarningImage, - Frame = new RectangleF (190, Frame.Height - 175, 24, 24) - }; - - WarningTextField = new NSTextField () { - Frame = new RectangleF (230, Frame.Height - 245, 325, 100), - StringValue = warnings [0], + using (var a = new NSAutoreleasePool ()) + { + InvokeOnMainThread (delegate { + Reset (); + + switch (type) { + case PageType.Setup: { + + Header = "Welcome to SparkleShare!"; + Description = "Before we get started, what's your name and email? " + + "Don't worry, this information will only visible to your team members."; + + + FullNameLabel = new NSTextField () { + Alignment = NSTextAlignment.Right, BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, + Frame = new RectangleF (165, Frame.Height - 234, 160, 17), + StringValue = "Full Name:", Font = SparkleUI.Font }; - - ContentView.AddSubview (WarningImageView); - ContentView.AddSubview (WarningTextField); - } - - FinishButton = new NSButton () { - Title = "Finish" - }; - - FinishButton.Activated += delegate { - Controller.FinishPageCompleted (); - }; - - OpenFolderButton = new NSButton () { - Title = "Open Folder" - }; - - OpenFolderButton.Activated += delegate { - Controller.OpenFolderClicked (); - }; - - Buttons.Add (FinishButton); - Buttons.Add (OpenFolderButton); - - NSApplication.SharedApplication.RequestUserAttention - (NSRequestUserAttentionType.CriticalRequest); - - NSSound.FromName ("Glass").Play (); - - break; - } - - case PageType.Tutorial: { - - switch (Controller.TutorialPageNumber) { - case 1: { - Header = "What's happening next?"; - Description = "SparkleShare creates a special folder on your computer " + - "that will keep track of your projects."; - - SkipTutorialButton = new NSButton () { - Title = "Skip Tutorial" + + FullNameTextField = new NSTextField () { + Frame = new RectangleF (330, Frame.Height - 238, 196, 22), + StringValue = Controller.GuessedUserName, + Delegate = new SparkleTextFieldDelegate () }; - - SkipTutorialButton.Activated += delegate { - Controller.TutorialSkipped (); + + EmailLabel = new NSTextField () { + Alignment = NSTextAlignment.Right, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF (165, Frame.Height - 264, 160, 17), + StringValue = "Email:", + Font = SparkleUI.Font }; - + + EmailTextField = new NSTextField () { + Frame = new RectangleF (330, Frame.Height - 268, 196, 22), + StringValue = Controller.GuessedUserEmail, + Delegate = new SparkleTextFieldDelegate () + }; + + + (FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { + Controller.CheckSetupPage ( + FullNameTextField.StringValue, + EmailTextField.StringValue + ); + }; + + (EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { + Controller.CheckSetupPage ( + FullNameTextField.StringValue, + EmailTextField.StringValue + ); + }; + + ContinueButton = new NSButton () { - Title = "Continue" + Title = "Continue", + Enabled = false }; - + ContinueButton.Activated += delegate { - Controller.TutorialPageCompleted (); + string full_name = FullNameTextField.StringValue.Trim (); + string email = EmailTextField.StringValue.Trim (); + + Controller.SetupPageCompleted (full_name, email); }; - - string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, - "Pixmaps", "tutorial-slide-1-mac.png"); - - SlideImage = new NSImage (slide_image_path) { - Size = new SizeF (350, 200) + + Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) { + InvokeOnMainThread (delegate { + ContinueButton.Enabled = button_enabled; + }); }; - - SlideImageView = new NSImageView () { - Image = SlideImage, - Frame = new RectangleF (215, Frame.Height - 350, 350, 200) - }; - - ContentView.AddSubview (SlideImageView); + + + ContentView.AddSubview (FullNameLabel); + ContentView.AddSubview (FullNameTextField); + ContentView.AddSubview (EmailLabel); + ContentView.AddSubview (EmailTextField); + Buttons.Add (ContinueButton); - Buttons.Add (SkipTutorialButton); - + + Controller.CheckSetupPage ( + FullNameTextField.StringValue, + EmailTextField.StringValue + ); + break; } - - case 2: { - Header = "Sharing files with others"; - Description = "All files added to your project folders are synced automatically with " + - "the host and your team members."; - - ContinueButton = new NSButton () { - Title = "Continue" + + case PageType.Invite: { + + Header = "You've received an invite!"; + Description = "Do you want to add this project to SparkleShare?"; + + + AddressLabel = new NSTextField () { + Alignment = NSTextAlignment.Right, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF (165, Frame.Height - 240, 160, 17), + StringValue = "Address:", + Font = SparkleUI.Font }; - - ContinueButton.Activated += delegate { - Controller.TutorialPageCompleted (); + + PathLabel = new NSTextField () { + Alignment = NSTextAlignment.Right, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF (165, Frame.Height - 264, 160, 17), + StringValue = "Remote Path:", + Font = SparkleUI.Font }; - - string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, - "Pixmaps", "tutorial-slide-2-mac.png"); - - SlideImage = new NSImage (slide_image_path) { - Size = new SizeF (350, 200) + + AddressTextField = new NSTextField () { + Alignment = NSTextAlignment.Left, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF (330, Frame.Height - 240, 260, 17), + StringValue = Controller.PendingInvite.Address, + Font = SparkleUI.BoldFont }; - - SlideImageView = new NSImageView () { - Image = SlideImage, - Frame = new RectangleF (215, Frame.Height - 350, 350, 200) + + PathTextField = new NSTextField () { + Alignment = NSTextAlignment.Left, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF (330, Frame.Height - 264, 260, 17), + StringValue = Controller.PendingInvite.RemotePath, + Font = SparkleUI.BoldFont }; - - ContentView.AddSubview (SlideImageView); - Buttons.Add (ContinueButton); - + + + ContentView.AddSubview (AddressLabel); + ContentView.AddSubview (PathLabel); + ContentView.AddSubview (AddressTextField); + ContentView.AddSubview (PathTextField); + + + CancelButton = new NSButton () { + Title = "Cancel" + }; + + CancelButton.Activated += delegate { + Controller.PageCancelled (); + }; + + AddButton = new NSButton () { + Title = "Add" + }; + + AddButton.Activated += delegate { + Controller.InvitePageCompleted (); + }; + + Buttons.Add (AddButton); + Buttons.Add (CancelButton); + break; } - - case 3: { - Header = "The status icon is here to help"; - Description = "It shows the syncing progress, provides easy access to " + - "your projects and let's you view recent changes."; - - ContinueButton = new NSButton () { - Title = "Continue" + + case PageType.Add: { + + Header = "Where's your project hosted?"; + Description = ""; + + AddressLabel = new NSTextField () { + Alignment = NSTextAlignment.Left, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF (190, Frame.Height - 308, 160, 17), + StringValue = "Address:", + Font = SparkleUI.BoldFont }; - - ContinueButton.Activated += delegate { - Controller.TutorialPageCompleted (); + + AddressTextField = new NSTextField () { + Frame = new RectangleF (190, Frame.Height - 336, 196, 22), + Font = SparkleUI.Font, + StringValue = Controller.PreviousAddress, + Enabled = (Controller.SelectedPlugin.Address == null), + Delegate = new SparkleTextFieldDelegate () }; - - string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, - "Pixmaps", "tutorial-slide-3-mac.png"); - - SlideImage = new NSImage (slide_image_path) { - Size = new SizeF (350, 200) + + + PathLabel = new NSTextField () { + Alignment = NSTextAlignment.Left, + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Frame = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17), + StringValue = "Remote Path:", + Font = SparkleUI.BoldFont }; - - SlideImageView = new NSImageView () { - Image = SlideImage, - Frame = new RectangleF (215, Frame.Height - 350, 350, 200) + + PathTextField = new NSTextField () { + Frame = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22), + StringValue = Controller.PreviousPath, + Enabled = (Controller.SelectedPlugin.Path == null), + Delegate = new SparkleTextFieldDelegate () }; - - ContentView.AddSubview (SlideImageView); - Buttons.Add (ContinueButton); - + + + AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; + PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; + + + PathHelpLabel = new NSTextField () { + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + TextColor = NSColor.DisabledControlText, + Editable = false, + Frame = new RectangleF (190 + 196 + 16, Frame.Height - 355, 204, 17), + StringValue = "", + Font = NSFontManager.SharedFontManager.FontWithFamily + ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11) + }; + + AddressHelpLabel = new NSTextField () { + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + TextColor = NSColor.DisabledControlText, + Editable = false, + Frame = new RectangleF (190, Frame.Height - 355, 204, 17), + StringValue = "", + Font = NSFontManager.SharedFontManager.FontWithFamily + ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11) + }; + + + TableView = new NSTableView () { + Frame = new RectangleF (0, 0, 0, 0), + RowHeight = 30, + IntercellSpacing = new SizeF (0, 12), + HeaderView = null, + Delegate = new SparkleTableViewDelegate () + }; + + ScrollView = new NSScrollView () { + Frame = new RectangleF (190, Frame.Height - 280, 408, 175), + DocumentView = TableView, + HasVerticalScroller = true, + BorderType = NSBorderType.BezelBorder + }; + + IconColumn = new NSTableColumn (new NSImage ()) { + Width = 42, + HeaderToolTip = "Icon", + DataCell = new NSImageCell () + }; + + DescriptionColumn = new NSTableColumn () { + Width = 350, + HeaderToolTip = "Description", + Editable = false + }; + + DescriptionColumn.DataCell.Font = + NSFontManager.SharedFontManager.FontWithFamily ( + "Lucida Grande", NSFontTraitMask.Condensed, 0, 11); + + TableView.AddColumn (IconColumn); + TableView.AddColumn (DescriptionColumn); + + DataSource = new SparkleDataSource (); + + foreach (SparklePlugin plugin in Controller.Plugins) + DataSource.Items.Add (plugin); + + TableView.DataSource = DataSource; + TableView.ReloadData (); + + + Controller.ChangeAddressFieldEvent += delegate (string text, + string example_text, FieldState state) { + + InvokeOnMainThread (delegate { + AddressTextField.StringValue = text; + AddressTextField.Enabled = (state == FieldState.Enabled); + AddressHelpLabel.StringValue = example_text; + }); + }; + + + Controller.ChangePathFieldEvent += delegate (string text, + string example_text, FieldState state) { + + InvokeOnMainThread (delegate { + PathTextField.StringValue = text; + PathTextField.Enabled = (state == FieldState.Enabled); + PathHelpLabel.StringValue = example_text; + }); + }; + + + TableView.SelectRow (Controller.SelectedPluginIndex, false); + + + (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { + Controller.CheckAddPage ( + AddressTextField.StringValue, + PathTextField.StringValue, + TableView.SelectedRow + ); + }; + + (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { + Controller.CheckAddPage ( + AddressTextField.StringValue, + PathTextField.StringValue, + TableView.SelectedRow + ); + }; + + (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate { + Controller.SelectedPluginChanged (TableView.SelectedRow); + + Controller.CheckAddPage ( + AddressTextField.StringValue, + PathTextField.StringValue, + TableView.SelectedRow + ); + }; + + + Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) { + InvokeOnMainThread (delegate { + AddButton.Enabled = button_enabled; + }); + }; + + + ContentView.AddSubview (ScrollView); + ContentView.AddSubview (AddressLabel); + ContentView.AddSubview (AddressTextField); + ContentView.AddSubview (AddressHelpLabel); + ContentView.AddSubview (PathLabel); + ContentView.AddSubview (PathTextField); + ContentView.AddSubview (PathHelpLabel); + + AddButton = new NSButton () { + Title = "Add", + Enabled = false + }; + + AddButton.Activated += delegate { + Controller.AddPageCompleted ( + AddressTextField.StringValue, + PathTextField.StringValue + ); + }; + + Buttons.Add (AddButton); + + CancelButton = new NSButton () { + Title = "Cancel" + }; + + CancelButton.Activated += delegate { + Controller.PageCancelled (); + }; + + Buttons.Add (CancelButton); + + Controller.CheckAddPage ( + AddressTextField.StringValue, + PathTextField.StringValue, + TableView.SelectedRow + ); + + break; } - - case 4: { - Header = "Adding projects to SparkleShare"; - Description = "You can do this through the status icon menu, or by clicking " + - "magic buttons on webpages that look like this:"; - - - StartupCheckButton = new NSButton () { - Frame = new RectangleF (190, Frame.Height - 400, 300, 18), - Title = "Add SparkleShare to startup items", - State = NSCellStateValue.On + + case PageType.Syncing: { + + Header = "Adding project ‘" + Controller.SyncingFolder + "’…"; + Description = "This may take a while.\n" + + "Are you sure it’s not coffee o'clock?"; + + ProgressIndicator = new NSProgressIndicator () { + Frame = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20), + Style = NSProgressIndicatorStyle.Bar, + MinValue = 0.0, + MaxValue = 100.0, + Indeterminate = false, + DoubleValue = 1.0 }; - - StartupCheckButton.SetButtonType (NSButtonType.Switch); - - StartupCheckButton.Activated += delegate { - Controller.StartupItemChanged (StartupCheckButton.State == NSCellStateValue.On); + + ProgressIndicator.StartAnimation (this); + + Controller.UpdateProgressBarEvent += delegate (double percentage) { + InvokeOnMainThread (delegate { + ProgressIndicator.DoubleValue = percentage; + }); }; - + + ContentView.AddSubview (ProgressIndicator); + + FinishButton = new NSButton () { + Title = "Finish", + Enabled = false + }; + + CancelButton = new NSButton () { + Title = "Cancel" + }; + + CancelButton.Activated += delegate { + Controller.SyncingCancelled (); + }; + + Buttons.Add (FinishButton); + Buttons.Add (CancelButton); + + break; + } + + case PageType.Error: { + + Header = "Something went wrong…"; + Description = "Please check the following:"; + + // Displaying marked up text with Cocoa is + // a pain, so we just use a webview instead + WebView web_view = new WebView (); + web_view.Frame = new RectangleF (190, Frame.Height - 525, 375, 400); + + string html = "" + + ""; + + web_view.MainFrame.LoadHtmlString (html, new NSUrl ("")); + web_view.DrawsBackground = false; + + ContentView.AddSubview (web_view); + + TryAgainButton = new NSButton () { + Title = "Try again…" + }; + + TryAgainButton.Activated += delegate { + Controller.ErrorPageCompleted (); + }; + + Buttons.Add (TryAgainButton); + + break; + } + + case PageType.Finished: { + + Header = "Project ‘" + Path.GetFileName (Controller.PreviousPath) + + "’ succesfully added!"; + Description = "Access the files from your SparkleShare folder."; + + if (warnings != null) { + WarningImage = NSImage.ImageNamed ("NSCaution"); + WarningImage.Size = new SizeF (24, 24); + + WarningImageView = new NSImageView () { + Image = WarningImage, + Frame = new RectangleF (190, Frame.Height - 175, 24, 24) + }; + + WarningTextField = new NSTextField () { + Frame = new RectangleF (230, Frame.Height - 245, 325, 100), + StringValue = warnings [0], + BackgroundColor = NSColor.WindowBackground, + Bordered = false, + Editable = false, + Font = SparkleUI.Font + }; + + ContentView.AddSubview (WarningImageView); + ContentView.AddSubview (WarningTextField); + } + FinishButton = new NSButton () { Title = "Finish" }; - + FinishButton.Activated += delegate { - Controller.TutorialPageCompleted (); + Controller.FinishPageCompleted (); }; - - - string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, - "Pixmaps", "tutorial-slide-4.png"); - - SlideImage = new NSImage (slide_image_path) { - Size = new SizeF (350, 64) + + OpenFolderButton = new NSButton () { + Title = "Open Folder" }; - - SlideImageView = new NSImageView () { - Image = SlideImage, - Frame = new RectangleF (215, Frame.Height - 215, 350, 64) + + OpenFolderButton.Activated += delegate { + Controller.OpenFolderClicked (); }; - - ContentView.AddSubview (SlideImageView); - ContentView.AddSubview (StartupCheckButton); + Buttons.Add (FinishButton); - + Buttons.Add (OpenFolderButton); + + NSApplication.SharedApplication.RequestUserAttention + (NSRequestUserAttentionType.CriticalRequest); + + NSSound.FromName ("Glass").Play (); + + break; + } + + case PageType.Tutorial: { + + switch (Controller.TutorialPageNumber) { + case 1: { + Header = "What's happening next?"; + Description = "SparkleShare creates a special folder on your computer " + + "that will keep track of your projects."; + + SkipTutorialButton = new NSButton () { + Title = "Skip Tutorial" + }; + + SkipTutorialButton.Activated += delegate { + Controller.TutorialSkipped (); + }; + + ContinueButton = new NSButton () { + Title = "Continue" + }; + + ContinueButton.Activated += delegate { + Controller.TutorialPageCompleted (); + }; + + string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, + "Pixmaps", "tutorial-slide-1-mac.png"); + + SlideImage = new NSImage (slide_image_path) { + Size = new SizeF (350, 200) + }; + + SlideImageView = new NSImageView () { + Image = SlideImage, + Frame = new RectangleF (215, Frame.Height - 350, 350, 200) + }; + + ContentView.AddSubview (SlideImageView); + Buttons.Add (ContinueButton); + Buttons.Add (SkipTutorialButton); + + break; + } + + case 2: { + Header = "Sharing files with others"; + Description = "All files added to your project folders are synced automatically with " + + "the host and your team members."; + + ContinueButton = new NSButton () { + Title = "Continue" + }; + + ContinueButton.Activated += delegate { + Controller.TutorialPageCompleted (); + }; + + string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, + "Pixmaps", "tutorial-slide-2-mac.png"); + + SlideImage = new NSImage (slide_image_path) { + Size = new SizeF (350, 200) + }; + + SlideImageView = new NSImageView () { + Image = SlideImage, + Frame = new RectangleF (215, Frame.Height - 350, 350, 200) + }; + + ContentView.AddSubview (SlideImageView); + Buttons.Add (ContinueButton); + + break; + } + + case 3: { + Header = "The status icon is here to help"; + Description = "It shows the syncing progress, provides easy access to " + + "your projects and let's you view recent changes."; + + ContinueButton = new NSButton () { + Title = "Continue" + }; + + ContinueButton.Activated += delegate { + Controller.TutorialPageCompleted (); + }; + + string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, + "Pixmaps", "tutorial-slide-3-mac.png"); + + SlideImage = new NSImage (slide_image_path) { + Size = new SizeF (350, 200) + }; + + SlideImageView = new NSImageView () { + Image = SlideImage, + Frame = new RectangleF (215, Frame.Height - 350, 350, 200) + }; + + ContentView.AddSubview (SlideImageView); + Buttons.Add (ContinueButton); + + break; + } + + case 4: { + Header = "Adding projects to SparkleShare"; + Description = "You can do this through the status icon menu, or by clicking " + + "magic buttons on webpages that look like this:"; + + + StartupCheckButton = new NSButton () { + Frame = new RectangleF (190, Frame.Height - 400, 300, 18), + Title = "Add SparkleShare to startup items", + State = NSCellStateValue.On + }; + + StartupCheckButton.SetButtonType (NSButtonType.Switch); + + StartupCheckButton.Activated += delegate { + Controller.StartupItemChanged (StartupCheckButton.State == NSCellStateValue.On); + }; + + FinishButton = new NSButton () { + Title = "Finish" + }; + + FinishButton.Activated += delegate { + Controller.TutorialPageCompleted (); + }; + + + string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, + "Pixmaps", "tutorial-slide-4.png"); + + SlideImage = new NSImage (slide_image_path) { + Size = new SizeF (350, 64) + }; + + SlideImageView = new NSImageView () { + Image = SlideImage, + Frame = new RectangleF (215, Frame.Height - 215, 350, 64) + }; + + ContentView.AddSubview (SlideImageView); + ContentView.AddSubview (StartupCheckButton); + Buttons.Add (FinishButton); + + break; + } + } + break; } } - - break; - } - } - - ShowAll (); - }); + + ShowAll (); + }); + } }; } } diff --git a/SparkleShare/Mac/SparkleStatusIcon.cs b/SparkleShare/Mac/SparkleStatusIcon.cs index 58c4d9cf..23a7b124 100755 --- a/SparkleShare/Mac/SparkleStatusIcon.cs +++ b/SparkleShare/Mac/SparkleStatusIcon.cs @@ -92,18 +92,23 @@ namespace SparkleShare { Menu.Delegate = new SparkleStatusIconMenuDelegate (); } + Controller.UpdateQuitItemEvent += delegate (bool quit_item_enabled) { - InvokeOnMainThread (delegate { - if (QuitMenuItem != null) { - QuitMenuItem.Enabled = quit_item_enabled; - StatusItem.Menu.Update (); - } - }); + using (var a = new NSAutoreleasePool ()) + { + InvokeOnMainThread (delegate { + if (QuitMenuItem != null) { + QuitMenuItem.Enabled = quit_item_enabled; + StatusItem.Menu.Update (); + } + }); + } }; Controller.UpdateMenuEvent += delegate (IconState state) { - InvokeOnMainThread (delegate { - using (var a = new NSAutoreleasePool ()) { + using (var a = new NSAutoreleasePool ()) + { + InvokeOnMainThread (delegate { switch (state) { case IconState.Idle: @@ -149,8 +154,8 @@ namespace SparkleShare { } StatusItem.Menu.Update (); - } - }); + }); + } }; } diff --git a/SparkleShare/Mac/SparkleUI.cs b/SparkleShare/Mac/SparkleUI.cs index 26c919bd..c4066421 100755 --- a/SparkleShare/Mac/SparkleUI.cs +++ b/SparkleShare/Mac/SparkleUI.cs @@ -81,9 +81,9 @@ namespace SparkleShare { { string folder_icon_path = Path.Combine (NSBundle.MainBundle.ResourcePath, "sparkleshare-mac.icns"); - + NSImage folder_icon = new NSImage (folder_icon_path); - + NSWorkspace.SharedWorkspace.SetIconforFile (folder_icon, Program.Controller.SparklePath, 0); } @@ -117,10 +117,7 @@ namespace SparkleShare { private void ShowDockIcon () { - using (var a = new NSAutoreleasePool ()) - { - NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular; - } + NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular; } @@ -137,7 +134,10 @@ namespace SparkleShare { public override void WillBecomeActive (NSNotification notification) { - NSApplication.SharedApplication.DockTile.BadgeLabel = null; + if (NSApplication.SharedApplication.DockTile.BadgeLabel != null) { + Program.Controller.ShowEventLogWindow (); + NSApplication.SharedApplication.DockTile.BadgeLabel = null; + } }