From eaaf13bdb7aeff63b3acedb51c0cbd728080b375 Mon Sep 17 00:00:00 2001 From: Jeff Lord Date: Sat, 16 Dec 2023 10:43:38 -0500 Subject: [PATCH] UI fixed --- .../ShortcutControl.cpp | 162 +++++++++++++++--- .../ShortcutControl.h | 2 + 2 files changed, 136 insertions(+), 28 deletions(-) diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp index 6668893752f4..649007004351 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp @@ -319,33 +319,40 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector().Children().GetAt(0).as(); - auto runProgramArgsForProgramInput = targetAppTextBox.Parent().as().Children().GetAt(0).as(); - auto runProgramStartInDirInput = targetAppTextBox.Parent().as().Children().GetAt(0).as(); + //auto parent = targetAppTextBox.Parent().as(); - Shortcut tempShortcut; - tempShortcut.operationType = Shortcut::OperationType::RunProgram; - //tempShortcut.isRunProgram = true; + /*auto runProgramPathInput = ShortcutControl::FindRowChildByName(parent, L"runProgramPathInput").as(); + auto runProgramArgsForProgramInput = ShortcutControl::FindRowChildByName(parent, L"runProgramArgsForProgramInput").as(); + auto runProgramStartInDirInput = ShortcutControl::FindRowChildByName(parent, L"runProgramStartInDirInput").as();*/ - tempShortcut.runProgramFilePath = ShortcutControl::RemoveExtraQuotes(runProgramPathInput.Text().c_str()); - tempShortcut.runProgramArgs = (runProgramArgsForProgramInput.Text().c_str()); - tempShortcut.runProgramStartInDir = (runProgramStartInDirInput.Text().c_str()); + auto runProgramPathInput = row.FindName(L"runProgramPathInput_" + std::to_wstring(rowIndex)).as(); + auto runProgramArgsForProgramInput = row.FindName(L"runProgramArgsForProgramInput_" + std::to_wstring(rowIndex)).as(); + auto runProgramStartInDirInput = row.FindName(L"runProgramStartInDirInput_" + std::to_wstring(rowIndex)).as(); - // Assign instead of setting the value in the buffer since the previous value may not be a Shortcut - shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; + Shortcut tempShortcut; + tempShortcut.operationType = Shortcut::OperationType::RunProgram; + + tempShortcut.runProgramFilePath = ShortcutControl::RemoveExtraQuotes(runProgramPathInput.Text().c_str()); + tempShortcut.runProgramArgs = (runProgramArgsForProgramInput.Text().c_str()); + tempShortcut.runProgramStartInDir = (runProgramStartInDirInput.Text().c_str()); + + auto runProgramElevationTypeCombo = row.FindName(L"runProgramElevationTypeCombo_" + std::to_wstring(rowIndex)).as(); + + if (runProgramElevationTypeCombo.SelectedIndex() == 0) + { + tempShortcut.elevationLevel = Shortcut::ElevationLevel::NonElevated; + } + else if (runProgramElevationTypeCombo.SelectedIndex() == 1) + { + tempShortcut.elevationLevel = Shortcut::ElevationLevel::Elevated; } - /* - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - START HERE~! - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - */ - auto parent = targetAppTextBox.Parent().as(); - while (parent.Name() != winrt::to_hstring(L"row")) + else if (runProgramElevationTypeCombo.SelectedIndex() == 2) { - parent = parent.Parent().as(); + tempShortcut.elevationLevel = Shortcut::ElevationLevel::DifferentUser; } + + // Assign instead of setting the value in the buffer since the previous value may not be a Shortcut + shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; } else if (openUri) { @@ -483,6 +490,57 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector(&panel); +// } +// +// for (const auto& child : panel.children) +// { +// StackPanel* found = findChildByName(child, name); +// if (found != nullptr) +// { +// return found; +// } +// } +// +// return nullptr; +//} + +//winrt::Windows::Foundation::IInspectable ShortcutControl::FindRowChildByName(const StackPanel& panel, const wchar_t* nameToFind) +//{ +// StackPanel returnPanel = panel; +// +// while (returnPanel.Name() != winrt::to_hstring(L"row")) +// { +// if (returnPanel.Parent() == nullptr) +// { +// return returnPanel; +// } +// else +// { +// try +// { +// returnPanel = returnPanel.Parent().as(); +// } +// catch (...) +// { +// // parent must not be StackPanel +// return nullptr; +// } +// } +// } +// +// if (returnPanel != nullptr) +// { +// return returnPanel.FindName(nameToFind); +// } +// +// return returnPanel; +//} + StackPanel SetupOpenURIControls(StackPanel& parent, StackPanel& row, Shortcut& shortCut, winrt::Windows::UI::Xaml::Thickness& textInputMargin, ::StackPanel& _controlStackPanel) { StackPanel openUriStackPanel; @@ -526,19 +584,25 @@ StackPanel SetupOpenURIControls(StackPanel& parent, StackPanel& row, Shortcut& s StackPanel SetupRunProgramControls(StackPanel& parent, StackPanel& row, Shortcut& shortCut, winrt::Windows::UI::Xaml::Thickness& textInputMargin, ::StackPanel& _controlStackPanel) { + uint32_t rowIndex; + // Get index of delete button + UIElementCollection children = parent.Children(); + children.IndexOf(row, rowIndex); + StackPanel controlStackPanel; - controlStackPanel.Name(L"RunProgramControls"); + controlStackPanel.Name(L"RunProgramControls_" + std::to_wstring(rowIndex)); auto runProgramPathInput = TextBox(); - runProgramPathInput.Name(L"runProgramPathInput"); + runProgramPathInput.Name(L"runProgramPathInput_" + std::to_wstring(rowIndex)); auto runProgramArgsForProgramInput = TextBox(); - runProgramArgsForProgramInput.Name(L"runProgramArgsForProgramInput"); + runProgramArgsForProgramInput.Name(L"runProgramArgsForProgramInput_" + std::to_wstring(rowIndex)); auto runProgramStartInDirInput = TextBox(); - runProgramStartInDirInput.Name(L"runProgramStartInDirInput"); + runProgramStartInDirInput.Name(L"runProgramStartInDirInput_" + std::to_wstring(rowIndex)); Button pickFileBtn; Button pickPathBtn; auto runProgramElevationTypeCombo = ComboBox(); + runProgramElevationTypeCombo.Name(L"runProgramElevationTypeCombo_" + std::to_wstring(rowIndex)); _controlStackPanel.Children().Append(controlStackPanel); @@ -605,7 +669,7 @@ StackPanel SetupRunProgramControls(StackPanel& parent, StackPanel& row, Shortcut controlStackPanel.Children().Append(runProgramElevationTypeCombo); // add events to TextBoxes for runProgram fields - runProgramPathInput.TextChanged([parent, row, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput](winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::TextChangedEventArgs const& e) mutable { + runProgramPathInput.TextChanged([parent, row, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput, runProgramElevationTypeCombo](winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::TextChangedEventArgs const& e) mutable { uint32_t rowIndex = -1; if (!parent.Children().IndexOf(row, rowIndex)) { @@ -618,12 +682,26 @@ StackPanel SetupRunProgramControls(StackPanel& parent, StackPanel& row, Shortcut tempShortcut.runProgramArgs = (runProgramArgsForProgramInput.Text().c_str()); tempShortcut.runProgramStartInDir = (runProgramStartInDirInput.Text().c_str()); // Assign instead of setting the value in the buffer since the previous value may not be a Shortcut + + if (runProgramElevationTypeCombo.SelectedIndex() == 0) + { + tempShortcut.elevationLevel = Shortcut::ElevationLevel::NonElevated; + } + else if (runProgramElevationTypeCombo.SelectedIndex() == 1) + { + tempShortcut.elevationLevel = Shortcut::ElevationLevel::Elevated; + } + else if (runProgramElevationTypeCombo.SelectedIndex() == 2) + { + tempShortcut.elevationLevel = Shortcut::ElevationLevel::DifferentUser; + } + ShortcutControl::shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; //ShortcutControl::RunProgramTextOnChange(rowIndex, shortcutRemapBuffer, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput); }); - runProgramArgsForProgramInput.TextChanged([parent, row, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput](winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::TextChangedEventArgs const& e) mutable { + runProgramArgsForProgramInput.TextChanged([parent, row, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput, runProgramElevationTypeCombo](winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::TextChangedEventArgs const& e) mutable { uint32_t rowIndex = -1; if (!parent.Children().IndexOf(row, rowIndex)) { @@ -636,11 +714,25 @@ StackPanel SetupRunProgramControls(StackPanel& parent, StackPanel& row, Shortcut tempShortcut.runProgramArgs = (runProgramArgsForProgramInput.Text().c_str()); tempShortcut.runProgramStartInDir = (runProgramStartInDirInput.Text().c_str()); // Assign instead of setting the value in the buffer since the previous value may not be a Shortcut + + if (runProgramElevationTypeCombo.SelectedIndex() == 0) + { + tempShortcut.elevationLevel = Shortcut::ElevationLevel::NonElevated; + } + else if (runProgramElevationTypeCombo.SelectedIndex() == 1) + { + tempShortcut.elevationLevel = Shortcut::ElevationLevel::Elevated; + } + else if (runProgramElevationTypeCombo.SelectedIndex() == 2) + { + tempShortcut.elevationLevel = Shortcut::ElevationLevel::DifferentUser; + } + ShortcutControl::shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; //ShortcutControl::RunProgramTextOnChange(rowIndex, shortcutRemapBuffer, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput); }); - runProgramStartInDirInput.TextChanged([parent, row, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput](winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::TextChangedEventArgs const& e) mutable { + runProgramStartInDirInput.TextChanged([parent, row, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput, runProgramElevationTypeCombo](winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::TextChangedEventArgs const& e) mutable { uint32_t rowIndex = -1; if (!parent.Children().IndexOf(row, rowIndex)) { @@ -654,6 +746,20 @@ StackPanel SetupRunProgramControls(StackPanel& parent, StackPanel& row, Shortcut tempShortcut.runProgramArgs = (runProgramArgsForProgramInput.Text().c_str()); tempShortcut.runProgramStartInDir = (runProgramStartInDirInput.Text().c_str()); // Assign instead of setting the value in the buffer since the previous value may not be a Shortcut + + if (runProgramElevationTypeCombo.SelectedIndex() == 0) + { + tempShortcut.elevationLevel = Shortcut::ElevationLevel::NonElevated; + } + else if (runProgramElevationTypeCombo.SelectedIndex() == 1) + { + tempShortcut.elevationLevel = Shortcut::ElevationLevel::Elevated; + } + else if (runProgramElevationTypeCombo.SelectedIndex() == 2) + { + tempShortcut.elevationLevel = Shortcut::ElevationLevel::DifferentUser; + } + ShortcutControl::shortcutRemapBuffer[rowIndex].first[1] = tempShortcut; //ShortcutControl::RunProgramTextOnChange(rowIndex, shortcutRemapBuffer, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput); diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.h b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.h index 84b251b7f71c..b1a6438b97f3 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.h +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.h @@ -68,6 +68,8 @@ class ShortcutControl // 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, std::vector>>& keyboardRemapControlObjects, const Shortcut& originalKeys = Shortcut(), const KeyShortcutTextUnion& newKeys = Shortcut(), const std::wstring& targetAppName = L""); + //static winrt::Windows::Foundation::IInspectable ShortcutControl::FindRowChildByName(const winrt::Windows::UI::Xaml::Controls::StackPanel& parent, const wchar_t* nameToFind); + // Function to get the shortcut type static ShortcutType GetShortcutType(const Controls::ComboBox& typeCombo);