mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 03:07:56 +01:00
[KBMEditor]Focus first button after adding a new key/shortcut row in the editor (#32487)
This commit is contained in:
@@ -339,8 +339,8 @@ inline void CreateEditKeyboardWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMan
|
||||
// Whenever a remap is added move to the bottom of the screen
|
||||
scrollViewer.ChangeView(nullptr, scrollViewer.ScrollableHeight(), nullptr);
|
||||
|
||||
// Set focus to the first Type Button in the newly added row
|
||||
UIHelpers::SetFocusOnTypeButtonInLastRow(keyRemapTable, EditorConstants::RemapTableColCount);
|
||||
// Set focus to the first "Select" Button in the newly added row
|
||||
UIHelpers::SetFocusOnFirstSelectButtonInLastRowOfEditKeyboardWindow(keyRemapTable, EditorConstants::RemapTableColCount);
|
||||
});
|
||||
|
||||
// Remap key button content
|
||||
|
||||
@@ -335,8 +335,8 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMa
|
||||
// Whenever a remap is added move to the bottom of the screen
|
||||
scrollViewer.ChangeView(nullptr, scrollViewer.ScrollableHeight(), nullptr);
|
||||
|
||||
// Set focus to the first Type Button in the newly added row
|
||||
UIHelpers::SetFocusOnTypeButtonInLastRow(shortcutTable, EditorConstants::ShortcutTableColCount);
|
||||
// Set focus to the first "Select" Button in the newly added row
|
||||
UIHelpers::SetFocusOnFirstSelectButtonInLastRowOfEditShortcutsWindow(shortcutTable, EditorConstants::ShortcutTableColCount);
|
||||
|
||||
//newShortcut.OpenNewShortcutControlRow(shortcutTable, shortcutTable.Children().GetAt(shortcutTable.Children().Size() - 1).as<StackPanel>());
|
||||
});
|
||||
|
||||
@@ -8,24 +8,39 @@ using namespace Windows::UI::Xaml::Automation::Peers;
|
||||
|
||||
namespace UIHelpers
|
||||
{
|
||||
// This method sets focus to the first Type button on the last row of the Grid
|
||||
void SetFocusOnTypeButtonInLastRow(StackPanel& parent, long colCount)
|
||||
// This method sets focus to the first "Select" button on the last row of the Grid of EditKeyboardWindow
|
||||
void SetFocusOnFirstSelectButtonInLastRowOfEditKeyboardWindow(StackPanel& parent, long colCount)
|
||||
{
|
||||
// First element in the last row (StackPanel)
|
||||
auto lastHotKeyLine = parent.Children().GetAt(parent.Children().Size() - 1).as<StackPanel>();
|
||||
|
||||
// Get "To" Column
|
||||
auto toColumn = lastHotKeyLine.Children().GetAt(2).as<StackPanel>();
|
||||
// Get "From" Column
|
||||
auto fromColumn = lastHotKeyLine.Children().GetAt(0).as<StackPanel>();
|
||||
|
||||
// Get first line in "To" Column
|
||||
auto firstLineIntoColumn = toColumn.Children().GetAt(0).as<StackPanel>();
|
||||
|
||||
// Get Type Button from the first line
|
||||
Button typeButton = firstLineIntoColumn.Children().GetAt(1).as<Button>();
|
||||
if (typeButton != nullptr)
|
||||
// Get "Select" Button from the "From" Column
|
||||
Button selectButton = fromColumn.Children().GetAt(0).as<Button>();
|
||||
if (selectButton != nullptr)
|
||||
{
|
||||
// Set programmatic focus on the button
|
||||
typeButton.Focus(FocusState::Programmatic);
|
||||
selectButton.Focus(FocusState::Programmatic);
|
||||
}
|
||||
}
|
||||
|
||||
// This method sets focus to the first "Select" button on the last row of the Grid of EditShortcutsWindow
|
||||
void SetFocusOnFirstSelectButtonInLastRowOfEditShortcutsWindow(StackPanel& parent, long colCount)
|
||||
{
|
||||
// First element in the last row (StackPanel)
|
||||
auto lastHotKeyLine = parent.Children().GetAt(parent.Children().Size() - 1).as<StackPanel>();
|
||||
|
||||
// Get "From" Column
|
||||
auto fromColumn = lastHotKeyLine.Children().GetAt(0).as<StackPanel>();
|
||||
|
||||
StackPanel selectButtonTry = fromColumn.Children().GetAt(1).as<StackPanel>();
|
||||
Button selectButtonTry2 = selectButtonTry.Children().GetAt(1).as<Button>();
|
||||
if (selectButtonTry2 != nullptr)
|
||||
{
|
||||
// Set programmatic focus on the button
|
||||
selectButtonTry2.Focus(FocusState::Programmatic);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,11 @@ namespace winrt
|
||||
// This namespace contains UI methods that are to be used for both KBM windows
|
||||
namespace UIHelpers
|
||||
{
|
||||
// This method sets focus to the first Type button on the last row of the Grid
|
||||
void SetFocusOnTypeButtonInLastRow(StackPanel& parent, long colCount);
|
||||
// This method sets focus to the first "Select" button on the last row of the Grid of EditKeyboardWindow
|
||||
void SetFocusOnFirstSelectButtonInLastRowOfEditKeyboardWindow(StackPanel& parent, long colCount);
|
||||
|
||||
// This method sets focus to the first "Select" button on the last row of the Grid of EditShortcutsWindow
|
||||
void SetFocusOnFirstSelectButtonInLastRowOfEditShortcutsWindow(StackPanel& parent, long colCount);
|
||||
|
||||
RECT GetForegroundWindowDesktopRect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user