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>2018-08-31 20:55:22 +0300
committerEric Maupin <ermaup@microsoft.com>2018-09-05 00:02:34 +0300
commit1afb2f28df3a9516c3cd42f6c4889d2122abe454 (patch)
tree3e946545dac346c32581b560788e5168b5e3c953 /Xamarin.PropertyEditing.Tests
parent738949a696525c3166ef8da269f522b525fdcc19 (diff)
[Core] Add ICompleteValues
This is the most basic version of this to support the status quo for Android. The hard part is really the UI, so this will get us a significant part of the way towards a more robust version.
Diffstat (limited to 'Xamarin.PropertyEditing.Tests')
-rw-r--r--Xamarin.PropertyEditing.Tests/MockEditorProvider.cs8
-rw-r--r--Xamarin.PropertyEditing.Tests/MockObjectEditor.cs27
2 files changed, 31 insertions, 4 deletions
diff --git a/Xamarin.PropertyEditing.Tests/MockEditorProvider.cs b/Xamarin.PropertyEditing.Tests/MockEditorProvider.cs
index 2225bca..dee6c71 100644
--- a/Xamarin.PropertyEditing.Tests/MockEditorProvider.cs
+++ b/Xamarin.PropertyEditing.Tests/MockEditorProvider.cs
@@ -13,8 +13,9 @@ namespace Xamarin.PropertyEditing.Tests
{
public static readonly TargetPlatform MockPlatform = new TargetPlatform (new MockEditorProvider ());
- public MockEditorProvider ()
+ public MockEditorProvider (IResourceProvider resources = null)
{
+ this.resources = resources;
}
public MockEditorProvider (IObjectEditor editor)
@@ -70,9 +71,9 @@ namespace Xamarin.PropertyEditing.Tests
{
switch (item) {
case MockWpfControl msc:
- return new MockObjectEditor (msc);
+ return new MockObjectEditor (msc) { Resources = this.resources };
case MockControl mc:
- return new MockNameableEditor (mc);
+ return new MockNameableEditor (mc) { Resources = this.resources };
case MockBinding mb:
return new MockBindingEditor (mb);
default:
@@ -99,6 +100,7 @@ namespace Xamarin.PropertyEditing.Tests
return Task.FromResult<IReadOnlyDictionary<Type, ITypeInfo>> (new Dictionary<Type, ITypeInfo> ());
}
+ private readonly IResourceProvider resources;
private readonly Dictionary<object, IObjectEditor> editorCache = new Dictionary<object, IObjectEditor> ();
}
} \ No newline at end of file
diff --git a/Xamarin.PropertyEditing.Tests/MockObjectEditor.cs b/Xamarin.PropertyEditing.Tests/MockObjectEditor.cs
index 80f11c0..3adb37e 100644
--- a/Xamarin.PropertyEditing.Tests/MockObjectEditor.cs
+++ b/Xamarin.PropertyEditing.Tests/MockObjectEditor.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
+using System.Threading;
using System.Threading.Tasks;
using Xamarin.PropertyEditing.Reflection;
using Xamarin.PropertyEditing.Tests.MockControls;
@@ -29,7 +30,7 @@ namespace Xamarin.PropertyEditing.Tests
}
internal class MockObjectEditor
- : IObjectEditor, IObjectEventEditor
+ : IObjectEditor, IObjectEventEditor, ICompleteValues
{
public MockObjectEditor ()
{
@@ -111,6 +112,12 @@ namespace Xamarin.PropertyEditing.Tests
set;
}
+ public IResourceProvider Resources
+ {
+ get;
+ set;
+ }
+
public void ChangeAllProperties ()
{
PropertyChanged?.Invoke (this, new EditorPropertyChangedEventArgs (null));
@@ -332,6 +339,24 @@ namespace Xamarin.PropertyEditing.Tests
return Task.FromResult<ITypeInfo> (new TypeInfo (asm, type.Namespace, type.Name));
}
+ public bool CanAutocomplete (string input)
+ {
+ return (input != null && input.Trim ().StartsWith ("@"));
+ }
+
+ public async Task<IReadOnlyList<string>> GetCompletionsAsync (IPropertyInfo property, string input, CancellationToken cancellationToken)
+ {
+ if (Resources == null)
+ return Array.Empty<string> ();
+
+ input = input.Trim ().TrimStart('@');
+ var resources = await Resources.GetResourcesAsync (Target, property, cancellationToken);
+ return resources.Where (r =>
+ r.Name.IndexOf (input, StringComparison.OrdinalIgnoreCase) != -1
+ && r.Name.Length > input.Length) // Skip exact matches
+ .Select (r => "@" + r.Name).ToList ();
+ }
+
internal readonly IDictionary<IPropertyInfo, object> values = new Dictionary<IPropertyInfo, object> ();
internal readonly IDictionary<IEventInfo, string> events = new Dictionary<IEventInfo, string> ();
internal readonly IReadOnlyDictionary<IPropertyInfo, IReadOnlyList<ITypeInfo>> assignableTypes;