Skip to content

Commit

Permalink
Space to toggle chord, combobox back
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflord committed Feb 27, 2024
1 parent 9d26f3e commit a53b8dc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@
<value>Keys selected:</value>
<comment>Keys on a keyboard</comment>
</data>
<data name="Type_HoldSpace" xml:space="preserve">
<value>Hold Space to toggle allow chord</value>
</data>
<data name="Type_HoldEnter" xml:space="preserve">
<value>Hold Enter to continue</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,110 +469,31 @@ void KeyDropDownControl::AddShortcutToControl(Shortcut shortcut, StackPanel tabl
ignoreWarning = true;
}

/*
I hope this mess goes away, but we need draw this shortcut, and it might be a chord and it might
be using a key already in use which id "detected" here by a ComboBox without a value, which
will marked as "IDS_EDITSHORTCUTS_BAD_KEY" for now.
*/
KeyDropDownControl::AddDropDown(table, row, parent, colIndex, remapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow, ignoreWarning);

StackPanel spForShortcutRowOne;
StackPanel spForShortcutRowTwo;
bool hasTwoRows = false;
spForShortcutRowOne.HorizontalAlignment(HorizontalAlignment::Left);
spForShortcutRowOne.Orientation(Orientation::Horizontal);

spForShortcutRowTwo.HorizontalAlignment(HorizontalAlignment::Left);
spForShortcutRowTwo.Orientation(Orientation::Horizontal);
spForShortcutRowTwo.Visibility(Visibility::Collapsed);

VariableSizedWrapGrid tempParent;

KeyDropDownControl::AddDropDown(table, row, tempParent, colIndex, remapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow, ignoreWarning);
StackPanel sp = spForShortcutRowOne;
/*while (true)
{
Sleep(1000);
}*/

for (int i = 0; i < shortcutKeyCodes.size(); i++)
{
// New drop down gets added automatically when the SelectedValue(key code) is set
if (i < (int)tempParent.Children().Size())
if (i < (int)parent.Children().Size())
{
ComboBox currentDropDown = tempParent.Children().GetAt(i).as<ComboBox>();
ComboBox currentDropDown = parent.Children().GetAt(i).as<ComboBox>();
currentDropDown.SelectedValue(winrt::box_value(std::to_wstring(shortcutKeyCodes[i])));

auto currentSelected = currentDropDown.SelectedItem();
if (currentSelected != nullptr)
{
auto keyText = winrt::unbox_value<hstring>(currentSelected.as<ComboBoxItem>().Content());
sp = spForShortcutRowOne;

if (currentDropDown.SelectedItem().as<ComboBoxItem>() != nullptr)
{
auto key = keyboardManagerState.AddKeyToLayout(sp, keyText);
}
else
{
auto badKey = keyboardManagerState.AddKeyToLayout(sp, GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_BAD_KEY).c_str());
badKey.Foreground(Media::SolidColorBrush(Colors::Red()));
}
}
else
{
auto badKey = keyboardManagerState.AddKeyToLayout(sp, GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_BAD_KEY).c_str());
badKey.Foreground(Media::SolidColorBrush(Colors::Red()));
}
}
}

if (shortcut.HasChord())
{
sp = spForShortcutRowOne;
if (hasTwoRows)
{
sp = spForShortcutRowTwo;
spForShortcutRowTwo.Visibility(Visibility::Visible);
hasTwoRows = true;
}

TextBlock txtComma;
txtComma.Text(L",");
txtComma.FontSize(20);
txtComma.Padding({ 0, 0, 10, 0 });
txtComma.VerticalAlignment(VerticalAlignment::Bottom);
txtComma.TextAlignment(TextAlignment::Left);
sp.Children().Append(txtComma);

// if this has a chord, render it last
KeyDropDownControl::AddDropDown(table, row, tempParent, colIndex, remapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow, ignoreWarning);
KeyDropDownControl::AddDropDown(table, row, parent, colIndex, remapBuffer, keyDropDownControlObjects, targetApp, isHybridControl, isSingleKeyWindow, ignoreWarning);
auto nextI = static_cast<int>(shortcutKeyCodes.size());
ComboBox currentDropDown = tempParent.Children().GetAt(nextI).as<ComboBox>();
ComboBox currentDropDown = parent.Children().GetAt(nextI).as<ComboBox>();
currentDropDown.SelectedValue(winrt::box_value(std::to_wstring(shortcut.GetSecondKey())));

if (currentDropDown.SelectedItem() != nullptr)
{
auto keyText = winrt::unbox_value<hstring>(currentDropDown.SelectedItem().as<ComboBoxItem>().Content());

if (currentDropDown.SelectedItem().as<ComboBoxItem>() != nullptr)
{
keyboardManagerState.AddKeyToLayout(sp, keyText);
}
else
{
auto badKey = keyboardManagerState.AddKeyToLayout(sp, L"BAD_KEY!");
badKey.Foreground(Media::SolidColorBrush(Colors::Red()));
}
}
else
{
auto badKey = keyboardManagerState.AddKeyToLayout(sp, GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_BAD_KEY).c_str());
badKey.Foreground(Media::SolidColorBrush(Colors::Red()));
}
}

// for some reason the first item in this parent needs to visible, so add the text version and then add the others as hidden.
parent.Children().Append(spForShortcutRowOne);
parent.Children().Append(spForShortcutRowTwo);

tempParent.Visibility(Visibility::Collapsed);
parent.Children().Append(tempParent);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,22 @@ void ShortcutControl::CreateDetectShortcutWindow(winrt::Windows::Foundation::IIn
unregisterKeys();
};

auto onReleaseSpace = [&keyboardManagerState,
unregisterKeys,
isSingleKeyWindow,
parentWindow,
allowChordSwitch] {

keyboardManagerState.AllowChord = !keyboardManagerState.AllowChord;
allowChordSwitch.IsOn(keyboardManagerState.AllowChord);

// Reset the keyboard manager UI state


//keyboardManagerState.ResetUIState();
//unregisterKeys();
};

auto onAccept = [onPressEnter,
onReleaseEnter] {
onPressEnter();
Expand Down Expand Up @@ -1090,6 +1106,22 @@ void ShortcutControl::CreateDetectShortcutWindow(winrt::Windows::Foundation::IIn
unregisterKeys();
};

// NOTE: UnregisterKeys should never be called on the DelayThread, as it will re-enter the mutex. To avoid this it is run on the dispatcher thread
if (true)
{
keyboardManagerState.RegisterKeyDelay(
VK_SPACE,
selectDetectedShortcutAndResetKeys,
[onReleaseSpace, detectShortcutBox](DWORD) {
detectShortcutBox.Dispatcher().RunAsync(
Windows::UI::Core::CoreDispatcherPriority::Normal,
[onReleaseSpace] {
onReleaseSpace();
});
},
nullptr);
}

// Cancel button
detectShortcutBox.CloseButtonText(GET_RESOURCE_STRING(IDS_CANCEL_BUTTON));
detectShortcutBox.CloseButtonClick([onCancel](winrt::Windows::Foundation::IInspectable const& sender, ContentDialogButtonClickEventArgs const& args) {
Expand Down Expand Up @@ -1182,6 +1214,12 @@ void ShortcutControl::CreateDetectShortcutWindow(winrt::Windows::Foundation::IIn
holdEnterInfo.Margin({ 0, 0, 0, 0 });
stackPanel.Children().Append(holdEnterInfo);

TextBlock holdSpaceInfo;
holdSpaceInfo.Text(GET_RESOURCE_STRING(IDS_TYPE_HOLDSPACE));
holdSpaceInfo.FontSize(12);
holdSpaceInfo.Margin({ 0, 0, 0, 0 });
stackPanel.Children().Append(holdSpaceInfo);

try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
Expand Down

1 comment on commit a53b8dc

@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 (1)

HOLDSPACE

Previously acknowledged words that are now absent COMMANDTITLE FILELOCKSMITHLIB OOBEPT 🫥
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/8058785418/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

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

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.