diff options
author | CartBlanche <savagesoftware@gmail.com> | 2019-11-13 14:54:51 +0300 |
---|---|---|
committer | CartBlanche <savagesoftware@gmail.com> | 2019-12-11 19:12:01 +0300 |
commit | f93638314a6449b9672a3a52fa638cc48f6a6792 (patch) | |
tree | 988298230a72911219b91d7ed5d56d2cf41f141c /Xamarin.PropertyEditing.Mac | |
parent | 70e8074aa62c2030cd60c68f963beb62abc2a5be (diff) |
[Mac] Make the button that popped up the PopOver have focus, once the popover closes.
Diffstat (limited to 'Xamarin.PropertyEditing.Mac')
3 files changed, 37 insertions, 30 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/CollectionEditorWindow.cs b/Xamarin.PropertyEditing.Mac/Controls/CollectionEditorWindow.cs index 6b42de2..c215e1e 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CollectionEditorWindow.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CollectionEditorWindow.cs @@ -1,10 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; using AppKit; using CoreGraphics; -using Foundation; using Xamarin.PropertyEditing.ViewModels; @@ -16,7 +13,12 @@ namespace Xamarin.PropertyEditing.Mac public CollectionEditorWindow (IHostResourceProvider hostResources, CollectionPropertyViewModel viewModel) : base (new CGRect (0, 0, 500, 400), NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Resizable, NSBackingStore.Buffered, true) { - Delegate = new ModalDialogDelegate (); + if (hostResources == null) + throw new ArgumentNullException (nameof (hostResources)); + if (viewModel == null) + throw new ArgumentNullException (nameof (viewModel)); + + Delegate = new ModalWindowCloseDelegate (); Title = String.Format (Properties.Resources.CollectionEditorTitle, viewModel.Property.Name); this.collectionEditor = new CollectionEditorControl (hostResources) { @@ -26,19 +28,28 @@ namespace Xamarin.PropertyEditing.Mac ContentView.AddSubview (this.collectionEditor); - this.ok = NSButton.CreateButton (Properties.Resources.OK, OnOked); - this.ok.AccessibilityEnabled = true; - this.ok.AccessibilityTitle = Properties.Resources.AccessibilityCollectionOKButton; - this.ok.Highlighted = true; - this.ok.TranslatesAutoresizingMaskIntoConstraints = false; - - //this.ok.KeyEquivalent = "\r"; // FIXME: The type selector popup doesn't eat this key, so it ends up closing both. + this.ok = new FocusableButton { + AccessibilityEnabled = true, + AccessibilityTitle = Properties.Resources.AccessibilityCollectionOKButton, + BezelStyle = NSBezelStyle.Rounded, + ControlSize = NSControlSize.Regular, + Highlighted = true, + //KeyEquivalent = "\r", // FIXME: The type selector popup doesn't eat this key, so it ends up closing both.Sw + Title = Properties.Resources.OK, + TranslatesAutoresizingMaskIntoConstraints = false + }; + this.ok.Activated += OnOked; ContentView.AddSubview (this.ok); - this.cancel = NSButton.CreateButton (Properties.Resources.Cancel, OnCanceled); - this.cancel.AccessibilityEnabled = true; - this.cancel.AccessibilityTitle = Properties.Resources.AccessibilityCollectionCancelButton; - this.cancel.TranslatesAutoresizingMaskIntoConstraints = false; + this.cancel = new FocusableButton { + AccessibilityEnabled = true, + AccessibilityTitle = Properties.Resources.AccessibilityCollectionCancelButton, + BezelStyle = NSBezelStyle.Rounded, + ControlSize = NSControlSize.Regular, + Title = Properties.Resources.Cancel, + TranslatesAutoresizingMaskIntoConstraints = false + }; + this.cancel.Activated += OnCanceled; ContentView.AddSubview (this.cancel); ContentView.AddConstraints (new[] { @@ -66,16 +77,20 @@ namespace Xamarin.PropertyEditing.Mac private CollectionEditorControl collectionEditor; private NSButton ok, cancel; - private void OnOked () + private void OnOked (object o, EventArgs e) { ModalResponse = NSModalResponse.OK; - this.collectionEditor.ViewModel = null; - Close (); + CloseWindow (); } - private void OnCanceled () + private void OnCanceled (object o, EventArgs e) { ModalResponse = NSModalResponse.Cancel; + CloseWindow (); + } + + private void CloseWindow () + { this.collectionEditor.ViewModel = null; Close (); } @@ -94,15 +109,5 @@ namespace Xamarin.PropertyEditing.Mac collectionVm.CommitCommand.Execute (null); } - - private class ModalDialogDelegate - : NSWindowDelegate - { - public override void WillClose (NSNotification notification) - { - NSModalResponse response = ((CollectionEditorWindow)notification.Object).ModalResponse; - NSApplication.SharedApplication.StopModalWithCode ((int)response); - } - } } }
\ No newline at end of file diff --git a/Xamarin.PropertyEditing.Mac/Controls/ControlExtensions.cs b/Xamarin.PropertyEditing.Mac/Controls/ControlExtensions.cs index 3e94781..cad49a8 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/ControlExtensions.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/ControlExtensions.cs @@ -37,6 +37,9 @@ namespace Xamarin.PropertyEditing.Mac popover.SetAppearance (hostResources.GetVibrantAppearance (source.EffectiveAppearance)); tcs.Task.ContinueWith (t => { + // Focus back to the button that popped us up + source.Superview?.Window?.MakeFirstResponder (source); + popover.PerformClose (popover); popover.Dispose (); }, TaskScheduler.FromCurrentSynchronizationContext ()); diff --git a/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs index 69a520e..9ee86d1 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/TypeEditorControl.cs @@ -112,7 +112,6 @@ namespace Xamarin.PropertyEditing.Mac private void OnSelectPressed (object sender, EventArgs e) { - Window.MakeFirstResponder (this.selectType); ViewModel.SelectTypeCommand.Execute (null); } } |