mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02: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
|
// Whenever a remap is added move to the bottom of the screen
|
||||||
scrollViewer.ChangeView(nullptr, scrollViewer.ScrollableHeight(), nullptr);
|
scrollViewer.ChangeView(nullptr, scrollViewer.ScrollableHeight(), nullptr);
|
||||||
|
|
||||||
// Set focus to the first Type Button in the newly added row
|
// Set focus to the first "Select" Button in the newly added row
|
||||||
UIHelpers::SetFocusOnTypeButtonInLastRow(keyRemapTable, EditorConstants::RemapTableColCount);
|
UIHelpers::SetFocusOnFirstSelectButtonInLastRowOfEditKeyboardWindow(keyRemapTable, EditorConstants::RemapTableColCount);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remap key button content
|
// 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
|
// Whenever a remap is added move to the bottom of the screen
|
||||||
scrollViewer.ChangeView(nullptr, scrollViewer.ScrollableHeight(), nullptr);
|
scrollViewer.ChangeView(nullptr, scrollViewer.ScrollableHeight(), nullptr);
|
||||||
|
|
||||||
// Set focus to the first Type Button in the newly added row
|
// Set focus to the first "Select" Button in the newly added row
|
||||||
UIHelpers::SetFocusOnTypeButtonInLastRow(shortcutTable, EditorConstants::ShortcutTableColCount);
|
UIHelpers::SetFocusOnFirstSelectButtonInLastRowOfEditShortcutsWindow(shortcutTable, EditorConstants::ShortcutTableColCount);
|
||||||
|
|
||||||
//newShortcut.OpenNewShortcutControlRow(shortcutTable, shortcutTable.Children().GetAt(shortcutTable.Children().Size() - 1).as<StackPanel>());
|
//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
|
namespace UIHelpers
|
||||||
{
|
{
|
||||||
// This method sets focus to the first Type button on the last row of the Grid
|
// This method sets focus to the first "Select" button on the last row of the Grid of EditKeyboardWindow
|
||||||
void SetFocusOnTypeButtonInLastRow(StackPanel& parent, long colCount)
|
void SetFocusOnFirstSelectButtonInLastRowOfEditKeyboardWindow(StackPanel& parent, long colCount)
|
||||||
{
|
{
|
||||||
// First element in the last row (StackPanel)
|
// First element in the last row (StackPanel)
|
||||||
auto lastHotKeyLine = parent.Children().GetAt(parent.Children().Size() - 1).as<StackPanel>();
|
auto lastHotKeyLine = parent.Children().GetAt(parent.Children().Size() - 1).as<StackPanel>();
|
||||||
|
|
||||||
// Get "To" Column
|
// Get "From" Column
|
||||||
auto toColumn = lastHotKeyLine.Children().GetAt(2).as<StackPanel>();
|
auto fromColumn = lastHotKeyLine.Children().GetAt(0).as<StackPanel>();
|
||||||
|
|
||||||
// Get first line in "To" Column
|
// Get "Select" Button from the "From" Column
|
||||||
auto firstLineIntoColumn = toColumn.Children().GetAt(0).as<StackPanel>();
|
Button selectButton = fromColumn.Children().GetAt(0).as<Button>();
|
||||||
|
if (selectButton != nullptr)
|
||||||
// Get Type Button from the first line
|
|
||||||
Button typeButton = firstLineIntoColumn.Children().GetAt(1).as<Button>();
|
|
||||||
if (typeButton != nullptr)
|
|
||||||
{
|
{
|
||||||
// Set programmatic focus on the button
|
// 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
|
// This namespace contains UI methods that are to be used for both KBM windows
|
||||||
namespace UIHelpers
|
namespace UIHelpers
|
||||||
{
|
{
|
||||||
// This method sets focus to the first Type button on the last row of the Grid
|
// This method sets focus to the first "Select" button on the last row of the Grid of EditKeyboardWindow
|
||||||
void SetFocusOnTypeButtonInLastRow(StackPanel& parent, long colCount);
|
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();
|
RECT GetForegroundWindowDesktopRect();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user