diff options
author | Jose Medrano <jose.medrano@microsoft.com> | 2020-07-21 02:36:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-21 02:36:11 +0300 |
commit | 2a1b772c42cb3972708cfdc5ca28cc60d1836641 (patch) | |
tree | 305f62495317d2a810e803e635f7b8b19315cc26 | |
parent | 8b05145b42e613b833ac69da84a75b29204380e5 (diff) |
Increases delay time and disables caller button to override vs4mac focus (#752)
Fixes #1002094 - A11Y_Xamarin Designers_Property pane_keyboard : After pressing the "cancel" button which is present inside the "edit" button focus is not visible
-rw-r--r-- | Xamarin.PropertyEditing.Mac/CocoaHelpers.cs | 51 | ||||
-rw-r--r-- | Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs | 26 |
2 files changed, 20 insertions, 57 deletions
diff --git a/Xamarin.PropertyEditing.Mac/CocoaHelpers.cs b/Xamarin.PropertyEditing.Mac/CocoaHelpers.cs deleted file mode 100644 index fa25e5b..0000000 --- a/Xamarin.PropertyEditing.Mac/CocoaHelpers.cs +++ /dev/null @@ -1,51 +0,0 @@ -// -// CocoaHelpers.cs -// -// Author: -// jmedrano <josmed@microsoft.com> -// -// Copyright (c) 2020 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -using System; -using AppKit; - -namespace Xamarin.PropertyEditing.Mac -{ - public static class CocoaHelpers - { - public static void RunModalForWindow (NSWindow window, NSView controlToFocusWhenWindowClosed, Action<NSModalResponse> responseHandler = null, int defaultDelayTime = 100) - { - //HACK: Because VS4Mac is a GTK application try force set to NSApplication.SharedApplication.RunModalForWindow - //breaks the current focused window. Try only focus the ID is not enought, because our IDE on get focus (gtk) will override the current - //focused element, then launch a task to allow the IDE to get the focus and wait for synchcontext to focus the correct view. - var parentWindow = NSApplication.SharedApplication.KeyWindow; - - var result = (NSModalResponse)(int)NSApplication.SharedApplication.RunModalForWindow (window); - - //after run modal our FocusedWindow is null, we set the parent again - parentWindow?.MakeKeyAndOrderFront (parentWindow); - - System.Threading.Tasks.Task.Delay (defaultDelayTime).ContinueWith (t => { - responseHandler?.Invoke (result); - parentWindow?.MakeFirstResponder (controlToFocusWhenWindowClosed); - }, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext ()); - } - } -} diff --git a/Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs index 9eb7cad..00608b1 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/CollectionInlineEditorControl.cs @@ -1,4 +1,5 @@ using System;
+using System.Threading.Tasks;
using AppKit; using Xamarin.PropertyEditing.ViewModels; @@ -7,6 +8,8 @@ namespace Xamarin.PropertyEditing.Mac internal class CollectionInlineEditorControl : PropertyEditorControl<CollectionPropertyViewModel> { + const int DefaultDelayTime = 500; + public CollectionInlineEditorControl (IHostResourceProvider hostResources) : base (hostResources) { @@ -25,16 +28,27 @@ namespace Xamarin.PropertyEditing.Mac }; this.openCollection.Activated += (o, e) => { + var parentWindow = Window; + var w = new CollectionEditorWindow (hostResources, ViewModel) { Appearance = EffectiveAppearance }; - CocoaHelpers.RunModalForWindow (w, this.openCollection, responseHandler: result => { - if (result != NSModalResponse.OK) - ViewModel.CancelCommand.Execute (null); - else - ViewModel.CommitCommand.Execute (null); - }); + var result = (NSModalResponse)(int)NSApplication.SharedApplication.RunModalForWindow (w); + + //after run modal our FocusedWindow is null, we set the parent again + parentWindow?.MakeKeyAndOrderFront (parentWindow); + + if (result != NSModalResponse.OK) + ViewModel.CancelCommand.Execute (null); + else + ViewModel.CommitCommand.Execute (null); + + //small hack to override vs4mac default focus + System.Threading.Tasks.Task.Delay (DefaultDelayTime) + .ContinueWith (t => { + parentWindow?.MakeFirstResponder (openCollection); + }, TaskScheduler.FromCurrentSynchronizationContext ()); }; AddSubview (this.openCollection); |