From 62f657a5a2f595ea06646fe0e5df244f6b2b45d2 Mon Sep 17 00:00:00 2001 From: Waheed Ahmad Date: Mon, 24 Jun 2024 16:24:31 +0500 Subject: [PATCH] issue fixed where short keys were not working at start fixes #25 --- src/WinUI.TableView/TableView.cs | 27 +++++++++++++++++++ src/WinUI.TableView/TableViewHeaderRow.cs | 12 --------- .../Themes/TableViewHeaderRow.xaml | 9 +++---- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/WinUI.TableView/TableView.cs b/src/WinUI.TableView/TableView.cs index e9c5502..c86ac34 100644 --- a/src/WinUI.TableView/TableView.cs +++ b/src/WinUI.TableView/TableView.cs @@ -94,6 +94,12 @@ protected override void OnPreviewKeyDown(KeyRoutedEventArgs e) var ctrlKey = KeyBoardHelper.IsCtrlKeyDown(); var currentCell = CurrentCellSlot.HasValue ? GetCellFromSlot(CurrentCellSlot.Value) : default; + if (HandleShortKeys(shiftKey, ctrlKey, e.Key)) + { + e.Handled = true; + return; + } + if (e.Key is VirtualKey.F2 && currentCell is not null && !IsEditing) { currentCell.PrepareForEdit(); @@ -155,6 +161,27 @@ protected override void OnPreviewKeyDown(KeyRoutedEventArgs e) } } + private bool HandleShortKeys(bool shiftKey, bool ctrlKey, VirtualKey key) + { + if (key == VirtualKey.A && ctrlKey && !shiftKey) + { + SelectAll(); + return true; + } + else if (key == VirtualKey.A && ctrlKey && shiftKey) + { + DeselectAll(); + return true; + } + else if (key == VirtualKey.C && ctrlKey) + { + CopyToClipboardInternal(shiftKey); + return true; + } + + return false; + } + protected override void OnApplyTemplate() { base.OnApplyTemplate(); diff --git a/src/WinUI.TableView/TableViewHeaderRow.cs b/src/WinUI.TableView/TableViewHeaderRow.cs index a99302e..71c8e95 100644 --- a/src/WinUI.TableView/TableViewHeaderRow.cs +++ b/src/WinUI.TableView/TableViewHeaderRow.cs @@ -50,18 +50,6 @@ protected override void OnApplyTemplate() if (_optionsButton is not null) { _optionsButton.DataContext = new OptionsFlyoutViewModel(TableView); - - // Hack: this will allow keyboard accelerators to get work - ShowAndHidOptionsFlyout(); - async void ShowAndHidOptionsFlyout() - { - if (_optionsButton.Visibility == Visibility.Visible) - { - _optionsButton.Flyout.ShowAt(_optionsButton); - await Task.Delay(5); - _optionsButton.Flyout.Hide(); - } - } } if (GetTemplateChild("selectAllButton") is Button selectAllButton) diff --git a/src/WinUI.TableView/Themes/TableViewHeaderRow.xaml b/src/WinUI.TableView/Themes/TableViewHeaderRow.xaml index 578d1f0..f44ddd3 100644 --- a/src/WinUI.TableView/Themes/TableViewHeaderRow.xaml +++ b/src/WinUI.TableView/Themes/TableViewHeaderRow.xaml @@ -107,8 +107,7 @@ Icon="ClearSelection"> + Modifiers="Control,Shift" /> @@ -120,12 +119,10 @@ ScopeOwner="{TemplateBinding TableView}" /> - + + Modifiers="Control,Shift" />