Skip to content

Commit

Permalink
Working, needs lots of cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflord committed Oct 20, 2023
1 parent b28f87b commit 356cb78
Show file tree
Hide file tree
Showing 13 changed files with 695 additions and 180 deletions.
10 changes: 8 additions & 2 deletions src/modules/keyboardmanager/KeyboardManagerEditor/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@
</data>
<data name="EditRunPrograms_WindowName" xml:space="preserve">
<value>Run program shortcuts</value>
</data>
<data name="Ok_Button" xml:space="preserve">
</data>
<data name="EditRunPrograms_ProgramName" xml:space="preserve">
<value>Program name</value>
</data>
<data name="Ok_Button" xml:space="preserve">
<value>OK</value>
</data>
<data name="Cancel_Button" xml:space="preserve">
Expand All @@ -169,6 +172,9 @@
<data name="EditShortcuts_TargetAppHeader" xml:space="preserve">
<value>Target app:</value>
</data>
<data name="EditShortcuts_RunProgramAppHeader" xml:space="preserve">
<value>Program:</value>
</data>
<data name="EditKeyboard_OrphanedDialogTitle" xml:space="preserve">
<value>Warning: The following keys do not have assignments:</value>
<comment>Key on a keyboard</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ RunProgramControl::RunProgramControl(StackPanel table, StackPanel row, const int
void RunProgramControl::SetAccessibleNameForTextBox(TextBox targetAppTextBox, int rowIndex)
{
// To set the accessible name of the target App text box by adding the string `All Apps` if the text box is empty, if not the application name is read by narrator.
std::wstring targetAppTextBoxAccessibleName = GET_RESOURCE_STRING(IDS_AUTOMATIONPROPERTIES_ROW) + std::to_wstring(rowIndex) + L", " + GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_TARGETAPPHEADER);
std::wstring targetAppTextBoxAccessibleName = GET_RESOURCE_STRING(IDS_AUTOMATIONPROPERTIES_ROW) + std::to_wstring(rowIndex) + L", " + GET_RESOURCE_STRING(IDS_EDITRUNPROGRAMS_PROGRAMNAME);

Check failure on line 63 in src/modules/keyboardmanager/KeyboardManagerEditorLibrary/RunProgramControl.cpp

View workflow job for this annotation

GitHub Actions / Spell checking

`PROGRAMNAME` is not a recognized word. (unrecognized-spelling)

Check failure on line 63 in src/modules/keyboardmanager/KeyboardManagerEditorLibrary/RunProgramControl.cpp

View workflow job for this annotation

GitHub Actions / Spell checking

`EDITRUNPROGRAMS` is not a recognized word. (unrecognized-spelling)
if (targetAppTextBox.Text() == L"")
{
targetAppTextBoxAccessibleName += GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_ALLAPPS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(CIBuild)'!='true'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="RunProgramSpec2.cpp" />
<ClCompile Include="Shortcut.cpp" />
</ItemGroup>
<ItemGroup>
Expand All @@ -56,6 +57,8 @@
<ClInclude Include="KeyboardManagerConstants.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="RemapShortcut.h" />
<ClInclude Include="RunProgramSpec.h" />
<ClInclude Include="RunProgramSpec2.h" />
<ClInclude Include="Shortcut.h" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<ClCompile Include="MappingConfiguration.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RunProgramSpec2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Helpers.h">
Expand Down Expand Up @@ -65,6 +68,12 @@
<ClInclude Include="MappingConfiguration.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RunProgramSpec.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RunProgramSpec2.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
165 changes: 165 additions & 0 deletions src/modules/keyboardmanager/common/RUNPROGRAMSPEC.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#pragma once

Check failure on line 1 in src/modules/keyboardmanager/common/RUNPROGRAMSPEC.H

View workflow job for this annotation

GitHub Actions / Spell checking

`RUNPROGRAMSPEC` is not a recognized word. (check-file-path)
#include "ModifierKey.h"

#include <compare>
#include <tuple>
#include <variant>


class RunProgramSpec
{
public:
ModifierKey winKey = ModifierKey::Disabled;
ModifierKey ctrlKey = ModifierKey::Disabled;
ModifierKey altKey = ModifierKey::Disabled;
ModifierKey shiftKey = ModifierKey::Disabled;
DWORD actionKey = {};

std::wstring path = L"";
std::vector<DWORD> keys;

RunProgramSpec() = default;

// Constructor to initialize Shortcut from it's virtual key code string representation.
RunProgramSpec(const std::wstring& shortcutVK);

private:
std::vector<std::wstring> splitwstring(const std::wstring& input, wchar_t delimiter);

bool RunProgramSpec::SetKey(const DWORD input);
};

RunProgramSpec::RunProgramSpec(const std::wstring& shortcutVK) :
winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL)
{
auto _keys = splitwstring(shortcutVK, ';');
for (auto it : _keys)
{
auto vkKeyCode = std::stoul(it);
SetKey(vkKeyCode);
}
}

std::vector<std::wstring> RunProgramSpec::splitwstring(const std::wstring& input, wchar_t delimiter)
{
std::wstringstream ss(input);
std::wstring item;
std::vector<std::wstring> splittedStrings;
while (std::getline(ss, item, delimiter))
{
splittedStrings.push_back(item);
}

return splittedStrings;
}

bool RunProgramSpec::SetKey(const DWORD input)
{
// Since there isn't a key for a common Win key we use the key code defined by us
if (input == CommonSharedConstants::VK_WIN_BOTH)
{
if (winKey == ModifierKey::Both)
{
return false;
}
winKey = ModifierKey::Both;
}
else if (input == VK_LWIN)
{
if (winKey == ModifierKey::Left)
{
return false;
}
winKey = ModifierKey::Left;
}
else if (input == VK_RWIN)
{
if (winKey == ModifierKey::Right)
{
return false;
}
winKey = ModifierKey::Right;
}
else if (input == VK_LCONTROL)
{
if (ctrlKey == ModifierKey::Left)
{
return false;
}
ctrlKey = ModifierKey::Left;
}
else if (input == VK_RCONTROL)
{
if (ctrlKey == ModifierKey::Right)
{
return false;
}
ctrlKey = ModifierKey::Right;
}
else if (input == VK_CONTROL)
{
if (ctrlKey == ModifierKey::Both)
{
return false;
}
ctrlKey = ModifierKey::Both;
}
else if (input == VK_LMENU)
{
if (altKey == ModifierKey::Left)
{
return false;
}
altKey = ModifierKey::Left;
}
else if (input == VK_RMENU)
{
if (altKey == ModifierKey::Right)
{
return false;
}
altKey = ModifierKey::Right;
}
else if (input == VK_MENU)
{
if (altKey == ModifierKey::Both)
{
return false;
}
altKey = ModifierKey::Both;
}
else if (input == VK_LSHIFT)
{
if (shiftKey == ModifierKey::Left)
{
return false;
}
shiftKey = ModifierKey::Left;
}
else if (input == VK_RSHIFT)
{
if (shiftKey == ModifierKey::Right)
{
return false;
}
shiftKey = ModifierKey::Right;
}
else if (input == VK_SHIFT)
{
if (shiftKey == ModifierKey::Both)
{
return false;
}
shiftKey = ModifierKey::Both;
}
else
{
if (actionKey == input)
{
return false;
}
actionKey = input;
}

return true;
}
150 changes: 150 additions & 0 deletions src/modules/keyboardmanager/common/RunProgramSpec.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#include "pch.h"
#include "RunProgramSpec.h"

class RunProgramSpec
{
public:
ModifierKey winKey = ModifierKey::Disabled;
ModifierKey ctrlKey = ModifierKey::Disabled;
ModifierKey altKey = ModifierKey::Disabled;
ModifierKey shiftKey = ModifierKey::Disabled;
DWORD actionKey = {};

std::wstring path = L"";
std::vector<DWORD> keys;

RunProgramSpec(const std::wstring& shortcutVK) :
winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL)
{
auto _keys = splitwstring(shortcutVK, ';');
for (auto it : _keys)
{
auto vkKeyCode = std::stoul(it);
SetKey(vkKeyCode);
}
}

std::vector<std::wstring> splitwstring(const std::wstring& input, wchar_t delimiter)
{
std::wstringstream ss(input);
std::wstring item;
std::vector<std::wstring> splittedStrings;
while (std::getline(ss, item, delimiter))
{
splittedStrings.push_back(item);
}

return splittedStrings;
}

bool SetKey(const DWORD input)
{
// Since there isn't a key for a common Win key we use the key code defined by us
if (input == CommonSharedConstants::VK_WIN_BOTH)
{
if (winKey == ModifierKey::Both)
{
return false;
}
winKey = ModifierKey::Both;
}
else if (input == VK_LWIN)
{
if (winKey == ModifierKey::Left)
{
return false;
}
winKey = ModifierKey::Left;
}
else if (input == VK_RWIN)
{
if (winKey == ModifierKey::Right)
{
return false;
}
winKey = ModifierKey::Right;
}
else if (input == VK_LCONTROL)
{
if (ctrlKey == ModifierKey::Left)
{
return false;
}
ctrlKey = ModifierKey::Left;
}
else if (input == VK_RCONTROL)
{
if (ctrlKey == ModifierKey::Right)
{
return false;
}
ctrlKey = ModifierKey::Right;
}
else if (input == VK_CONTROL)
{
if (ctrlKey == ModifierKey::Both)
{
return false;
}
ctrlKey = ModifierKey::Both;
}
else if (input == VK_LMENU)
{
if (altKey == ModifierKey::Left)
{
return false;
}
altKey = ModifierKey::Left;
}
else if (input == VK_RMENU)
{
if (altKey == ModifierKey::Right)
{
return false;
}
altKey = ModifierKey::Right;
}
else if (input == VK_MENU)
{
if (altKey == ModifierKey::Both)
{
return false;
}
altKey = ModifierKey::Both;
}
else if (input == VK_LSHIFT)
{
if (shiftKey == ModifierKey::Left)
{
return false;
}
shiftKey = ModifierKey::Left;
}
else if (input == VK_RSHIFT)
{
if (shiftKey == ModifierKey::Right)
{
return false;
}
shiftKey = ModifierKey::Right;
}
else if (input == VK_SHIFT)
{
if (shiftKey == ModifierKey::Both)
{
return false;
}
shiftKey = ModifierKey::Both;
}
else
{
if (actionKey == input)
{
return false;
}
actionKey = input;
}

return true;
}
};
Loading

1 comment on commit 356cb78

@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 for details.

Unrecognized words (6)

EDITRUNPROGRAMS
JLO
PROGRAMNAME
Programtool
RUNPROGRAMSPEC
shorcut

Previously acknowledged words that are now absent administra RSAT systemroot sysvol :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

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

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

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

Dictionary Entries Covers
cspell:win32/src/win32.txt 53509 139
cspell:cpp/src/cpp.txt 30216 132
cspell:python/src/python/python-lib.txt 3873 29
cspell:php/php.txt 2597 20
cspell:node/node.txt 1768 15
cspell:typescript/typescript.txt 1211 13
cspell:java/java.txt 7642 12
cspell:python/src/python/python.txt 453 10
cspell:aws/aws.txt 218 9
cspell:python/src/common/extra.txt 741 8

Consider adding them using (in .github/workflows/spelling2.yml):

      with:
        extra_dictionaries:
          cspell:win32/src/win32.txt
          cspell:cpp/src/cpp.txt
          cspell:python/src/python/python-lib.txt
          cspell:php/php.txt
          cspell:node/node.txt
          cspell:typescript/typescript.txt
          cspell:java/java.txt
          cspell:python/src/python/python.txt
          cspell:aws/aws.txt
          cspell:python/src/common/extra.txt

To stop checking additional dictionaries, add:

      with:
        check_extra_dictionaries: ''
Errors (1)

See the 📜action log for details.

❌ Errors Count
❌ check-file-path 1

See ❌ Event descriptions for more information.

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.