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-03-26 20:26:15 +0300
committerEric Maupin <ermaup@microsoft.com>2018-03-26 20:26:15 +0300
commit6f81982bc0e118da384c9332d38d092e0d5cb255 (patch)
tree57ba1c0a954e6e62eb19fede7940a00a5075bbf1 /Xamarin.PropertyEditing
parentc78f988a6c848c037e1d063cc127a735501eb1be (diff)
[Core/Win] Add Navigate to Source support
Diffstat (limited to 'Xamarin.PropertyEditing')
-rw-r--r--Xamarin.PropertyEditing/ICanNavigateToSource.cs24
-rw-r--r--Xamarin.PropertyEditing/Properties/Resources.Designer.cs9
-rw-r--r--Xamarin.PropertyEditing/Properties/Resources.resx3
-rw-r--r--Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs31
-rw-r--r--Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj1
5 files changed, 68 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing/ICanNavigateToSource.cs b/Xamarin.PropertyEditing/ICanNavigateToSource.cs
new file mode 100644
index 0000000..564883d
--- /dev/null
+++ b/Xamarin.PropertyEditing/ICanNavigateToSource.cs
@@ -0,0 +1,24 @@
+using System;
+
+namespace Xamarin.PropertyEditing
+{
+ /// <summary>
+ /// <see cref="IPropertyInfo"/> light-up interface for navigating to value sources.
+ /// </summary>
+ /// <remarks>
+ /// Not all possible values and value sources must be navigatable to implement this interface. That determination can
+ /// be made in <see cref="CanNavigateToSource"/>. Implementing this interface will simply light-up the UI element, but
+ /// its enabled status will depend on <see cref="CanNavigateToSource"/> and other dynamic factors.
+ /// </remarks>
+ public interface ICanNavigateToSource
+ {
+ /// <summary>
+ /// Gets whether the value of the property attached to in the <paramref name="editor"/> can be navigated to.
+ /// </summary>
+ /// <exception cref="ArgumentNullException"><paramref name="editor"/> is <c>null</c>.</exception>
+ bool CanNavigateToSource (IObjectEditor editor);
+
+ /// <exception cref="ArgumentNullException"><paramref name="editor"/> is <c>null</c>.</exception>
+ void NavigateToSource (IObjectEditor editor);
+ }
+} \ No newline at end of file
diff --git a/Xamarin.PropertyEditing/Properties/Resources.Designer.cs b/Xamarin.PropertyEditing/Properties/Resources.Designer.cs
index 4805f4b..6ce3cde 100644
--- a/Xamarin.PropertyEditing/Properties/Resources.Designer.cs
+++ b/Xamarin.PropertyEditing/Properties/Resources.Designer.cs
@@ -259,6 +259,15 @@ namespace Xamarin.PropertyEditing.Properties {
}
/// <summary>
+ /// Looks up a localized string similar to Go to Source.
+ /// </summary>
+ public static string GoToSource {
+ get {
+ return ResourceManager.GetString("GoToSource", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Green.
/// </summary>
public static string Green {
diff --git a/Xamarin.PropertyEditing/Properties/Resources.resx b/Xamarin.PropertyEditing/Properties/Resources.resx
index a64ada5..1adfec2 100644
--- a/Xamarin.PropertyEditing/Properties/Resources.resx
+++ b/Xamarin.PropertyEditing/Properties/Resources.resx
@@ -455,4 +455,7 @@
<value>Resource ({0})</value>
<comment>Resource with the raw embedded resource name</comment>
</data>
+ <data name="GoToSource" xml:space="preserve">
+ <value>Go to Source</value>
+ </data>
</root> \ No newline at end of file
diff --git a/Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs
index 2c3d12a..b17eb11 100644
--- a/Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs
+++ b/Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs
@@ -25,8 +25,10 @@ namespace Xamarin.PropertyEditing.ViewModels
{
this.coerce = property as ICoerce<TValue>;
this.validator = property as IValidator<TValue>;
+ this.valueNavigator = property as ICanNavigateToSource;
this.isNullable = (!property.ValueSources.HasFlag (ValueSources.Default) || property.Type.Name == NullableName);
+ NavigateToValueSourceCommand = new RelayCommand (OnNavigateToSource, CanNavigateToSource);
SetValueResourceCommand = new RelayCommand<Resource> (OnSetValueToResource, CanSetValueToResource);
ClearValueCommand = new RelayCommand (OnClearValue, CanClearValue);
ConvertToLocalValueCommand = new RelayCommand(OnConvertToLocalValue, CanClearToLocalValue);
@@ -89,6 +91,8 @@ namespace Xamarin.PropertyEditing.ViewModels
}
}
+ public override bool SupportsValueSourceNavigation => this.valueNavigator != null;
+
protected virtual TValue CoerceValue (TValue validationValue)
{
if (!this.isNullable && validationValue == null) {
@@ -194,6 +198,7 @@ namespace Xamarin.PropertyEditing.ViewModels
private readonly ICoerce<TValue> coerce;
private readonly IValidator<TValue> validator;
+ private readonly ICanNavigateToSource valueNavigator;
internal const string NullableName = "Nullable`1";
private bool isNullable;
private ValueInfo<TValue> value;
@@ -220,6 +225,7 @@ namespace Xamarin.PropertyEditing.ViewModels
((RelayCommand) ConvertToLocalValueCommand)?.ChangeCanExecute ();
((RelayCommand) ClearValueCommand)?.ChangeCanExecute ();
+ ((RelayCommand) NavigateToValueSourceCommand)?.ChangeCanExecute ();
return true;
}
@@ -270,6 +276,23 @@ namespace Xamarin.PropertyEditing.ViewModels
});
}
+ private bool CanNavigateToSource ()
+ {
+ if (this.valueNavigator == null)
+ return false;
+ if (Editors.Count != 1)
+ return false;
+ if (ValueSource == ValueSource.Default || ValueSource == ValueSource.Unset)
+ return false;
+
+ return this.valueNavigator.CanNavigateToSource (Editors.Single());
+ }
+
+ private void OnNavigateToSource ()
+ {
+ this.valueNavigator?.NavigateToSource (Editors.FirstOrDefault ());
+ }
+
private static TValue DefaultValue;
}
@@ -374,6 +397,14 @@ namespace Xamarin.PropertyEditing.ViewModels
protected set;
}
+ public ICommand NavigateToValueSourceCommand
+ {
+ get;
+ protected set;
+ }
+
+ public virtual bool SupportsValueSourceNavigation => false;
+
public bool HasErrors => this.error != null;
public IEnumerable GetErrors (string propertyName)
diff --git a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
index 91c10ec..fdc38df 100644
--- a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
+++ b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj
@@ -72,6 +72,7 @@
<Compile Include="Drawing\CommonImageBrush.cs" />
<Compile Include="IAssemblyInfo.cs" />
<Compile Include="IAvailabilityConstraint.cs" />
+ <Compile Include="ICanNavigateToSource.cs" />
<Compile Include="IClampedPropertyInfo.cs" />
<Compile Include="IColorSpaced.cs" />
<Compile Include="ICoerce.cs" />