Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Maupin <ermaup@microsoft.com>2019-03-21 22:42:36 +0300
committerEric Maupin <ermaup@microsoft.com>2019-03-26 01:15:53 +0300
commitdd739a72a67c266badff831c0f6335e3745f7c01 (patch)
tree43422de84a6f9c32b78e7bfabf3add6e7e15e119 /Xamarin.PropertyEditing.Mac/Controls
parent05850cfee27656d614b6b1ed82aeedef619a7fb2 (diff)
[mac] Add basic TimeSpan editor
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls')
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs25
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/TimeSpanEditorControl.cs45
2 files changed, 70 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs
index ed250c0..ff394e8 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs
@@ -88,6 +88,24 @@ namespace Xamarin.PropertyEditing.Mac
get;
}
+ public override void EditingBegan (NSNotification notification)
+ {
+ NSTextField text = (NSTextField)notification.Object;
+ this.lastValid = text.StringValue;
+ }
+
+ public override bool TextShouldEndEditing (NSControl control, NSText fieldEditor)
+ {
+ if (!CanGetValue (fieldEditor.Value)) {
+ NSTextField text = (NSTextField)control;
+ text.StringValue = this.lastValid;
+ AppKitFramework.NSBeep ();
+ return false;
+ }
+
+ return true;
+ }
+
protected virtual T GetValue (string value)
{
if (String.IsNullOrEmpty (value))
@@ -95,5 +113,12 @@ namespace Xamarin.PropertyEditing.Mac
return (T)Convert.ChangeType (value, typeof(T));
}
+
+ protected virtual bool CanGetValue (string value)
+ {
+ return true;
+ }
+
+ private string lastValid;
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/TimeSpanEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/TimeSpanEditorControl.cs
new file mode 100644
index 0000000..7277acb
--- /dev/null
+++ b/Xamarin.PropertyEditing.Mac/Controls/TimeSpanEditorControl.cs
@@ -0,0 +1,45 @@
+using System;
+using Xamarin.PropertyEditing.Mac.Resources;
+using Xamarin.PropertyEditing.ViewModels;
+
+namespace Xamarin.PropertyEditing.Mac
+{
+ internal class TimeSpanEditorControl
+ : EntryPropertyEditor<TimeSpan>
+ {
+ public TimeSpanEditorControl (IHostResourceProvider hostResources)
+ : base (hostResources)
+ {
+ }
+
+ protected override EntryPropertyEditorDelegate<TimeSpan> CreateDelegate (PropertyViewModel<TimeSpan> viewModel)
+ {
+ return new TimeSpanDelegate (viewModel);
+ }
+
+ protected override void UpdateAccessibilityValues ()
+ {
+ base.UpdateAccessibilityValues ();
+ Entry.AccessibilityTitle = string.Format (LocalizationResources.AccessibilityTimeSpan, ViewModel.Property.Name);
+ }
+
+ private class TimeSpanDelegate
+ : EntryPropertyEditorDelegate<TimeSpan>
+ {
+ public TimeSpanDelegate (PropertyViewModel<TimeSpan> viewModel)
+ : base (viewModel)
+ {
+ }
+
+ protected override TimeSpan GetValue (string value)
+ {
+ return TimeSpan.Parse (value);
+ }
+
+ protected override bool CanGetValue (string value)
+ {
+ return TimeSpan.TryParse (value, out _);
+ }
+ }
+ }
+}