diff options
10 files changed, 136 insertions, 27 deletions
diff --git a/Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs b/Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs new file mode 100644 index 0000000..38150cb --- /dev/null +++ b/Xamarin.PropertyEditing.Tests/PanelViewModelTests.cs @@ -0,0 +1,36 @@ +using System.Linq; +using System.Threading.Tasks; +using NUnit.Framework; +using Xamarin.PropertyEditing.Reflection; +using Xamarin.PropertyEditing.ViewModels; + +namespace Xamarin.PropertyEditing.Tests +{ + [TestFixture] + public class PanelViewModelTests + { + private class TestClass + { + public string Property + { + get; + set; + } + } + + [Test] + public async Task PropertiesAddedFromEditor () + { + var provider = new ReflectionEditorProvider (); + var obj = new TestClass(); + var editor = await provider.GetObjectEditorAsync (obj); + Assume.That (editor.Properties.Count, Is.EqualTo (1)); + + var vm = new PanelViewModel (provider); + vm.SelectedObjects.Add (obj); + + Assert.That (vm.Properties, Is.Not.Empty); + Assert.That (vm.Properties[0].Property, Is.EqualTo (editor.Properties.Single())); + } + } +}
\ No newline at end of file diff --git a/Xamarin.PropertyEditing.Tests/ReflectionPropertyProviderTests.cs b/Xamarin.PropertyEditing.Tests/ReflectionPropertyProviderTests.cs new file mode 100644 index 0000000..7bb9e80 --- /dev/null +++ b/Xamarin.PropertyEditing.Tests/ReflectionPropertyProviderTests.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; +using Xamarin.PropertyEditing.Reflection; + +namespace Xamarin.PropertyEditing.Tests +{ + [TestFixture] + public class ReflectionPropertyProviderTests + { + [Test] + public async Task EditorHasSimpleProperty () + { + var provider = new ReflectionEditorProvider (); + IObjectEditor editor = await provider.GetObjectEditorAsync (new TestClass ()); + Assume.That (editor, Is.Not.Null); + + Assert.That (editor.Properties.Count, Is.EqualTo (1)); + + var property = editor.Properties.Single(); + Assert.That (property.Name, Is.EqualTo (nameof (TestClass.Property))); + Assert.That (property.Type, Is.EqualTo (typeof (string))); + } + + private class TestClass + { + public string Property + { + get; + set; + } + } + } +} diff --git a/Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj b/Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj index ee66ca5..dbb94eb 100644 --- a/Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj +++ b/Xamarin.PropertyEditing.Tests/Xamarin.PropertyEditing.Tests.csproj @@ -30,6 +30,14 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL"> + <HintPath>..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Moq, Version=4.5.30.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL"> + <HintPath>..\packages\Moq.4.5.30\lib\net45\Moq.dll</HintPath> + <Private>True</Private> + </Reference> <Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> <HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath> <Private>True</Private> @@ -44,10 +52,18 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> + <Compile Include="PanelViewModelTests.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="ReflectionPropertyProviderTests.cs" /> </ItemGroup> <ItemGroup> <None Include="packages.config" /> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\Xamarin.PropertyEditing\Xamarin.PropertyEditing.csproj"> + <Project>{A0B6FE73-D046-4E1C-BA9D-F20683889C5A}</Project> + <Name>Xamarin.PropertyEditing</Name> + </ProjectReference> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file diff --git a/Xamarin.PropertyEditing.Tests/packages.config b/Xamarin.PropertyEditing.Tests/packages.config index e733ad5..6c0c86d 100644 --- a/Xamarin.PropertyEditing.Tests/packages.config +++ b/Xamarin.PropertyEditing.Tests/packages.config @@ -1,4 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <packages> + <package id="Castle.Core" version="3.3.3" targetFramework="net452" /> + <package id="Moq" version="4.5.30" targetFramework="net452" /> <package id="NUnit" version="2.6.4" targetFramework="net452" /> </packages>
\ No newline at end of file diff --git a/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml b/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml index 634152b..d6c3312 100644 --- a/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml +++ b/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml @@ -18,9 +18,9 @@ <RowDefinition /> </Grid.RowDefinitions> - <Button Grid.Row="0" Grid.Column="0">Select me</Button> - <Button Grid.Row="1" Grid.Column="0">Select me 2</Button> + <Button Grid.Row="0" Grid.Column="0" Click="Button_Click">Select me</Button> + <Button Grid.Row="1" Grid.Column="0" Click="Button_Click">Select me 2</Button> - <xamarinprops:PropertyEditorPanel Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" /> + <xamarinprops:PropertyEditorPanel Name="panel" Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" /> </Grid> </Window>
\ No newline at end of file diff --git a/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml.cs b/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml.cs index ead267f..b30f3f8 100644 --- a/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml.cs +++ b/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml.cs @@ -1,17 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; +using System.Windows; +using Xamarin.PropertyEditing.Reflection; namespace Xamarin.PropertyEditing.Windows.Standalone { @@ -23,6 +11,13 @@ namespace Xamarin.PropertyEditing.Windows.Standalone public MainWindow () { InitializeComponent (); + this.panel.EditorProvider = new ReflectionEditorProvider(); + } + + private void Button_Click (object sender, RoutedEventArgs e) + { + this.panel.SelectedItems.Clear(); + this.panel.SelectedItems.Add (sender); } } } diff --git a/Xamarin.PropertyEditing.Windows/EditorPropertySelector.cs b/Xamarin.PropertyEditing.Windows/EditorPropertySelector.cs index 641437c..1d5063e 100644 --- a/Xamarin.PropertyEditing.Windows/EditorPropertySelector.cs +++ b/Xamarin.PropertyEditing.Windows/EditorPropertySelector.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Windows; using System.Windows.Controls; +using System.Windows.Data; using Xamarin.PropertyEditing.ViewModels; namespace Xamarin.PropertyEditing.Windows @@ -21,6 +22,7 @@ namespace Xamarin.PropertyEditing.Windows this.templates[type] = template = new DataTemplate (type) { VisualTree = new FrameworkElementFactory (controlType) }; + template.VisualTree.SetBinding (PropertyEditorControl.LabelProperty, new Binding ("Property.Name") { Mode = BindingMode.OneTime }); } } diff --git a/Xamarin.PropertyEditing.Windows/PropertyEditorPanel.cs b/Xamarin.PropertyEditing.Windows/PropertyEditorPanel.cs index dfb4837..7266091 100644 --- a/Xamarin.PropertyEditing.Windows/PropertyEditorPanel.cs +++ b/Xamarin.PropertyEditing.Windows/PropertyEditorPanel.cs @@ -1,5 +1,8 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.Linq; using System.Windows; using System.Windows.Controls; using Xamarin.PropertyEditing.ViewModels; @@ -13,11 +16,14 @@ namespace Xamarin.PropertyEditing.Windows public PropertyEditorPanel () { DefaultStyleKey = typeof(PropertyEditorPanel); - SelectedItems = new ObservableCollection<object> (); + + var selectedItems = new ObservableCollection<object> (); + selectedItems.CollectionChanged += OnSelectedItemsChanged; + SelectedItems = selectedItems; } public static readonly DependencyProperty EditorProviderProperty = DependencyProperty.Register ( - "EditorProvider", typeof(IEditorProvider), typeof(PropertyEditorPanel), new PropertyMetadata (default(IEditorProvider))); + "EditorProvider", typeof(IEditorProvider), typeof(PropertyEditorPanel), new PropertyMetadata (default(IEditorProvider), (o, args) => ((PropertyEditorPanel)o).OnEditorProviderChanged())); public IEditorProvider EditorProvider { @@ -41,14 +47,28 @@ namespace Xamarin.PropertyEditing.Windows base.OnApplyTemplate (); this.items = (ItemsControl)GetTemplateChild ("propertyItems"); - this.items.DataContext = new PanelViewModel (EditorProvider); + this.items.DataContext = this.vm = new PanelViewModel (EditorProvider); } + private PanelViewModel vm; private ItemsControl items; - private void OnEditorChanged () + private void OnSelectedItemsChanged (object sender, NotifyCollectionChangedEventArgs e) + { + if (this.vm == null) + return; + + // TODO properly + this.vm.SelectedObjects.Clear(); + this.vm.SelectedObjects.AddRange (SelectedItems.Cast<object>()); + } + + private void OnEditorProviderChanged () { - + if (this.items == null) + return; + + this.items.DataContext = this.vm = (EditorProvider != null) ? new PanelViewModel (EditorProvider) : null; } } }
\ No newline at end of file diff --git a/Xamarin.PropertyEditing.Windows/Resources.xaml b/Xamarin.PropertyEditing.Windows/Resources.xaml index d79ee64..aa9121e 100644 --- a/Xamarin.PropertyEditing.Windows/Resources.xaml +++ b/Xamarin.PropertyEditing.Windows/Resources.xaml @@ -23,8 +23,8 @@ <Setter Property="Grid.IsSharedSizeScope" Value="True" /> <Setter Property="Template"> <Setter.Value> - <ControlTemplate> - <ItemsControl Name="propertyItems"> + <ControlTemplate TargetType="local:PropertyEditorPanel"> + <ItemsControl Name="propertyItems" ItemsSource="{Binding Properties}"> <ItemsControl.ItemTemplateSelector> <local:EditorPropertySelector /> </ItemsControl.ItemTemplateSelector> diff --git a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs index 4377a47..64db6b9 100644 --- a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs @@ -34,8 +34,8 @@ namespace Xamarin.PropertyEditing.ViewModels return; } - var newSet = new HashSet<IPropertyInfo> (this.properties.Select (vm => vm.Property)); - for (int i = 0; i < editors.Count; i++) { + var newSet = new HashSet<IPropertyInfo> (editors[0].Properties); + for (int i = 1; i < editors.Count; i++) { newSet.IntersectWith (editors[i].Properties); } @@ -60,6 +60,7 @@ namespace Xamarin.PropertyEditing.ViewModels private PropertyViewModel GetViewModel (IPropertyInfo property, IEnumerable<IObjectEditor> editors) { + // TODO return new StringPropertyViewModel (property, editors); } } |