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:
authorDominique Louis <dominique@Dominiques-MacBook-Pro-2.local>2019-03-21 16:54:10 +0300
committerCartBlanche <savagesoftware@gmail.com>2019-06-26 21:17:31 +0300
commitbbe46e57cb1627d26ccc0e68dc9b2ed877b3d170 (patch)
treedb3205f282da1b63cf92c1a5cee3d7586743c525 /Xamarin.PropertyEditing.Mac/Controls/BindingEditor/BindingResourceSelectorControl.cs
parent6be4f60fa2d4adf31893c75d8a8ef8ce879b6bd3 (diff)
[Mac] Make Binding Dialog Modal
[Mac] Ensure property button view is cleared
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/BindingEditor/BindingResourceSelectorControl.cs')
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/BindingEditor/BindingResourceSelectorControl.cs243
1 files changed, 37 insertions, 206 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/BindingEditor/BindingResourceSelectorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BindingEditor/BindingResourceSelectorControl.cs
index afcf746..54a5e4b 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/BindingEditor/BindingResourceSelectorControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/BindingEditor/BindingResourceSelectorControl.cs
@@ -7,209 +7,24 @@ using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
{
- internal class BindingResourceSelectorControl : NSView
+ internal class BindingResourceSelectorControl
+ : NotifyingView<CreateBindingViewModel>
{
- internal class ResourceOutlineView : NSOutlineView
- {
- private ILookup<ResourceSource, Resource> viewModel;
- public ILookup<ResourceSource, Resource> ViewModel {
- get => this.viewModel;
- set {
- if (this.viewModel != value) {
- this.viewModel = value;
- var dataSource = new ResourceOutlineViewDataSource (this.viewModel);
- Delegate = new ResourceOutlineViewDelegate (dataSource);
- DataSource = dataSource;
- }
-
- if (this.viewModel != null) {
- ReloadData ();
-
- ExpandItem (null, true);
- }
- }
- }
+ private const string ResourceSelectorColId = "ResourceSelectorColumn";
- public ResourceOutlineView ()
- {
- Initialize ();
- }
-
- // Called when created from unmanaged code
- public ResourceOutlineView (IntPtr handle) : base (handle)
- {
- Initialize ();
- }
-
- // Called when created directly from a XIB file
- [Export ("initWithCoder:")]
- public ResourceOutlineView (NSCoder coder) : base (coder)
- {
- Initialize ();
- }
-
- [Export ("validateProposedFirstResponder:forEvent:")]
- public bool ValidateProposedFirstResponder (NSResponder responder, NSEvent forEvent)
- {
- return true;
- }
-
- public void Initialize ()
- {
- AutoresizingMask = NSViewResizingMask.WidthSizable;
- HeaderView = null;
- TranslatesAutoresizingMaskIntoConstraints = false;
- }
- }
-
- internal class ResourceOutlineViewDelegate : NSOutlineViewDelegate
- {
- private readonly ResourceOutlineViewDataSource dataSource;
+ public BindingResourceOutlineView resourceOutlineView;
- public ResourceOutlineViewDelegate (ResourceOutlineViewDataSource datasource)
- {
- this.dataSource = datasource;
- }
-
- public override nfloat GetRowHeight (NSOutlineView outlineView, NSObject item)
- {
- return PropertyEditorControl.DefaultControlHeight;
- }
-
- public override NSView GetView (NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
- {
- var labelContainer = (UnfocusableTextField)outlineView.MakeView ("resource", this);
- if (labelContainer == null) {
- labelContainer = new UnfocusableTextField {
- Identifier = "resource",
- };
- }
- var target = (item as NSObjectFacade).Target;
-
- switch (target) {
- case IGrouping<ResourceSource, Resource> kvp:
- labelContainer.StringValue = kvp.Key.Name;
- break;
- case Resource resource:
- labelContainer.StringValue = resource.Name;
- break;
- default:
- labelContainer.StringValue = "Resource Not Supported";
- break;
- }
-
- return labelContainer;
- }
-
- public override bool ShouldSelectItem (NSOutlineView outlineView, NSObject item)
- {
- var target = (item as NSObjectFacade).Target;
- switch (target) {
- case IGrouping<ResourceSource, Resource> kvp:
- return false;
- case Resource resource:
- return true;
-
- default:
- return false;
- }
- }
- }
-
- internal class ResourceOutlineViewDataSource : NSOutlineViewDataSource
+ internal BindingResourceSelectorControl (CreateBindingViewModel viewModel)
{
- public ILookup<ResourceSource, Resource> ViewModel { get; }
+ if (viewModel == null)
+ throw new ArgumentNullException (nameof (viewModel));
- internal ResourceOutlineViewDataSource (ILookup<ResourceSource, Resource> viewModel)
- {
- if (viewModel == null)
- throw new ArgumentNullException (nameof (viewModel));
-
- ViewModel = viewModel;
- }
+ ViewModel = viewModel;
- public override nint GetChildrenCount (NSOutlineView outlineView, NSObject item)
- {
- var childCount = 0;
- if (item == null) {
- childCount = this.ViewModel != null ? this.ViewModel.Count () : 0;
- } else {
- var target = (item as NSObjectFacade).Target;
- switch (target) {
- case IGrouping < ResourceSource, Resource> kvp:
- childCount = kvp.Count ();
- break;
- case Resource resource:
- childCount = 0;
- break;
- default:
- childCount = 0;
- break;
- }
- }
-
- return childCount;
- }
-
- public override NSObject GetChild (NSOutlineView outlineView, nint childIndex, NSObject item)
- {
- object element;
-
- if (item == null) {
- element = this.ViewModel.ElementAt ((int)childIndex);
- } else {
- var target = (item as NSObjectFacade).Target;
- switch (target) {
- case IGrouping<ResourceSource, Resource> kvp:
- element = kvp.ElementAt ((int)childIndex);
- break;
- case Resource resource:
- element = resource;
- break;
- default:
- return null;
- }
- }
-
- return new NSObjectFacade (element);
- }
-
- public override bool ItemExpandable (NSOutlineView outlineView, NSObject item)
- {
- var target = (item as NSObjectFacade).Target;
- switch (target) {
- case IGrouping<ResourceSource, Resource> kvp:
- return kvp.Count() > 0;
- case Resource resource:
- return false;
- default:
- return false;
- }
- }
- }
-
- internal const string ResourceSelectorColId = "ResourceSelectorColumn";
-
- public ResourceOutlineView resourceOutlineView;
-
- internal BindingResourceSelectorControl (CreateBindingViewModel viewModel)
- {
TranslatesAutoresizingMaskIntoConstraints = false;
- this.resourceOutlineView = new ResourceOutlineView {
-
- };
- this.resourceOutlineView.Activated += (sender, e) => {
- if (sender is ResourceOutlineView rov) {
- if (rov.SelectedRow != -1) {
- if (rov.ItemAtRow (rov.SelectedRow) is NSObjectFacade item) {
- if (item.Target is Resource resource) {
- viewModel.SelectedResource = resource;
- }
- }
- }
- }
- };
+ this.resourceOutlineView = new BindingResourceOutlineView ();
+ this.resourceOutlineView.Activated += OnResourceOutlineViewSelected;
var resourceColumn = new NSTableColumn (ResourceSelectorColId);
this.resourceOutlineView.AddColumn (resourceColumn);
@@ -227,21 +42,37 @@ namespace Xamarin.PropertyEditing.Mac
AddSubview (outlineViewContainer);
AddConstraints (new[] {
- NSLayoutConstraint.Create (outlineViewContainer, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 45f),
- NSLayoutConstraint.Create (outlineViewContainer, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 5f),
- NSLayoutConstraint.Create (outlineViewContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -10f),
- NSLayoutConstraint.Create (outlineViewContainer, NSLayoutAttribute.Height, NSLayoutRelation.Equal,this, NSLayoutAttribute.Height, 1f, -50f),
+ NSLayoutConstraint.Create (outlineViewContainer, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1f, 28f),
+ NSLayoutConstraint.Create (outlineViewContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0f),
+ NSLayoutConstraint.Create (outlineViewContainer, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterX, 1, 0),
+ NSLayoutConstraint.Create (outlineViewContainer, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal,this, NSLayoutAttribute.Bottom, 1f, 0f),
});
- viewModel.PropertyChanged += (sender, e) => {
- if (e.PropertyName == nameof (CreateBindingViewModel.ShowResourceSelector)) {
- Hidden = !viewModel.ShowResourceSelector;
+ viewModel.PropertyChanged += OnPropertyChanged;
+ }
+
+ public override void OnPropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName == nameof (CreateBindingViewModel.ShowResourceSelector)) {
+ Hidden = !ViewModel.ShowResourceSelector;
- if (viewModel.ShowResourceSelector && viewModel.SourceResources != null) {
- this.resourceOutlineView.ViewModel = viewModel.SourceResources.Value;
- };
+ if (ViewModel.ShowResourceSelector && ViewModel.SourceResources != null) {
+ this.resourceOutlineView.ItemsSource = ViewModel.SourceResources.Value;
+ };
+ }
+ }
+
+ private void OnResourceOutlineViewSelected (object sender, EventArgs e)
+ {
+ if (sender is BindingResourceOutlineView rov) {
+ if (rov.SelectedRow != -1) {
+ if (rov.ItemAtRow (rov.SelectedRow) is NSObjectFacade item) {
+ if (item.Target is Resource resource) {
+ ViewModel.SelectedResource = resource;
+ }
+ }
}
- };
+ }
}
}
}