diff options
author | Eric Maupin <ermaup@microsoft.com> | 2018-08-17 23:31:27 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2018-10-17 22:12:52 +0300 |
commit | 017d4d85fc75bd77cfabdc9536f007695cfcf8b2 (patch) | |
tree | f0e5c9f209243f7e94d16b8e5fd7d18992959d32 /Xamarin.PropertyEditing | |
parent | 41bb09e03bc5fc9cfdeb1a2d5bcf1008c7064190 (diff) |
[Core/Win] CreateVariant
Diffstat (limited to 'Xamarin.PropertyEditing')
6 files changed, 198 insertions, 8 deletions
diff --git a/Xamarin.PropertyEditing/Properties/Resources.Designer.cs b/Xamarin.PropertyEditing/Properties/Resources.Designer.cs index eb2c7f1..277ee1d 100644 --- a/Xamarin.PropertyEditing/Properties/Resources.Designer.cs +++ b/Xamarin.PropertyEditing/Properties/Resources.Designer.cs @@ -47,6 +47,9 @@ namespace Xamarin.PropertyEditing.Properties { } } + /// <summary> + /// Looks up a localized string similar to Alpha. + /// </summary> public static string Alpha { get { return ResourceManager.GetString("Alpha", resourceCulture); @@ -59,6 +62,24 @@ namespace Xamarin.PropertyEditing.Properties { } } + /// <summary> + /// Looks up a localized string similar to Introduce variation based on:. + /// </summary> + public static string AddVariationHelpText { + get { + return ResourceManager.GetString("AddVariationHelpText", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Add a Variation. + /// </summary> + public static string AddVariationTitle { + get { + return ResourceManager.GetString("AddVariationTitle", resourceCulture); + } + } + public static string Black { get { return ResourceManager.GetString("Black", resourceCulture); @@ -71,6 +92,24 @@ namespace Xamarin.PropertyEditing.Properties { } } + /// <summary> + /// Looks up a localized string similar to Any. + /// </summary> + public static string Any { + get { + return ResourceManager.GetString("Any", resourceCulture); + } + } + + /// <summary> + /// Looks up a localized string similar to Application. + /// </summary> + public static string Application { + get { + return ResourceManager.GetString("Application", resourceCulture); + } + } + public static string Blue { get { return ResourceManager.GetString("Blue", resourceCulture); @@ -707,12 +746,6 @@ namespace Xamarin.PropertyEditing.Properties { } } - public static string Application { - get { - return ResourceManager.GetString("Application", resourceCulture); - } - } - public static string ApplyToAll { get { return ResourceManager.GetString("ApplyToAll", resourceCulture); diff --git a/Xamarin.PropertyEditing/Properties/Resources.resx b/Xamarin.PropertyEditing/Properties/Resources.resx index 081dc7e..72000a5 100644 --- a/Xamarin.PropertyEditing/Properties/Resources.resx +++ b/Xamarin.PropertyEditing/Properties/Resources.resx @@ -554,4 +554,13 @@ <data name="Shared" xml:space="preserve"> <value>Shared</value> </data> -</root>
\ No newline at end of file + <data name="AddVariationHelpText" xml:space="preserve"> + <value>Introduce variation based on:</value> + </data> + <data name="AddVariationTitle" xml:space="preserve"> + <value>Add a Variation</value> + </data> + <data name="Any" xml:space="preserve"> + <value>Any</value> + </data> +</root> diff --git a/Xamarin.PropertyEditing/PropertyVariationSet.cs b/Xamarin.PropertyEditing/PropertyVariationSet.cs index 2aa459d..4e6bfa0 100644 --- a/Xamarin.PropertyEditing/PropertyVariationSet.cs +++ b/Xamarin.PropertyEditing/PropertyVariationSet.cs @@ -7,6 +7,15 @@ namespace Xamarin.PropertyEditing public class PropertyVariationSet : IList<PropertyVariation> { + public PropertyVariationSet (params PropertyVariation[] variations) + { + if (variations == null) + throw new ArgumentNullException (nameof(variations)); + + for (int i = 0; i < variations.Length; i++) + Add (variations[i]); + } + public int Count => this.variations.Count; bool ICollection<PropertyVariation>.IsReadOnly => false; diff --git a/Xamarin.PropertyEditing/ViewModels/CreateVariantEventArgs.cs b/Xamarin.PropertyEditing/ViewModels/CreateVariantEventArgs.cs new file mode 100644 index 0000000..3506a4a --- /dev/null +++ b/Xamarin.PropertyEditing/ViewModels/CreateVariantEventArgs.cs @@ -0,0 +1,14 @@ +using System; + +namespace Xamarin.PropertyEditing.ViewModels +{ + internal class CreateVariantEventArgs + : EventArgs + { + public PropertyVariationSet Variant + { + get; + set; + } + } +}
\ No newline at end of file diff --git a/Xamarin.PropertyEditing/ViewModels/CreateVariantViewModel.cs b/Xamarin.PropertyEditing/ViewModels/CreateVariantViewModel.cs new file mode 100644 index 0000000..53949c7 --- /dev/null +++ b/Xamarin.PropertyEditing/ViewModels/CreateVariantViewModel.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Windows.Input; +using Xamarin.PropertyEditing.Properties; + +namespace Xamarin.PropertyEditing.ViewModels +{ + internal class VariationViewModel + : NotifyingObject + { + public VariationViewModel (string category, IEnumerable<PropertyVariation> variations) + { + if (category == null) + throw new ArgumentNullException (nameof(category)); + if (variations == null) + throw new ArgumentNullException (nameof (variations)); + + Name = category; + var vs = variations.ToList (); + vs.Insert (0, new PropertyVariation (category, Resources.Any)); + Variations = vs; + + this.selectedVariation = vs[0]; + } + + public string Name + { + get; + } + + public IReadOnlyList<PropertyVariation> Variations + { + get; + } + + public bool IsAnySelected => SelectedVariation == Variations[0]; + + public PropertyVariation SelectedVariation + { + get { return this.selectedVariation; } + set + { + if (this.selectedVariation == value) + return; + + this.selectedVariation = value; + OnPropertyChanged(); + OnPropertyChanged (nameof(IsAnySelected)); + } + } + + private PropertyVariation selectedVariation; + } + + internal class CreateVariantViewModel + : NotifyingObject + { + public CreateVariantViewModel (IPropertyInfo property) + { + if (property == null) + throw new ArgumentNullException (nameof (property)); + + this.property = property; + VariationCategories = property.Variations + .GroupBy (v => v.Category) + .Select (g => new VariationViewModel (g.Key, g)) + .ToList(); + + foreach (var vvm in VariationCategories) { + vvm.PropertyChanged += OnCategoryPropertyChanged; + } + + CreateVariantCommand = new RelayCommand (OnCreateVariant, CanCreateVariant); + } + + public IReadOnlyList<VariationViewModel> VariationCategories + { + get; + } + + public ICommand CreateVariantCommand + { + get; + } + + public PropertyVariationSet Variant + { + get { return this.variant; } + private set + { + if (this.variant == value) + return; + + this.variant = value; + OnPropertyChanged(); + } + } + + private readonly IPropertyInfo property; + private PropertyVariationSet variant; + + private void OnCategoryPropertyChanged (object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == nameof (VariationViewModel.SelectedVariation)) + ((RelayCommand)CreateVariantCommand).ChangeCanExecute (); + } + + private void OnCreateVariant () + { + Variant = new PropertyVariationSet (VariationCategories + .Where (vm => !vm.IsAnySelected) + .Select (vm => vm.SelectedVariation) + .ToArray ()); + } + + private bool CanCreateVariant () + { + return !VariationCategories.All (vm => vm.IsAnySelected); + } + } +} diff --git a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj index 41b2f98..d17e0b7 100644 --- a/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj +++ b/Xamarin.PropertyEditing/Xamarin.PropertyEditing.csproj @@ -129,6 +129,7 @@ <Compile Include="ViewModels\CreateBindingViewModel.cs" /> <Compile Include="ViewModels\CreateResourceRequestedEventArgs.cs" /> <Compile Include="ViewModels\CreateResourceViewModel.cs" /> + <Compile Include="ViewModels\CreateVariantViewModel.cs" /> <Compile Include="ViewModels\MaterialColorScale.cs" /> <Compile Include="ViewModels\MaterialDesignColorViewModel.cs" /> <Compile Include="ViewModels\CombinablePropertyViewModel.cs" /> @@ -168,6 +169,7 @@ <Compile Include="ViewModels\RatioViewModel.cs" /> <Compile Include="Drawing\CommonRatio.cs" /> <Compile Include="IReadOnlyOrderedDictionary.cs" /> + <Compile Include="ViewModels\CreateVariantEventArgs.cs" /> </ItemGroup> <ItemGroup> <Compile Include="Themes\BaseThemeManager.cs" /> @@ -184,4 +186,4 @@ </EmbeddedResource> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -</Project>
\ No newline at end of file +</Project> |