mac: move logic from setup to its controller, check events instead of timers
This commit is contained in:
parent
baa69f943d
commit
789748972c
|
@ -193,7 +193,7 @@ namespace SparkleShare {
|
||||||
public override void DecidePolicyForNavigation (WebView web_view, NSDictionary action_info,
|
public override void DecidePolicyForNavigation (WebView web_view, NSDictionary action_info,
|
||||||
NSUrlRequest request, WebFrame frame, NSObject decision_token)
|
NSUrlRequest request, WebFrame frame, NSObject decision_token)
|
||||||
{
|
{
|
||||||
Controller.LinkClicked (request.Url.ToString ());
|
SparkleEventLogController.LinkClicked (request.Url.ToString ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,9 @@
|
||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Timers;
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
using Mono.Unix;
|
using Mono.Unix;
|
||||||
using MonoMac.Foundation;
|
using MonoMac.Foundation;
|
||||||
|
@ -54,7 +52,6 @@ namespace SparkleShare {
|
||||||
private NSTextField PathLabel;
|
private NSTextField PathLabel;
|
||||||
private NSTextField PathHelpLabel;
|
private NSTextField PathHelpLabel;
|
||||||
private NSTextField AddProjectTextField;
|
private NSTextField AddProjectTextField;
|
||||||
private Timer timer;
|
|
||||||
private NSTableView TableView;
|
private NSTableView TableView;
|
||||||
private NSScrollView ScrollView;
|
private NSScrollView ScrollView;
|
||||||
private NSTableColumn IconColumn;
|
private NSTableColumn IconColumn;
|
||||||
|
@ -88,7 +85,8 @@ namespace SparkleShare {
|
||||||
|
|
||||||
FullNameTextField = new NSTextField () {
|
FullNameTextField = new NSTextField () {
|
||||||
Frame = new RectangleF (330, Frame.Height - 238, 196, 22),
|
Frame = new RectangleF (330, Frame.Height - 238, 196, 22),
|
||||||
StringValue = Controller.GuessedUserName
|
StringValue = Controller.GuessedUserName,
|
||||||
|
Delegate = new SparkleTextFieldDelegate ()
|
||||||
};
|
};
|
||||||
|
|
||||||
EmailLabel = new NSTextField () {
|
EmailLabel = new NSTextField () {
|
||||||
|
@ -103,41 +101,44 @@ namespace SparkleShare {
|
||||||
|
|
||||||
EmailTextField = new NSTextField () {
|
EmailTextField = new NSTextField () {
|
||||||
Frame = new RectangleF (330, Frame.Height - 268, 196, 22),
|
Frame = new RectangleF (330, Frame.Height - 268, 196, 22),
|
||||||
StringValue = Controller.GuessedUserEmail
|
StringValue = Controller.GuessedUserEmail,
|
||||||
|
Delegate = new SparkleTextFieldDelegate ()
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Ugly hack, do properly with events
|
|
||||||
timer = new Timer () {
|
(FullNameTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
|
||||||
Interval = 50
|
Controller.CheckSetupPage (
|
||||||
|
FullNameTextField.StringValue,
|
||||||
|
EmailTextField.StringValue
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
(EmailTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
|
||||||
|
Controller.CheckSetupPage (
|
||||||
|
FullNameTextField.StringValue,
|
||||||
|
EmailTextField.StringValue
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
ContinueButton = new NSButton () {
|
ContinueButton = new NSButton () {
|
||||||
Title = "Continue",
|
Title = "Continue",
|
||||||
Enabled = false
|
Enabled = false
|
||||||
};
|
};
|
||||||
|
|
||||||
ContinueButton.Activated += delegate {
|
ContinueButton.Activated += delegate {
|
||||||
timer.Stop ();
|
|
||||||
timer = null;
|
|
||||||
|
|
||||||
string full_name = FullNameTextField.StringValue.Trim ();
|
string full_name = FullNameTextField.StringValue.Trim ();
|
||||||
string email = EmailTextField.StringValue.Trim ();
|
string email = EmailTextField.StringValue.Trim ();
|
||||||
|
|
||||||
Controller.SetupPageCompleted (full_name, email);
|
Controller.SetupPageCompleted (full_name, email);
|
||||||
};
|
};
|
||||||
|
|
||||||
timer.Elapsed += delegate {
|
Controller.UpdateSetupContinueButtonEvent += delegate (bool button_enabled) {
|
||||||
InvokeOnMainThread (delegate {
|
InvokeOnMainThread (delegate {
|
||||||
bool name_is_valid = !FullNameTextField.StringValue.Trim ().Equals ("");
|
ContinueButton.Enabled = button_enabled;
|
||||||
|
|
||||||
bool email_is_valid = Program.Controller.IsValidEmail (
|
|
||||||
EmailTextField.StringValue.Trim ());
|
|
||||||
|
|
||||||
ContinueButton.Enabled = (name_is_valid && email_is_valid);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
timer.Start ();
|
|
||||||
|
|
||||||
ContentView.AddSubview (FullNameLabel);
|
ContentView.AddSubview (FullNameLabel);
|
||||||
ContentView.AddSubview (FullNameTextField);
|
ContentView.AddSubview (FullNameTextField);
|
||||||
|
@ -168,7 +169,8 @@ namespace SparkleShare {
|
||||||
Frame = new RectangleF (190, Frame.Height - 336, 196, 22),
|
Frame = new RectangleF (190, Frame.Height - 336, 196, 22),
|
||||||
Font = SparkleUI.Font,
|
Font = SparkleUI.Font,
|
||||||
StringValue = Controller.PreviousAddress,
|
StringValue = Controller.PreviousAddress,
|
||||||
Enabled = (Controller.SelectedPlugin.Address == null)
|
Enabled = (Controller.SelectedPlugin.Address == null),
|
||||||
|
Delegate = new SparkleTextFieldDelegate ()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -186,7 +188,7 @@ namespace SparkleShare {
|
||||||
Frame = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22),
|
Frame = new RectangleF (190 + 196 + 16, Frame.Height - 336, 196, 22),
|
||||||
StringValue = Controller.PreviousPath,
|
StringValue = Controller.PreviousPath,
|
||||||
Enabled = (Controller.SelectedPlugin.Path == null),
|
Enabled = (Controller.SelectedPlugin.Path == null),
|
||||||
Bezeled = true
|
Delegate = new SparkleTextFieldDelegate ()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,7 +212,8 @@ namespace SparkleShare {
|
||||||
Frame = new RectangleF (0, 0, 0, 0),
|
Frame = new RectangleF (0, 0, 0, 0),
|
||||||
RowHeight = 30,
|
RowHeight = 30,
|
||||||
IntercellSpacing = new SizeF (0, 12),
|
IntercellSpacing = new SizeF (0, 12),
|
||||||
HeaderView = null
|
HeaderView = null,
|
||||||
|
Delegate = new SparkleTableViewDelegate ()
|
||||||
};
|
};
|
||||||
|
|
||||||
ScrollView = new NSScrollView () {
|
ScrollView = new NSScrollView () {
|
||||||
|
@ -270,32 +273,42 @@ namespace SparkleShare {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TableView.SelectRow (Controller.SelectedPluginIndex, false);
|
TableView.SelectRow (Controller.SelectedPluginIndex, false);
|
||||||
|
|
||||||
|
|
||||||
timer = new Timer () {
|
(AddressTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
|
||||||
Interval = 50
|
Controller.CheckAddPage (
|
||||||
|
AddressTextField.StringValue,
|
||||||
|
PathTextField.StringValue,
|
||||||
|
TableView.SelectedRow
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Use an event
|
(PathTextField.Delegate as SparkleTextFieldDelegate).StringValueChanged += delegate {
|
||||||
timer.Elapsed += delegate {
|
Controller.CheckAddPage (
|
||||||
if (TableView.SelectedRow != Controller.SelectedPluginIndex)
|
AddressTextField.StringValue,
|
||||||
|
PathTextField.StringValue,
|
||||||
|
TableView.SelectedRow
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
(TableView.Delegate as SparkleTableViewDelegate).SelectionChanged += delegate {
|
||||||
Controller.SelectedPluginChanged (TableView.SelectedRow);
|
Controller.SelectedPluginChanged (TableView.SelectedRow);
|
||||||
|
|
||||||
InvokeOnMainThread (delegate {
|
Controller.CheckAddPage (
|
||||||
// TODO: Move checking logic to controller
|
AddressTextField.StringValue,
|
||||||
if (!string.IsNullOrWhiteSpace (AddressTextField.StringValue) &&
|
PathTextField.StringValue,
|
||||||
!string.IsNullOrWhiteSpace (PathTextField.StringValue)) {
|
TableView.SelectedRow
|
||||||
|
);
|
||||||
SyncButton.Enabled = true;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
SyncButton.Enabled = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
timer.Start ();
|
|
||||||
|
Controller.UpdateAddProjectButtonEvent += delegate (bool button_enabled) {
|
||||||
|
InvokeOnMainThread (delegate {
|
||||||
|
SyncButton.Enabled = button_enabled;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
ContentView.AddSubview (ScrollView);
|
ContentView.AddSubview (ScrollView);
|
||||||
|
@ -311,9 +324,6 @@ namespace SparkleShare {
|
||||||
};
|
};
|
||||||
|
|
||||||
SyncButton.Activated += delegate {
|
SyncButton.Activated += delegate {
|
||||||
timer.Stop ();
|
|
||||||
timer = null;
|
|
||||||
|
|
||||||
Controller.AddPageCompleted (
|
Controller.AddPageCompleted (
|
||||||
AddressTextField.StringValue,
|
AddressTextField.StringValue,
|
||||||
PathTextField.StringValue
|
PathTextField.StringValue
|
||||||
|
@ -673,4 +683,39 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class SparkleTextFieldDelegate : NSTextFieldDelegate {
|
||||||
|
|
||||||
|
public event StringValueChangedHandler StringValueChanged;
|
||||||
|
public delegate void StringValueChangedHandler ();
|
||||||
|
|
||||||
|
|
||||||
|
public override void Changed (NSNotification notification)
|
||||||
|
{
|
||||||
|
if (StringValueChanged!= null)
|
||||||
|
StringValueChanged ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override string [] GetCompletions (NSControl control, NSTextView text_view,
|
||||||
|
string [] a, MonoMac.Foundation.NSRange range, int b)
|
||||||
|
{
|
||||||
|
return new string [0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class SparkleTableViewDelegate : NSTableViewDelegate {
|
||||||
|
|
||||||
|
public event SelectionChangedHandler SelectionChanged;
|
||||||
|
public delegate void SelectionChangedHandler ();
|
||||||
|
|
||||||
|
|
||||||
|
public override void SelectionDidChange (NSNotification notification)
|
||||||
|
{
|
||||||
|
if (SelectionChanged != null)
|
||||||
|
SelectionChanged ();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,12 @@ namespace SparkleShare {
|
||||||
public event UpdateProgressBarEventHandler UpdateProgressBarEvent;
|
public event UpdateProgressBarEventHandler UpdateProgressBarEvent;
|
||||||
public delegate void UpdateProgressBarEventHandler (double percentage);
|
public delegate void UpdateProgressBarEventHandler (double percentage);
|
||||||
|
|
||||||
|
public event UpdateSetupContinueButtonEventHandler UpdateSetupContinueButtonEvent;
|
||||||
|
public delegate void UpdateSetupContinueButtonEventHandler (bool button_enabled);
|
||||||
|
|
||||||
|
public event UpdateAddProjectButtonEventHandler UpdateAddProjectButtonEvent;
|
||||||
|
public delegate void UpdateAddProjectButtonEventHandler (bool button_enabled);
|
||||||
|
|
||||||
public event ChangeAddressFieldEventHandler ChangeAddressFieldEvent;
|
public event ChangeAddressFieldEventHandler ChangeAddressFieldEvent;
|
||||||
public delegate void ChangeAddressFieldEventHandler (string text,
|
public delegate void ChangeAddressFieldEventHandler (string text,
|
||||||
string example_text, FieldState state);
|
string example_text, FieldState state);
|
||||||
|
@ -153,6 +159,19 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void CheckSetupPage (string full_name, string email)
|
||||||
|
{
|
||||||
|
full_name = full_name.Trim ();
|
||||||
|
email = email.Trim ();
|
||||||
|
|
||||||
|
bool fields_valid = (!string.IsNullOrWhiteSpace (full_name) &&
|
||||||
|
Program.Controller.IsValidEmail (email));
|
||||||
|
|
||||||
|
if (UpdateSetupContinueButtonEvent != null)
|
||||||
|
UpdateSetupContinueButtonEvent (fields_valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void SetupPageCompleted (string full_name, string email)
|
public void SetupPageCompleted (string full_name, string email)
|
||||||
{
|
{
|
||||||
Program.Controller.UserName = full_name;
|
Program.Controller.UserName = full_name;
|
||||||
|
@ -193,6 +212,22 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void CheckAddPage (string address, string remote_path, int selected_plugin)
|
||||||
|
{
|
||||||
|
if (SelectedPluginIndex != selected_plugin)
|
||||||
|
SelectedPluginChanged (selected_plugin);
|
||||||
|
|
||||||
|
address = address.Trim ();
|
||||||
|
remote_path = remote_path.Trim ();
|
||||||
|
|
||||||
|
bool fields_valid = (!string.IsNullOrWhiteSpace (address) &&
|
||||||
|
!string.IsNullOrWhiteSpace (remote_path));
|
||||||
|
|
||||||
|
if (UpdateAddProjectButtonEvent != null)
|
||||||
|
UpdateAddProjectButtonEvent (fields_valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void AddPageCompleted (string address, string path)
|
public void AddPageCompleted (string address, string path)
|
||||||
{
|
{
|
||||||
this.syncing_folder = Path.GetFileNameWithoutExtension (path);
|
this.syncing_folder = Path.GetFileNameWithoutExtension (path);
|
||||||
|
|
Loading…
Reference in a new issue