Skip to content

Commit

Permalink
UI getting better.
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflord committed Dec 17, 2023
1 parent bfffec9 commit 4757ea6
Show file tree
Hide file tree
Showing 16 changed files with 619 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,22 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
//}

std::wstring keysForShortcutToEdit = L"";
std::wstring action = L"";


if (numArgs >= 3)
{
if (numArgs == 4)
if (numArgs >= 4)
{
keysForShortcutToEdit = std::wstring(cmdArgs[3]);
}

if (numArgs >= 5)
{
action = std::wstring(cmdArgs[4]);
}


std::wstring pid = std::wstring(cmdArgs[2]);
Logger::trace(L"Editor started from the settings with pid {}", pid);
if (!pid.empty())
Expand Down Expand Up @@ -120,7 +128,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
return -1;
}

editor->OpenEditorWindow(type, keysForShortcutToEdit);
editor->OpenEditorWindow(type, keysForShortcutToEdit, action);

editor = nullptr;

Expand Down Expand Up @@ -161,15 +169,15 @@ bool KeyboardManagerEditor::StartLowLevelKeyboardHook()
return (hook != nullptr);
}

void KeyboardManagerEditor::OpenEditorWindow(KeyboardManagerEditorType type, std::wstring keysForShortcutToEdit)
void KeyboardManagerEditor::OpenEditorWindow(KeyboardManagerEditorType type, std::wstring keysForShortcutToEdit, std::wstring action)
{
switch (type)
{
case KeyboardManagerEditorType::KeyEditor:
CreateEditKeyboardWindow(hInstance, keyboardManagerState, mappingConfiguration);
break;
case KeyboardManagerEditorType::ShortcutEditor:
CreateEditShortcutsWindow(hInstance, keyboardManagerState, mappingConfiguration, keysForShortcutToEdit);
CreateEditShortcutsWindow(hInstance, keyboardManagerState, mappingConfiguration, keysForShortcutToEdit, action);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class KeyboardManagerEditor
}

bool StartLowLevelKeyboardHook();
void OpenEditorWindow(KeyboardManagerEditorType type, std::wstring keysForShortcutToEdit);
void OpenEditorWindow(KeyboardManagerEditorType type, std::wstring keysForShortcutToEdit, std::wstring action);

// Function called by the hook procedure to handle the events. This is the starting point function for remapping
intptr_t HandleKeyboardHookEvent(LowlevelKeyboardEvent* data) noexcept;
Expand Down
25 changes: 23 additions & 2 deletions src/modules/keyboardmanager/KeyboardManagerEditor/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@
<data name="EditShortcuts_WindowName" xml:space="preserve">
<value>Remap shortcuts</value>
</data>
<data name="Browse_For_Program_Button" xml:space="preserve">
<data name="EditThisShortcut_WindowName" xml:space="preserve">
<value>Edit shortcut</value>
</data>
<data name="Browse_For_Program_Button" xml:space="preserve">
<value>Select program</value>
</data>
<data name="Browse_For_Path_Button" xml:space="preserve">
Expand Down Expand Up @@ -334,7 +337,25 @@
<data name="Delete_Remapping_Button" xml:space="preserve">
<value>Delete remapping</value>
</data>
<data name="ElevationTypeNormal" xml:space="preserve">
<data name="AlreadyRunningDoNothing" xml:space="preserve">
<value>Do nothing</value>
</data>
<data name="AlreadyRunningShowWindow" xml:space="preserve">
<value>Show window</value>
</data>
<data name="AlreadyRunningStartAnother" xml:space="preserve">
<value>Start another</value>
</data>
<data name="AlreadyRunningClose" xml:space="preserve">
<value>Close</value>
</data>
<data name="AlreadyRunningTerminate" xml:space="preserve">
<value>End task</value>
</data>
<data name="AlreadyRunningCloseAndTerminate" xml:space="preserve">
<value>Close and end task</value>
</data>
<data name="ElevationTypeNormal" xml:space="preserve">
<value>Normal</value>
</data>
<data name="ElevationTypeElevated" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,17 @@ static IAsyncAction OnClickAccept(
ApplyRemappings();
}

static void OnClickAcceptNoCheck()
{
//ApplyRemappings();
}

static bool isInSingleEditMode = false;
static bool isInCreateNewMode = false;
static bool isDelete = false;

// Function to create the Edit Shortcuts Window
inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardManagerState& keyboardManagerState, MappingConfiguration& mappingConfiguration, std::wstring keysForShortcutToEdit)
inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardManagerState& keyboardManagerState, MappingConfiguration& mappingConfiguration, std::wstring keysForShortcutToEdit, std::wstring action)
{
Logger::trace("CreateEditShortcutsWindowImpl()");
auto locker = EventLocker::Get(KeyboardManagerConstants::EditorWindowEventName.c_str());
Expand Down Expand Up @@ -253,10 +262,36 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMa
// Create copy of the remaps to avoid concurrent access
ShortcutRemapTable osLevelShortcutReMapCopy = mappingConfiguration.osLevelShortcutReMap;

bool isInSingleEditMode = false;
// Apply button
Button applyButton;
applyButton.Name(L"applyButton");
applyButton.Content(winrt::box_value(GET_RESOURCE_STRING(IDS_OK_BUTTON)));
applyButton.Style(AccentButtonStyle());
applyButton.MinWidth(EditorConstants::HeaderButtonWidth);
cancelButton.MinWidth(EditorConstants::HeaderButtonWidth);
header.SetAlignRightWithPanel(cancelButton, true);
header.SetLeftOf(applyButton, cancelButton);

auto ApplyRemappings = [&mappingConfiguration, _hWndEditShortcutsWindow]() {
LoadingAndSavingRemappingHelper::ApplyShortcutRemappings(mappingConfiguration, ShortcutControl::shortcutRemapBuffer, true);
bool saveResult = mappingConfiguration.SaveSettingsToFile();
PostMessage(_hWndEditShortcutsWindow, WM_CLOSE, 0, 0);
};

applyButton.Click([&keyboardManagerState, applyButton, ApplyRemappings](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
OnClickAccept(keyboardManagerState, applyButton.XamlRoot(), ApplyRemappings);
});

auto OnClickAcceptNoCheckFn = ApplyRemappings;

if (!keysForShortcutToEdit.empty())
{
isInSingleEditMode = true;

if (keysForShortcutToEdit == L"inCreateNewMode")
{
isInCreateNewMode = true;
}
}

for (const auto& it : osLevelShortcutReMapCopy)
Expand All @@ -279,7 +314,7 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMa
);
*/

ShortcutControl::AddNewShortcutControlRow(shortcutTable, keyboardRemapControlObjects, it.first, it.second.targetShortcut, L"", isHidden);
ShortcutControl::AddNewShortcutControlRow(shortcutTable, keyboardRemapControlObjects, it.first, it.second.targetShortcut, L"", isHidden, isInSingleEditMode, OnClickAcceptNoCheckFn, action);
}

// Load existing app-specific shortcuts into UI
Expand All @@ -298,32 +333,18 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMa
{
isHidden = (keysForShortcutToEdit != itShortcut.first.ToHstringVK());
}
ShortcutControl::AddNewShortcutControlRow(shortcutTable, keyboardRemapControlObjects, itShortcut.first, itShortcut.second.targetShortcut, itApp.first, isHidden);

ShortcutControl::AddNewShortcutControlRow(shortcutTable, keyboardRemapControlObjects, itShortcut.first, itShortcut.second.targetShortcut, itApp.first, isHidden, isInSingleEditMode, OnClickAcceptNoCheckFn, action);
}
}

// Apply button
Button applyButton;
applyButton.Content(winrt::box_value(GET_RESOURCE_STRING(IDS_OK_BUTTON)));
applyButton.Style(AccentButtonStyle());
applyButton.MinWidth(EditorConstants::HeaderButtonWidth);
cancelButton.MinWidth(EditorConstants::HeaderButtonWidth);
header.SetAlignRightWithPanel(cancelButton, true);
header.SetLeftOf(applyButton, cancelButton);

auto ApplyRemappings = [&mappingConfiguration, _hWndEditShortcutsWindow]() {
LoadingAndSavingRemappingHelper::ApplyShortcutRemappings(mappingConfiguration, ShortcutControl::shortcutRemapBuffer, true);
bool saveResult = mappingConfiguration.SaveSettingsToFile();
PostMessage(_hWndEditShortcutsWindow, WM_CLOSE, 0, 0);
};

applyButton.Click([&keyboardManagerState, applyButton, ApplyRemappings](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
OnClickAccept(keyboardManagerState, applyButton.XamlRoot(), ApplyRemappings);
});

header.Children().Append(headerText);
header.Children().Append(applyButton);
header.Children().Append(cancelButton);

if (!isInSingleEditMode)
{
header.Children().Append(applyButton);
header.Children().Append(cancelButton);
}

ScrollViewer scrollViewer;
scrollViewer.VerticalScrollMode(ScrollMode::Enabled);
Expand All @@ -345,16 +366,44 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMa
UIHelpers::SetFocusOnTypeButtonInLastRow(shortcutTable, EditorConstants::ShortcutTableColCount);
});

// Remap shortcut button content
StackPanel addShortcutContent;
/*while (true)
{
Sleep(1000);
}*/

if (isInSingleEditMode)
if (action == L"isDelete")
{
addShortcut.Visibility(Visibility::Collapsed);
//shortcutRemapInfoExample.Visibility(Visibility::Collapsed);
shortcutRemapInfoHeader.Text(GET_RESOURCE_STRING(IDS_EDITSINGLESHORTCUT_INFO));
auto indexToDelete = -1;
for (int i = 0; i < ShortcutControl::shortcutRemapBuffer.size(); i++)
{
auto tempShortcut = std::get<Shortcut>(ShortcutControl::shortcutRemapBuffer[i].first[0]);
if (tempShortcut.ToHstringVK() == keysForShortcutToEdit)
{
indexToDelete = i;
}
}
if (indexToDelete >= 0)
{
ShortcutControl::shortcutRemapBuffer.erase(ShortcutControl::shortcutRemapBuffer.begin() + indexToDelete);
}
OnClickAcceptNoCheckFn();
return;
}

if (isInCreateNewMode)
{
ShortcutControl::AddNewShortcutControlRow(shortcutTable, keyboardRemapControlObjects);

// Whenever a remap is added move to the bottom of the screen
scrollViewer.ChangeView(nullptr, scrollViewer.ScrollableHeight(), nullptr);

// Set focus to the first Type Button in the newly added row
UIHelpers::SetFocusOnTypeButtonInLastRow(shortcutTable, EditorConstants::ShortcutTableColCount);
}

// Remap shortcut button content
StackPanel addShortcutContent;

addShortcutContent.Orientation(Orientation::Horizontal);
addShortcutContent.Spacing(10);
addShortcutContent.Children().Append(SymbolIcon(Symbol::Add));
Expand Down Expand Up @@ -392,6 +441,7 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMa
xamlContainer.Children().Append(header);
xamlContainer.Children().Append(helperText);
xamlContainer.Children().Append(scrollViewer);

try
{
// If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception.
Expand All @@ -413,7 +463,39 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMa
// Mica isn't available
xamlContainer.Background(Application::Current().Resources().Lookup(box_value(L"ApplicationPageBackgroundThemeBrush")).as<Media::SolidColorBrush>());
}
Window::Current().Content(xamlContent);

if (isInSingleEditMode)
{
headerText.Text(GET_RESOURCE_STRING(IDS_EDITTHISSHORTCUT_WINDOWNAME));
addShortcut.Visibility(Visibility::Collapsed);
headerText.Visibility(Visibility::Collapsed);
//shortcutRemapInfoExample.Visibility(Visibility::Collapsed);
//shortcutRemapInfoHeader.Visibility(Visibility::Collapsed);
shortcutRemapInfoHeader.Text(GET_RESOURCE_STRING(IDS_EDITSINGLESHORTCUT_INFO));

StackPanel tempSp;

tempSp.HorizontalAlignment(HorizontalAlignment::Right);

tempSp.Orientation(Orientation::Horizontal);
tempSp.Children().Append(applyButton);
tempSp.Children().Append(cancelButton);

//mappingsPanel.Children().Append(tempSp);
//xamlContainer.Children().Append(tempSp);
//xamlContainer.SetBelow(tempSp, scrollViewer);

StackPanel tempSp2;
tempSp.Margin({ 10, 10, 10, 0 });
tempSp2.Children().Append(xamlContent);
tempSp2.Children().Append(tempSp);

Window::Current().Content(tempSp2);
}
else
{
Window::Current().Content(xamlContent);
}

////End XAML Island section
if (_hWndEditShortcutsWindow)
Expand All @@ -434,10 +516,10 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMa
keyboardManagerState.ClearRegisteredKeyDelays();
}

void CreateEditShortcutsWindow(HINSTANCE hInst, KBMEditor::KeyboardManagerState& keyboardManagerState, MappingConfiguration& mappingConfiguration, std::wstring keysForShortcutToEdit)
void CreateEditShortcutsWindow(HINSTANCE hInst, KBMEditor::KeyboardManagerState& keyboardManagerState, MappingConfiguration& mappingConfiguration, std::wstring keysForShortcutToEdit, std::wstring action)
{
// Move implementation into the separate method so resources get destroyed correctly
CreateEditShortcutsWindowImpl(hInst, keyboardManagerState, mappingConfiguration, keysForShortcutToEdit);
CreateEditShortcutsWindowImpl(hInst, keyboardManagerState, mappingConfiguration, keysForShortcutToEdit, action);

// Calling ClearXamlIslands() outside of the message loop is not enough to prevent
// Microsoft.UI.XAML.dll from crashing during deinitialization, see https://github.com/microsoft/PowerToys/issues/10906
Expand Down Expand Up @@ -465,9 +547,23 @@ LRESULT CALLBACK EditShortcutsWindowProc(HWND hWnd, UINT messageCode, WPARAM wPa
LPMINMAXINFO mmi = reinterpret_cast<LPMINMAXINFO>(lParam);
float minWidth = EditorConstants::MinimumEditShortcutsWindowWidth;
float minHeight = EditorConstants::MinimumEditShortcutsWindowHeight;

if (isInSingleEditMode)
{
minWidth = EditorConstants::MinimumEditSingleShortcutsWindowWidth;
minHeight = EditorConstants::MinimumEditSingleShortcutsWindowHeight;
}

DPIAware::Convert(MonitorFromWindow(hWnd, MONITOR_DEFAULTTONULL), minWidth, minHeight);

mmi->ptMinTrackSize.x = static_cast<LONG>(minWidth);
mmi->ptMinTrackSize.y = static_cast<LONG>(minHeight);

//if (isInSingleEditMode)
//{
// mmi->ptMaxTrackSize.x = static_cast<LONG>(minWidth);
// mmi->ptMaxTrackSize.y = static_cast<LONG>(minHeight);
//}
}
break;
case WM_GETDPISCALEDSIZE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace KBMEditor
class MappingConfiguration;

// Function to create the Edit Shortcuts Window
void CreateEditShortcutsWindow(HINSTANCE hInst, KBMEditor::KeyboardManagerState& keyboardManagerState, MappingConfiguration& mappingConfiguration, std::wstring keysForShortcutToEdit);
void CreateEditShortcutsWindow(HINSTANCE hInst, KBMEditor::KeyboardManagerState& keyboardManagerState, MappingConfiguration& mappingConfiguration, std::wstring keysForShortcutToEdit, std::wstring action);

// Function to check if there is already a window active if yes bring to foreground
bool CheckEditShortcutsWindowActive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ namespace EditorConstants
inline const int DefaultEditShortcutsWindowWidth = 1410;
inline const int DefaultEditShortcutsWindowHeight = 600;
inline const int DefaultEditSingleShortcutsWindowWidth = 1410;
inline const int DefaultEditSingleShortcutsWindowHeight = 500;
inline const int DefaultEditSingleShortcutsWindowHeight = 400;
inline const int MinimumEditShortcutsWindowWidth = 500;
inline const int MinimumEditShortcutsWindowHeight = 500;

inline const int MinimumEditSingleShortcutsWindowWidth = 500;
inline const int MinimumEditSingleShortcutsWindowHeight = 400;

inline const int EditShortcutsTableMinWidth = 1000;

// Key Remap table constants
Expand Down
Loading

1 comment on commit 4757ea6

@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 (43)
actio
ALLOWCHORDS
ALREADYRUNNINGCLOSE
ALREADYRUNNINGCLOSEANDTERMINATE
ALREADYRUNNINGDONOTHING
ALREADYRUNNINGSHOWWINDOW
ALREADYRUNNINGSTARTANOTHER
ALREADYRUNNINGTERMINATE
ARGSFORPROGRAM
BIF
BROWSEINFO
CKBH
CLOSE'ing
cmdow
commdlg
CRTL
EDITSINGLESHORTCUT
EDITTHISSHORTCUT
ELEVATIONTYPEDIFFERENTUSER
ELEVATIONTYPEELEVATED
ELEVATIONTYPENORMAL
FILEMUSTEXIST
Lencode
LPITEMIDLIST
lpstr
NEWDIALOGSTYLE
ofn
OPENFILENAME
PATHMUSTEXIST
PATHTOPROGRAM
pids
PROCESSENTRY
Procses
RETURNONLYFSDIRS
ritchielawrence
runasuser
SNAPPROCESS
STARTINDIRFORPROGRAM
tlhelp
Toolhelp
URIOr
urlmon
wcsicmp
Previously acknowledged words that are now absent CHT constexpr DEU hashcode HEB JPN LAlt Lambson langword nodiscard pcs qps roundf RUS RValue SVE tonos weakme 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/7241685238/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

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

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.