diff options
author | CartBlanche <savagesoftware@gmail.com> | 2020-02-20 02:54:56 +0300 |
---|---|---|
committer | CartBlanche <savagesoftware@gmail.com> | 2020-02-20 18:22:27 +0300 |
commit | d148a22c16ca83f86303b4fd281d721c1648071a (patch) | |
tree | 4bb7f67fac2025d7547310cb23710321499b448d /Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs | |
parent | 916ce67a863c84092e6abe8fb7d1cba7ae77e9ff (diff) |
[Mac] Refocus to original brush type when repopped up.
Diffstat (limited to 'Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs')
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs | 37 |
1 files changed, 34 insertions, 3 deletions
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<BrushPropertyViewModel> { 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)), |