From 38841e24c3246100c2bafaec982c7dd11c95d33c Mon Sep 17 00:00:00 2001 From: Jeff Lord Date: Sat, 2 Dec 2023 14:26:45 -0500 Subject: [PATCH] Working UI update with just runProgram Path and isRunProgram --- .../KeyboardManagerEditor.vcxproj | 4 +- .../KeyboardManagerEditor/Resources.resx | 4 + .../EditShortcutsWindow.cpp | 6 + .../EditorHelpers.cpp | 5 + .../KeyDropDownControl.cpp | 6 +- .../KeyboardManagerEditorStrings.h | 5 + .../ShortcutControl.cpp | 150 ++++++++++++++++-- .../ShortcutControl.h | 12 ++ .../common/KeyboardManagerConstants.h | 9 ++ .../common/MappingConfiguration.cpp | 26 ++- .../keyboardmanager/common/Shortcut.cpp | 22 +++ src/modules/keyboardmanager/common/Shortcut.h | 8 + .../Settings.UI.Library/KeysDataModel.cs | 3 + 13 files changed, 237 insertions(+), 23 deletions(-) diff --git a/src/modules/keyboardmanager/KeyboardManagerEditor/KeyboardManagerEditor.vcxproj b/src/modules/keyboardmanager/KeyboardManagerEditor/KeyboardManagerEditor.vcxproj index 5f513f8831c7..802b186f73a9 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditor/KeyboardManagerEditor.vcxproj +++ b/src/modules/keyboardmanager/KeyboardManagerEditor/KeyboardManagerEditor.vcxproj @@ -154,7 +154,9 @@ - + + Designer + diff --git a/src/modules/keyboardmanager/KeyboardManagerEditor/Resources.resx b/src/modules/keyboardmanager/KeyboardManagerEditor/Resources.resx index 1e342b4414f4..84fdcfa84f3f 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditor/Resources.resx +++ b/src/modules/keyboardmanager/KeyboardManagerEditor/Resources.resx @@ -294,6 +294,10 @@ Key/Shortcut Key on a keyboard + + Run Program + Run Program + Add key remapping Key on a keyboard diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditShortcutsWindow.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditShortcutsWindow.cpp index e5a80db5a7a4..37d18837065c 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditShortcutsWindow.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditShortcutsWindow.cpp @@ -246,6 +246,12 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMa // Create copy of the remaps to avoid concurrent access ShortcutRemapTable osLevelShortcutReMapCopy = mappingConfiguration.osLevelShortcutReMap; + while (!true) + { + // debugger wait + Sleep(1000); + } + for (const auto& it : osLevelShortcutReMapCopy) { ShortcutControl::AddNewShortcutControlRow(shortcutTable, keyboardRemapControlObjects, it.first, it.second.targetShortcut); diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditorHelpers.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditorHelpers.cpp index e21f0c9aa914..d2c8df204a41 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditorHelpers.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditorHelpers.cpp @@ -52,6 +52,11 @@ namespace EditorHelpers // Function to return true if the shortcut is valid. A valid shortcut has atleast one modifier, as well as an action key bool IsValidShortcut(Shortcut shortcut) { + if (shortcut.isRunProgram) + { + return true; + } + if (shortcut.actionKey != NULL) { if (shortcut.winKey != ModifierKey::Disabled || shortcut.ctrlKey != ModifierKey::Disabled || shortcut.altKey != ModifierKey::Disabled || shortcut.shiftKey != ModifierKey::Disabled) diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyDropDownControl.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyDropDownControl.cpp index 39a7bb2aa321..8f029af53b11 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyDropDownControl.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyDropDownControl.cpp @@ -87,7 +87,7 @@ void KeyDropDownControl::SetDefaultProperties(bool isShortcut, bool renderDisabl auto child0 = Media::VisualTreeHelper::GetChild(combo, 0); if (!child0) return; - + auto grid = child0.as(); if (!grid) return; @@ -95,7 +95,7 @@ void KeyDropDownControl::SetDefaultProperties(bool isShortcut, bool renderDisabl auto& gridChildren = grid.Children(); if (!gridChildren) return; - + gridChildren.Append(warningTip); }); @@ -432,7 +432,7 @@ void KeyDropDownControl::AddShortcutToControl(Shortcut shortcut, StackPanel tabl // Remove references to the old drop down objects to destroy them keyDropDownControlObjects.clear(); std::vector shortcutKeyCodes = shortcut.GetKeyCodes(); - if (shortcutKeyCodes.size() != 0) + if (shortcutKeyCodes.size() != 0 || shortcut.isRunProgram) { bool ignoreWarning = false; diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyboardManagerEditorStrings.h b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyboardManagerEditorStrings.h index 360e9fe0bc1e..d64207540256 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyboardManagerEditorStrings.h +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyboardManagerEditorStrings.h @@ -22,6 +22,11 @@ namespace KeyboardManagerEditorStrings return GET_RESOURCE_STRING(IDS_MAPPING_TYPE_DROPDOWN_KEY_SHORTCUT); } + inline std::wstring MappingTypeRunProgram() + { + return GET_RESOURCE_STRING(IDS_MAPPING_TYPE_DROPDOWN_RUN_PROGRAM); + } + // Function to return the error message winrt::hstring GetErrorMessage(ShortcutErrorType errorType); } diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp index 4091c4e4d2d4..19a06c8cc276 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp @@ -122,14 +122,17 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vectorGetShortcutControl(); target.Width(EditorConstants::ShortcutTargetColumnWidth); + // add shortcut type choice auto typeCombo = ComboBox(); typeCombo.Width(EditorConstants::RemapTableDropDownWidth); typeCombo.Items().Append(winrt::box_value(KeyboardManagerEditorStrings::MappingTypeKeyShortcut())); typeCombo.Items().Append(winrt::box_value(KeyboardManagerEditorStrings::MappingTypeText())); + typeCombo.Items().Append(winrt::box_value(KeyboardManagerEditorStrings::MappingTypeRunProgram())); auto controlStackPanel = keyboardRemapControlObjects.back()[1]->shortcutControlLayout.as(); auto firstLineStackPanel = keyboardRemapControlObjects.back()[1]->keyComboAndSelectStackPanel.as(); firstLineStackPanel.Children().InsertAt(0, typeCombo); + // add textbox for when it's a text input auto textInput = TextBox(); auto textInputMargin = Windows::UI::Xaml::Thickness(); textInputMargin.Top = -EditorConstants::ShortcutTableDropDownSpacing; @@ -141,6 +144,7 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector(); auto text = textbox.Text(); @@ -154,26 +158,100 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vectorshortcutDropDownVariableSizedWrapGrid.as(); - auto gridMargin = Windows::UI::Xaml::Thickness(); - gridMargin.Bottom = -EditorConstants::ShortcutTableDropDownSpacing; // compensate for a collapsed textInput - grid.Margin(gridMargin); - auto button = keyboardRemapControlObjects.back()[1]->typeShortcut.as