This commit is contained in:
Dominique Louis 2017-03-16 14:09:49 +00:00 коммит произвёл Eric Maupin
Родитель 3b1da22cf8
Коммит eb2105ceae
5 изменённых файлов: 103 добавлений и 11 удалений

Просмотреть файл

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CoreGraphics;
using Foundation;
using AppKit;
using Xamarin.PropertyEditing;
@ -16,6 +17,9 @@ namespace Xamarin.PropertyEditing.Mac
{
public partial class PropertyEditorPanel : AppKit.NSView
{
NSSearchField propertyFilter;
NSComboBox propertyFilterMode;
public PropertyEditorPanel ()
{
Initialize ();
@ -73,8 +77,41 @@ namespace Xamarin.PropertyEditing.Mac
{
AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;
propertyFilter = new NSSearchField (new CGRect (10, Frame.Height - 25, 170, 24));
propertyFilter.PlaceholderString = "Property Filter";
propertyFilter.ControlSize = NSControlSize.Regular;
AddSubview (propertyFilter);
var label = new NSTextField (new CGRect (195, Frame.Height - 28, 150, 24)) {
BackgroundColor = NSColor.Clear,
TextColor = NSColor.Black,
Editable = false,
Bezeled = false,
ControlSize = NSControlSize.Regular,
StringValue = "Property Filter Mode"
};
AddSubview (label);
propertyFilterMode = new NSComboBox (new CGRect (320, Frame.Height - 25, 100, 24));
propertyFilterMode.ControlSize = NSControlSize.Regular;
AddSubview (propertyFilter);
var enumValues = Enum.GetValues (typeof (PropertyArrangeMode));
foreach (var item in enumValues) {
propertyFilterMode.Add (new NSString (item.ToString ()));
}
propertyFilterMode.SelectItem (0);
AddSubview (propertyFilterMode);
// If either the Filter Mode or PropertySearchFilter Change Filter the Data
propertyFilterMode.Changed += PropertyFilterMode_Changed;
propertyFilter.Changed += PropertyFilterMode_Changed;
// create a table view and a scroll view
NSScrollView tableContainer = new NSScrollView (Frame) {
var tableContainer = new NSScrollView (new CGRect (10, Frame.Height - 240, Frame.Width - 20, Frame.Height - 30)) {
AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable
};
propertyTable = new NSTableView {
@ -100,5 +137,26 @@ namespace Xamarin.PropertyEditing.Mac
tableContainer.DocumentView = propertyTable;
AddSubview (tableContainer);
}
void PropertyFilterMode_Changed (object sender, EventArgs e)
{
PropertyArrangeMode filterMode;
Enum.TryParse<PropertyArrangeMode> (propertyFilterMode.GetItemObject (0).ToString (), out filterMode);
FilterData (propertyFilter.Cell.Title, filterMode);
}
public void FilterData (string title, PropertyArrangeMode filterMode)
{
viewModel.FilterData (title, filterMode);
}
class FirstResponderTableView : NSTableView
{
[Export ("validateProposedFirstResponder:forEvent:")]
public bool validateProposedFirstResponder (NSResponder responder, NSEvent ev)
{
return true;
}
}
}
}

Просмотреть файл

@ -11,13 +11,6 @@ using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Windows
{
public enum PropertyArrangeMode
{
Name = 0,
Category = 1,
ValueSource = 2
}
[TemplatePart (Name = "search", Type = typeof(TextBox))]
[TemplatePart (Name = "propertyItems", Type = typeof(ItemsControl))]
public class PropertyEditorPanel

Просмотреть файл

@ -0,0 +1,10 @@
using System;
namespace Xamarin.PropertyEditing
{
public enum PropertyArrangeMode
{
Name = 0,
Category = 1,
ValueSource = 2
}
}

Просмотреть файл

@ -90,13 +90,16 @@ namespace Xamarin.PropertyEditing.ViewModels
}
private readonly List<IObjectEditor> editors = new List<IObjectEditor> ();
private readonly ObservableCollection<PropertyViewModel> properties = new ObservableCollection<PropertyViewModel> ();
private ObservableCollection<PropertyViewModel> properties = new ObservableCollection<PropertyViewModel> ();
private readonly ObservableCollectionEx<object> selectedObjects = new ObservableCollectionEx<object> ();
string filterText;
PropertyArrangeMode filterMode;
private void UpdateProperties (IObjectEditor[] removedEditors = null, IObjectEditor[] newEditors = null)
{
if (this.editors.Count == 0) {
this.properties.Clear();
this.properties.Clear ();
return;
}
@ -124,7 +127,25 @@ namespace Xamarin.PropertyEditing.ViewModels
}
foreach (IPropertyInfo property in newSet) {
this.properties.Add (GetViewModel (property));
if (string.IsNullOrEmpty (filterText)) {
this.properties.Add (GetViewModel (property));
}
else {
switch (filterMode) {
case PropertyArrangeMode.Name:
if (property.Name.StartsWith (filterText, StringComparison.InvariantCultureIgnoreCase)) {
this.properties.Add (GetViewModel (property));
}
break;
case PropertyArrangeMode.Category:
if (property.Name.StartsWith (filterText, StringComparison.InvariantCultureIgnoreCase)) {
this.properties.Add (GetViewModel (property));
}
break;
case PropertyArrangeMode.ValueSource:
break;
}
}
}
}
@ -165,6 +186,15 @@ namespace Xamarin.PropertyEditing.ViewModels
return new StringPropertyViewModel (property, this.editors);
}
internal void FilterData (string filterText, PropertyArrangeMode filterMode)
{
this.filterText = filterText;
this.filterMode = filterMode;
this.properties.Clear ();
UpdateProperties ();
}
private Task busyTask;
public static readonly Dictionary<Type,Func<IPropertyInfo,IEnumerable<IObjectEditor>,PropertyViewModel>> ViewModelMap = new Dictionary<Type, Func<IPropertyInfo, IEnumerable<IObjectEditor>, PropertyViewModel>> {

Просмотреть файл

@ -68,6 +68,7 @@
<Compile Include="ViewModels\RelayCommand.cs" />
<Compile Include="ViewModels\StringPropertyViewModel.cs" />
<Compile Include="ViewModels\ViewModelBase.cs" />
<Compile Include="PropertyArrangeMode.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />