mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
Edit Shortcuts UI (dev/keyboardManager) (#1647)
* Added EditShortcuts Window and added Detecting shortcuts functionality * Fixed build error * Changed detection to take place only when window is in focus * Added solution folder * Added a common project and refactored shared variables to an object with wrapper functions * Added dynamic addition of shortcuts * Moved all shared variables in detection to state variable with wrapper functions * Added code to re-load saved shortcuts in the UI * Added comments * Fixed argument modifiers in Helpers * Updated arg modifiers in all functions * Removed unused headers and added precompiled headers
This commit is contained in:
committed by
Udit Singh
parent
fc7e7074ce
commit
b713083574
48
src/modules/keyboardmanager/ui/ShortcutControl.h
Normal file
48
src/modules/keyboardmanager/ui/ShortcutControl.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
#include <keyboardManager/common/Helpers.h>
|
||||
|
||||
class ShortcutControl
|
||||
{
|
||||
private:
|
||||
// Textblock to display the selected shortcut
|
||||
TextBlock shortcutText;
|
||||
|
||||
// Button to type the shortcut
|
||||
Button typeShortcut;
|
||||
|
||||
// StackPanel to parent the above controls
|
||||
StackPanel shortcutControlLayout;
|
||||
|
||||
public:
|
||||
// Handle to the current Edit Shortcuts Window
|
||||
static HWND EditShortcutsWindowHandle;
|
||||
// Pointer to the keyboard manager state
|
||||
static KeyboardManagerState* keyboardManagerState;
|
||||
|
||||
ShortcutControl()
|
||||
{
|
||||
typeShortcut.Content(winrt::box_value(winrt::to_hstring("Type Shortcut")));
|
||||
typeShortcut.Click([&](IInspectable const& sender, RoutedEventArgs const&) {
|
||||
keyboardManagerState->SetUIState(KeyboardManagerUIState::DetectShortcutWindowActivated, EditShortcutsWindowHandle);
|
||||
// Using the XamlRoot of the typeShortcut to get the root of the XAML host
|
||||
createDetectShortcutWindow(sender, sender.as<Button>().XamlRoot(), *keyboardManagerState);
|
||||
});
|
||||
|
||||
shortcutControlLayout.Background(Windows::UI::Xaml::Media::SolidColorBrush{ Windows::UI::Colors::LightGray() });
|
||||
shortcutControlLayout.Margin({ 0, 0, 0, 10 });
|
||||
shortcutControlLayout.Spacing(10);
|
||||
|
||||
shortcutControlLayout.Children().Append(typeShortcut);
|
||||
shortcutControlLayout.Children().Append(shortcutText);
|
||||
}
|
||||
|
||||
// Function to add a new row to the shortcut table. If the originalKeys and newKeys args are provided, then the displayed shortcuts are set to those values.
|
||||
static void AddNewShortcutControlRow(StackPanel& parent, const std::vector<DWORD>& originalKeys = std::vector<DWORD>(), const std::vector<WORD>& newKeys = std::vector<WORD>());
|
||||
|
||||
// Function to return the stack panel element of the ShortcutControl. This is the externally visible UI element which can be used to add it to other layouts
|
||||
StackPanel getShortcutControl();
|
||||
|
||||
// Function to create the detect shortcut UI window
|
||||
void createDetectShortcutWindow(IInspectable const& sender, XamlRoot xamlRoot, KeyboardManagerState& keyboardManagerState);
|
||||
};
|
||||
Reference in New Issue
Block a user