protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (Control == null) { NSTextField textField; if (e.NewElement.IsPassword) { textField = new NSSecureTextField(); } else { textField = new FormsNSTextField(); (textField as FormsNSTextField).FocusChanged += TextFieldFocusChanged; } SetNativeControl(textField); _defaultTextColor = textField.TextColor; textField.Changed += OnChanged; textField.EditingBegan += OnEditingBegan; textField.EditingEnded += OnEditingEnded; } if (e.NewElement != null) { UpdatePlaceholder(); UpdateText(); UpdateColor(); UpdateFont(); UpdateAlignment(); } }
public static void CheckPassword(SqliteConnection connection, SqliteConnection _conn, string password, bool isError = false) { var passwordInput = new NSSecureTextField(new CGRect(0, 0, 300, 20)); passwordInput.PlaceholderAttributedString = new Foundation.NSAttributedString("Enter password..."); var passwordAlert = new NSAlert() { AlertStyle = isError ? NSAlertStyle.Critical : NSAlertStyle.Informational, InformativeText = isError ? "Previous password attempt was incorrect, please retry" : "Enter SittingDucks Password", MessageText = "Authentication Required", }; passwordAlert.AddButton("Enter"); passwordAlert.AddButton("Change Password"); passwordAlert.AccessoryView = passwordInput; passwordAlert.Layout(); var result = passwordAlert.RunModal(); passwordAlert.Dispose(); if (passwordInput.StringValue != password) { CheckPassword(connection, _conn, password, true); } else if (result == 1001) { NewPassword(connection, _conn); } }
public override IDisposable Login(LoginConfig config) => this.Present(() => { var alert = new NSAlert { AlertStyle = NSAlertStyle.Informational, MessageText = config.Title ?? string.Empty, InformativeText = config.Message ?? string.Empty }; alert.AddButton(config.OkText); alert.AddButton(config.CancelText); var inputView = new NSStackView(new CGRect(0, 2, 200, 58)); var txtUser = new NSTextField(new CGRect(0, 28, 200, 24)) { PlaceholderString = config.LoginPlaceholder, StringValue = config.LoginValue ?? string.Empty }; var txtPassword = new NSSecureTextField(new CGRect(0, 2, 200, 24)) { PlaceholderString = config.PasswordPlaceholder }; inputView.AddSubview(txtUser); inputView.AddSubview(txtPassword); alert.AccessoryView = inputView; alert.Layout(); alert.BeginSheetForResponse(this.windowFunc(), result => config.OnAction?.Invoke(new LoginResult(result == 1000, txtUser.StringValue, txtPassword.StringValue))); return(alert); });
public ICredentials GetCredentials(Uri uri, IWebProxy proxy, CredentialType credentialType, ICredentials existingCredentials, bool retrying) { bool result = false; DispatchService.GuiSyncDispatch(() => { using (var ns = new NSAutoreleasePool()) { var message = string.Format("{0} needs {1} credentials to access {2}.", BrandingService.ApplicationName, credentialType == CredentialType.ProxyCredentials ? "proxy" : "request", uri.Host); NSAlert alert = NSAlert.WithMessage("Credentials Required", "OK", "Cancel", null, message); alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; NSView view = new NSView(new RectangleF(0, 0, 313, 91)); var creds = Utility.GetCredentialsForUriFromICredentials(uri, existingCredentials); var usernameLabel = new NSTextField(new RectangleF(17, 55, 71, 17)) { Identifier = "usernameLabel", StringValue = "Username:"******"Password:", Alignment = NSTextAlignment.Right, Editable = false, Bordered = false, DrawsBackground = false, Bezeled = false, Selectable = false, }; view.AddSubview(passwordLabel); var passwordInput = new NSSecureTextField(new RectangleF(93, 20, 200, 22)); passwordInput.StringValue = creds != null ? creds.Password : string.Empty; view.AddSubview(passwordInput); alert.AccessoryView = view; result = alert.RunModal() == 1; username = usernameInput.StringValue; password = passwordInput.StringValue; } }); return(result ? new NetworkCredential(username, password) : null); }
public ICredentials GetCredentials (Uri uri, IWebProxy proxy, CredentialType credentialType, ICredentials existingCredentials, bool retrying) { bool result = false; DispatchService.GuiSyncDispatch (() => { using (var ns = new NSAutoreleasePool ()) { var message = string.Format ("{0} needs {1} credentials to access {2}.", BrandingService.ApplicationName, credentialType == CredentialType.ProxyCredentials ? "proxy" : "request", uri.Host); NSAlert alert = NSAlert.WithMessage ("Credentials Required", "OK", "Cancel", null, message); alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; NSView view = new NSView (new RectangleF (0, 0, 313, 91)); var creds = Utility.GetCredentialsForUriFromICredentials (uri, existingCredentials); var usernameLabel = new NSTextField (new RectangleF (17, 55, 71, 17)) { Identifier = "usernameLabel", StringValue = "Username:"******"Password:", Alignment = NSTextAlignment.Right, Editable = false, Bordered = false, DrawsBackground = false, Bezeled = false, Selectable = false, }; view.AddSubview (passwordLabel); var passwordInput = new NSSecureTextField (new RectangleF (93, 20, 200, 22)); passwordInput.StringValue = creds != null ? creds.Password : string.Empty; view.AddSubview (passwordInput); alert.AccessoryView = view; result = alert.RunModal () == 1; username = usernameInput.StringValue; password = passwordInput.StringValue; } }); return result ? new NetworkCredential (username, password) : null; }
protected override IView OnConvertToView(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { var textField = new NSTextField(); var frame = (FigmaFrame)currentNode; frame.TryGetNativeControlType(out var controlType); frame.TryGetNativeControlVariant(out var controlVariant); if (controlType == NativeControlType.SearchField) { textField = new NSSearchField(); } FigmaNode optionsGroup = frame.Options(); FigmaNode passwordNode = optionsGroup?.GetChildren() .OfType <FigmaNode>() .FirstOrDefault(s => s.name == ComponentString.PASSWORD && s.visible); if (passwordNode != null) { textField = new NSSecureTextField(); textField.StringValue = "Password"; } FigmaText placeholderText = optionsGroup?.GetChildren() .OfType <FigmaText>() .FirstOrDefault(s => s.name == ComponentString.PLACEHOLDER && s.visible); if (placeholderText != null && !placeholderText.characters.Equals(ComponentString.PLACEHOLDER, StringComparison.InvariantCultureIgnoreCase)) { textField.PlaceholderString = placeholderText.characters; } FigmaText text = frame.children .OfType <FigmaText> () .FirstOrDefault(s => s.name == ComponentString.TITLE && s.visible); if (text != null) { textField.Alignment = CocoaHelpers.GetNSTextAlignment(text); textField.StringValue = text.characters; } textField.ControlSize = CocoaHelpers.GetNSControlSize(controlVariant); textField.Font = CocoaHelpers.GetNSFont(controlVariant); return(new View(textField)); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { this.OnElementChanged(e); var control = this.Control; if (this.Control == null) { NSTextField uiTextField; if (Element.IsPassword) { uiTextField = new NSSecureTextField(); } else { uiTextField = new NSTextField(); } this.SetNativeControl(uiTextField); this.defaultTextColor = uiTextField.TextColor; //uiTextField.BorderStyle = UITextBorderStyle.RoundedRect; uiTextField.Changed += new EventHandler(this.OnEditingChanged); //uiTextField.ShouldReturn = new UITextFieldCondition (this.OnShouldReturn); uiTextField.EditingBegan += new EventHandler(this.OnEditingBegan); uiTextField.EditingEnded += new EventHandler(this.OnEditingEnded); } if (e.NewElement == null) { return; } this.UpdatePlaceholder(); this.UpdatePassword(); this.UpdateText(); this.UpdateColor(); this.UpdateFont(); //this.UpdateKeyboard (); this.UpdateAlignment(); }
public override NSView CreateView() { var text = owner.Text; var size = owner.Bounds.Size; textField = new NSSecureTextField(new CGRect(0, 0, size.Width, size.Height)); textField.Changed += TextFieldChanged; textField.DoCommandBySelector = DoCommandBySelector; ApplyBorderStyle(owner.BorderStyle); ApplyForeColor(owner.ForeColor, owner.forecolor_set); ApplyBackColor(owner.BackColor, owner.backcolor_set); ApplyAlignment(owner.alignment); ApplyFont(owner.Font); ApplyScrollbars(owner.scrollbars); ApplyReadOnly(owner.read_only); ApplyEnabled(owner.is_enabled); ApplyText(text); return(textField); }
void CreateControl() { NSTextField textField; if (Element.IsPassword) { textField = new NSSecureTextField(); } else { textField = new FormsNSTextField(); (textField as FormsNSTextField).FocusChanged += TextFieldFocusChanged; (textField as FormsNSTextField).Completed += OnCompleted; } SetNativeControl(textField); _defaultTextColor = ColorExtensions.TextColor; textField.Changed += OnChanged; textField.EditingBegan += OnEditingBegan; textField.EditingEnded += OnEditingEnded; }
static ICredentials GetCredentialsFromUser(Uri uri, IWebProxy proxy, CredentialType credentialType) { NetworkCredential result = null; Runtime.RunInMainThread(() => { using (var ns = new NSAutoreleasePool()) { var message = credentialType == CredentialType.ProxyCredentials ? GettextCatalog.GetString( "{0} needs credentials to access the proxy server {1}.", BrandingService.ApplicationName, uri.Host ) : GettextCatalog.GetString( "{0} needs credentials to access {1}.", BrandingService.ApplicationName, uri.Host ); using (var alert = new NSAlert()) { alert.MessageText = GettextCatalog.GetString("Credentials Required"); alert.InformativeText = message; var okButton = alert.AddButton(GettextCatalog.GetString("OK")); var cancelButton = alert.AddButton(GettextCatalog.GetString("Cancel")); alert.Icon = MacPlatformService.ApplicationIcon; var view = new NSView(new CGRect(0, 0, 313, 91)); var usernameLabel = new NSTextField(new CGRect(17, 55, 71, 17)) { Identifier = "usernameLabel", StringValue = "Username:"******"Password:", Alignment = NSTextAlignment.Right, Editable = false, Bordered = false, DrawsBackground = false, Bezeled = false, Selectable = false, }; view.AddSubview(passwordLabel); var passwordInput = new NSSecureTextField(new CGRect(93, 20, 200, 22)); view.AddSubview(passwordInput); using (var alertDelegate = new PasswordAlertWindowDelegate(usernameInput, passwordInput, cancelButton, okButton)) { alert.AccessoryView = view; MonoDevelop.Components.IdeTheme.ApplyTheme(alert.Window); alert.Window.WeakDelegate = alertDelegate; alert.Window.InitialFirstResponder = usernameInput; alert.Window.ReleasedWhenClosed = true; if (alert.RunModal() == NSAlertFirstButtonReturn) { var username = usernameInput.StringValue; var password = passwordInput.StringValue; result = new NetworkCredential(username, password); } alert.Window.Close(); } } } }).Wait(); // store the obtained credentials in the keychain // but don't store for the root url since it may have other credentials if (result != null) { Keychain.AddInternetPassword(uri, result.UserName, result.Password); } return(result); }
public void ShowPage (PageType type, string [] warnings) { if (type == PageType.Setup) { Header = "Welcome to SparkleShare!"; Description = "First off, what’s your name and email?\n(visible only to team members)"; FullNameLabel = new SparkleLabel ("Full Name:", NSTextAlignment.Right); FullNameLabel.Frame = new RectangleF (165, Frame.Height - 234, 160, 17); FullNameTextField = new NSTextField () { Frame = new RectangleF (330, Frame.Height - 238, 196, 22), StringValue = UnixUserInfo.GetRealUser ().RealName, Delegate = new SparkleTextFieldDelegate () }; EmailLabel = new SparkleLabel ("Email:", NSTextAlignment.Right); EmailLabel.Frame = new RectangleF (165, Frame.Height - 264, 160, 17); EmailTextField = new NSTextField () { Frame = new RectangleF (330, Frame.Height - 268, 196, 22), Delegate = new SparkleTextFieldDelegate () }; CancelButton = new NSButton () { Title = "Cancel" }; ContinueButton = new NSButton () { Title = "Continue", Enabled = false }; (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.Activated += delegate { string full_name = FullNameTextField.StringValue.Trim (); string email = EmailTextField.StringValue.Trim (); Controller.SetupPageCompleted (full_name, email); }; CancelButton.Activated += delegate { Controller.SetupPageCancelled (); }; Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) { Program.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; }); }; ContentView.AddSubview (FullNameLabel); ContentView.AddSubview (FullNameTextField); ContentView.AddSubview (EmailLabel); ContentView.AddSubview (EmailTextField); Buttons.Add (ContinueButton); Buttons.Add (CancelButton); Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue); } if (type == PageType.Invite) { Header = "You’ve received an invite!"; Description = "Do you want to add this project to SparkleShare?"; AddressLabel = new SparkleLabel ("Address:", NSTextAlignment.Right); AddressLabel.Frame = new RectangleF (165, Frame.Height - 240, 160, 17); AddressTextField = new SparkleLabel (Controller.PendingInvite.Address, NSTextAlignment.Left) { Frame = new RectangleF (330, Frame.Height - 240, 260, 17), Font = SparkleUI.BoldFont }; PathLabel = new SparkleLabel ("Remote Path:", NSTextAlignment.Right); PathLabel.Frame = new RectangleF (165, Frame.Height - 264, 160, 17); PathTextField = new SparkleLabel (Controller.PendingInvite.RemotePath, NSTextAlignment.Left) { Frame = new RectangleF (330, Frame.Height - 264, 260, 17), Font = SparkleUI.BoldFont }; CancelButton = new NSButton () { Title = "Cancel" }; AddButton = new NSButton () { Title = "Add" }; CancelButton.Activated += delegate { Controller.PageCancelled (); }; AddButton.Activated += delegate { Controller.InvitePageCompleted (); }; ContentView.AddSubview (AddressLabel); ContentView.AddSubview (PathLabel); ContentView.AddSubview (AddressTextField); ContentView.AddSubview (PathTextField); Buttons.Add (AddButton); Buttons.Add (CancelButton); } if (type == PageType.Add) { Header = "Where’s your project hosted?"; Description = ""; AddressLabel = new SparkleLabel ("Address:", NSTextAlignment.Left) { Frame = new RectangleF (190, Frame.Height - 308, 160, 17), Font = SparkleUI.BoldFont }; AddressTextField = new NSTextField () { Frame = new RectangleF (190, Frame.Height - 336, 196, 22), Font = SparkleUI.Font, Enabled = (Controller.SelectedPlugin.Address == null), Delegate = new SparkleTextFieldDelegate (), StringValue = "" + Controller.PreviousAddress }; AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; PathLabel = new SparkleLabel ("Remote Path:", NSTextAlignment.Left) { Frame = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17), Font = SparkleUI.BoldFont }; PathTextField = new NSTextField () { Frame = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22), Enabled = (Controller.SelectedPlugin.Path == null), Delegate = new SparkleTextFieldDelegate (), StringValue = "" + Controller.PreviousPath }; PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; PathHelpLabel = new SparkleLabel (Controller.SelectedPlugin.PathExample, NSTextAlignment.Left) { TextColor = NSColor.DisabledControlText, Frame = new RectangleF (190 + 196 + 16, Frame.Height - 355, 204, 17), Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11), }; AddressHelpLabel = new SparkleLabel (Controller.SelectedPlugin.AddressExample, NSTextAlignment.Left) { TextColor = NSColor.DisabledControlText, Frame = new RectangleF (190, Frame.Height - 355, 204, 17), Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11), }; if (TableView == null || TableView.RowCount != Controller.Plugins.Count) { TableView = new NSTableView () { Frame = new RectangleF (0, 0, 0, 0), RowHeight = 34, IntercellSpacing = new SizeF (8, 12), HeaderView = null, Delegate = new SparkleTableViewDelegate () }; ScrollView = new NSScrollView () { Frame = new RectangleF (190, Frame.Height - 280, 408, 185), DocumentView = TableView, HasVerticalScroller = true, BorderType = NSBorderType.BezelBorder }; IconColumn = new NSTableColumn () { Width = 36, HeaderToolTip = "Icon", DataCell = new NSImageCell () { ImageAlignment = NSImageAlignment.Right } }; 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); // Hi-res display support was added after Snow Leopard if (Environment.OSVersion.Version.Major < 11) DataSource = new SparkleDataSource (1, Controller.Plugins); else DataSource = new SparkleDataSource (BackingScaleFactor, Controller.Plugins); TableView.DataSource = DataSource; TableView.ReloadData (); (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate { Controller.SelectedPluginChanged (TableView.SelectedRow); Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow); }; } TableView.SelectRow (Controller.SelectedPluginIndex, false); TableView.ScrollRowToVisible (Controller.SelectedPluginIndex); HistoryCheckButton = new NSButton () { Frame = new RectangleF (190, Frame.Height - 400, 300, 18), Title = "Fetch prior revisions" }; if (Controller.FetchPriorHistory) HistoryCheckButton.State = NSCellStateValue.On; HistoryCheckButton.SetButtonType (NSButtonType.Switch); AddButton = new NSButton () { Title = "Add", Enabled = false }; CancelButton = new NSButton () { Title = "Cancel" }; Controller.ChangeAddressFieldEvent += delegate (string text, string example_text, FieldState state) { Program.Controller.Invoke (() => { AddressTextField.StringValue = text; AddressTextField.Enabled = (state == FieldState.Enabled); AddressHelpLabel.StringValue = example_text; }); }; Controller.ChangePathFieldEvent += delegate (string text, string example_text, FieldState state) { Program.Controller.Invoke (() => { PathTextField.StringValue = text; PathTextField.Enabled = (state == FieldState.Enabled); PathHelpLabel.StringValue = example_text; }); }; (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); }; HistoryCheckButton.Activated += delegate { Controller.HistoryItemChanged (HistoryCheckButton.State == NSCellStateValue.On); }; AddButton.Activated += delegate { Controller.AddPageCompleted (AddressTextField.StringValue, PathTextField.StringValue); }; CancelButton.Activated += delegate { Controller.PageCancelled (); }; Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) { Program.Controller.Invoke (() => { 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); ContentView.AddSubview (HistoryCheckButton); Buttons.Add (AddButton); Buttons.Add (CancelButton); Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow); } if (type == PageType.Syncing) { Header = "Adding project ‘" + Controller.SyncingFolder + "’…"; Description = "This may take a while for large projects.\nIsn’t it 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 = Controller.ProgressBarPercentage }; ProgressIndicator.StartAnimation (this); CancelButton = new NSButton () { Title = "Cancel" }; FinishButton = new NSButton () { Title = "Finish", Enabled = false }; Controller.UpdateProgressBarEvent += delegate (double percentage) { Program.Controller.Invoke (() => { ProgressIndicator.DoubleValue = percentage; }); }; CancelButton.Activated += delegate { Controller.SyncingCancelled (); }; ContentView.AddSubview (ProgressIndicator); Buttons.Add (FinishButton); Buttons.Add (CancelButton); } if (type == PageType.Error) { Header = "Oops! 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 = "<style>" + "* {" + " font-family: 'Lucida Grande';" + " font-size: 12px; cursor: default;" + "}" + "body {" + " -webkit-user-select: none;" + " margin: 0;" + " padding: 3px;" + "}" + "li {" + " margin-bottom: 16px;" + " margin-left: 0;" + " padding-left: 0;" + " line-height: 20px;" + " word-wrap: break-word;" + "}" + "ul {" + " padding-left: 24px;" + "}" + "</style>" + "<ul>" + " <li><b>" + Controller.PreviousUrl + "</b> is the address we’ve compiled. Does this look alright?</li>" + " <li>Is this computer’s Client ID known by the host?</li>" + "</ul>"; if (warnings.Length > 0) { string warnings_markup = ""; foreach (string warning in warnings) warnings_markup += "<br><b>" + warning + "</b>"; html = html.Replace ("</ul>", "<li>Here’s the raw error message: " + warnings_markup + "</li></ul>"); } web_view.MainFrame.LoadHtmlString (html, new NSUrl ("")); web_view.DrawsBackground = false; CancelButton = new NSButton () { Title = "Cancel" }; TryAgainButton = new NSButton () { Title = "Try Again…" }; CancelButton.Activated += delegate { Controller.PageCancelled (); }; TryAgainButton.Activated += delegate { Controller.ErrorPageCompleted (); }; ContentView.AddSubview (web_view); Buttons.Add (TryAgainButton); Buttons.Add (CancelButton); } if (type == PageType.CryptoSetup || type == PageType.CryptoPassword) { if (type == PageType.CryptoSetup) { Header = "Set up file encryption"; Description = "Please a provide a strong password that you don’t use elsewhere."; } else { Header = "This project contains encrypted files"; Description = "Please enter the password to see their contents."; } int extra_pos_y = 0; if (type == PageType.CryptoPassword) extra_pos_y = 20; PasswordLabel = new SparkleLabel ("Password:"******"Show password", State = NSCellStateValue.Off }; ShowPasswordCheckButton.SetButtonType (NSButtonType.Switch); WarningImage = NSImage.ImageNamed ("NSInfo"); WarningImage.Size = new SizeF (24, 24); WarningImageView = new NSImageView () { Image = WarningImage, Frame = new RectangleF (200, Frame.Height - 320, 24, 24) }; WarningTextField = new SparkleLabel ("This password can’t be changed later, and your files can’t be recovered if it’s forgotten.", NSTextAlignment.Left) { Frame = new RectangleF (235, Frame.Height - 390, 325, 100), }; CancelButton = new NSButton () { Title = "Cancel" }; ContinueButton = new NSButton () { Title = "Continue", Enabled = false }; Controller.UpdateCryptoPasswordContinueButtonEvent += delegate (bool button_enabled) { Program.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; }); }; Controller.UpdateCryptoSetupContinueButtonEvent += delegate (bool button_enabled) { Program.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; }); }; ShowPasswordCheckButton.Activated += delegate { if (PasswordTextField.Superview == ContentView) { PasswordTextField.RemoveFromSuperview (); ContentView.AddSubview (VisiblePasswordTextField); } else { VisiblePasswordTextField.RemoveFromSuperview (); ContentView.AddSubview (PasswordTextField); } }; (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { VisiblePasswordTextField.StringValue = PasswordTextField.StringValue; if (type == PageType.CryptoSetup) Controller.CheckCryptoSetupPage (PasswordTextField.StringValue); else Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue); }; (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { PasswordTextField.StringValue = VisiblePasswordTextField.StringValue; if (type == PageType.CryptoSetup) Controller.CheckCryptoSetupPage (PasswordTextField.StringValue); else Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue); }; ContinueButton.Activated += delegate { if (type == PageType.CryptoSetup) Controller.CryptoSetupPageCompleted (PasswordTextField.StringValue); else Controller.CryptoPasswordPageCompleted (PasswordTextField.StringValue); }; CancelButton.Activated += delegate { Controller.CryptoPageCancelled (); }; ContentView.AddSubview (PasswordLabel); ContentView.AddSubview (PasswordTextField); ContentView.AddSubview (ShowPasswordCheckButton); if (type == PageType.CryptoSetup) { ContentView.AddSubview (WarningImageView); ContentView.AddSubview (WarningTextField); } Buttons.Add (ContinueButton); Buttons.Add (CancelButton); NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest); } if (type == PageType.Finished) { Header = "Your shared project is ready!"; Description = "You can find the files in your SparkleShare folder."; if (warnings.Length > 0) { WarningImage = NSImage.ImageNamed ("NSInfo"); WarningImage.Size = new SizeF (24, 24); WarningImageView = new NSImageView () { Image = WarningImage, Frame = new RectangleF (200, Frame.Height - 175, 24, 24) }; WarningTextField = new SparkleLabel (warnings [0], NSTextAlignment.Left); WarningTextField.Frame = new RectangleF (235, Frame.Height - 245, 325, 100); ContentView.AddSubview (WarningImageView); ContentView.AddSubview (WarningTextField); } ShowFilesButton = new NSButton () { Title = "Show Files…" }; FinishButton = new NSButton () { Title = "Finish" }; ShowFilesButton.Activated += delegate { Controller.ShowFilesClicked (); }; FinishButton.Activated += delegate { Controller.FinishPageCompleted (); }; Buttons.Add (FinishButton); Buttons.Add (ShowFilesButton); NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest); } if (type == PageType.Tutorial) { SlideImage = NSImage.ImageNamed ("tutorial-slide-" + Controller.TutorialPageNumber); if (SlideImage != null) { SlideImage.Size = new SizeF (324, 200); SlideImageView = new NSImageView () { Image = SlideImage, Frame = new RectangleF (228, Frame.Height - 350, 324, 200) }; ContentView.AddSubview (SlideImageView); } 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" }; ContinueButton = new NSButton () { Title = "Continue" }; SkipTutorialButton.Activated += delegate { Controller.TutorialSkipped (); }; ContinueButton.Activated += delegate { Controller.TutorialPageCompleted (); }; 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 (); }; Buttons.Add (ContinueButton); break; } case 3: { Header = "The status icon helps you"; Description = "It shows the syncing progress, provides easy access to " + "your projects, and lets you view recent changes."; ContinueButton = new NSButton () { Title = "Continue" }; ContinueButton.Activated += delegate { Controller.TutorialPageCompleted (); }; Buttons.Add (ContinueButton); break; } case 4: { Header = "Here’s your unique Client ID"; Description = "You’ll need it whenever you want to link this computer to a host. " + "You can also find it in the status icon menu."; LinkCodeTextField = new NSTextField () { StringValue = Program.Controller.CurrentUser.PublicKey, Enabled = false, Selectable = false, Frame = new RectangleF (230, Frame.Height - 238, 246, 22) }; LinkCodeTextField.Cell.UsesSingleLineMode = true; LinkCodeTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; CopyButton = new NSButton () { Title = "Copy", BezelStyle = NSBezelStyle.RoundRect, Frame = new RectangleF (480, Frame.Height - 238, 60, 22) }; 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); FinishButton = new NSButton () { Title = "Finish" }; StartupCheckButton.Activated += delegate { Controller.StartupItemChanged (StartupCheckButton.State == NSCellStateValue.On); }; CopyButton.Activated += delegate { Controller.CopyToClipboardClicked (); }; FinishButton.Activated += delegate { Controller.TutorialPageCompleted (); }; ContentView.AddSubview (LinkCodeTextField); ContentView.AddSubview (CopyButton); ContentView.AddSubview (StartupCheckButton); Buttons.Add (FinishButton); break; } } } }
static ICredentials GetCredentialsFromUser (Uri uri, IWebProxy proxy, CredentialType credentialType) { NetworkCredential result = null; DispatchService.GuiSyncDispatch (() => { using (var ns = new NSAutoreleasePool ()) { var message = credentialType == CredentialType.ProxyCredentials ? GettextCatalog.GetString ( "{0} needs credentials to access the proxy server {1}.", BrandingService.ApplicationName, uri.Host ) : GettextCatalog.GetString ( "{0} needs credentials to access {1}.", BrandingService.ApplicationName, uri.Host ); var alert = NSAlert.WithMessage ( GettextCatalog.GetString ("Credentials Required"), GettextCatalog.GetString ("OK"), GettextCatalog.GetString ("Cancel"), null, message ); alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; var view = new NSView (new RectangleF (0, 0, 313, 91)); var usernameLabel = new NSTextField (new RectangleF (17, 55, 71, 17)) { Identifier = "usernameLabel", StringValue = "Username:"******"Password:", Alignment = NSTextAlignment.Right, Editable = false, Bordered = false, DrawsBackground = false, Bezeled = false, Selectable = false, }; view.AddSubview (passwordLabel); var passwordInput = new NSSecureTextField (new RectangleF (93, 20, 200, 22)); view.AddSubview (passwordInput); alert.AccessoryView = view; if (alert.RunModal () != 1) return; var username = usernameInput.StringValue; var password = passwordInput.StringValue; result = new NetworkCredential (username, password); } }); // store the obtained credentials in the keychain // but don't store for the root url since it may have other credentials if (result != null) Keychain.AddInternetPassword (uri, result.UserName, result.Password); return result; }
static ICredentials GetCredentialsFromUser(Uri uri, IWebProxy proxy, CredentialType credentialType) { NetworkCredential result = null; DispatchService.GuiSyncDispatch(() => { using (var ns = new NSAutoreleasePool()) { var message = credentialType == CredentialType.ProxyCredentials ? GettextCatalog.GetString( "{0} needs credentials to access the proxy server {1}.", BrandingService.ApplicationName, uri.Host ) : GettextCatalog.GetString( "{0} needs credentials to access {1}.", BrandingService.ApplicationName, uri.Host ); var alert = NSAlert.WithMessage( GettextCatalog.GetString("Credentials Required"), GettextCatalog.GetString("OK"), GettextCatalog.GetString("Cancel"), null, message ); alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; var view = new NSView(new RectangleF(0, 0, 313, 91)); var usernameLabel = new NSTextField(new RectangleF(17, 55, 71, 17)) { Identifier = "usernameLabel", StringValue = "Username:"******"Password:", Alignment = NSTextAlignment.Right, Editable = false, Bordered = false, DrawsBackground = false, Bezeled = false, Selectable = false, }; view.AddSubview(passwordLabel); var passwordInput = new NSSecureTextField(new RectangleF(93, 20, 200, 22)); view.AddSubview(passwordInput); alert.AccessoryView = view; if (alert.RunModal() != 1) { return; } var username = usernameInput.StringValue; var password = passwordInput.StringValue; result = new NetworkCredential(username, password); } }); // store the obtained credentials in the keychain // but don't store for the root url since it may have other credentials if (result != null) { Keychain.AddInternetPassword(uri, result.UserName, result.Password); } return(result); }
public void ShowPage(PageType type, string [] warnings) { if (type == PageType.Setup) { Header = "Welcome to SparkleShare!"; Description = "First off, what’s your name and email?\n(visible only to team members)"; FullNameLabel = new SparkleLabel("Full Name:", NSTextAlignment.Right); FullNameLabel.Frame = new CGRect(165, Frame.Height - 234, 160, 17); FullNameTextField = new NSTextField() { Frame = new CGRect(330, Frame.Height - 238, 196, 22), StringValue = new NSProcessInfo().GetFullUserName(), Delegate = new SparkleTextFieldDelegate() }; EmailLabel = new SparkleLabel("Email:", NSTextAlignment.Right); EmailLabel.Frame = new CGRect(165, Frame.Height - 264, 160, 17); EmailTextField = new NSTextField() { Frame = new CGRect(330, Frame.Height - 268, 196, 22), Delegate = new SparkleTextFieldDelegate() }; CancelButton = new NSButton() { Title = "Cancel" }; ContinueButton = new NSButton() { Title = "Continue", Enabled = false }; (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.Activated += delegate { string full_name = FullNameTextField.StringValue.Trim(); string email = EmailTextField.StringValue.Trim(); Controller.SetupPageCompleted(full_name, email); }; CancelButton.Activated += delegate { Controller.SetupPageCancelled(); }; Controller.UpdateSetupContinueButtonEvent += delegate(bool button_enabled) { SparkleShare.Controller.Invoke(() => { ContinueButton.Enabled = button_enabled; }); }; ContentView.AddSubview(FullNameLabel); ContentView.AddSubview(FullNameTextField); ContentView.AddSubview(EmailLabel); ContentView.AddSubview(EmailTextField); Buttons.Add(ContinueButton); Buttons.Add(CancelButton); Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue); if (FullNameTextField.StringValue.Equals("")) { MakeFirstResponder((NSResponder)FullNameTextField); } else { MakeFirstResponder((NSResponder)EmailTextField); } } if (type == PageType.Invite) { Header = "You’ve received an invite!"; Description = "Do you want to add this project to SparkleShare?"; AddressLabel = new SparkleLabel("Address:", NSTextAlignment.Right); AddressLabel.Frame = new CGRect(165, Frame.Height - 238, 160, 17); AddressLabel.Font = NSFont.BoldSystemFontOfSize(12); AddressTextField = new SparkleLabel(Controller.PendingInvite.Address, NSTextAlignment.Left) { Frame = new CGRect(330, Frame.Height - 240, 260, 17) }; PathLabel = new SparkleLabel("Remote Path:", NSTextAlignment.Right); PathLabel.Frame = new CGRect(165, Frame.Height - 262, 160, 17); PathLabel.Font = NSFont.BoldSystemFontOfSize(12); PathTextField = new SparkleLabel(Controller.PendingInvite.RemotePath, NSTextAlignment.Left) { Frame = new CGRect(330, Frame.Height - 264, 260, 17) }; CancelButton = new NSButton() { Title = "Cancel" }; AddButton = new NSButton() { Title = "Add" }; CancelButton.Activated += delegate { Controller.PageCancelled(); }; AddButton.Activated += delegate { Controller.InvitePageCompleted(); }; ContentView.AddSubview(AddressLabel); ContentView.AddSubview(PathLabel); ContentView.AddSubview(AddressTextField); ContentView.AddSubview(PathTextField); Buttons.Add(AddButton); Buttons.Add(CancelButton); } if (type == PageType.Add) { Header = "Where’s your project hosted?"; Description = ""; AddressLabel = new SparkleLabel("Address:", NSTextAlignment.Left) { Frame = new CGRect(190, Frame.Height - 310, 160, 17), Font = NSFont.BoldSystemFontOfSize(12) }; AddressTextField = new NSTextField() { Frame = new CGRect(190, Frame.Height - 336, 196, 22), Enabled = (Controller.SelectedPreset.Address == null), Delegate = new SparkleTextFieldDelegate(), StringValue = "" + Controller.PreviousAddress }; AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; PathLabel = new SparkleLabel("Remote Path:", NSTextAlignment.Left) { Frame = new CGRect(190 + 196 + 16, Frame.Height - 310, 160, 17), Font = NSFont.BoldSystemFontOfSize(12) }; PathTextField = new NSTextField() { Frame = new CGRect(190 + 196 + 16, Frame.Height - 336, 196, 22), Enabled = (Controller.SelectedPreset.Path == null), Delegate = new SparkleTextFieldDelegate(), StringValue = "" + Controller.PreviousPath }; PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; PathHelpLabel = new SparkleLabel(Controller.SelectedPreset.PathExample, NSTextAlignment.Left) { TextColor = NSColor.DisabledControlText, Frame = new CGRect(190 + 196 + 16, Frame.Height - 358, 204, 19) }; AddressHelpLabel = new SparkleLabel(Controller.SelectedPreset.AddressExample, NSTextAlignment.Left) { TextColor = NSColor.DisabledControlText, Frame = new CGRect(190, Frame.Height - 358, 204, 19) }; if (TableView == null || TableView.RowCount != Controller.Presets.Count) { TableView = new NSTableView() { Frame = new CGRect(0, 0, 0, 0), RowHeight = 38, IntercellSpacing = new CGSize(8, 12), HeaderView = null, Delegate = new SparkleTableViewDelegate() }; ScrollView = new NSScrollView() { Frame = new CGRect(190, Frame.Height - 280, 408, 185), DocumentView = TableView, HasVerticalScroller = true, BorderType = NSBorderType.BezelBorder }; IconColumn = new NSTableColumn() { Width = 36, HeaderToolTip = "Icon", DataCell = new NSImageCell() { ImageAlignment = NSImageAlignment.Right } }; DescriptionColumn = new NSTableColumn() { Width = 350, HeaderToolTip = "Description", Editable = false }; TableView.AddColumn(IconColumn); TableView.AddColumn(DescriptionColumn); // Hi-res display support was added after Snow Leopard if (Environment.OSVersion.Version.Major < 11) { DataSource = new SparkleDataSource(1, Controller.Presets); } else { DataSource = new SparkleDataSource((float)BackingScaleFactor, Controller.Presets); } TableView.DataSource = DataSource; TableView.ReloadData(); (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate { Controller.SelectedPresetChanged((int)TableView.SelectedRow); Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, (int)TableView.SelectedRow); }; } TableView.SelectRow(Controller.SelectedPresetIndex, byExtendingSelection: false); TableView.ScrollRowToVisible(Controller.SelectedPresetIndex); MakeFirstResponder((NSResponder)TableView); HistoryCheckButton = new NSButton() { Frame = new CGRect(190, Frame.Height - 400, 300, 18), Title = "Fetch prior revisions" }; if (Controller.FetchPriorHistory) { HistoryCheckButton.State = NSCellStateValue.On; } HistoryCheckButton.SetButtonType(NSButtonType.Switch); AddButton = new NSButton() { Title = "Add", Enabled = false }; CancelButton = new NSButton() { Title = "Cancel" }; Controller.ChangeAddressFieldEvent += delegate(string text, string example_text, FieldState state) { SparkleShare.Controller.Invoke(() => { AddressTextField.StringValue = text; AddressTextField.Enabled = (state == FieldState.Enabled); AddressHelpLabel.StringValue = example_text; }); }; Controller.ChangePathFieldEvent += delegate(string text, string example_text, FieldState state) { SparkleShare.Controller.Invoke(() => { PathTextField.StringValue = text; PathTextField.Enabled = (state == FieldState.Enabled); PathHelpLabel.StringValue = example_text; }); }; (AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, (int)TableView.SelectedRow); }; (PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, (int)TableView.SelectedRow); }; HistoryCheckButton.Activated += delegate { Controller.HistoryItemChanged(HistoryCheckButton.State == NSCellStateValue.On); }; AddButton.Activated += delegate { Controller.AddPageCompleted(AddressTextField.StringValue, PathTextField.StringValue); }; CancelButton.Activated += delegate { Controller.PageCancelled(); }; Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) { SparkleShare.Controller.Invoke(() => { 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); ContentView.AddSubview(HistoryCheckButton); Buttons.Add(AddButton); Buttons.Add(CancelButton); Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, (int)TableView.SelectedRow); } if (type == PageType.Syncing) { Header = "Adding project ‘" + Controller.SyncingFolder + "’…"; Description = "This may take a while for large projects.\nIsn’t it coffee-o’clock?"; ProgressIndicator = new NSProgressIndicator() { Frame = new CGRect(190, Frame.Height - 200, 640 - 150 - 80, 20), Style = NSProgressIndicatorStyle.Bar, MinValue = 0.0, MaxValue = 100.0, Indeterminate = false, DoubleValue = Controller.ProgressBarPercentage }; ProgressIndicator.StartAnimation(this); CancelButton = new NSButton() { Title = "Cancel" }; FinishButton = new NSButton() { Title = "Finish", Enabled = false }; ProgressLabel = new SparkleLabel("Preparing to fetch files…", NSTextAlignment.Right); ProgressLabel.Frame = new CGRect(Frame.Width - 40 - 250, 185, 250, 25); Controller.UpdateProgressBarEvent += delegate(double percentage, string speed) { SparkleShare.Controller.Invoke(() => { ProgressIndicator.DoubleValue = percentage; ProgressLabel.StringValue = speed; }); }; CancelButton.Activated += delegate { Controller.SyncingCancelled(); }; ContentView.AddSubview(ProgressLabel); ContentView.AddSubview(ProgressIndicator); Buttons.Add(FinishButton); Buttons.Add(CancelButton); } if (type == PageType.Error) { Header = "Oops! 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 CGRect(190, Frame.Height - 525, 375, 400); string html = "<style>" + "* {" + " font-family: -apple-system, '" + UserInterface.FontName + "';" + " font-size: 12px; cursor: default;" + "}" + "body {" + " -webkit-user-select: none;" + " margin: 0;" + " padding: 3px;" + "}" + "li {" + " margin-bottom: 16px;" + " margin-left: 0;" + " padding-left: 0;" + " line-height: 20px;" + " word-wrap: break-word;" + "}" + "ul {" + " padding-left: 24px;" + "}" + "</style>" + "<ul>" + " <li><b>" + Controller.PreviousUrl + "</b> is the address we’ve compiled. Does this look alright?</li>" + " <li>Is this computer’s Client ID known by the host?</li>" + "</ul>"; if (warnings.Length > 0) { string warnings_markup = ""; foreach (string warning in warnings) { warnings_markup += "<br><b>" + warning + "</b>"; } html = html.Replace("</ul>", "<li>Here’s the raw error message: " + warnings_markup + "</li></ul>"); } web_view.MainFrame.LoadHtmlString(html, new NSUrl("")); web_view.DrawsBackground = false; CancelButton = new NSButton() { Title = "Cancel" }; TryAgainButton = new NSButton() { Title = "Retry" }; CancelButton.Activated += delegate { Controller.PageCancelled(); }; TryAgainButton.Activated += delegate { Controller.ErrorPageCompleted(); }; ContentView.AddSubview(web_view); Buttons.Add(TryAgainButton); Buttons.Add(CancelButton); } if (type == PageType.StorageSetup) { Header = string.Format("Storage type for ‘{0}’", Controller.SyncingFolder); Description = "What type of storage would you like to use?"; storage_type_descriptions = new List <NSTextField> (); ButtonCellProto = new NSButtonCell(); ButtonCellProto.SetButtonType(NSButtonType.Radio); ButtonCellProto.Font = NSFont.BoldSystemFontOfSize(12); Matrix = new NSMatrix(new CGRect(202, Frame.Height - 256 - 128, 256, 256), NSMatrixMode.Radio, ButtonCellProto, SparkleShare.Controller.FetcherAvailableStorageTypes.Count, 1); Matrix.CellSize = new CGSize(256, 36); Matrix.IntercellSpacing = new CGSize(32, 32); int i = 0; foreach (StorageTypeInfo storage_type in SparkleShare.Controller.FetcherAvailableStorageTypes) { Matrix.Cells [i].Title = " " + storage_type.Name; NSTextField storage_type_description = new SparkleLabel(storage_type.Description, NSTextAlignment.Left) { TextColor = NSColor.DisabledControlText, Frame = new CGRect(223, Frame.Height - 190 - (68 * i), 256, 32) }; storage_type_descriptions.Add(storage_type_description); ContentView.AddSubview(storage_type_description); i++; } ContentView.AddSubview(Matrix); CancelButton = new NSButton() { Title = "Cancel" }; ContinueButton = new NSButton() { Title = "Continue" }; ContinueButton.Activated += delegate { StorageTypeInfo selected_storage_type = SparkleShare.Controller.FetcherAvailableStorageTypes [(int)Matrix.SelectedRow]; Controller.StoragePageCompleted(selected_storage_type.Type); }; CancelButton.Activated += delegate { Controller.SyncingCancelled(); }; Buttons.Add(ContinueButton); Buttons.Add(CancelButton); NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest); } if (type == PageType.CryptoSetup || type == PageType.CryptoPassword) { if (type == PageType.CryptoSetup) { Header = "Set up file encryption"; Description = "Please a provide a strong password that you don’t use elsewhere."; } else { Header = "This project contains encrypted files"; Description = "Please enter the password to see their contents."; } int extra_pos_y = 0; if (type == PageType.CryptoPassword) { extra_pos_y = 20; } PasswordLabel = new SparkleLabel("Password:"******"Show password", State = NSCellStateValue.Off }; ShowPasswordCheckButton.SetButtonType(NSButtonType.Switch); WarningImage = NSImage.ImageNamed("NSInfo"); WarningImage.Size = new CGSize(24, 24); WarningImageView = new NSImageView() { Image = WarningImage, Frame = new CGRect(200, Frame.Height - 320, 24, 24) }; WarningTextField = new SparkleLabel("This password can’t be changed later, and your files can’t be recovered if it’s forgotten.", NSTextAlignment.Left) { Frame = new CGRect(235, Frame.Height - 390, 325, 100), }; CancelButton = new NSButton() { Title = "Cancel" }; ContinueButton = new NSButton() { Title = "Continue", Enabled = false }; Controller.UpdateCryptoPasswordContinueButtonEvent += delegate(bool button_enabled) { SparkleShare.Controller.Invoke(() => { ContinueButton.Enabled = button_enabled; }); }; Controller.UpdateCryptoSetupContinueButtonEvent += delegate(bool button_enabled) { SparkleShare.Controller.Invoke(() => { ContinueButton.Enabled = button_enabled; }); }; ShowPasswordCheckButton.Activated += delegate { if (PasswordTextField.Superview == ContentView) { PasswordTextField.RemoveFromSuperview(); ContentView.AddSubview(VisiblePasswordTextField); } else { VisiblePasswordTextField.RemoveFromSuperview(); ContentView.AddSubview(PasswordTextField); } }; (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { VisiblePasswordTextField.StringValue = PasswordTextField.StringValue; if (type == PageType.CryptoSetup) { Controller.CheckCryptoSetupPage(PasswordTextField.StringValue); } else { Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue); } }; (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { PasswordTextField.StringValue = VisiblePasswordTextField.StringValue; if (type == PageType.CryptoSetup) { Controller.CheckCryptoSetupPage(PasswordTextField.StringValue); } else { Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue); } }; ContinueButton.Activated += delegate { if (type == PageType.CryptoSetup) { Controller.CryptoSetupPageCompleted(PasswordTextField.StringValue); } else { Controller.CryptoPasswordPageCompleted(PasswordTextField.StringValue); } }; CancelButton.Activated += delegate { Controller.CryptoPageCancelled(); }; ContentView.AddSubview(PasswordLabel); ContentView.AddSubview(PasswordTextField); ContentView.AddSubview(ShowPasswordCheckButton); if (type == PageType.CryptoSetup) { ContentView.AddSubview(WarningImageView); ContentView.AddSubview(WarningTextField); } Buttons.Add(ContinueButton); Buttons.Add(CancelButton); MakeFirstResponder((NSResponder)PasswordTextField); NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest); } if (type == PageType.Finished) { Header = "Your shared project is ready!"; Description = "You can find the files in your SparkleShare folder."; if (warnings.Length > 0) { WarningImage = NSImage.ImageNamed("NSInfo"); WarningImage.Size = new CGSize(24, 24); WarningImageView = new NSImageView() { Image = WarningImage, Frame = new CGRect(200, Frame.Height - 175, 24, 24) }; WarningTextField = new SparkleLabel(warnings [0], NSTextAlignment.Left); WarningTextField.Frame = new CGRect(235, Frame.Height - 245, 325, 100); ContentView.AddSubview(WarningImageView); ContentView.AddSubview(WarningTextField); } ShowFilesButton = new NSButton() { Title = "Show Files" }; FinishButton = new NSButton() { Title = "Finish" }; ShowFilesButton.Activated += delegate { Controller.ShowFilesClicked(); }; FinishButton.Activated += delegate { Controller.FinishPageCompleted(); }; Buttons.Add(FinishButton); Buttons.Add(ShowFilesButton); NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest); } }
public void ShowPage(PageType type, string [] warnings) { if (type == PageType.Setup) { Header = "Welcome to SparkleShare!"; Description = "First off, what’s your name and email?\n(visible only to team members)"; FullNameLabel = new SparkleLabel("Full Name:", NSTextAlignment.Right); FullNameLabel.Frame = new RectangleF(165, Frame.Height - 234, 160, 17); FullNameTextField = new NSTextField() { Frame = new RectangleF(330, Frame.Height - 238, 196, 22), StringValue = UnixUserInfo.GetRealUser().RealName, Delegate = new SparkleTextFieldDelegate() }; EmailLabel = new SparkleLabel("Email:", NSTextAlignment.Right); EmailLabel.Frame = new RectangleF(165, Frame.Height - 264, 160, 17); EmailTextField = new NSTextField() { Frame = new RectangleF(330, Frame.Height - 268, 196, 22), Delegate = new SparkleTextFieldDelegate() }; CancelButton = new NSButton() { Title = "Cancel" }; ContinueButton = new NSButton() { Title = "Continue", Enabled = false }; (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.Activated += delegate { string full_name = FullNameTextField.StringValue.Trim(); string email = EmailTextField.StringValue.Trim(); Controller.SetupPageCompleted(full_name, email); }; CancelButton.Activated += delegate { Controller.SetupPageCancelled(); }; Controller.UpdateSetupContinueButtonEvent += delegate(bool button_enabled) { Program.Controller.Invoke(() => { ContinueButton.Enabled = button_enabled; }); }; ContentView.AddSubview(FullNameLabel); ContentView.AddSubview(FullNameTextField); ContentView.AddSubview(EmailLabel); ContentView.AddSubview(EmailTextField); Buttons.Add(ContinueButton); Buttons.Add(CancelButton); Controller.CheckSetupPage(FullNameTextField.StringValue, EmailTextField.StringValue); if (FullNameTextField.StringValue.Equals("")) { MakeFirstResponder((NSResponder)FullNameTextField); } else { MakeFirstResponder((NSResponder)EmailTextField); } } if (type == PageType.Invite) { Header = "You’ve received an invite!"; Description = "Do you want to add this project to SparkleShare?"; AddressLabel = new SparkleLabel("Address:", NSTextAlignment.Right); AddressLabel.Frame = new RectangleF(165, Frame.Height - 240, 160, 17); AddressTextField = new SparkleLabel(Controller.PendingInvite.Address, NSTextAlignment.Left) { Frame = new RectangleF(330, Frame.Height - 240, 260, 17), Font = SparkleUI.BoldFont }; PathLabel = new SparkleLabel("Remote Path:", NSTextAlignment.Right); PathLabel.Frame = new RectangleF(165, Frame.Height - 264, 160, 17); PathTextField = new SparkleLabel(Controller.PendingInvite.RemotePath, NSTextAlignment.Left) { Frame = new RectangleF(330, Frame.Height - 264, 260, 17), Font = SparkleUI.BoldFont }; CancelButton = new NSButton() { Title = "Cancel" }; AddButton = new NSButton() { Title = "Add" }; CancelButton.Activated += delegate { Controller.PageCancelled(); }; AddButton.Activated += delegate { Controller.InvitePageCompleted(); }; ContentView.AddSubview(AddressLabel); ContentView.AddSubview(PathLabel); ContentView.AddSubview(AddressTextField); ContentView.AddSubview(PathTextField); Buttons.Add(AddButton); Buttons.Add(CancelButton); } if (type == PageType.Add) { Header = "Where’s your project hosted?"; Description = ""; AddressLabel = new SparkleLabel("Address:", NSTextAlignment.Left) { Frame = new RectangleF(190, Frame.Height - 308, 160, 17), Font = SparkleUI.BoldFont }; AddressTextField = new NSTextField() { Frame = new RectangleF(190, Frame.Height - 336, 196, 22), Font = SparkleUI.Font, Enabled = (Controller.SelectedPlugin.Address == null), Delegate = new SparkleTextFieldDelegate(), StringValue = "" + Controller.PreviousAddress }; AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; PathLabel = new SparkleLabel("Remote Path:", NSTextAlignment.Left) { Frame = new RectangleF(190 + 196 + 16, Frame.Height - 308, 160, 17), Font = SparkleUI.BoldFont }; PathTextField = new NSTextField() { Frame = new RectangleF(190 + 196 + 16, Frame.Height - 336, 196, 22), Enabled = (Controller.SelectedPlugin.Path == null), Delegate = new SparkleTextFieldDelegate(), StringValue = "" + Controller.PreviousPath }; PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; PathHelpLabel = new SparkleLabel(Controller.SelectedPlugin.PathExample, NSTextAlignment.Left) { TextColor = NSColor.DisabledControlText, Frame = new RectangleF(190 + 196 + 16, Frame.Height - 355, 204, 17), Font = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande", NSFontTraitMask.Condensed, 0, 11), }; AddressHelpLabel = new SparkleLabel(Controller.SelectedPlugin.AddressExample, NSTextAlignment.Left) { TextColor = NSColor.DisabledControlText, Frame = new RectangleF(190, Frame.Height - 355, 204, 17), Font = NSFontManager.SharedFontManager.FontWithFamily("Lucida Grande", NSFontTraitMask.Condensed, 0, 11), }; if (TableView == null || TableView.RowCount != Controller.Plugins.Count) { TableView = new NSTableView() { Frame = new RectangleF(0, 0, 0, 0), RowHeight = 34, IntercellSpacing = new SizeF(8, 12), HeaderView = null, Delegate = new SparkleTableViewDelegate() }; ScrollView = new NSScrollView() { Frame = new RectangleF(190, Frame.Height - 280, 408, 185), DocumentView = TableView, HasVerticalScroller = true, BorderType = NSBorderType.BezelBorder }; IconColumn = new NSTableColumn() { Width = 36, HeaderToolTip = "Icon", DataCell = new NSImageCell() { ImageAlignment = NSImageAlignment.Right } }; 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); // Hi-res display support was added after Snow Leopard if (Environment.OSVersion.Version.Major < 11) { DataSource = new SparkleDataSource(1, Controller.Plugins); } else { DataSource = new SparkleDataSource(BackingScaleFactor, Controller.Plugins); } TableView.DataSource = DataSource; TableView.ReloadData(); (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate { Controller.SelectedPluginChanged(TableView.SelectedRow); Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow); }; } TableView.SelectRow(Controller.SelectedPluginIndex, false); TableView.ScrollRowToVisible(Controller.SelectedPluginIndex); MakeFirstResponder((NSResponder)TableView); HistoryCheckButton = new NSButton() { Frame = new RectangleF(190, Frame.Height - 400, 300, 18), Title = "Fetch prior revisions" }; if (Controller.FetchPriorHistory) { HistoryCheckButton.State = NSCellStateValue.On; } HistoryCheckButton.SetButtonType(NSButtonType.Switch); AddButton = new NSButton() { Title = "Add", Enabled = false }; CancelButton = new NSButton() { Title = "Cancel" }; Controller.ChangeAddressFieldEvent += delegate(string text, string example_text, FieldState state) { Program.Controller.Invoke(() => { AddressTextField.StringValue = text; AddressTextField.Enabled = (state == FieldState.Enabled); AddressHelpLabel.StringValue = example_text; }); }; Controller.ChangePathFieldEvent += delegate(string text, string example_text, FieldState state) { Program.Controller.Invoke(() => { PathTextField.StringValue = text; PathTextField.Enabled = (state == FieldState.Enabled); PathHelpLabel.StringValue = example_text; }); }; (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); }; HistoryCheckButton.Activated += delegate { Controller.HistoryItemChanged(HistoryCheckButton.State == NSCellStateValue.On); }; AddButton.Activated += delegate { Controller.AddPageCompleted(AddressTextField.StringValue, PathTextField.StringValue); }; CancelButton.Activated += delegate { Controller.PageCancelled(); }; Controller.UpdateAddProjectButtonEvent += delegate(bool button_enabled) { Program.Controller.Invoke(() => { 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); ContentView.AddSubview(HistoryCheckButton); Buttons.Add(AddButton); Buttons.Add(CancelButton); Controller.CheckAddPage(AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow); } if (type == PageType.Syncing) { Header = "Adding project ‘" + Controller.SyncingFolder + "’…"; Description = "This may take a while for large projects.\nIsn’t it 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 = Controller.ProgressBarPercentage }; ProgressIndicator.StartAnimation(this); CancelButton = new NSButton() { Title = "Cancel" }; FinishButton = new NSButton() { Title = "Finish", Enabled = false }; ProgressLabel = new SparkleLabel("Preparing to fetch files…", NSTextAlignment.Right); ProgressLabel.Frame = new RectangleF(Frame.Width - 40 - 250, 185, 250, 25); Controller.UpdateProgressBarEvent += delegate(double percentage, string speed) { Program.Controller.Invoke(() => { ProgressIndicator.DoubleValue = percentage; ProgressLabel.StringValue = speed; }); }; CancelButton.Activated += delegate { Controller.SyncingCancelled(); }; ContentView.AddSubview(ProgressLabel); ContentView.AddSubview(ProgressIndicator); Buttons.Add(FinishButton); Buttons.Add(CancelButton); } if (type == PageType.Error) { Header = "Oops! 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 = "<style>" + "* {" + " font-family: 'Lucida Grande';" + " font-size: 12px; cursor: default;" + "}" + "body {" + " -webkit-user-select: none;" + " margin: 0;" + " padding: 3px;" + "}" + "li {" + " margin-bottom: 16px;" + " margin-left: 0;" + " padding-left: 0;" + " line-height: 20px;" + " word-wrap: break-word;" + "}" + "ul {" + " padding-left: 24px;" + "}" + "</style>" + "<ul>" + " <li><b>" + Controller.PreviousUrl + "</b> is the address we’ve compiled. Does this look alright?</li>" + " <li>Is this computer’s Client ID known by the host?</li>" + "</ul>"; if (warnings.Length > 0) { string warnings_markup = ""; foreach (string warning in warnings) { warnings_markup += "<br><b>" + warning + "</b>"; } html = html.Replace("</ul>", "<li>Here’s the raw error message: " + warnings_markup + "</li></ul>"); } web_view.MainFrame.LoadHtmlString(html, new NSUrl("")); web_view.DrawsBackground = false; CancelButton = new NSButton() { Title = "Cancel" }; TryAgainButton = new NSButton() { Title = "Try Again…" }; CancelButton.Activated += delegate { Controller.PageCancelled(); }; TryAgainButton.Activated += delegate { Controller.ErrorPageCompleted(); }; ContentView.AddSubview(web_view); Buttons.Add(TryAgainButton); Buttons.Add(CancelButton); } if (type == PageType.CryptoSetup || type == PageType.CryptoPassword) { if (type == PageType.CryptoSetup) { Header = "Set up file encryption"; Description = "Please a provide a strong password that you don’t use elsewhere."; } else { Header = "This project contains encrypted files"; Description = "Please enter the password to see their contents."; } int extra_pos_y = 0; if (type == PageType.CryptoPassword) { extra_pos_y = 20; } PasswordLabel = new SparkleLabel("Password:"******"Show password", State = NSCellStateValue.Off }; ShowPasswordCheckButton.SetButtonType(NSButtonType.Switch); WarningImage = NSImage.ImageNamed("NSInfo"); WarningImage.Size = new SizeF(24, 24); WarningImageView = new NSImageView() { Image = WarningImage, Frame = new RectangleF(200, Frame.Height - 320, 24, 24) }; WarningTextField = new SparkleLabel("This password can’t be changed later, and your files can’t be recovered if it’s forgotten.", NSTextAlignment.Left) { Frame = new RectangleF(235, Frame.Height - 390, 325, 100), }; CancelButton = new NSButton() { Title = "Cancel" }; ContinueButton = new NSButton() { Title = "Continue", Enabled = false }; Controller.UpdateCryptoPasswordContinueButtonEvent += delegate(bool button_enabled) { Program.Controller.Invoke(() => { ContinueButton.Enabled = button_enabled; }); }; Controller.UpdateCryptoSetupContinueButtonEvent += delegate(bool button_enabled) { Program.Controller.Invoke(() => { ContinueButton.Enabled = button_enabled; }); }; ShowPasswordCheckButton.Activated += delegate { if (PasswordTextField.Superview == ContentView) { PasswordTextField.RemoveFromSuperview(); ContentView.AddSubview(VisiblePasswordTextField); } else { VisiblePasswordTextField.RemoveFromSuperview(); ContentView.AddSubview(PasswordTextField); } }; (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { VisiblePasswordTextField.StringValue = PasswordTextField.StringValue; if (type == PageType.CryptoSetup) { Controller.CheckCryptoSetupPage(PasswordTextField.StringValue); } else { Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue); } }; (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { PasswordTextField.StringValue = VisiblePasswordTextField.StringValue; if (type == PageType.CryptoSetup) { Controller.CheckCryptoSetupPage(PasswordTextField.StringValue); } else { Controller.CheckCryptoPasswordPage(PasswordTextField.StringValue); } }; ContinueButton.Activated += delegate { if (type == PageType.CryptoSetup) { Controller.CryptoSetupPageCompleted(PasswordTextField.StringValue); } else { Controller.CryptoPasswordPageCompleted(PasswordTextField.StringValue); } }; CancelButton.Activated += delegate { Controller.CryptoPageCancelled(); }; ContentView.AddSubview(PasswordLabel); ContentView.AddSubview(PasswordTextField); ContentView.AddSubview(ShowPasswordCheckButton); if (type == PageType.CryptoSetup) { ContentView.AddSubview(WarningImageView); ContentView.AddSubview(WarningTextField); } Buttons.Add(ContinueButton); Buttons.Add(CancelButton); MakeFirstResponder((NSResponder)PasswordTextField); NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest); } if (type == PageType.Finished) { Header = "Your shared project is ready!"; Description = "You can find the files in your SparkleShare folder."; if (warnings.Length > 0) { WarningImage = NSImage.ImageNamed("NSInfo"); WarningImage.Size = new SizeF(24, 24); WarningImageView = new NSImageView() { Image = WarningImage, Frame = new RectangleF(200, Frame.Height - 175, 24, 24) }; WarningTextField = new SparkleLabel(warnings [0], NSTextAlignment.Left); WarningTextField.Frame = new RectangleF(235, Frame.Height - 245, 325, 100); ContentView.AddSubview(WarningImageView); ContentView.AddSubview(WarningTextField); } ShowFilesButton = new NSButton() { Title = "Show Files…" }; FinishButton = new NSButton() { Title = "Finish" }; ShowFilesButton.Activated += delegate { Controller.ShowFilesClicked(); }; FinishButton.Activated += delegate { Controller.FinishPageCompleted(); }; Buttons.Add(FinishButton); Buttons.Add(ShowFilesButton); NSApplication.SharedApplication.RequestUserAttention(NSRequestUserAttentionType.CriticalRequest); } if (type == PageType.Tutorial) { SlideImage = NSImage.ImageNamed("tutorial-slide-" + Controller.TutorialPageNumber); if (SlideImage != null) { SlideImage.Size = new SizeF(324, 200); SlideImageView = new NSImageView() { Image = SlideImage, Frame = new RectangleF(228, Frame.Height - 350, 324, 200) }; ContentView.AddSubview(SlideImageView); } 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" }; ContinueButton = new NSButton() { Title = "Continue" }; SkipTutorialButton.Activated += delegate { Controller.TutorialSkipped(); }; ContinueButton.Activated += delegate { Controller.TutorialPageCompleted(); }; 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(); }; Buttons.Add(ContinueButton); break; } case 3: { Header = "The status icon helps you"; Description = "It shows the syncing progress, provides easy access to " + "your projects, and lets you view recent changes."; ContinueButton = new NSButton() { Title = "Continue" }; ContinueButton.Activated += delegate { Controller.TutorialPageCompleted(); }; Buttons.Add(ContinueButton); break; } case 4: { Header = "Here’s your unique Client ID"; Description = "You’ll need it whenever you want to link this computer to a host. " + "You can also find it in the status icon menu."; LinkCodeTextField = new NSTextField() { StringValue = Program.Controller.CurrentUser.PublicKey, Enabled = false, Selectable = false, Frame = new RectangleF(230, Frame.Height - 238, 246, 22) }; LinkCodeTextField.Cell.UsesSingleLineMode = true; LinkCodeTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; CopyButton = new NSButton() { Title = "Copy", BezelStyle = NSBezelStyle.RoundRect, Frame = new RectangleF(480, Frame.Height - 238, 60, 22) }; 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); FinishButton = new NSButton() { Title = "Finish" }; StartupCheckButton.Activated += delegate { Controller.StartupItemChanged(StartupCheckButton.State == NSCellStateValue.On); }; CopyButton.Activated += delegate { Controller.CopyToClipboardClicked(); }; FinishButton.Activated += delegate { Controller.TutorialPageCompleted(); }; ContentView.AddSubview(LinkCodeTextField); ContentView.AddSubview(CopyButton); ContentView.AddSubview(StartupCheckButton); Buttons.Add(FinishButton); break; } } } }
public static void NewPassword(SqliteConnection connection, SqliteConnection _conn) { var newPasswordInput = new NSStackView(new CGRect(0, 0, 300, 50)); var originalPassword = new NSSecureTextField(new CGRect(0, 25, 300, 20)); originalPassword.PlaceholderAttributedString = new Foundation.NSAttributedString("Type new password..."); var confirmedPassword = new NSSecureTextField(new CGRect(0, 0, 300, 20)); confirmedPassword.PlaceholderAttributedString = new Foundation.NSAttributedString("Confirm password..."); newPasswordInput.AddSubview(originalPassword); newPasswordInput.AddSubview(confirmedPassword); var newPasswordAlert = new NSAlert() { AlertStyle = NSAlertStyle.Informational, InformativeText = "Enter new password to secure SittingDucks", MessageText = "Adding New Password", }; var enterButton = newPasswordAlert.AddButton("Enter"); originalPassword.NextKeyView = confirmedPassword; confirmedPassword.NextKeyView = enterButton; newPasswordAlert.AccessoryView = newPasswordInput; newPasswordAlert.Layout(); var result = newPasswordAlert.RunModal(); if (result == 1000 && originalPassword.StringValue == confirmedPassword.StringValue) { bool shouldClose; var encryptedPassword = EncryptionTool.Encrypt(originalPassword.StringValue); (_conn, shouldClose) = SqliteManager.OpenConnection(connection); // Execute query using (var command = connection.CreateCommand()) { // Create new command command.CommandText = "UPDATE [System] SET ID = @COL1, Password = @COL2, INIT = @COL3"; // Populate with data from the record command.Parameters.AddWithValue("@COL1", new Guid()); command.Parameters.AddWithValue("@COL2", encryptedPassword); command.Parameters.AddWithValue("@COL3", true); // Write to database command.ExecuteNonQuery(); } _conn = SqliteManager.CloseConnection(shouldClose, connection); newPasswordAlert.Dispose(); var confirmPasswordAlert = new NSAlert() { AlertStyle = NSAlertStyle.Informational, InformativeText = "Remember this password, store it somewhere safe! You will not be able to recover it if lost.", MessageText = "Password sucessfully saved", }; confirmPasswordAlert.AddButton("OK"); var confirmResult = confirmPasswordAlert.RunModal(); if (confirmResult == 1000) { confirmPasswordAlert.Dispose(); } } else if (result == 1000 && originalPassword.StringValue != confirmedPassword.StringValue) { newPasswordAlert.AlertStyle = NSAlertStyle.Warning; newPasswordAlert.InformativeText = "Passwords do not match"; } }
public void ShowPage(Controller.PageType type, string [] warnings) { EventHandler WillCloseDelegate = delegate { if(currentWindowCloseApplication){ Program.Controller.Quit(); } else { SparkleSetupController.FinishPageCompleted (); } }; this.WillClose += WillCloseDelegate; if (type == Controller.PageType.Login) { currentWindowCloseApplication = true; background_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "loginScreen.png"); FullNameTextField = new NSTextField () { Frame = new RectangleF (90, Frame.Height - 337, 270, 25), Delegate = new SparkleTextFieldDelegate (), Bordered = false, Bezeled = false, FocusRingType = NSFocusRingType.None, Alignment = NSTextAlignment.Center }; NSSecureTextField PasswordTextField = new NSSecureTextField(){ Frame = new RectangleF (90, Frame.Height - 397, 270, 25), Delegate = new SparkleTextFieldDelegate (), Bordered = false, Bezeled = false, FocusRingType = NSFocusRingType.None, Alignment = NSTextAlignment.Center }; NSTextField MessageLabel = new NSTextField () { Alignment = NSTextAlignment.Left, BackgroundColor = NSColor.Clear, Bordered = false, Editable = false, Frame = new RectangleF (88, 70 , Frame.Width, 60), StringValue = "The username or password you entered is incorrect.\n", Font = NSFontManager.SharedFontManager.FontWithFamily ( "Lucida Grande", NSFontTraitMask.Bold, 0, 10), TextColor = NSColor.Red }; RegisterButton = new NSButton () { Frame = new RectangleF (49, 18, 137, 40), Image = new NSImage(Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "CreateButton159.png")), Transparent = false, Bordered = false, Enabled = true }; ContinueButton = new NSButton () { Frame = new RectangleF (264, 18, 137, 40), Image = new NSImage(Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "LoginButton242.png")), Transparent = false, Bordered = false, Enabled = true }; RegisterButton.Activated += delegate { Program.Controller.OpenWebsite("https://my.greenqloud.com/registration/qloudsync"); }; ContinueButton.Activated += delegate { try{ S3Connection.Authenticate (FullNameTextField.StringValue, PasswordTextField.StringValue); Credential.Username = FullNameTextField.StringValue; SparkleSetupController.LoginDone(); } catch (System.Net.WebException) { ContentView.AddSubview (MessageLabel); } }; ContentView.AddSubview (FullNameTextField); ContentView.AddSubview (PasswordTextField); Buttons.Add (ContinueButton); Buttons.Add (RegisterButton); } if (type == Controller.PageType.ConfigureFolders) { try { currentWindowCloseApplication = true; this.background_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "SelectSync1.png"); NSTextField SQFolderTextLabel = new NSTextField () { Alignment = NSTextAlignment.Center, BackgroundColor = NSColor.Clear, Bordered = false, Editable = false, Frame = new RectangleF (0, 75 , Frame.Width, 60), StringValue = "Current StorageQloud Path:", Font = NSFontManager.SharedFontManager.FontWithFamily ( "Lucida Grande", NSFontTraitMask.Unbold, 0, 9), TextColor = NSColor.White }; if(SQFolderText == null) { SQFolderText = new NSTextField () { Alignment = NSTextAlignment.Center, BackgroundColor = NSColor.Clear, Bordered = false, Editable = false, Frame = new RectangleF (0, 60 , Frame.Width, 60), StringValue = RuntimeSettings.DefaultHomePath, Font = NSFontManager.SharedFontManager.FontWithFamily ( "Lucida Grande", NSFontTraitMask.Unbold, 0, 9), TextColor = NSColor.White }; } ChangeSQFolder = new NSButton () { Frame = new RectangleF (49, 18, 137, 40), Image = new NSImage(Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "Changeit220.png")), Transparent = false, Bordered = false, Enabled = true }; ChangeSQFolder.Activated += delegate { SQFolderText.StringValue = SparkleSetupController.ChangeSQFolder (); Reset (); ShowPage(AbstractApplicationController.PageType.ConfigureFolders, null); ShowAll(); }; FinishButton = new NSButton () { Frame = new RectangleF (264, 18, 137, 40), Image = new NSImage(Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "Continue159.png")), Transparent = false, Bordered = false, Enabled = true }; FinishButton.Activated += delegate { DirectoryInfo dir = new DirectoryInfo(SQFolderText.StringValue); bool proceed = true; if(dir.Exists && (dir.GetDirectories().Length > 0 || dir.GetFiles().Length > 0) ){ if(!Program.Controller.Confirm("This folder is not empty, do you want to proceed? QloudSync will merge all files with your account.") ){ proceed = false; } } if(proceed){ SparkleSetupController.Finish (SQFolderText.StringValue, remoteFoldersCheckboxes); } else { Reset (); ShowPage(AbstractApplicationController.PageType.ConfigureFolders, null); ShowAll(); } }; InitializeCheckboxesFolders (); ContentView.AddSubview (SQFolderTextLabel); ContentView.AddSubview (SQFolderText); Buttons.Add (ChangeSQFolder); Buttons.Add (FinishButton); NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest); } catch (Exception e) { Logger.LogInfo ("ERROR ON LOADING CONFIG FOLDERS", e); Reset (); ShowPage(AbstractApplicationController.PageType.Login, null); ShowAll (); NSTextField MessageLabel = new NSTextField () { Alignment = NSTextAlignment.Left, BackgroundColor = NSColor.Clear, Bordered = false, Editable = false, Frame = new RectangleF (88, 55 , Frame.Width, 60), StringValue = "An unexpected error occurred, please try again later.\n", Font = NSFontManager.SharedFontManager.FontWithFamily ( "Lucida Grande", NSFontTraitMask.Bold, 0, 10), TextColor = NSColor.Red }; ContentView.AddSubview (MessageLabel); } } if (type == Controller.PageType.Finished) { currentWindowCloseApplication = false; this.background_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "getStarted.png"); OpenFolderButton = new NSButton () { Frame = new RectangleF (157, 18, 137, 40), Image = new NSImage(Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "getstartedbutton.png")), Transparent = false, Bordered = false, Enabled = true }; OpenFolderButton.Activated += delegate { SparkleSetupController.FinishPageCompleted (); SparkleSetupController.GetStartedClicked (); }; Buttons.Add (OpenFolderButton); NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest); } }
public void ShowPage(PageType type, string [] warnings) { if (type == PageType.Setup) { Header = "Welcome to QloudSync!"; FullNameLabel = new NSTextField () { Alignment = NSTextAlignment.Right, BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Frame = new RectangleF (165, Frame.Height - 234, 160, 17), StringValue = "Username:"******"Password:"******"The password you entered is incorrect.\n", Font = NSFontManager.SharedFontManager.FontWithFamily ( "Lucida Grande", NSFontTraitMask.Bold, 0, 10) }; CancelButton = new NSButton () { Title = "Cancel" }; ContinueButton = new NSButton () { Title = "Continue", Enabled = false }; (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { if(PasswordTextField.StringValue.Length < 3) ContinueButton.Enabled = false; else ContinueButton.Enabled = true; }; CancelButton.Activated += delegate { Controller.PageCancelled (); }; ContinueButton.Activated += delegate { try{ SQ.Net.Authentication aut = new SQ.Net.Authentication(); aut.Authenticate (FullNameTextField.StringValue, PasswordTextField.StringValue); SQ.QloudSyncPlugin.WriteKeys(); Controller.AddPageCompleted (FullNameTextField.StringValue, PasswordTextField.StringValue); } catch (System.Net.WebException) { ContentView.AddSubview (MessageLabel); } }; ContentView.AddSubview (FullNameLabel); ContentView.AddSubview (FullNameTextField); ContentView.AddSubview (EmailLabel); ContentView.AddSubview (PasswordTextField); Buttons.Add (ContinueButton); Buttons.Add (CancelButton); //Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue); } if (type == PageType.Invite) { Header = "You've received an invite!"; Description = "Do you want to add this project to QloudSync?"; 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 }; CancelButton = new NSButton () { Title = "Cancel" }; AddButton = new NSButton () { Title = "Add" }; CancelButton.Activated += delegate { Controller.PageCancelled (); }; AddButton.Activated += delegate { Controller.InvitePageCompleted (); }; ContentView.AddSubview (AddressLabel); ContentView.AddSubview (PathLabel); ContentView.AddSubview (AddressTextField); ContentView.AddSubview (PathTextField); Buttons.Add (AddButton); Buttons.Add (CancelButton); } if (type == 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, Enabled = (Controller.SelectedPlugin.Address == null), Delegate = new SparkleTextFieldDelegate (), StringValue = "" + Controller.PreviousAddress }; AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; 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), Enabled = (Controller.SelectedPlugin.Path == null), Delegate = new SparkleTextFieldDelegate (), StringValue = "" + Controller.PreviousPath }; 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), Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11), StringValue = "" //+ Controller.SelectedPlugin.PathExample }; AddressHelpLabel = new NSTextField () { BackgroundColor = NSColor.WindowBackground, Bordered = false, TextColor = NSColor.DisabledControlText, Editable = false, Frame = new RectangleF (190, Frame.Height - 355, 204, 17), Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande", NSFontTraitMask.Condensed, 0, 11), StringValue = "" + Controller.SelectedPlugin.AddressExample }; TableView = new NSTableView () { Frame = new RectangleF (0, 0, 0, 0), RowHeight = 34, IntercellSpacing = new SizeF (8, 12), HeaderView = null, Delegate = new SparkleTableViewDelegate () }; ScrollView = new NSScrollView () { Frame = new RectangleF (190, Frame.Height - 280, 408, 185), DocumentView = TableView, HasVerticalScroller = true, BorderType = NSBorderType.BezelBorder }; IconColumn = new NSTableColumn (new NSImage ()) { Width = 36, HeaderToolTip = "Icon", DataCell = new NSImageCell () { ImageAlignment = NSImageAlignment.Right } }; 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 (Controller.Plugins); TableView.DataSource = DataSource; TableView.ReloadData (); HistoryCheckButton = new NSButton () { Frame = new RectangleF (190, Frame.Height - 400, 300, 18), Title = "Fetch prior revisions" }; if (Controller.FetchPriorHistory) HistoryCheckButton.State = NSCellStateValue.On; HistoryCheckButton.SetButtonType (NSButtonType.Switch); AddButton = new NSButton () { Title = "Add", Enabled = false }; CancelButton = new NSButton () { Title = "Cancel" }; NSSecureTextField Password = new NSSecureTextField(){ Frame = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22), Enabled = (Controller.SelectedPlugin.Path == null), Delegate = new SparkleTextFieldDelegate (), Hidden = true }; ContentView.AddSubview (Password); //adding the plugin support to the program Controller.ChangeAddressFieldEvent += delegate(string text, string example_text, FieldState state) { if (text == "QloudSync" && example_text == "QloudSync"){ InvokeOnMainThread (delegate { AddressLabel.StringValue = "Login:"******""; PathLabel.StringValue = "Password:"******""; PathTextField.Enabled = true; PathHelpLabel.StringValue = ""; AddressHelpLabel.StringValue = ""; Password.Hidden = false; PathTextField.Hidden = true; PathTextField.Enabled = false; }); } else { InvokeOnMainThread (delegate { AddressTextField.StringValue = text; AddressTextField.Enabled = (state == FieldState.Enabled); AddressHelpLabel.StringValue = example_text; Password.StringValue = ""; Password.Hidden = true; PathTextField.Hidden = false; //PathTextField.StringValue = ""; AddressLabel.StringValue = "Address:"; PathLabel.StringValue = "Remote Path:"; }); } }; 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); TableView.ScrollRowToVisible (Controller.SelectedPluginIndex); (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); }; (Password.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { Controller.CheckAddPage (AddressTextField.StringValue, Password.StringValue, TableView.SelectedRow); }; (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate { Controller.SelectedPluginChanged (TableView.SelectedRow); Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow); }; HistoryCheckButton.Activated += delegate { Controller.HistoryItemChanged (HistoryCheckButton.State == NSCellStateValue.On); }; AddButton.Activated += delegate { if (Password.StringValue == "") Controller.AddPageCompleted (AddressTextField.StringValue, PathTextField.StringValue); else Controller.AddPageCompleted (AddressTextField.StringValue, Password.StringValue); }; CancelButton.Activated += delegate { Controller.PageCancelled (); }; 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); ContentView.AddSubview (HistoryCheckButton); Buttons.Add (AddButton); Buttons.Add (CancelButton); Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow); } if (type == PageType.Syncing) { Header = "Adding project ‘" + Controller.SyncingFolder + "’…"; Description = "This may take a while for large projects.\nIsn't it 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 = Controller.ProgressBarPercentage }; ProgressIndicator.StartAnimation (this); CancelButton = new NSButton () { Title = "Cancel" }; FinishButton = new NSButton () { Title = "Finish", Enabled = false }; Controller.UpdateProgressBarEvent += delegate (double percentage) { InvokeOnMainThread (() => { ProgressIndicator.DoubleValue = percentage; }); }; CancelButton.Activated += delegate { Controller.SyncingCancelled (); }; ContentView.AddSubview (ProgressIndicator); Buttons.Add (FinishButton); Buttons.Add (CancelButton); } if (type == PageType.Error) { Header = "Oops! 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 = "<style>" + "* {" + " font-family: 'Lucida Grande';" + " font-size: 12px; cursor: default;" + "}" + "body {" + " -webkit-user-select: none;" + " margin: 0;" + " padding: 3px;" + "}" + "li {" + " margin-bottom: 16px;" + " margin-left: 0;" + " padding-left: 0;" + " line-height: 20px;" + "}" + "ul {" + " padding-left: 24px;" + "}" + "</style>" + "<ul>" + " <li><b>" + Controller.PreviousUrl + "</b> is the address we've compiled. Does this look alright?</li>" + " <li>Do you have access rights to this remote project?</li>" + "</ul>"; if (warnings.Length > 0) { string warnings_markup = ""; foreach (string warning in warnings) warnings_markup += "<br><b>" + warning + "</b>"; html = html.Replace ("</ul>", "<li>Here's the raw error message: " + warnings_markup + "</li></ul>"); } web_view.MainFrame.LoadHtmlString (html, new NSUrl ("")); web_view.DrawsBackground = false; CancelButton = new NSButton () { Title = "Cancel" }; TryAgainButton = new NSButton () { Title = "Try again…" }; CancelButton.Activated += delegate { Controller.PageCancelled (); }; TryAgainButton.Activated += delegate { Controller.ErrorPageCompleted (); }; ContentView.AddSubview (web_view); Buttons.Add (TryAgainButton); Buttons.Add (CancelButton); } if (type == PageType.CryptoSetup) { Header = "Set up file encryption"; Description = "This project is supposed to be encrypted, but it doesn't yet have a password set. Please provide one below:"; PasswordLabel = new NSTextField () { Alignment = NSTextAlignment.Right, BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Frame = new RectangleF (155, Frame.Height - 204, 160, 17), StringValue = "Password:"******"Show password", State = NSCellStateValue.Off }; ShowPasswordCheckButton.SetButtonType (NSButtonType.Switch); WarningImage = NSImage.ImageNamed ("NSInfo"); WarningImage.Size = new SizeF (24, 24); WarningImageView = new NSImageView () { Image = WarningImage, Frame = new RectangleF (200, Frame.Height - 320, 24, 24) }; WarningTextField = new NSTextField () { Frame = new RectangleF (235, Frame.Height - 390, 325, 100), StringValue = "This password can't be changed later, and your files can't be recovered if it's forgotten.", BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Font = SparkleUI.Font }; CancelButton = new NSButton () { Title = "Cancel" }; ContinueButton = new NSButton () { Title = "Continue", Enabled = false }; ShowPasswordCheckButton.Activated += delegate { if (PasswordTextField.Superview == ContentView) { PasswordTextField.RemoveFromSuperview (); ContentView.AddSubview (VisiblePasswordTextField); } else { VisiblePasswordTextField.RemoveFromSuperview (); ContentView.AddSubview (PasswordTextField); } }; (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { VisiblePasswordTextField.StringValue = PasswordTextField.StringValue; Controller.CheckCryptoSetupPage (PasswordTextField.StringValue); }; (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { PasswordTextField.StringValue = VisiblePasswordTextField.StringValue; Controller.CheckCryptoSetupPage (PasswordTextField.StringValue); }; Controller.UpdateCryptoSetupContinueButtonEvent += delegate (bool button_enabled) { InvokeOnMainThread (() => { ContinueButton.Enabled = button_enabled; }); }; ContinueButton.Activated += delegate { Controller.CryptoSetupPageCompleted (PasswordTextField.StringValue); }; CancelButton.Activated += delegate { Controller.CryptoPageCancelled (); }; ContentView.AddSubview (PasswordLabel); ContentView.AddSubview (PasswordTextField); ContentView.AddSubview (ShowPasswordCheckButton); ContentView.AddSubview (WarningImageView); ContentView.AddSubview (WarningTextField); Buttons.Add (ContinueButton); Buttons.Add (CancelButton); NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest); } if (type == PageType.CryptoPassword) { Header = "This project contains encrypted files"; Description = "Please enter the password to see their contents."; PasswordLabel = new NSTextField () { Alignment = NSTextAlignment.Right, BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Frame = new RectangleF (155, Frame.Height - 224, 160, 17), StringValue = "Password:"******"Show password", State = NSCellStateValue.Off }; ShowPasswordCheckButton.SetButtonType (NSButtonType.Switch); CancelButton = new NSButton () { Title = "Cancel" }; ContinueButton = new NSButton () { Title = "Continue", Enabled = false }; Controller.UpdateCryptoPasswordContinueButtonEvent += delegate (bool button_enabled) { InvokeOnMainThread (() => { ContinueButton.Enabled = button_enabled; }); }; ShowPasswordCheckButton.Activated += delegate { if (PasswordTextField.Superview == ContentView) { PasswordTextField.RemoveFromSuperview (); ContentView.AddSubview (VisiblePasswordTextField); } else { VisiblePasswordTextField.RemoveFromSuperview (); ContentView.AddSubview (PasswordTextField); } }; (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { VisiblePasswordTextField.StringValue = PasswordTextField.StringValue; Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue); }; (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { PasswordTextField.StringValue = VisiblePasswordTextField.StringValue; Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue); }; ContinueButton.Activated += delegate { Controller.CryptoPasswordPageCompleted (PasswordTextField.StringValue); }; CancelButton.Activated += delegate { Controller.CryptoPageCancelled (); }; ContentView.AddSubview (PasswordLabel); ContentView.AddSubview (PasswordTextField); ContentView.AddSubview (ShowPasswordCheckButton); Buttons.Add (ContinueButton); Buttons.Add (CancelButton); NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest); } if (type == PageType.Finished) { Header = "Your shared project is ready!"; Description = "You can find the files in your QloudSync folder."; if (warnings.Length > 0) { WarningImage = NSImage.ImageNamed ("NSInfo"); WarningImage.Size = new SizeF (24, 24); WarningImageView = new NSImageView () { Image = WarningImage, Frame = new RectangleF (200, Frame.Height - 175, 24, 24) }; WarningTextField = new NSTextField () { Frame = new RectangleF (235, Frame.Height - 245, 325, 100), StringValue = warnings [0], BackgroundColor = NSColor.WindowBackground, Bordered = false, Editable = false, Font = SparkleUI.Font }; ContentView.AddSubview (WarningImageView); ContentView.AddSubview (WarningTextField); } OpenFolderButton = new NSButton () { Title = "Show folder" }; FinishButton = new NSButton () { Title = "Finish" }; OpenFolderButton.Activated += delegate { Controller.OpenFolderClicked (); }; FinishButton.Activated += delegate { SQ.QloudSyncPlugin.InitRepo = true; Controller.FinishPageCompleted (); }; Buttons.Add (FinishButton); Buttons.Add (OpenFolderButton); NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest); } if (type == PageType.Tutorial) { string slide_image_path = Path.Combine (NSBundle.MainBundle.ResourcePath, "Pixmaps", "tutorial-slide-" + Controller.TutorialPageNumber + ".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); switch (Controller.TutorialPageNumber) { case 1: { Header = "What's happening next?"; Description = "QloudSync creates a special folder on your computer " + "that will keep track of your projects."; SkipTutorialButton = new NSButton () { Title = "Skip Tutorial" }; ContinueButton = new NSButton () { Title = "Continue" }; SkipTutorialButton.Activated += delegate { Controller.TutorialSkipped (); }; ContinueButton.Activated += delegate { Controller.TutorialPageCompleted (); }; 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 (); }; 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 (); }; Buttons.Add (ContinueButton); break; } case 4: { Header = "Adding projects to QloudSync"; 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 QloudSync to startup items", State = NSCellStateValue.On }; StartupCheckButton.SetButtonType (NSButtonType.Switch); FinishButton = new NSButton () { Title = "Finish" }; SlideImage.Size = new SizeF (350, 64); StartupCheckButton.Activated += delegate { Controller.StartupItemChanged (StartupCheckButton.State == NSCellStateValue.On); }; FinishButton.Activated += delegate { Controller.TutorialPageCompleted (); }; ContentView.AddSubview (StartupCheckButton); Buttons.Add (FinishButton); break; } } } }
public void ShowPage (PageType type, string [] warnings) { if (type == PageType.Setup) { Header = "Welcome to SparkleShare!"; Description = "First off, what’s your name and email?\n(visible only to team members)"; FullNameLabel = new SparkleLabel ("Full Name:", NSTextAlignment.Right); FullNameLabel.Frame = new RectangleF (165, Frame.Height - 234, 160, 17); FullNameTextField = new NSTextField () { Frame = new RectangleF (330, Frame.Height - 238, 196, 22), StringValue = UnixUserInfo.GetRealUser ().RealName, Delegate = new SparkleTextFieldDelegate () }; EmailLabel = new SparkleLabel ("Email:", NSTextAlignment.Right); EmailLabel.Frame = new RectangleF (165, Frame.Height - 264, 160, 17); EmailTextField = new NSTextField () { Frame = new RectangleF (330, Frame.Height - 268, 196, 22), Delegate = new SparkleTextFieldDelegate () }; CancelButton = new NSButton () { Title = "Cancel" }; ContinueButton = new NSButton () { Title = "Continue", Enabled = false }; (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.Activated += delegate { string full_name = FullNameTextField.StringValue.Trim (); string email = EmailTextField.StringValue.Trim (); Controller.SetupPageCompleted (full_name, email); }; CancelButton.Activated += delegate { Controller.SetupPageCancelled (); }; Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) { SparkleShare.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; }); }; ContentView.AddSubview (FullNameLabel); ContentView.AddSubview (FullNameTextField); ContentView.AddSubview (EmailLabel); ContentView.AddSubview (EmailTextField); Buttons.Add (ContinueButton); Buttons.Add (CancelButton); Controller.CheckSetupPage (FullNameTextField.StringValue, EmailTextField.StringValue); if (FullNameTextField.StringValue.Equals ("")) MakeFirstResponder ((NSResponder) FullNameTextField); else MakeFirstResponder ((NSResponder) EmailTextField); } if (type == PageType.Invite) { Header = "You’ve received an invite!"; Description = "Do you want to add this project to SparkleShare?"; AddressLabel = new SparkleLabel ("Address:", NSTextAlignment.Right); AddressLabel.Frame = new RectangleF (165, Frame.Height - 238, 160, 17); AddressLabel.Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize); AddressTextField = new SparkleLabel (Controller.PendingInvite.Address, NSTextAlignment.Left) { Frame = new RectangleF (330, Frame.Height - 240, 260, 17) }; PathLabel = new SparkleLabel ("Remote Path:", NSTextAlignment.Right); PathLabel.Frame = new RectangleF (165, Frame.Height - 262, 160, 17); PathLabel.Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize); PathTextField = new SparkleLabel (Controller.PendingInvite.RemotePath, NSTextAlignment.Left) { Frame = new RectangleF (330, Frame.Height - 264, 260, 17) }; CancelButton = new NSButton () { Title = "Cancel" }; AddButton = new NSButton () { Title = "Add" }; CancelButton.Activated += delegate { Controller.PageCancelled (); }; AddButton.Activated += delegate { Controller.InvitePageCompleted (); }; ContentView.AddSubview (AddressLabel); ContentView.AddSubview (PathLabel); ContentView.AddSubview (AddressTextField); ContentView.AddSubview (PathTextField); Buttons.Add (AddButton); Buttons.Add (CancelButton); } if (type == PageType.Add) { Header = "Where’s your project hosted?"; Description = ""; AddressLabel = new SparkleLabel ("Address:", NSTextAlignment.Left) { Frame = new RectangleF (190, Frame.Height - 308, 160, 17), Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize) }; AddressTextField = new NSTextField () { Frame = new RectangleF (190, Frame.Height - 336, 196, 22), Enabled = (Controller.SelectedPreset.Address == null), Delegate = new SparkleTextFieldDelegate (), StringValue = "" + Controller.PreviousAddress }; AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; PathLabel = new SparkleLabel ("Remote Path:", NSTextAlignment.Left) { Frame = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17), Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize) }; PathTextField = new NSTextField () { Frame = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22), Enabled = (Controller.SelectedPreset.Path == null), Delegate = new SparkleTextFieldDelegate (), StringValue = "" + Controller.PreviousPath }; PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; PathHelpLabel = new SparkleLabel (Controller.SelectedPreset.PathExample, NSTextAlignment.Left) { TextColor = NSColor.DisabledControlText, Frame = new RectangleF (190 + 196 + 16, Frame.Height - 358, 204, 19) }; AddressHelpLabel = new SparkleLabel (Controller.SelectedPreset.AddressExample, NSTextAlignment.Left) { TextColor = NSColor.DisabledControlText, Frame = new RectangleF (190, Frame.Height - 358, 204, 19) }; if (TableView == null || TableView.RowCount != Controller.Presets.Count) { TableView = new NSTableView () { Frame = new RectangleF (0, 0, 0, 0), RowHeight = 38, IntercellSpacing = new SizeF (8, 12), HeaderView = null, Delegate = new SparkleTableViewDelegate () }; ScrollView = new NSScrollView () { Frame = new RectangleF (190, Frame.Height - 280, 408, 185), DocumentView = TableView, HasVerticalScroller = true, BorderType = NSBorderType.BezelBorder }; IconColumn = new NSTableColumn () { Width = 36, HeaderToolTip = "Icon", DataCell = new NSImageCell () { ImageAlignment = NSImageAlignment.Right } }; DescriptionColumn = new NSTableColumn () { Width = 350, HeaderToolTip = "Description", Editable = false }; DescriptionColumn.DataCell.Font = NSFontManager.SharedFontManager.FontWithFamily ( UserInterface.FontName, NSFontTraitMask.Condensed, 0, 11); TableView.AddColumn (IconColumn); TableView.AddColumn (DescriptionColumn); // Hi-res display support was added after Snow Leopard if (Environment.OSVersion.Version.Major < 11) DataSource = new SparkleDataSource (1, Controller.Presets); else DataSource = new SparkleDataSource (BackingScaleFactor, Controller.Presets); TableView.DataSource = DataSource; TableView.ReloadData (); (TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate { Controller.SelectedPresetChanged (TableView.SelectedRow); Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow); }; } TableView.SelectRow (Controller.SelectedPresetIndex, false); TableView.ScrollRowToVisible (Controller.SelectedPresetIndex); MakeFirstResponder ((NSResponder) TableView); HistoryCheckButton = new NSButton () { Frame = new RectangleF (190, Frame.Height - 400, 300, 18), Title = "Fetch prior revisions" }; if (Controller.FetchPriorHistory) HistoryCheckButton.State = NSCellStateValue.On; HistoryCheckButton.SetButtonType (NSButtonType.Switch); AddButton = new NSButton () { Title = "Add", Enabled = false }; CancelButton = new NSButton () { Title = "Cancel" }; Controller.ChangeAddressFieldEvent += delegate (string text, string example_text, FieldState state) { SparkleShare.Controller.Invoke (() => { AddressTextField.StringValue = text; AddressTextField.Enabled = (state == FieldState.Enabled); AddressHelpLabel.StringValue = example_text; }); }; Controller.ChangePathFieldEvent += delegate (string text, string example_text, FieldState state) { SparkleShare.Controller.Invoke (() => { PathTextField.StringValue = text; PathTextField.Enabled = (state == FieldState.Enabled); PathHelpLabel.StringValue = example_text; }); }; (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); }; HistoryCheckButton.Activated += delegate { Controller.HistoryItemChanged (HistoryCheckButton.State == NSCellStateValue.On); }; AddButton.Activated += delegate { Controller.AddPageCompleted (AddressTextField.StringValue, PathTextField.StringValue); }; CancelButton.Activated += delegate { Controller.PageCancelled (); }; Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) { SparkleShare.Controller.Invoke (() => { 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); ContentView.AddSubview (HistoryCheckButton); Buttons.Add (AddButton); Buttons.Add (CancelButton); Controller.CheckAddPage (AddressTextField.StringValue, PathTextField.StringValue, TableView.SelectedRow); } if (type == PageType.Syncing) { Header = "Adding project ‘" + Controller.SyncingFolder + "’…"; Description = "This may take a while for large projects.\nIsn’t it 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 = Controller.ProgressBarPercentage }; ProgressIndicator.StartAnimation (this); CancelButton = new NSButton () { Title = "Cancel" }; FinishButton = new NSButton () { Title = "Finish", Enabled = false }; ProgressLabel = new SparkleLabel ("Preparing to fetch files…", NSTextAlignment.Right); ProgressLabel.Frame = new RectangleF (Frame.Width - 40 - 250, 185, 250, 25); Controller.UpdateProgressBarEvent += delegate (double percentage, string speed) { SparkleShare.Controller.Invoke (() => { ProgressIndicator.DoubleValue = percentage; ProgressLabel.StringValue = speed; }); }; CancelButton.Activated += delegate { Controller.SyncingCancelled (); }; ContentView.AddSubview (ProgressLabel); ContentView.AddSubview (ProgressIndicator); Buttons.Add (FinishButton); Buttons.Add (CancelButton); } if (type == PageType.Error) { Header = "Oops! 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 = "<style>" + "* {" + " font-family: '" + UserInterface.FontName + "';" + " font-size: 12px; cursor: default;" + "}" + "body {" + " -webkit-user-select: none;" + " margin: 0;" + " padding: 3px;" + "}" + "li {" + " margin-bottom: 16px;" + " margin-left: 0;" + " padding-left: 0;" + " line-height: 20px;" + " word-wrap: break-word;" + "}" + "ul {" + " padding-left: 24px;" + "}" + "</style>" + "<ul>" + " <li><b>" + Controller.PreviousUrl + "</b> is the address we’ve compiled. Does this look alright?</li>" + " <li>Is this computer’s Client ID known by the host?</li>" + "</ul>"; if (warnings.Length > 0) { string warnings_markup = ""; foreach (string warning in warnings) warnings_markup += "<br><b>" + warning + "</b>"; html = html.Replace ("</ul>", "<li>Here’s the raw error message: " + warnings_markup + "</li></ul>"); } web_view.MainFrame.LoadHtmlString (html, new NSUrl ("")); web_view.DrawsBackground = false; CancelButton = new NSButton () { Title = "Cancel" }; TryAgainButton = new NSButton () { Title = "Retry" }; CancelButton.Activated += delegate { Controller.PageCancelled (); }; TryAgainButton.Activated += delegate { Controller.ErrorPageCompleted (); }; ContentView.AddSubview (web_view); Buttons.Add (TryAgainButton); Buttons.Add (CancelButton); } if (type == PageType.StorageSetup) { Header = string.Format ("Storage type for ‘{0}’", Controller.SyncingFolder); Description = "What type of storage would you like to use?"; storage_type_descriptions = new List<NSTextField> (); ButtonCellProto = new NSButtonCell (); ButtonCellProto.SetButtonType (NSButtonType.Radio); ButtonCellProto.Font = NSFont.FromFontName (UserInterface.FontName + " Bold", NSFont.SystemFontSize); Matrix = new NSMatrix (new RectangleF (202, Frame.Height - 256 - 128, 256, 256), NSMatrixMode.Radio, ButtonCellProto, SparkleShare.Controller.FetcherAvailableStorageTypes.Count, 1); Matrix.CellSize = new SizeF (256, 36); Matrix.IntercellSpacing = new SizeF (32, 32); int i = 0; foreach (StorageTypeInfo storage_type in SparkleShare.Controller.FetcherAvailableStorageTypes) { Matrix.Cells [i].Title = " " + storage_type.Name; NSTextField storage_type_description = new SparkleLabel (storage_type.Description, NSTextAlignment.Left) { TextColor = NSColor.DisabledControlText, Frame = new RectangleF (223, Frame.Height - 190 - (68 * i), 256, 32) }; storage_type_descriptions.Add (storage_type_description); ContentView.AddSubview (storage_type_description); i++; } ContentView.AddSubview (Matrix); CancelButton = new NSButton () { Title = "Cancel" }; ContinueButton = new NSButton () { Title = "Continue" }; ContinueButton.Activated += delegate { StorageTypeInfo selected_storage_type = SparkleShare.Controller.FetcherAvailableStorageTypes [Matrix.SelectedRow]; Controller.StoragePageCompleted (selected_storage_type.Type); }; CancelButton.Activated += delegate { Controller.SyncingCancelled (); }; Buttons.Add (ContinueButton); Buttons.Add (CancelButton); NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest); } if (type == PageType.CryptoSetup || type == PageType.CryptoPassword) { if (type == PageType.CryptoSetup) { Header = "Set up file encryption"; Description = "Please a provide a strong password that you don’t use elsewhere."; } else { Header = "This project contains encrypted files"; Description = "Please enter the password to see their contents."; } int extra_pos_y = 0; if (type == PageType.CryptoPassword) extra_pos_y = 20; PasswordLabel = new SparkleLabel ("Password:"******" Bold", NSFont.SystemFontSize) }; PasswordTextField = new NSSecureTextField () { Frame = new RectangleF (320, Frame.Height - 208 - extra_pos_y, 196, 22), Delegate = new SparkleTextFieldDelegate () }; VisiblePasswordTextField = new NSTextField () { Frame = new RectangleF (320, Frame.Height - 208 - extra_pos_y, 196, 22), Delegate = new SparkleTextFieldDelegate () }; ShowPasswordCheckButton = new NSButton () { Frame = new RectangleF (318, Frame.Height - 235 - extra_pos_y, 300, 18), Title = "Show password", State = NSCellStateValue.Off }; ShowPasswordCheckButton.SetButtonType (NSButtonType.Switch); WarningImage = NSImage.ImageNamed ("NSInfo"); WarningImage.Size = new SizeF (24, 24); WarningImageView = new NSImageView () { Image = WarningImage, Frame = new RectangleF (200, Frame.Height - 320, 24, 24) }; WarningTextField = new SparkleLabel ("This password can’t be changed later, and your files can’t be recovered if it’s forgotten.", NSTextAlignment.Left) { Frame = new RectangleF (235, Frame.Height - 390, 325, 100), }; CancelButton = new NSButton () { Title = "Cancel" }; ContinueButton = new NSButton () { Title = "Continue", Enabled = false }; Controller.UpdateCryptoPasswordContinueButtonEvent += delegate (bool button_enabled) { SparkleShare.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; }); }; Controller.UpdateCryptoSetupContinueButtonEvent += delegate (bool button_enabled) { SparkleShare.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; }); }; ShowPasswordCheckButton.Activated += delegate { if (PasswordTextField.Superview == ContentView) { PasswordTextField.RemoveFromSuperview (); ContentView.AddSubview (VisiblePasswordTextField); } else { VisiblePasswordTextField.RemoveFromSuperview (); ContentView.AddSubview (PasswordTextField); } }; (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { VisiblePasswordTextField.StringValue = PasswordTextField.StringValue; if (type == PageType.CryptoSetup) Controller.CheckCryptoSetupPage (PasswordTextField.StringValue); else Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue); }; (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { PasswordTextField.StringValue = VisiblePasswordTextField.StringValue; if (type == PageType.CryptoSetup) Controller.CheckCryptoSetupPage (PasswordTextField.StringValue); else Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue); }; ContinueButton.Activated += delegate { if (type == PageType.CryptoSetup) Controller.CryptoSetupPageCompleted (PasswordTextField.StringValue); else Controller.CryptoPasswordPageCompleted (PasswordTextField.StringValue); }; CancelButton.Activated += delegate { Controller.CryptoPageCancelled (); }; ContentView.AddSubview (PasswordLabel); ContentView.AddSubview (PasswordTextField); ContentView.AddSubview (ShowPasswordCheckButton); if (type == PageType.CryptoSetup) { ContentView.AddSubview (WarningImageView); ContentView.AddSubview (WarningTextField); } Buttons.Add (ContinueButton); Buttons.Add (CancelButton); MakeFirstResponder ((NSResponder) PasswordTextField); NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest); } if (type == PageType.Finished) { Header = "Your shared project is ready!"; Description = "You can find the files in your SparkleShare folder."; if (warnings.Length > 0) { WarningImage = NSImage.ImageNamed ("NSInfo"); WarningImage.Size = new SizeF (24, 24); WarningImageView = new NSImageView () { Image = WarningImage, Frame = new RectangleF (200, Frame.Height - 175, 24, 24) }; WarningTextField = new SparkleLabel (warnings [0], NSTextAlignment.Left); WarningTextField.Frame = new RectangleF (235, Frame.Height - 245, 325, 100); ContentView.AddSubview (WarningImageView); ContentView.AddSubview (WarningTextField); } ShowFilesButton = new NSButton () { Title = "Show Files" }; FinishButton = new NSButton () { Title = "Finish" }; ShowFilesButton.Activated += delegate { Controller.ShowFilesClicked (); }; FinishButton.Activated += delegate { Controller.FinishPageCompleted (); }; Buttons.Add (FinishButton); Buttons.Add (ShowFilesButton); NSApplication.SharedApplication.RequestUserAttention (NSRequestUserAttentionType.CriticalRequest); } }