mac: clean up

This commit is contained in:
Hylke Bons 2012-11-27 21:57:15 +00:00
parent c45d883728
commit d06de980c8
3 changed files with 89 additions and 227 deletions

View file

@ -22,7 +22,6 @@ using System.IO;
using MonoMac.Foundation; using MonoMac.Foundation;
using MonoMac.AppKit; using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
using MonoMac.WebKit; using MonoMac.WebKit;
using Mono.Unix; using Mono.Unix;
@ -36,7 +35,7 @@ namespace SparkleShare {
private NSButton ContinueButton, AddButton, CopyButton, TryAgainButton, CancelButton, private NSButton ContinueButton, AddButton, CopyButton, TryAgainButton, CancelButton,
SkipTutorialButton, FinishButton, ShowFilesButton; SkipTutorialButton, FinishButton, ShowFilesButton;
private NSTextField FullNameTextField, FullNameLabel, EmailLabel, EmailTextField, EmailHelpLabel, private NSTextField FullNameTextField, FullNameLabel, EmailLabel, EmailTextField,
LinkCodeTextField, AddressTextField, AddressLabel, AddressHelpLabel, PathTextField, PathLabel, LinkCodeTextField, AddressTextField, AddressLabel, AddressHelpLabel, PathTextField, PathLabel,
PathHelpLabel, PasswordTextField, VisiblePasswordTextField, PasswordLabel, WarningTextField; PathHelpLabel, PasswordTextField, VisiblePasswordTextField, PasswordLabel, WarningTextField;
@ -81,14 +80,10 @@ namespace SparkleShare {
Description = "First off, what's your name and email?\n(visible only to team members)"; Description = "First off, what's your name and email?\n(visible only to team members)";
FullNameLabel = new NSTextField () { FullNameLabel = new SparkleLabel () {
Alignment = NSTextAlignment.Right, Alignment = NSTextAlignment.Right,
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Frame = new RectangleF (165, Frame.Height - 234, 160, 17), Frame = new RectangleF (165, Frame.Height - 234, 160, 17),
StringValue = "Full Name:", StringValue = "Full Name:"
Font = SparkleUI.Font
}; };
FullNameTextField = new NSTextField () { FullNameTextField = new NSTextField () {
@ -97,14 +92,10 @@ namespace SparkleShare {
Delegate = new SparkleTextFieldDelegate () Delegate = new SparkleTextFieldDelegate ()
}; };
EmailLabel = new NSTextField () { EmailLabel = new SparkleLabel () {
Alignment = NSTextAlignment.Right, Alignment = NSTextAlignment.Right,
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Frame = new RectangleF (165, Frame.Height - 264, 160, 17), Frame = new RectangleF (165, Frame.Height - 264, 160, 17),
StringValue = "Email:", StringValue = "Email:"
Font = SparkleUI.Font
}; };
EmailTextField = new NSTextField () { EmailTextField = new NSTextField () {
@ -112,18 +103,6 @@ namespace SparkleShare {
Delegate = new SparkleTextFieldDelegate () Delegate = new SparkleTextFieldDelegate ()
}; };
EmailHelpLabel = new NSTextField () {
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
TextColor = NSColor.DisabledControlText,
Editable = false,
Frame = new RectangleF (330, Frame.Height - 290, 204, 17),
Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
NSFontTraitMask.Condensed, 0, 11),
StringValue = "(used to find your Gravatar)"
};
CancelButton = new NSButton () { CancelButton = new NSButton () {
Title = "Cancel" Title = "Cancel"
@ -165,7 +144,6 @@ namespace SparkleShare {
ContentView.AddSubview (FullNameTextField); ContentView.AddSubview (FullNameTextField);
ContentView.AddSubview (EmailLabel); ContentView.AddSubview (EmailLabel);
ContentView.AddSubview (EmailTextField); ContentView.AddSubview (EmailTextField);
ContentView.AddSubview (EmailHelpLabel);
Buttons.Add (ContinueButton); Buttons.Add (ContinueButton);
Buttons.Add (CancelButton); Buttons.Add (CancelButton);
@ -178,41 +156,25 @@ namespace SparkleShare {
Description = "Do you want to add this project to SparkleShare?"; Description = "Do you want to add this project to SparkleShare?";
AddressLabel = new NSTextField () { AddressLabel = new SparkleLabel () {
Alignment = NSTextAlignment.Right, Alignment = NSTextAlignment.Right,
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Frame = new RectangleF (165, Frame.Height - 240, 160, 17), Frame = new RectangleF (165, Frame.Height - 240, 160, 17),
StringValue = "Address:", StringValue = "Address:"
Font = SparkleUI.Font
}; };
PathLabel = new NSTextField () { PathLabel = new SparkleLabel () {
Alignment = NSTextAlignment.Right, Alignment = NSTextAlignment.Right,
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Frame = new RectangleF (165, Frame.Height - 264, 160, 17), Frame = new RectangleF (165, Frame.Height - 264, 160, 17),
StringValue = "Remote Path:", StringValue = "Remote Path:"
Font = SparkleUI.Font
}; };
AddressTextField = new NSTextField () { AddressTextField = new SparkleLabel () {
Alignment = NSTextAlignment.Left,
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Frame = new RectangleF (330, Frame.Height - 240, 260, 17), Frame = new RectangleF (330, Frame.Height - 240, 260, 17),
StringValue = Controller.PendingInvite.Address, StringValue = Controller.PendingInvite.Address,
Font = SparkleUI.BoldFont Font = SparkleUI.BoldFont
}; };
PathTextField = new NSTextField () { PathTextField = new SparkleLabel () {
Alignment = NSTextAlignment.Left,
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Frame = new RectangleF (330, Frame.Height - 264, 260, 17), Frame = new RectangleF (330, Frame.Height - 264, 260, 17),
StringValue = Controller.PendingInvite.RemotePath, StringValue = Controller.PendingInvite.RemotePath,
Font = SparkleUI.BoldFont Font = SparkleUI.BoldFont
@ -250,11 +212,7 @@ namespace SparkleShare {
Description = ""; Description = "";
AddressLabel = new NSTextField () { AddressLabel = new SparkleLabel () {
Alignment = NSTextAlignment.Left,
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Frame = new RectangleF (190, Frame.Height - 308, 160, 17), Frame = new RectangleF (190, Frame.Height - 308, 160, 17),
StringValue = "Address:", StringValue = "Address:",
Font = SparkleUI.BoldFont Font = SparkleUI.BoldFont
@ -270,11 +228,7 @@ namespace SparkleShare {
AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; AddressTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
PathLabel = new NSTextField () { PathLabel = new SparkleLabel () {
Alignment = NSTextAlignment.Left,
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Frame = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17), Frame = new RectangleF (190 + 196 + 16, Frame.Height - 308, 160, 17),
StringValue = "Remote Path:", StringValue = "Remote Path:",
Font = SparkleUI.BoldFont Font = SparkleUI.BoldFont
@ -289,22 +243,16 @@ namespace SparkleShare {
PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail; PathTextField.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
PathHelpLabel = new NSTextField () { PathHelpLabel = new SparkleLabel () {
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
TextColor = NSColor.DisabledControlText, TextColor = NSColor.DisabledControlText,
Editable = false,
Frame = new RectangleF (190 + 196 + 16, Frame.Height - 355, 204, 17), Frame = new RectangleF (190 + 196 + 16, Frame.Height - 355, 204, 17),
Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande", Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
NSFontTraitMask.Condensed, 0, 11), NSFontTraitMask.Condensed, 0, 11),
StringValue = "" + Controller.SelectedPlugin.PathExample StringValue = "" + Controller.SelectedPlugin.PathExample
}; };
AddressHelpLabel = new NSTextField () { AddressHelpLabel = new SparkleLabel () {
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
TextColor = NSColor.DisabledControlText, TextColor = NSColor.DisabledControlText,
Editable = false,
Frame = new RectangleF (190, Frame.Height - 355, 204, 17), Frame = new RectangleF (190, Frame.Height - 355, 204, 17),
Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande", Font = NSFontManager.SharedFontManager.FontWithFamily ("Lucida Grande",
NSFontTraitMask.Condensed, 0, 11), NSFontTraitMask.Condensed, 0, 11),
@ -371,9 +319,7 @@ namespace SparkleShare {
}; };
Controller.ChangeAddressFieldEvent += delegate (string text, Controller.ChangeAddressFieldEvent += delegate (string text, string example_text, FieldState state) {
string example_text, FieldState state) {
Program.Controller.Invoke (() => { Program.Controller.Invoke (() => {
AddressTextField.StringValue = text; AddressTextField.StringValue = text;
AddressTextField.Enabled = (state == FieldState.Enabled); AddressTextField.Enabled = (state == FieldState.Enabled);
@ -381,9 +327,7 @@ namespace SparkleShare {
}); });
}; };
Controller.ChangePathFieldEvent += delegate (string text, Controller.ChangePathFieldEvent += delegate (string text, string example_text, FieldState state) {
string example_text, FieldState state) {
Program.Controller.Invoke (() => { Program.Controller.Invoke (() => {
PathTextField.StringValue = text; PathTextField.StringValue = text;
PathTextField.Enabled = (state == FieldState.Enabled); PathTextField.Enabled = (state == FieldState.Enabled);
@ -556,33 +500,40 @@ namespace SparkleShare {
Buttons.Add (CancelButton); Buttons.Add (CancelButton);
} }
if (type == PageType.CryptoSetup) { if (type == PageType.CryptoSetup || type == PageType.CryptoPassword) {
Header = "Set up file encryption"; if (type == PageType.CryptoSetup) {
Description = "Please a provide a strong password that you don't use elsewhere below:"; Header = "Set up file encryption";
Description = "Please a provide a strong password that you don't use elsewhere below:";
} else {
Header = "This project contains encrypted files";
Description = "Please enter the password to see their contents.";
}
int extra_pos_y = 0;
PasswordLabel = new NSTextField () { if (type == PageType.CryptoPassword)
extra_pos_y = 20;
PasswordLabel = new SparkleLabel () {
Alignment = NSTextAlignment.Right, Alignment = NSTextAlignment.Right,
BackgroundColor = NSColor.WindowBackground, Frame = new RectangleF (155, Frame.Height - 204 - extra_pos_y, 160, 17),
Bordered = false,
Editable = false,
Frame = new RectangleF (155, Frame.Height - 204, 160, 17),
StringValue = "Password:", StringValue = "Password:",
Font = SparkleUI.BoldFont Font = SparkleUI.BoldFont
}; };
PasswordTextField = new NSSecureTextField () { PasswordTextField = new NSSecureTextField () {
Frame = new RectangleF (320, Frame.Height - 208, 196, 22), Frame = new RectangleF (320, Frame.Height - 208 - extra_pos_y, 196, 22),
Delegate = new SparkleTextFieldDelegate () Delegate = new SparkleTextFieldDelegate ()
}; };
VisiblePasswordTextField = new NSTextField () { VisiblePasswordTextField = new NSTextField () {
Frame = new RectangleF (320, Frame.Height - 208, 196, 22), Frame = new RectangleF (320, Frame.Height - 208 - extra_pos_y, 196, 22),
Delegate = new SparkleTextFieldDelegate () Delegate = new SparkleTextFieldDelegate ()
}; };
ShowPasswordCheckButton = new NSButton () { ShowPasswordCheckButton = new NSButton () {
Frame = new RectangleF (318, Frame.Height - 235, 300, 18), Frame = new RectangleF (318, Frame.Height - 235 - extra_pos_y, 300, 18),
Title = "Show password", Title = "Show password",
State = NSCellStateValue.Off State = NSCellStateValue.Off
}; };
@ -597,13 +548,9 @@ namespace SparkleShare {
Frame = new RectangleF (200, Frame.Height - 320, 24, 24) Frame = new RectangleF (200, Frame.Height - 320, 24, 24)
}; };
WarningTextField = new NSTextField () { WarningTextField = new SparkleLabel () {
Frame = new RectangleF (235, Frame.Height - 390, 325, 100), 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.", 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 () { CancelButton = new NSButton () {
@ -629,23 +576,36 @@ namespace SparkleShare {
(PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { (PasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
VisiblePasswordTextField.StringValue = PasswordTextField.StringValue; VisiblePasswordTextField.StringValue = PasswordTextField.StringValue;
Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
if (type == PageType.CryptoSetup)
Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
else
Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue);
}; };
(VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate { (VisiblePasswordTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
PasswordTextField.StringValue = VisiblePasswordTextField.StringValue; PasswordTextField.StringValue = VisiblePasswordTextField.StringValue;
Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
if (type == PageType.CryptoSetup)
Controller.CheckCryptoSetupPage (PasswordTextField.StringValue);
else
Controller.CheckCryptoPasswordPage (PasswordTextField.StringValue);
}; };
Controller.UpdateCryptoPasswordContinueButtonEvent += delegate (bool button_enabled) {
Program.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; });
};
Controller.UpdateCryptoSetupContinueButtonEvent += delegate (bool button_enabled) { Controller.UpdateCryptoSetupContinueButtonEvent += delegate (bool button_enabled) {
Program.Controller.Invoke (() => { Program.Controller.Invoke (() => { ContinueButton.Enabled = button_enabled; });
ContinueButton.Enabled = button_enabled;
});
}; };
ContinueButton.Activated += delegate { ContinueButton.Activated += delegate {
Controller.CryptoSetupPageCompleted (PasswordTextField.StringValue); if (type == PageType.CryptoSetup)
Controller.CryptoSetupPageCompleted (PasswordTextField.StringValue);
else
Controller.CryptoPasswordPageCompleted (PasswordTextField.StringValue);
}; };
CancelButton.Activated += delegate { CancelButton.Activated += delegate {
@ -656,96 +616,11 @@ namespace SparkleShare {
ContentView.AddSubview (PasswordLabel); ContentView.AddSubview (PasswordLabel);
ContentView.AddSubview (PasswordTextField); ContentView.AddSubview (PasswordTextField);
ContentView.AddSubview (ShowPasswordCheckButton); ContentView.AddSubview (ShowPasswordCheckButton);
ContentView.AddSubview (WarningImageView);
ContentView.AddSubview (WarningTextField);
Buttons.Add (ContinueButton); if (type == PageType.CryptoSetup) {
Buttons.Add (CancelButton); ContentView.AddSubview (WarningImageView);
ContentView.AddSubview (WarningTextField);
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:",
Font = SparkleUI.BoldFont
};
PasswordTextField = new NSSecureTextField () {
Frame = new RectangleF (320, Frame.Height - 228, 196, 22),
Delegate = new SparkleTextFieldDelegate ()
};
VisiblePasswordTextField = new NSTextField () {
Frame = new RectangleF (320, Frame.Height - 228, 196, 22),
Delegate = new SparkleTextFieldDelegate ()
};
ShowPasswordCheckButton = new NSButton () {
Frame = new RectangleF (318, Frame.Height - 255, 300, 18),
Title = "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) {
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;
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 (ContinueButton);
Buttons.Add (CancelButton); Buttons.Add (CancelButton);
@ -768,13 +643,9 @@ namespace SparkleShare {
Frame = new RectangleF (200, Frame.Height - 175, 24, 24) Frame = new RectangleF (200, Frame.Height - 175, 24, 24)
}; };
WarningTextField = new NSTextField () { WarningTextField = new SparkleLabel () {
Frame = new RectangleF (235, Frame.Height - 245, 325, 100), Frame = new RectangleF (235, Frame.Height - 245, 325, 100),
StringValue = warnings [0], StringValue = warnings [0]
BackgroundColor = NSColor.WindowBackground,
Bordered = false,
Editable = false,
Font = SparkleUI.Font
}; };
ContentView.AddSubview (WarningImageView); ContentView.AddSubview (WarningImageView);
@ -1078,4 +949,16 @@ namespace SparkleShare {
SelectionChanged (); SelectionChanged ();
} }
} }
public class SparkleLabel : NSTextField {
public SparkleLabel () : base ()
{
BackgroundColor = NSColor.WindowBackground;
Bordered = false;
Editable = false;
Font = SparkleUI.Font;
}
}
} }

View file

@ -16,6 +16,8 @@
using System; using System;
using System.Text;
using SparkleLib; using SparkleLib;
namespace SparkleShare { namespace SparkleShare {
@ -33,7 +35,7 @@ namespace SparkleShare {
}; };
Program.Controller.NotificationRaised += delegate (SparkleChangeSet change_set) { Program.Controller.NotificationRaised += delegate (SparkleChangeSet change_set) {
ShowBubble (change_set.User.Name, FormatMessage (change_set), ShowBubble (change_set.User.Name, change_set.ToMessage (),
Program.Controller.GetAvatar (change_set.User.Email, 48)); Program.Controller.GetAvatar (change_set.User.Email, 48));
}; };
} }
@ -41,6 +43,11 @@ namespace SparkleShare {
public void ShowBubble (string title, string subtext, string image_path) public void ShowBubble (string title, string subtext, string image_path)
{ {
byte [] title_bytes = Encoding.Default.GetBytes (title);
byte [] subtext_bytes = Encoding.Default.GetBytes (subtext);
title = Encoding.UTF8.GetString (title_bytes);
subtext = Encoding.UTF8.GetString (subtext_bytes);
ShowBubbleEvent (title, subtext, image_path); ShowBubbleEvent (title, subtext, image_path);
} }
@ -49,32 +56,5 @@ namespace SparkleShare {
{ {
Program.Controller.ShowEventLogWindow (); Program.Controller.ShowEventLogWindow ();
} }
private string FormatMessage (SparkleChangeSet change_set)
{
string message = "added {0}";
switch (change_set.Changes [0].Type) {
case SparkleChangeType.Edited: message = "edited {0}"; break;
case SparkleChangeType.Deleted: message = "deleted {0}"; break;
case SparkleChangeType.Moved: message = "moved {0}"; break;
}
if (change_set.Changes.Count == 1) {
return message = string.Format (message, change_set.Changes [0].Path);
} else if (change_set.Changes.Count > 1) {
message = string.Format (message, change_set.Changes [0].Path);
if ((change_set.Changes.Count - 1) == 1)
return string.Format (message + " and one other event", change_set.Changes.Count - 1);
else
return string.Format (message + " and {0} other events", change_set.Changes.Count - 1);
} else {
return "did something magical";
}
}
} }
} }

View file

@ -256,6 +256,8 @@ namespace SparkleShare {
int i = 0; int i = 0;
foreach (SparkleRepoBase repo in Program.Controller.Repositories) { foreach (SparkleRepoBase repo in Program.Controller.Repositories) {
FolderErrors [i] = "";
if (repo.Error == ErrorStatus.HostUnreachable) { if (repo.Error == ErrorStatus.HostUnreachable) {
FolderErrors [i] = "Can't reach the host"; FolderErrors [i] = "Can't reach the host";
@ -272,12 +274,9 @@ namespace SparkleShare {
FolderErrors [i] = "Some local files are locked or in use"; FolderErrors [i] = "Some local files are locked or in use";
} else if (repo.Error == ErrorStatus.NotFound) { } else if (repo.Error == ErrorStatus.NotFound) {
FolderErrors [i] = "Project doesn't exist on host"; FolderErrors [i] = "Project doesn't exist on host";
} else {
FolderErrors [i] = "";
} }
i++; i++;
} }
} }