Skip to content

Commit

Permalink
Some clean up, working with config file monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflord committed Dec 3, 2023
1 parent 0fe0807 commit 7df4385
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@
<data name="EditShortcuts_AllApps" xml:space="preserve">
<value>All apps</value>
</data>
<data name="EditShortcuts_PathToProgram" xml:space="preserve">
<value>Path to program</value>
</data>
<data name="EditShortcuts_ArgsForProgram" xml:space="preserve">
<value>Arguments for program</value>
</data>
<data name="EditShortcuts_StartInDirForProgram" xml:space="preserve">
<value>Start in direcotry</value>
</data>
<data name="ErrorMessage_RemapSuccessful" xml:space="preserve">
<value>Remapping successful</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ namespace KeyboardManagerEditorStrings
return GET_RESOURCE_STRING(IDS_MAPPING_TYPE_DROPDOWN_RUN_PROGRAM);
}

inline std::wstring EditShortcutsPathToProgram()
{
return GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_PATHTOPROGRAM);
}

inline std::wstring EditShortcutsArgsForProgram()
{
return GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_ARGSFORPROGRAM);
}

inline std::wstring EditShortcutsStartInDirForProgram()
{
return GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_STARTINDIRFORPROGRAM);
}

// Function to return the error message
winrt::hstring GetErrorMessage(ShortcutErrorType errorType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,14 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector<s
shortcutRemapBuffer[rowIndex].first[1] = text.c_str();
});

// add textbox for when it's a runProgram
auto runProgramPathInput = TextBox();
// add textbox for when it's a runProgramPath

auto runProgramPathInputMargin = Windows::UI::Xaml::Thickness();
runProgramPathInputMargin.Top = -EditorConstants::ShortcutTableDropDownSpacing;
runProgramPathInputMargin.Bottom = EditorConstants::ShortcutTableDropDownSpacing; // compensate for a collapsed UIElement

auto runProgramPathInput = TextBox();
runProgramPathInput.PlaceholderText(KeyboardManagerEditorStrings::EditShortcutsPathToProgram());
runProgramPathInput.Margin(runProgramPathInputMargin);

runProgramPathInput.AcceptsReturn(false);
Expand All @@ -171,23 +174,80 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector<s
controlStackPanel.Children().Append(runProgramPathInput);
runProgramPathInput.HorizontalAlignment(HorizontalAlignment::Left);

runProgramPathInput.TextChanged([parent, row](winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Controls::TextChangedEventArgs const& e) mutable {
auto textbox = sender.as<TextBox>();
auto text = textbox.Text();
uint32_t rowIndex = -1;
auto runProgramArgsForProgramInput = TextBox();
//runProgramArgsForProgramInput.PlaceholderText(KeyboardManagerEditorStrings::EditShortcutsArgsForProgram());
//runProgramArgsForProgramInput.Margin(runProgramPathInputMargin);

//runProgramArgsForProgramInput.AcceptsReturn(false);
//runProgramArgsForProgramInput.Visibility(Visibility::Collapsed);
//runProgramArgsForProgramInput.Width(EditorConstants::TableDropDownHeight);
//controlStackPanel.Children().Append(runProgramArgsForProgramInput);
//runProgramArgsForProgramInput.HorizontalAlignment(HorizontalAlignment::Left);

//auto runProgramStartInDirInput = TextBox();
//runProgramPathInput.PlaceholderText(KeyboardManagerEditorStrings::EditShortcutsStartInDirForProgram());
//runProgramStartInDirInput.Margin(runProgramPathInputMargin);

//runProgramStartInDirInput.AcceptsReturn(false);
//runProgramStartInDirInput.Visibility(Visibility::Collapsed);
//runProgramStartInDirInput.Width(EditorConstants::TableDropDownHeight);
//controlStackPanel.Children().Append(runProgramStartInDirInput);
//runProgramStartInDirInput.HorizontalAlignment(HorizontalAlignment::Left);

runProgramPathInput.TextChanged([parent, row, runProgramPathInput, runProgramArgsForProgramInput](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))
{
return;
}

Shortcut tempShortcut;
tempShortcut.isRunProgram = true;
tempShortcut.runProgramPath = text.c_str();
tempShortcut.runProgramFilePath = runProgramPathInput.Text().c_str();
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
shortcutRemapBuffer[rowIndex].first[1] = tempShortcut;

//ShortcutControl::RunProgramTextOnChange(parent, row, shortcutRemapBuffer, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput);
});

//runProgramArgsForProgramInput.TextChanged([parent, row, runProgramPathInput, runProgramArgsForProgramInput](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))
// {
// return;
// }

// Shortcut tempShortcut;
// tempShortcut.isRunProgram = true;
// tempShortcut.runProgramFilePath = runProgramPathInput.Text().c_str();
// 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
// shortcutRemapBuffer[rowIndex].first[1] = tempShortcut;

// //ShortcutControl::RunProgramTextOnChange(parent, row, 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 {
// uint32_t rowIndex = -1;
// if (!parent.Children().IndexOf(row, rowIndex))
// {
// return;
// }

// Shortcut tempShortcut;
// tempShortcut.isRunProgram = true;
// tempShortcut.runProgramFilePath = runProgramPathInput.Text().c_str();
// 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
// shortcutRemapBuffer[rowIndex].first[1] = tempShortcut;

// //ShortcutControl::RunProgramTextOnChange(parent, row, shortcutRemapBuffer, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput);
//});

// add grid for when it's a key/shortcut
auto shortcutGrid = keyboardRemapControlObjects.back()[1]->shortcutDropDownVariableSizedWrapGrid.as<VariableSizedWrapGrid>();
auto gridMargin = Windows::UI::Xaml::Thickness();
Expand Down Expand Up @@ -245,13 +305,9 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector<s
auto shortCut = std::get<Shortcut>(newKeys);
if (shortCut.isRunProgram)
{
Shortcut tempShortcut;
isRunProgram = true;
tempShortcut.isRunProgram = true;
tempShortcut.runProgramPath = runProgramPathInput.Text().c_str();
// Assign instead of setting the value in the buffer since the previous value may not be a Shortcut
//shortcutRemapBuffer[index].first[1] = tempShortcut;
runProgramPathInput.Text(shortCut.runProgramPath);
runProgramPathInput.Text(shortCut.runProgramFilePath);
runProgramArgsForProgramInput.Text(shortCut.runProgramArgs);
typeCombo.SelectedIndex(2);
}
else
Expand Down Expand Up @@ -469,6 +525,29 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector<s
}
}

void ShortcutControl::RunProgramTextOnChange(
StackPanel& parent,
const winrt::Windows::UI::Xaml::Controls::StackPanel& row,
RemapBuffer shortcutRemapBuffer,
const winrt::Windows::UI::Xaml::Controls::TextBox& runProgramPathInput,
const winrt::Windows::UI::Xaml::Controls::TextBox& runProgramArgsForProgramInput,
const winrt::Windows::UI::Xaml::Controls::TextBox& runProgramStartInDirInput)
{
uint32_t rowIndex = -1;
if (!parent.Children().IndexOf(row, rowIndex))
{
return;
}

Shortcut tempShortcut;
tempShortcut.isRunProgram = true;
tempShortcut.runProgramFilePath = runProgramPathInput.Text().c_str();
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
shortcutRemapBuffer[rowIndex].first[1] = tempShortcut;
}

ShortcutControl::ShortcutType ShortcutControl::GetShortcutType(const winrt::Windows::UI::Xaml::Controls::ComboBox& typeCombo)
{
if (typeCombo.SelectedIndex() == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ class ShortcutControl

static ShortcutType GetShortcutType(const winrt::Windows::UI::Xaml::Controls::ComboBox& typeCombo);

void ShortcutControl::RunProgramTextOnChange(
StackPanel& parent,
const winrt::Windows::UI::Xaml::Controls::StackPanel& row,
RemapBuffer shortcutRemapBuffer,
const winrt::Windows::UI::Xaml::Controls::TextBox& runProgramPathInput,
const winrt::Windows::UI::Xaml::Controls::TextBox& runProgramArgsForProgramInput,
const winrt::Windows::UI::Xaml::Controls::TextBox& runProgramStartInDirInput);

// 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ namespace KeyboardManagerConstants
// Name of the property use to store new remapped string.
inline const std::wstring NewTextSettingName = L"unicodeText";

// Name of the property use to store runProgramStartInDir.
inline const std::wstring RunProgramStartInDirSettingName = L"runProgramStartInDir";

// Name of the property use to store runProgramArgs.
inline const std::wstring RunProgramArgsSettingName = L"runProgramArgs";

// Name of the property use to store runProgramFilePath.
inline const std::wstring RunProgramSettingName = L"runProgram";
inline const std::wstring RunProgramFilePathSettingName = L"runProgramFilePath";

// Name of the property use to store runProgramFilePath.
inline const std::wstring IsRunProgramSettingName = L"isRunProgram";
Expand Down
10 changes: 7 additions & 3 deletions src/modules/keyboardmanager/common/MappingConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ bool MappingConfiguration::LoadShortcutRemaps(const json::JsonObject& jsonData,
// debugger wait
Sleep(1000);
}
auto runProgram = it.GetObjectW().GetNamedString(KeyboardManagerConstants::RunProgramSettingName, L"");
AddOSLevelShortcut(Shortcut(originalKeys.c_str()), Shortcut(newRemapKeys.c_str(), isRunProgram, runProgram.c_str()));
auto runProgramFilePath = it.GetObjectW().GetNamedString(KeyboardManagerConstants::RunProgramFilePathSettingName, L"");
auto runProgramArgs = it.GetObjectW().GetNamedString(KeyboardManagerConstants::RunProgramArgsSettingName, L"");
auto runProgramStartInDir = it.GetObjectW().GetNamedString(KeyboardManagerConstants::RunProgramStartInDirSettingName, L"");
AddOSLevelShortcut(Shortcut(originalKeys.c_str()), Shortcut(newRemapKeys.c_str(), isRunProgram, runProgramFilePath.c_str(), runProgramArgs.c_str(), runProgramStartInDir.c_str()));
}
else if (!newRemapKeys.empty())
{
Expand Down Expand Up @@ -443,7 +445,9 @@ bool MappingConfiguration::SaveSettingsToFile()

if (targetShortcut.isRunProgram)
{
keys.SetNamedValue(KeyboardManagerConstants::RunProgramSettingName, json::value(targetShortcut.ToHstring___()));
keys.SetNamedValue(KeyboardManagerConstants::RunProgramFilePathSettingName, json::value(targetShortcut.runProgramFilePath));
keys.SetNamedValue(KeyboardManagerConstants::RunProgramArgsSettingName, json::value(targetShortcut.runProgramArgs));
keys.SetNamedValue(KeyboardManagerConstants::RunProgramStartInDirSettingName, json::value(targetShortcut.runProgramStartInDir));
}
else
{
Expand Down
8 changes: 5 additions & 3 deletions src/modules/keyboardmanager/common/Shortcut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ Shortcut::Shortcut(const std::wstring& shortcutVK) :
}
}

Shortcut::Shortcut(const std::wstring& shortcutVK, const bool isRunProgram, const std::wstring& runProgram) :
Shortcut::Shortcut(const std::wstring& shortcutVK, const bool isRunProgram, const std::wstring& _runProgramFilePath, const std::wstring& _runProgramArgs, const std::wstring& _runProgramStartInDir) :
winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL)
{
Shortcut::isRunProgram = isRunProgram;
if (Shortcut::isRunProgram)
{
runProgramPath = runProgram;
runProgramFilePath = _runProgramFilePath;
runProgramArgs = _runProgramArgs;
runProgramStartInDir = _runProgramStartInDir;
}

auto keys = splitwstring(shortcutVK, ';');
Expand Down Expand Up @@ -438,7 +440,7 @@ void Shortcut::ResetKey(const DWORD input)

winrt::hstring Shortcut::ToHstring___() const
{
return runProgramPath.c_str();
return runProgramFilePath.c_str();
}

// Function to return the string representation of the shortcut in virtual key codes appended in a string by ";" separator.
Expand Down
8 changes: 5 additions & 3 deletions src/modules/keyboardmanager/common/Shortcut.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class Shortcut
ModifierKey shiftKey = ModifierKey::Disabled;

bool isRunProgram = false;
std::wstring runProgramPath;
std::wstring runProgramFilePath;
std::wstring runProgramArgs;
std::wstring runProgramStartInDir;

DWORD actionKey = {};

Expand All @@ -38,8 +40,8 @@ class Shortcut
// Constructor to initialize Shortcut from it's virtual key code string representation.
Shortcut(const std::wstring& shortcutVK);

Shortcut(const std::wstring& shortcutVK, const bool isRunProgram, const std::wstring& runProgram);

Shortcut(const std::wstring& shortcutVK, const bool isRunProgram, const std::wstring& runProgramFilePath, const std::wstring& runProgramArgs, const std::wstring& runProgramStartInDir);
// Constructor to initialize shortcut from a list of keys
Shortcut(const std::vector<int32_t>& keys);

Expand Down
Loading

1 comment on commit 7df4385

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (12)
ARGSFORPROGRAM
cmdow
direcotry
PATHTOPROGRAM
PROCESSENTRY
ritchielawrence
SNAPPROCESS
splitw
STARTINDIRFORPROGRAM
tlhelp
Toolhelp
wcsicmp
Previously acknowledged words that are now absent CHT constexpr DEU hashcode HEB JPN nodiscard pcs qps roundf RUS RValue SVE wifi 🫥
To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the git@github.com:jefflord/PowerToys.git repository
on the launch-apps-3350 branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' |
perl - 'https://github.com/jefflord/PowerToys/actions/runs/7074277468/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (1848) from .github/actions/spell-check/expect.txt and unrecognized words (12)

Dictionary Entries Covers Uniquely
cspell:r/src/r.txt 543 1 1
cspell:cpp/src/people.txt 23 1
cspell:cpp/src/ecosystem.txt 51 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/check-spelling@v0.0.22 in its with:

      with:
        extra_dictionaries:
          cspell:r/src/r.txt
          cspell:cpp/src/people.txt
          cspell:cpp/src/ecosystem.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/check-spelling@v0.0.22 in its with:

check_extra_dictionaries: ''
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.