Move hardcoded strings in Keyboard Manager projects to rc file (#5921)

* moved all strings in c++ side to rc file

* Fixed formatting
This commit is contained in:
Arjun Balgovind 2020-08-17 13:46:50 -07:00 committed by GitHub
parent 8dec9d5fe9
commit 8f8b200f24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 178 additions and 70 deletions

View File

@ -3,7 +3,10 @@
#include <sstream>
#include "../common/shared_constants.h"
#include <shlwapi.h>
#include "../../common/common.h"
#include "keyboardmanager/dll/resource.h"
#include "../common/keyboard_layout.h"
extern "C" IMAGE_DOS_HEADER __ImageBase;
using namespace winrt::Windows::Foundation;
@ -137,43 +140,41 @@ namespace KeyboardManagerHelper
switch (errorType)
{
case ErrorType::NoError:
return L"Remapping successful";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_REMAPSUCCESSFUL).c_str();
case ErrorType::SameKeyPreviouslyMapped:
return L"Cannot remap a key more than once for the same target app";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_SAMEKEYPREVIOUSLYMAPPED).c_str();
case ErrorType::MapToSameKey:
return L"Cannot remap a key to itself";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_MAPPEDTOSAMEKEY).c_str();
case ErrorType::ConflictingModifierKey:
return L"Cannot remap this key as it conflicts with another remapped key";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_CONFLICTINGMODIFIERKEY).c_str();
case ErrorType::SameShortcutPreviouslyMapped:
return L"Cannot remap a shortcut more than once for the same target app";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_SAMESHORTCUTPREVIOUSLYMAPPED).c_str();
case ErrorType::MapToSameShortcut:
return L"Cannot remap a shortcut to itself";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_MAPTOSAMESHORTCUT).c_str();
case ErrorType::ConflictingModifierShortcut:
return L"Cannot remap this shortcut as it conflicts with another remapped shortcut";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_CONFLICTINGMODIFIERSHORTCUT).c_str();
case ErrorType::WinL:
return L"Cannot remap from/to Win L";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_WINL).c_str();
case ErrorType::CtrlAltDel:
return L"Cannot remap from/to Ctrl Alt Del";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_CTRLALTDEL).c_str();
case ErrorType::RemapUnsuccessful:
return L"Some remappings were not applied";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_REMAPUNSUCCESSFUL).c_str();
case ErrorType::SaveFailed:
return L"Failed to save the remappings";
case ErrorType::MissingKey:
return L"Incomplete remapping";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_SAVEFAILED).c_str();
case ErrorType::ShortcutStartWithModifier:
return L"Shortcut must start with a modifier key";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_SHORTCUTSTARTWITHMODIFIER).c_str();
case ErrorType::ShortcutCannotHaveRepeatedModifier:
return L"Shortcut cannot contain a repeated modifier";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_SHORTCUTNOREPEATEDMODIFIER).c_str();
case ErrorType::ShortcutAtleast2Keys:
return L"Shortcut must have atleast 2 keys";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_SHORTCUTATLEAST2KEYS).c_str();
case ErrorType::ShortcutOneActionKey:
return L"Shortcut must contain an action key";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_SHORTCUTONEACTIONKEY).c_str();
case ErrorType::ShortcutNotMoreThanOneActionKey:
return L"Shortcut cannot have more than one action key";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_SHORTCUTMAXONEACTIONKEY).c_str();
case ErrorType::ShortcutMaxShortcutSizeOneActionKey:
return L"Shortcuts can only have up to 2 modifier keys";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_MAXSHORTCUTSIZE).c_str();
default:
return L"Unexpected error";
return GET_RESOURCE_STRING(IDS_ERRORMESSAGE_DEFAULT).c_str();
}
}

View File

@ -43,7 +43,6 @@ namespace KeyboardManagerHelper
CtrlAltDel,
RemapUnsuccessful,
SaveFailed,
MissingKey,
ShortcutStartWithModifier,
ShortcutCannotHaveRepeatedModifier,
ShortcutAtleast2Keys,

View File

@ -1,6 +1,9 @@
#pragma once
#include <string>
#include <winrt/base.h>
#include "../../common/common.h"
#include "keyboardmanager/dll/resource.h"
extern "C" IMAGE_DOS_HEADER __ImageBase;
namespace KeyboardManagerConstants
{
@ -43,9 +46,6 @@ namespace KeyboardManagerConstants
// Name of the dummy update file.
inline const std::wstring DummyUpdateFileName = L"settings-updated.json";
// Initial value for tooltip
inline const winrt::hstring ToolTipInitialContent = L"Initialised";
// Minimum and maximum size of a shortcut
inline const long MinShortcutSize = 2;
inline const long MaxShortcutSize = 3;
@ -95,7 +95,7 @@ namespace KeyboardManagerConstants
inline const DWORD DUMMY_KEY = 0xFF;
// String constant for the default app name in Remap shortcuts
inline const std::wstring DefaultAppName = L"All Apps";
inline const std::wstring DefaultAppName = GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_ALLAPPS);
// String constant to represent no activated application in app-specific shortcuts
inline const std::wstring NoActivatedApp = L"";

View File

@ -4,8 +4,55 @@
STRINGTABLE
BEGIN
IDS_SETTINGS_DESCRIPTION L"This feature requires Windows 10 version 1903 or higher"
IDS_KEYBOARDMANAGER L"Keyboard Manager"
IDS_SETTINGS_DESCRIPTION L"This feature requires Windows 10 version 1903 or higher"
IDS_KEYBOARDMANAGER L"Keyboard Manager"
IDS_CREATEWINDOWFAILED_ERRORMESSAGE L"Call to CreateWindow failed!"
IDS_CREATEWINDOWFAILED_ERRORTITLE L"Error"
IDS_REGISTERCLASSFAILED_ERRORMESSAGE L"Windows registration failed!"
IDS_REGISTERCLASSFAILED_ERRORTITLE L"Error"
IDS_EDITKEYBOARD_WINDOWNAME L"Remap keys"
IDS_EDITSHORTCUTS_WINDOWNAME L"Remap shortcuts"
IDS_OK_BUTTON L"OK"
IDS_CANCEL_BUTTON L"Cancel"
IDS_CONTINUE_BUTTON L"Continue Anyway"
IDS_EDITKEYBOARD_SOURCEHEADER L"Key:"
IDS_EDITKEYBOARD_TARGETHEADER L"Mapped To:"
IDS_EDITSHORTCUTS_SOURCEHEADER L"Shortcut:"
IDS_EDITSHORTCUTS_TARGETHEADER L"Mapped To:"
IDS_EDITSHORTCUTS_TARGETAPPHEADER L"Target App:"
IDS_EDITKEYBOARD_ORPHANEDDIALOGTITLE L"The following keys are unassigned and you won't be able to use them:"
IDS_EDITKEYBOARD_PARTIALCONFIRMATIONDIALOGTITLE L"Some of the keys could not be remapped. Do you want to continue anyway?"
IDS_EDITSHORTCUTS_PARTIALCONFIRMATIONDIALOGTITLE L"Some of the shortcuts could not be remapped. Do you want to continue anyway?"
IDS_EDITKEYBOARD_INFO L"Select the key you want to change (Key) and then the key or shortcut you want it to become (Mapped To)."
IDS_EDITKEYBOARD_INFOEXAMPLE L"For example, if you want to press A and get ""Ctrl+C"", key ""A"" would be your ""Key"" column and the shortcut ""Ctrl+C"" would be your ""Mapped To"" column."
IDS_EDITSHORTCUTS_INFO L"Select the shortcut you want to change (Shortcut) and then the key or shortcut you want it to invoke (Mapped To)."
IDS_EDITSHORTCUTS_INFOEXAMPLE L"For example, if you want to press ""Ctrl+C"" and get ""Alt"" only on Microsoft Edge, ""Ctrl+C"" would be your ""Shortcut"" column, the key ""Alt"" would be your ""Mapped To"" column, and ""MSEdge"" would be your ""Target App"" column. If no target app is entered, it will apply globally. The name must be the process name and not the app name."
IDS_TYPE_BUTTON L"Type"
IDS_TYPEKEY_TITLE L"Press a key on selected keyboard:"
IDS_TYPESHORTCUT_TITLE L"Press the keys in shortcut:"
IDS_TYPEKEY_HEADER L"Key Pressed:"
IDS_TYPESHORTCUT_HEADER L"Keys Pressed:"
IDS_TYPE_HOLDENTER L"Hold Enter to continue"
IDS_TYPE_HOLDESC L"Hold Esc to discard"
IDS_EDITSHORTCUTS_ALLAPPS L"All Apps"
IDS_ERRORMESSAGE_REMAPSUCCESSFUL L"Remapping successful"
IDS_ERRORMESSAGE_REMAPUNSUCCESSFUL L"Some remappings were not applied"
IDS_ERRORMESSAGE_SAMEKEYPREVIOUSLYMAPPED L"Cannot remap a key more than once"
IDS_ERRORMESSAGE_MAPPEDTOSAMEKEY L"Cannot remap a key to itself"
IDS_ERRORMESSAGE_CONFLICTINGMODIFIERKEY L"Cannot remap this key as it conflicts with another remapped key"
IDS_ERRORMESSAGE_SAMESHORTCUTPREVIOUSLYMAPPED L"Cannot remap a shortcut more than once for the same target app"
IDS_ERRORMESSAGE_MAPTOSAMESHORTCUT L"Cannot remap a shortcut to itself"
IDS_ERRORMESSAGE_CONFLICTINGMODIFIERSHORTCUT L"Cannot remap this shortcut as it conflicts with another remapped shortcut"
IDS_ERRORMESSAGE_WINL L"Cannot remap from/to Win L"
IDS_ERRORMESSAGE_CTRLALTDEL L"Cannot remap from/to Ctrl Alt Del"
IDS_ERRORMESSAGE_SAVEFAILED L"Failed to save the remappings"
IDS_ERRORMESSAGE_SHORTCUTSTARTWITHMODIFIER L"Shortcut must start with a modifier key"
IDS_ERRORMESSAGE_SHORTCUTNOREPEATEDMODIFIER L"Shortcut cannot contain a repeated modifier"
IDS_ERRORMESSAGE_SHORTCUTATLEAST2KEYS L"Shortcut must have atleast 2 keys"
IDS_ERRORMESSAGE_SHORTCUTONEACTIONKEY L"Shortcut must contain an action key"
IDS_ERRORMESSAGE_SHORTCUTMAXONEACTIONKEY L"Shortcut cannot have more than one action key"
IDS_ERRORMESSAGE_MAXSHORTCUTSIZE L"Shortcuts can only have up to 2 modifier keys"
IDS_ERRORMESSAGE_DEFAULT L"Unexpected error"
END
IDS_KEYBOARDMANAGER_ICON ICON L"Keyboard.ico"

View File

@ -13,5 +13,52 @@
//////////////////////////////
#define IDS_SETTINGS_DESCRIPTION 101
#define IDS_KEYBOARDMANAGER 102
#define IDS_KEYBOARDMANAGER 102
#define IDS_KEYBOARDMANAGER_ICON 103
#define IDS_CREATEWINDOWFAILED_ERRORMESSAGE 104
#define IDS_CREATEWINDOWFAILED_ERRORTITLE 105
#define IDS_REGISTERCLASSFAILED_ERRORMESSAGE 106
#define IDS_REGISTERCLASSFAILED_ERRORTITLE 107
#define IDS_EDITKEYBOARD_WINDOWNAME 108
#define IDS_EDITSHORTCUTS_WINDOWNAME 109
#define IDS_CANCEL_BUTTON 110
#define IDS_OK_BUTTON 111
#define IDS_CONTINUE_BUTTON 112
#define IDS_EDITKEYBOARD_SOURCEHEADER 113
#define IDS_EDITKEYBOARD_TARGETHEADER 114
#define IDS_EDITSHORTCUTS_SOURCEHEADER 115
#define IDS_EDITSHORTCUTS_TARGETHEADER 116
#define IDS_EDITSHORTCUTS_TARGETAPPHEADER 117
#define IDS_EDITKEYBOARD_ORPHANEDDIALOGTITLE 118
#define IDS_EDITKEYBOARD_PARTIALCONFIRMATIONDIALOGTITLE 119
#define IDS_EDITSHORTCUTS_PARTIALCONFIRMATIONDIALOGTITLE 120
#define IDS_EDITKEYBOARD_INFO 121
#define IDS_EDITKEYBOARD_INFOEXAMPLE 122
#define IDS_EDITSHORTCUTS_INFO 123
#define IDS_EDITSHORTCUTS_INFOEXAMPLE 124
#define IDS_TYPE_BUTTON 125
#define IDS_TYPEKEY_TITLE 126
#define IDS_TYPESHORTCUT_TITLE 127
#define IDS_TYPEKEY_HEADER 128
#define IDS_TYPESHORTCUT_HEADER 129
#define IDS_TYPE_HOLDENTER 130
#define IDS_TYPE_HOLDESC 131
#define IDS_EDITSHORTCUTS_ALLAPPS 132
#define IDS_ERRORMESSAGE_REMAPSUCCESSFUL 133
#define IDS_ERRORMESSAGE_REMAPUNSUCCESSFUL 134
#define IDS_ERRORMESSAGE_SAMEKEYPREVIOUSLYMAPPED 135
#define IDS_ERRORMESSAGE_MAPPEDTOSAMEKEY 136
#define IDS_ERRORMESSAGE_CONFLICTINGMODIFIERKEY 137
#define IDS_ERRORMESSAGE_SAMESHORTCUTPREVIOUSLYMAPPED 138
#define IDS_ERRORMESSAGE_MAPTOSAMESHORTCUT 139
#define IDS_ERRORMESSAGE_CONFLICTINGMODIFIERSHORTCUT 140
#define IDS_ERRORMESSAGE_WINL 141
#define IDS_ERRORMESSAGE_CTRLALTDEL 142
#define IDS_ERRORMESSAGE_SAVEFAILED 143
#define IDS_ERRORMESSAGE_SHORTCUTSTARTWITHMODIFIER 144
#define IDS_ERRORMESSAGE_SHORTCUTNOREPEATEDMODIFIER 145
#define IDS_ERRORMESSAGE_SHORTCUTATLEAST2KEYS 146
#define IDS_ERRORMESSAGE_SHORTCUTONEACTIONKEY 147
#define IDS_ERRORMESSAGE_SHORTCUTMAXONEACTIONKEY 148
#define IDS_ERRORMESSAGE_MAXSHORTCUTSIZE 149
#define IDS_ERRORMESSAGE_DEFAULT 150

View File

@ -1,5 +1,9 @@
#include "pch.h"
#include "Dialog.h"
#include <set>
#include "common/common.h"
#include "keyboardmanager/dll/resource.h"
extern "C" IMAGE_DOS_HEADER __ImageBase;
using namespace winrt::Windows::Foundation;
@ -10,9 +14,9 @@ IAsyncOperation<bool> Dialog::PartialRemappingConfirmationDialog(XamlRoot root,
confirmationDialog.Title(box_value(dialogTitle));
confirmationDialog.IsPrimaryButtonEnabled(true);
confirmationDialog.DefaultButton(ContentDialogButton::Primary);
confirmationDialog.PrimaryButtonText(winrt::hstring(L"Continue Anyway"));
confirmationDialog.PrimaryButtonText(winrt::hstring(GET_RESOURCE_STRING(IDS_CONTINUE_BUTTON)));
confirmationDialog.IsSecondaryButtonEnabled(true);
confirmationDialog.SecondaryButtonText(winrt::hstring(L"Cancel"));
confirmationDialog.SecondaryButtonText(winrt::hstring(GET_RESOURCE_STRING(IDS_CANCEL_BUTTON)));
ContentDialogResult res = co_await confirmationDialog.ShowAsync();
co_return res == ContentDialogResult::Primary;

View File

@ -13,7 +13,9 @@
#include <keyboardmanager/dll/resource.h>
#include "../common/shared_constants.h"
#include "keyboardmanager/common/KeyboardManagerState.h"
#include "common/common.h"
#include "LoadingAndSavingRemappingHelper.h"
extern "C" IMAGE_DOS_HEADER __ImageBase;
using namespace winrt::Windows::Foundation;
@ -36,13 +38,13 @@ static IAsyncOperation<bool> OrphanKeysConfirmationDialog(
{
ContentDialog confirmationDialog;
confirmationDialog.XamlRoot(root);
confirmationDialog.Title(box_value(L"The following keys are unassigned and you won't be able to use them:"));
confirmationDialog.Title(box_value(GET_RESOURCE_STRING(IDS_EDITKEYBOARD_ORPHANEDDIALOGTITLE)));
confirmationDialog.Content(nullptr);
confirmationDialog.IsPrimaryButtonEnabled(true);
confirmationDialog.DefaultButton(ContentDialogButton::Primary);
confirmationDialog.PrimaryButtonText(winrt::hstring(L"Continue Anyway"));
confirmationDialog.PrimaryButtonText(winrt::hstring(GET_RESOURCE_STRING(IDS_CONTINUE_BUTTON)));
confirmationDialog.IsSecondaryButtonEnabled(true);
confirmationDialog.SecondaryButtonText(winrt::hstring(L"Cancel"));
confirmationDialog.SecondaryButtonText(winrt::hstring(GET_RESOURCE_STRING(IDS_CANCEL_BUTTON)));
TextBlock orphanKeysBlock;
std::wstring orphanKeyString;
@ -67,7 +69,7 @@ static IAsyncAction OnClickAccept(KeyboardManagerState& keyboardManagerState, Xa
if (isSuccess != KeyboardManagerHelper::ErrorType::NoError)
{
if (!co_await Dialog::PartialRemappingConfirmationDialog(root, L"Some of the keys could not be remapped. Do you want to continue anyway?"))
if (!co_await Dialog::PartialRemappingConfirmationDialog(root, GET_RESOURCE_STRING(IDS_EDITKEYBOARD_PARTIALCONFIRMATIONDIALOGTITLE)))
{
co_return;
}
@ -108,7 +110,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
LR_DEFAULTCOLOR);
if (RegisterClassEx(&windowClass) == NULL)
{
MessageBox(NULL, L"Windows registration failed!", L"Error", NULL);
MessageBox(NULL, GET_RESOURCE_STRING(IDS_REGISTERCLASSFAILED_ERRORMESSAGE).c_str(), GET_RESOURCE_STRING(IDS_REGISTERCLASSFAILED_ERRORTITLE).c_str(), NULL);
return;
}
@ -126,7 +128,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
// Window Creation
HWND _hWndEditKeyboardWindow = CreateWindow(
szWindowClass,
L"Remap keys",
GET_RESOURCE_STRING(IDS_EDITKEYBOARD_WINDOWNAME).c_str(),
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX,
(desktopRect.right / 2) - (windowWidth / 2),
(desktopRect.bottom / 2) - (windowHeight / 2),
@ -138,7 +140,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
NULL);
if (_hWndEditKeyboardWindow == NULL)
{
MessageBox(NULL, L"Call to CreateWindow failed!", L"Error", NULL);
MessageBox(NULL, GET_RESOURCE_STRING(IDS_CREATEWINDOWFAILED_ERRORMESSAGE).c_str(), GET_RESOURCE_STRING(IDS_CREATEWINDOWFAILED_ERRORTITLE).c_str(), NULL);
return;
}
// Ensures the window is in foreground on first startup. If this is not done, the window appears behind because the thread is not on the foreground.
@ -168,14 +170,14 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
// Header text
TextBlock headerText;
headerText.Text(L"Remap keys");
headerText.Text(GET_RESOURCE_STRING(IDS_EDITKEYBOARD_WINDOWNAME));
headerText.FontSize(30);
headerText.Margin({ 0, 0, 0, 0 });
header.SetAlignLeftWithPanel(headerText, true);
// Header Cancel button
Button cancelButton;
cancelButton.Content(winrt::box_value(L"Cancel"));
cancelButton.Content(winrt::box_value(GET_RESOURCE_STRING(IDS_CANCEL_BUTTON)));
cancelButton.Margin({ 10, 0, 0, 0 });
cancelButton.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
// Close the window since settings do not need to be saved
@ -184,13 +186,13 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
// Text block for information about remap key section.
TextBlock keyRemapInfoHeader;
keyRemapInfoHeader.Text(L"Select the key you want to change (Key) and then the key or shortcut you want it to become (Mapped To).");
keyRemapInfoHeader.Text(GET_RESOURCE_STRING(IDS_EDITKEYBOARD_INFO));
keyRemapInfoHeader.Margin({ 10, 0, 0, 10 });
keyRemapInfoHeader.FontWeight(Text::FontWeights::SemiBold());
keyRemapInfoHeader.TextWrapping(TextWrapping::Wrap);
TextBlock keyRemapInfoExample;
keyRemapInfoExample.Text(L"For example, if you want to press A and get \"Ctrl+C\", key \"A\" would be your \"Key\" column and the shortcut \"Ctrl+C\" would be your \"Mapped To\" column.");
keyRemapInfoExample.Text(GET_RESOURCE_STRING(IDS_EDITKEYBOARD_INFOEXAMPLE));
keyRemapInfoExample.Margin({ 10, 0, 0, 20 });
keyRemapInfoExample.FontStyle(Text::FontStyle::Italic);
keyRemapInfoExample.TextWrapping(TextWrapping::Wrap);
@ -217,13 +219,13 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
// First header textblock in the header row of the keys remap table
TextBlock originalKeyRemapHeader;
originalKeyRemapHeader.Text(L"Key:");
originalKeyRemapHeader.Text(GET_RESOURCE_STRING(IDS_EDITKEYBOARD_SOURCEHEADER));
originalKeyRemapHeader.FontWeight(Text::FontWeights::Bold());
originalKeyRemapHeader.Margin({ 0, 0, 0, 10 });
// Second header textblock in the header row of the keys remap table
TextBlock newKeyRemapHeader;
newKeyRemapHeader.Text(L"Mapped To:");
newKeyRemapHeader.Text(GET_RESOURCE_STRING(IDS_EDITKEYBOARD_TARGETHEADER));
newKeyRemapHeader.FontWeight(Text::FontWeights::Bold());
newKeyRemapHeader.Margin({ 0, 0, 0, 10 });
@ -261,7 +263,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
// Main Header Apply button
Button applyButton;
applyButton.Content(winrt::box_value(L"OK"));
applyButton.Content(winrt::box_value(GET_RESOURCE_STRING(IDS_OK_BUTTON)));
applyButton.Style(AccentButtonStyle());
applyButton.MinWidth(KeyboardManagerConstants::HeaderButtonWidth);
cancelButton.MinWidth(KeyboardManagerConstants::HeaderButtonWidth);

View File

@ -11,7 +11,9 @@
#include "Dialog.h"
#include <keyboardmanager/dll/resource.h>
#include <keyboardmanager/common/KeyboardManagerState.h>
#include "common/common.h"
#include "LoadingAndSavingRemappingHelper.h"
extern "C" IMAGE_DOS_HEADER __ImageBase;
using namespace winrt::Windows::Foundation;
@ -36,7 +38,7 @@ static IAsyncAction OnClickAccept(
if (isSuccess != KeyboardManagerHelper::ErrorType::NoError)
{
if (!co_await Dialog::PartialRemappingConfirmationDialog(root, L"Some of the shortcuts could not be remapped. Do you want to continue anyway?"))
if (!co_await Dialog::PartialRemappingConfirmationDialog(root, GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_PARTIALCONFIRMATIONDIALOGTITLE)))
{
co_return;
}
@ -67,7 +69,7 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
LR_DEFAULTCOLOR);
if (RegisterClassEx(&windowClass) == NULL)
{
MessageBox(NULL, L"Windows registration failed!", L"Error", NULL);
MessageBox(NULL, GET_RESOURCE_STRING(IDS_REGISTERCLASSFAILED_ERRORMESSAGE).c_str(), GET_RESOURCE_STRING(IDS_REGISTERCLASSFAILED_ERRORTITLE).c_str(), NULL);
return;
}
@ -85,7 +87,7 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
// Window Creation
HWND _hWndEditShortcutsWindow = CreateWindow(
szWindowClass,
L"Remap shortcuts",
GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_WINDOWNAME).c_str(),
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX,
(desktopRect.right / 2) - (windowWidth / 2),
(desktopRect.bottom / 2) - (windowHeight / 2),
@ -97,7 +99,7 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
NULL);
if (_hWndEditShortcutsWindow == NULL)
{
MessageBox(NULL, L"Call to CreateWindow failed!", L"Error", NULL);
MessageBox(NULL, GET_RESOURCE_STRING(IDS_CREATEWINDOWFAILED_ERRORMESSAGE).c_str(), GET_RESOURCE_STRING(IDS_CREATEWINDOWFAILED_ERRORTITLE).c_str(), NULL);
return;
}
// Ensures the window is in foreground on first startup. If this is not done, the window appears behind because the thread is not on the foreground.
@ -127,14 +129,14 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
// Header text
TextBlock headerText;
headerText.Text(L"Remap shortcuts");
headerText.Text(GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_WINDOWNAME));
headerText.FontSize(30);
headerText.Margin({ 0, 0, 0, 0 });
header.SetAlignLeftWithPanel(headerText, true);
// Cancel button
Button cancelButton;
cancelButton.Content(winrt::box_value(L"Cancel"));
cancelButton.Content(winrt::box_value(GET_RESOURCE_STRING(IDS_CANCEL_BUTTON)));
cancelButton.Margin({ 10, 0, 0, 0 });
cancelButton.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
// Close the window since settings do not need to be saved
@ -143,13 +145,13 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
// Text block for information about remap key section.
TextBlock shortcutRemapInfoHeader;
shortcutRemapInfoHeader.Text(L"Select the shortcut you want to change (Shortcut) and then the key or shortcut you want it to invoke (Mapped To).");
shortcutRemapInfoHeader.Text(GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_INFO));
shortcutRemapInfoHeader.Margin({ 10, 0, 0, 10 });
shortcutRemapInfoHeader.FontWeight(Text::FontWeights::SemiBold());
shortcutRemapInfoHeader.TextWrapping(TextWrapping::Wrap);
TextBlock shortcutRemapInfoExample;
shortcutRemapInfoExample.Text(L"For example, if you want to press \"Ctrl+C\" and get \"Alt\" only on Microsoft Edge, \"Ctrl+C\" would be your \"Shortcut\" column, the key \"Alt\" would be your \"Mapped To\" column, and \"MSEdge\" would be your \"Target App\" column. If no target app is entered, it will apply globally. The name must be the process name and not the app name.");
shortcutRemapInfoExample.Text(GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_INFOEXAMPLE));
shortcutRemapInfoExample.Margin({ 10, 0, 0, 20 });
shortcutRemapInfoExample.FontStyle(Text::FontStyle::Italic);
shortcutRemapInfoExample.TextWrapping(TextWrapping::Wrap);
@ -180,19 +182,19 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
// First header textblock in the header row of the shortcut table
TextBlock originalShortcutHeader;
originalShortcutHeader.Text(L"Shortcut:");
originalShortcutHeader.Text(GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_SOURCEHEADER));
originalShortcutHeader.FontWeight(Text::FontWeights::Bold());
originalShortcutHeader.Margin({ 0, 0, 0, 10 });
// Second header textblock in the header row of the shortcut table
TextBlock newShortcutHeader;
newShortcutHeader.Text(L"Mapped To:");
newShortcutHeader.Text(GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_TARGETHEADER));
newShortcutHeader.FontWeight(Text::FontWeights::Bold());
newShortcutHeader.Margin({ 0, 0, 0, 10 });
// Third header textblock in the header row of the shortcut table
TextBlock targetAppHeader;
targetAppHeader.Text(L"Target App:");
targetAppHeader.Text(GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_TARGETAPPHEADER));
targetAppHeader.Width(KeyboardManagerConstants::ShortcutTableDropDownWidth);
targetAppHeader.FontWeight(Text::FontWeights::Bold());
targetAppHeader.Margin({ 0, 0, 0, 10 });
@ -245,7 +247,7 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
// Apply button
Button applyButton;
applyButton.Content(winrt::box_value(L"OK"));
applyButton.Content(winrt::box_value(GET_RESOURCE_STRING(IDS_OK_BUTTON)));
applyButton.Style(AccentButtonStyle());
applyButton.MinWidth(KeyboardManagerConstants::HeaderButtonWidth);
cancelButton.MinWidth(KeyboardManagerConstants::HeaderButtonWidth);

View File

@ -3,6 +3,9 @@
#include "KeyDropDownControl.h"
#include "keyboardmanager/common/KeyboardManagerState.h"
#include "keyboardmanager/common/Helpers.h"
#include "common/common.h"
#include "keyboardmanager/dll/resource.h"
extern "C" IMAGE_DOS_HEADER __ImageBase;
//Both static members are initialized to null
HWND ShortcutControl::EditShortcutsWindowHandle = nullptr;
@ -20,7 +23,7 @@ ShortcutControl::ShortcutControl(Grid table, const int colIndex, TextBox targetA
shortcutDropDownStackPanel.as<StackPanel>().Spacing(KeyboardManagerConstants::ShortcutTableDropDownSpacing);
shortcutDropDownStackPanel.as<StackPanel>().Orientation(Windows::UI::Xaml::Controls::Orientation::Horizontal);
typeShortcut.as<Button>().Content(winrt::box_value(L"Type"));
typeShortcut.as<Button>().Content(winrt::box_value(GET_RESOURCE_STRING(IDS_TYPE_BUTTON)));
typeShortcut.as<Button>().Width(KeyboardManagerConstants::ShortcutTableDropDownWidth);
typeShortcut.as<Button>().Click([&, table, colIndex, isHybridControl, targetApp](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
keyboardManagerState->SetUIState(KeyboardManagerUIState::DetectShortcutWindowActivated, EditShortcutsWindowHandle);
@ -210,7 +213,7 @@ void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IIn
// ContentDialog requires manually setting the XamlRoot (https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.contentdialog#contentdialog-in-appwindow-or-xaml-islands)
detectShortcutBox.XamlRoot(xamlRoot);
detectShortcutBox.Title(box_value(L"Press the keys in shortcut:"));
detectShortcutBox.Title(box_value(GET_RESOURCE_STRING(IDS_TYPESHORTCUT_TITLE)));
detectShortcutBox.IsPrimaryButtonEnabled(false);
detectShortcutBox.IsSecondaryButtonEnabled(false);
@ -280,7 +283,7 @@ void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IIn
};
TextBlock primaryButtonText;
primaryButtonText.Text(L"OK");
primaryButtonText.Text(GET_RESOURCE_STRING(IDS_OK_BUTTON));
Button primaryButton;
primaryButton.HorizontalAlignment(HorizontalAlignment::Stretch);
@ -309,7 +312,7 @@ void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IIn
});
TextBlock cancelButtonText;
cancelButtonText.Text(L"Cancel");
cancelButtonText.Text(GET_RESOURCE_STRING(IDS_CANCEL_BUTTON));
Button cancelButton;
cancelButton.HorizontalAlignment(HorizontalAlignment::Stretch);
@ -364,7 +367,7 @@ void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IIn
// Header textblock
TextBlock text;
text.Text(L"Keys Pressed:");
text.Text(GET_RESOURCE_STRING(IDS_TYPESHORTCUT_HEADER));
text.Margin({ 0, 0, 0, 10 });
stackPanel.Children().Append(text);
@ -381,13 +384,13 @@ void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IIn
stackPanel.Children().Append(keyStackPanel2);
TextBlock holdEscInfo;
holdEscInfo.Text(L"Hold Esc to discard");
holdEscInfo.Text(GET_RESOURCE_STRING(IDS_TYPE_HOLDESC));
holdEscInfo.FontSize(12);
holdEscInfo.Margin({ 0, 20, 0, 0 });
stackPanel.Children().Append(holdEscInfo);
TextBlock holdEnterInfo;
holdEnterInfo.Text(L"Hold Enter to continue");
holdEnterInfo.Text(GET_RESOURCE_STRING(IDS_TYPE_HOLDENTER));
holdEnterInfo.FontSize(12);
holdEnterInfo.Margin({ 0, 0, 0, 0 });
stackPanel.Children().Append(holdEnterInfo);

View File

@ -4,6 +4,9 @@
#include "keyboardmanager/common/KeyboardManagerConstants.h"
#include "keyboardmanager/common/KeyboardManagerState.h"
#include "ShortcutControl.h"
#include "common/common.h"
#include "keyboardmanager/dll/resource.h"
extern "C" IMAGE_DOS_HEADER __ImageBase;
//Both static members are initialized to null
HWND SingleKeyRemapControl::EditKeyboardWindowHandle = nullptr;
@ -15,7 +18,7 @@ SingleKeyRemapControl::SingleKeyRemapControl(Grid table, const int colIndex)
{
typeKey = Button();
typeKey.as<Button>().Width(KeyboardManagerConstants::RemapTableDropDownWidth);
typeKey.as<Button>().Content(winrt::box_value(L"Type"));
typeKey.as<Button>().Content(winrt::box_value(GET_RESOURCE_STRING(IDS_TYPE_BUTTON)));
singleKeyRemapControlLayout = StackPanel();
singleKeyRemapControlLayout.as<StackPanel>().Margin({ 0, 0, 0, 10 });
@ -176,7 +179,7 @@ void SingleKeyRemapControl::createDetectKeyWindow(winrt::Windows::Foundation::II
// ContentDialog requires manually setting the XamlRoot (https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.contentdialog#contentdialog-in-appwindow-or-xaml-islands)
detectRemapKeyBox.XamlRoot(xamlRoot);
detectRemapKeyBox.Title(box_value(L"Press a key on selected keyboard:"));
detectRemapKeyBox.Title(box_value(GET_RESOURCE_STRING(IDS_TYPEKEY_TITLE)));
detectRemapKeyBox.IsPrimaryButtonEnabled(false);
detectRemapKeyBox.IsSecondaryButtonEnabled(false);
@ -228,7 +231,7 @@ void SingleKeyRemapControl::createDetectKeyWindow(winrt::Windows::Foundation::II
};
TextBlock primaryButtonText;
primaryButtonText.Text(L"OK");
primaryButtonText.Text(GET_RESOURCE_STRING(IDS_OK_BUTTON));
Button primaryButton;
primaryButton.HorizontalAlignment(HorizontalAlignment::Stretch);
@ -255,7 +258,7 @@ void SingleKeyRemapControl::createDetectKeyWindow(winrt::Windows::Foundation::II
});
TextBlock cancelButtonText;
cancelButtonText.Text(L"Cancel");
cancelButtonText.Text(GET_RESOURCE_STRING(IDS_CANCEL_BUTTON));
Button cancelButton;
cancelButton.HorizontalAlignment(HorizontalAlignment::Stretch);
@ -294,7 +297,7 @@ void SingleKeyRemapControl::createDetectKeyWindow(winrt::Windows::Foundation::II
// Header textblock
TextBlock text;
text.Text(L"Key Pressed:");
text.Text(GET_RESOURCE_STRING(IDS_TYPEKEY_HEADER));
text.Margin({ 0, 0, 0, 10 });
stackPanel.Children().Append(text);
@ -304,13 +307,13 @@ void SingleKeyRemapControl::createDetectKeyWindow(winrt::Windows::Foundation::II
stackPanel.Children().Append(keyStackPanel);
TextBlock holdEscInfo;
holdEscInfo.Text(L"Hold Esc to discard");
holdEscInfo.Text(GET_RESOURCE_STRING(IDS_TYPE_HOLDESC));
holdEscInfo.FontSize(12);
holdEscInfo.Margin({ 0, 20, 0, 0 });
stackPanel.Children().Append(holdEscInfo);
TextBlock holdEnterInfo;
holdEnterInfo.Text(L"Hold Enter to continue");
holdEnterInfo.Text(GET_RESOURCE_STRING(IDS_TYPE_HOLDENTER));
holdEnterInfo.FontSize(12);
holdEnterInfo.Margin({ 0, 0, 0, 0 });
stackPanel.Children().Append(holdEnterInfo);