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
parent05850cfee27656d614b6b1ed82aeedef619a7fb2 (diff)
[mac] Add basic TimeSpan editor
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/EntryPropertyEditor.cs25
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/TimeSpanEditorControl.cs45
-rw-r--r--Xamarin.PropertyEditing.Mac/PropertyEditorSelector.cs1
-rw-r--r--Xamarin.PropertyEditing.Mac/Resources/LocalizationResources.Designer.cs6
-rw-r--r--Xamarin.PropertyEditing.Mac/Resources/LocalizationResources.resx4
-rw-r--r--Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj1
-rw-r--r--Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs2
-rw-r--r--Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs1
8 files changed, 85 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 _);
+ }
+ }
+ }
+}
diff --git a/Xamarin.PropertyEditing.Mac/PropertyEditorSelector.cs b/Xamarin.PropertyEditing.Mac/PropertyEditorSelector.cs
index 34cc51c..b1717e9 100644
--- a/Xamarin.PropertyEditing.Mac/PropertyEditorSelector.cs
+++ b/Xamarin.PropertyEditing.Mac/PropertyEditorSelector.cs
@@ -40,6 +40,7 @@ namespace Xamarin.PropertyEditing.Mac
private static readonly Dictionary<Type, Type> ViewModelTypes = new Dictionary<Type, Type> {
{typeof (PropertyViewModel<DateTime>), typeof (DateTimeEditorControl)},
+ {typeof (PropertyViewModel<TimeSpan>), typeof(TimeSpanEditorControl)},
{typeof (StringPropertyViewModel), typeof (StringEditorControl)},
{typeof (NumericPropertyViewModel<>), typeof (NumericEditorControl<>)},
{typeof (PropertyViewModel<bool?>), typeof (BooleanEditorControl)},
diff --git a/Xamarin.PropertyEditing.Mac/Resources/LocalizationResources.Designer.cs b/Xamarin.PropertyEditing.Mac/Resources/LocalizationResources.Designer.cs
index de42d93..b48ee15 100644
--- a/Xamarin.PropertyEditing.Mac/Resources/LocalizationResources.Designer.cs
+++ b/Xamarin.PropertyEditing.Mac/Resources/LocalizationResources.Designer.cs
@@ -119,6 +119,12 @@ namespace Xamarin.PropertyEditing.Mac.Resources {
}
}
+ internal static string AccessibilityTimeSpan {
+ get {
+ return ResourceManager.GetString("AccessibilityTimeSpan", resourceCulture);
+ }
+ }
+
internal static string AccessibilityDateTime {
get {
return ResourceManager.GetString("AccessibilityDateTime", resourceCulture);
diff --git a/Xamarin.PropertyEditing.Mac/Resources/LocalizationResources.resx b/Xamarin.PropertyEditing.Mac/Resources/LocalizationResources.resx
index 8d90192..a2c52f6 100644
--- a/Xamarin.PropertyEditing.Mac/Resources/LocalizationResources.resx
+++ b/Xamarin.PropertyEditing.Mac/Resources/LocalizationResources.resx
@@ -56,6 +56,10 @@
<value>{0} String Editor</value>
<comment>Editor for String Value</comment>
</data>
+ <data name="AccessibilityTimeSpan" xml:space="preserve">
+ <value>{0} TimeSpan Editor</value>
+ <comment>Editor for TimeSpan Value</comment>
+ </data>
<data name="AccessibilityDateTime" xml:space="preserve">
<value>{0} DateTime Editor</value>
<comment>Editor for DateTime Value</comment>
diff --git a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj
index d483fe3..84845bf 100644
--- a/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj
+++ b/Xamarin.PropertyEditing.Mac/Xamarin.PropertyEditing.Mac.csproj
@@ -165,6 +165,7 @@
<Compile Include="Controls\DateTimeEditorControl.cs" />
<Compile Include="Controls\DateExtensions.cs" />
<Compile Include="Controls\EntryPropertyEditor.cs" />
+ <Compile Include="Controls\TimeSpanEditorControl.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controls\" />
diff --git a/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs b/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs
index cb7886e..095188b 100644
--- a/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs
+++ b/Xamarin.PropertyEditing.Tests/MockControls/MockSampleControl.cs
@@ -11,6 +11,8 @@ namespace Xamarin.PropertyEditing.Tests.MockControls
{
public MockSampleControl ()
{
+ AddProperty<TimeSpan> ("TimeSpan", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding);
+ AddProperty<TimeSpan> ("TimeSpanReadOnly", ReadOnly, canWrite: false, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding);
AddProperty<bool> ("Boolean", ReadWrite, valueSources: ValueSources.Local | ValueSources.Resource | ValueSources.Binding);
AddProperty<bool> ("UnsetBoolean", ReadWrite, valueSources: ValueSources.Local);
AddProperty<int> ("Integer", ReadWrite);
diff --git a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
index c2e9fe9..0f6fec2 100644
--- a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
+++ b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
@@ -599,6 +599,7 @@ namespace Xamarin.PropertyEditing.ViewModels
private static readonly Dictionary<Type, Func<TargetPlatform, IPropertyInfo, IEnumerable<IObjectEditor>, PropertyVariation, PropertyViewModel>> ViewModelMap = new Dictionary<Type, Func<TargetPlatform, IPropertyInfo, IEnumerable<IObjectEditor>, PropertyVariation, PropertyViewModel>> {
{ typeof(DateTime), (tp,p,e,v) => new PropertyViewModel<DateTime> (tp, p, e, v) },
+ { typeof(TimeSpan), (tp,p,e,v) => new PropertyViewModel<TimeSpan> (tp, p, e, v) },
{ typeof(string), (tp,p,e,v) => new StringPropertyViewModel (tp, p, e, v) },
{ typeof(bool), (tp,p,e,v) => new PropertyViewModel<bool?> (tp, p, e, v) },
{ typeof(float), (tp,p,e,v) => new NumericPropertyViewModel<float?> (tp, p, e, v) },