From d148a22c16ca83f86303b4fd281d721c1648071a Mon Sep 17 00:00:00 2001 From: CartBlanche Date: Wed, 19 Feb 2020 23:54:56 +0000 Subject: [Mac] Refocus to original brush type when repopped up. --- .../Controls/BrushEditorControl.cs | 37 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs') diff --git a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs index 6a8b213..7520f31 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs @@ -1,8 +1,11 @@ using System; using System.Collections; using System.ComponentModel; +using System.Threading; +using System.Threading.Tasks; using AppKit; using CoreGraphics; +using Foundation; using Xamarin.PropertyEditing.Drawing; using Xamarin.PropertyEditing.ViewModels; @@ -26,15 +29,41 @@ namespace Xamarin.PropertyEditing.Mac public override void KeyDown (NSEvent theEvent) { - if (theEvent.KeyCode == 36 || theEvent.KeyCode == 49) { + if (theEvent.KeyCode == (ushort)NSKey.Space) { MouseDown (theEvent); - } - else { + } else { base.KeyDown (theEvent); } } } + internal class ColorPopOverDelegate : NSPopoverDelegate + { + private BrushTabViewController brushTabViewController; + private CommonBrushType selectedBrushType = CommonBrushType.None; + + internal ColorPopOverDelegate (BrushTabViewController brushTabViewController) + { + if (brushTabViewController == null) + throw new ArgumentNullException (nameof (brushTabViewController)); + + this.brushTabViewController = brushTabViewController; + } + + public override void WillShow (NSNotification notification) + { + if (this.brushTabViewController.ViewModel != null) { + var ct = new CancellationTokenSource (); + Task.Factory.StartNew (()=> { + if (this.selectedBrushType == CommonBrushType.None) + this.selectedBrushType = this.brushTabViewController.ViewModel.SelectedBrushType; + else + this.brushTabViewController.ViewModel.SelectedBrushType = this.selectedBrushType; + }, ct.Token, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext ()); + } + } + } + internal class BrushEditorControl : PropertyEditorControl { public BrushEditorControl (IHostResourceProvider hostResources) @@ -52,6 +81,8 @@ namespace Xamarin.PropertyEditing.Mac } }; + this.popover.Delegate = new ColorPopOverDelegate (this.brushTabViewController); + this.popUpButton = new ColorPopUpButton { ControlSize = NSControlSize.Small, Font = NSFont.SystemFontOfSize (NSFont.SystemFontSizeForControlSize (NSControlSize.Small)), -- cgit v1.2.3