mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
added toggles for key remappings
This commit is contained in:
@@ -12,9 +12,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace KeyboardManagerEditorUI.Helpers
|
||||
{
|
||||
public partial class Remapping : INotifyPropertyChanged
|
||||
public partial class Remapping : INotifyPropertyChanged, IToggleableShortcut
|
||||
{
|
||||
public List<string> OriginalKeys { get; set; } = new List<string>();
|
||||
public List<string> Shortcut { get; set; } = new List<string>();
|
||||
|
||||
public List<string> RemappedKeys { get; set; } = new List<string>();
|
||||
|
||||
@@ -24,6 +24,10 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
|
||||
private bool IsEnabledValue { get; set; } = true;
|
||||
|
||||
public string Id { get; set; } = string.Empty;
|
||||
|
||||
public bool IsActive { get; set; } = true;
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public bool IsEnabled
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using KeyboardManagerEditorUI.Interop;
|
||||
using KeyboardManagerEditorUI.Settings;
|
||||
using ManagedCommon;
|
||||
using Windows.System;
|
||||
|
||||
@@ -16,7 +17,7 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
{
|
||||
public static class RemappingHelper
|
||||
{
|
||||
public static bool SaveMapping(KeyboardMappingService mappingService, List<string> originalKeys, List<string> remappedKeys, bool isAppSpecific, string appName)
|
||||
public static bool SaveMapping(KeyboardMappingService mappingService, List<string> originalKeys, List<string> remappedKeys, bool isAppSpecific, string appName, bool saveToSettings = true)
|
||||
{
|
||||
if (mappingService == null)
|
||||
{
|
||||
@@ -34,8 +35,17 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
if (originalKeys.Count == 1)
|
||||
{
|
||||
int originalKey = mappingService.GetKeyCodeFromName(originalKeys[0]);
|
||||
|
||||
if (originalKey != 0)
|
||||
{
|
||||
string targetKeysString = string.Join(";", remappedKeys.Select(k => mappingService.GetKeyCodeFromName(k).ToString(CultureInfo.InvariantCulture)));
|
||||
ShortcutKeyMapping shortcutKeyMapping = new ShortcutKeyMapping()
|
||||
{
|
||||
OperationType = ShortcutOperationType.RemapShortcut,
|
||||
OriginalKeys = originalKey.ToString(CultureInfo.InvariantCulture),
|
||||
TargetKeys = targetKeysString,
|
||||
TargetApp = isAppSpecific ? appName : string.Empty,
|
||||
};
|
||||
if (remappedKeys.Count == 1)
|
||||
{
|
||||
int targetKey = mappingService.GetKeyCodeFromName(remappedKeys[0]);
|
||||
@@ -46,8 +56,12 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
}
|
||||
else
|
||||
{
|
||||
string targetKeys = string.Join(";", remappedKeys.Select(k => mappingService.GetKeyCodeFromName(k).ToString(CultureInfo.InvariantCulture)));
|
||||
mappingService.AddSingleKeyMapping(originalKey, targetKeys);
|
||||
mappingService.AddSingleKeyMapping(originalKey, targetKeysString);
|
||||
}
|
||||
|
||||
if (saveToSettings)
|
||||
{
|
||||
SettingsManager.AddShortcutKeyMappingToSettings(shortcutKeyMapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +70,14 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
string originalKeysString = string.Join(";", originalKeys.Select(k => mappingService.GetKeyCodeFromName(k).ToString(CultureInfo.InvariantCulture)));
|
||||
string targetKeysString = string.Join(";", remappedKeys.Select(k => mappingService.GetKeyCodeFromName(k).ToString(CultureInfo.InvariantCulture)));
|
||||
|
||||
ShortcutKeyMapping shortcutKeyMapping = new ShortcutKeyMapping()
|
||||
{
|
||||
OperationType = ShortcutOperationType.RemapShortcut,
|
||||
OriginalKeys = originalKeysString,
|
||||
TargetKeys = targetKeysString,
|
||||
TargetApp = isAppSpecific ? appName : string.Empty,
|
||||
};
|
||||
|
||||
if (isAppSpecific && !string.IsNullOrEmpty(appName))
|
||||
{
|
||||
mappingService.AddShortcutMapping(originalKeysString, targetKeysString, appName);
|
||||
@@ -64,6 +86,11 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
{
|
||||
mappingService.AddShortcutMapping(originalKeysString, targetKeysString);
|
||||
}
|
||||
|
||||
if (saveToSettings)
|
||||
{
|
||||
SettingsManager.AddShortcutKeyMappingToSettings(shortcutKeyMapping);
|
||||
}
|
||||
}
|
||||
|
||||
return mappingService.SaveSettings();
|
||||
@@ -75,7 +102,7 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DeleteRemapping(KeyboardMappingService mappingService, Remapping remapping)
|
||||
public static bool DeleteRemapping(KeyboardMappingService mappingService, Remapping remapping, bool deleteFromSettings = true)
|
||||
{
|
||||
if (mappingService == null)
|
||||
{
|
||||
@@ -84,23 +111,27 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
|
||||
try
|
||||
{
|
||||
if (remapping.OriginalKeys.Count == 1)
|
||||
if (remapping.Shortcut.Count == 1)
|
||||
{
|
||||
// Single key mapping
|
||||
int originalKey = mappingService.GetKeyCodeFromName(remapping.OriginalKeys[0]);
|
||||
int originalKey = mappingService.GetKeyCodeFromName(remapping.Shortcut[0]);
|
||||
if (originalKey != 0)
|
||||
{
|
||||
if (mappingService.DeleteSingleKeyMapping(originalKey))
|
||||
{
|
||||
// Save settings after successful deletion
|
||||
if (deleteFromSettings)
|
||||
{
|
||||
SettingsManager.RemoveShortcutKeyMappingFromSettings(remapping.Id);
|
||||
}
|
||||
|
||||
return mappingService.SaveSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (remapping.OriginalKeys.Count > 1)
|
||||
else if (remapping.Shortcut.Count > 1)
|
||||
{
|
||||
// Shortcut mapping
|
||||
string originalKeysString = string.Join(";", remapping.OriginalKeys.Select(k => mappingService.GetKeyCodeFromName(k).ToString(CultureInfo.InvariantCulture)));
|
||||
string originalKeysString = string.Join(";", remapping.Shortcut.Select(k => mappingService.GetKeyCodeFromName(k).ToString(CultureInfo.InvariantCulture)));
|
||||
|
||||
bool deleteResult;
|
||||
if (!remapping.IsAllApps && !string.IsNullOrEmpty(remapping.AppName))
|
||||
@@ -114,6 +145,11 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
deleteResult = mappingService.DeleteShortcutMapping(originalKeysString);
|
||||
}
|
||||
|
||||
if (deleteResult && deleteFromSettings)
|
||||
{
|
||||
SettingsManager.RemoveShortcutKeyMappingFromSettings(remapping.Id);
|
||||
}
|
||||
|
||||
return deleteResult ? mappingService.SaveSettings() : false;
|
||||
}
|
||||
|
||||
|
||||
@@ -180,8 +180,8 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
{
|
||||
// Skip if the remapping is the same as the one being edited
|
||||
if (isEditMode && editingRemapping != null &&
|
||||
editingRemapping.OriginalKeys.Count == 1 &&
|
||||
mappingService.GetKeyCodeFromName(editingRemapping.OriginalKeys[0]) == originalKeyCode)
|
||||
editingRemapping.Shortcut.Count == 1 &&
|
||||
mappingService.GetKeyCodeFromName(editingRemapping.Shortcut[0]) == originalKeyCode)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
bool isEditingExistingRemapping = false;
|
||||
if (isEditMode && editingRemapping != null)
|
||||
{
|
||||
string editingOriginalKeysString = string.Join(";", editingRemapping.OriginalKeys.Select(k =>
|
||||
string editingOriginalKeysString = string.Join(";", editingRemapping.Shortcut.Select(k =>
|
||||
mappingService.GetKeyCodeFromName(k).ToString(CultureInfo.InvariantCulture)));
|
||||
|
||||
if (KeyboardManagerInterop.AreShortcutsEqual(originalKeysString, editingOriginalKeysString))
|
||||
@@ -219,7 +219,7 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
if (!isAppSpecific && string.IsNullOrEmpty(mapping.TargetApp))
|
||||
{
|
||||
// Skip if the remapping is the same as the one being edited
|
||||
if (editingRemapping != null && editingRemapping.OriginalKeys.Count > 1 && editingRemapping.IsAllApps && isEditingExistingRemapping)
|
||||
if (editingRemapping != null && editingRemapping.Shortcut.Count > 1 && editingRemapping.IsAllApps && isEditingExistingRemapping)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -232,7 +232,7 @@ namespace KeyboardManagerEditorUI.Helpers
|
||||
&& string.Equals(mapping.TargetApp, appName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// Skip if the remapping is the same as the one being edited
|
||||
if (editingRemapping != null && editingRemapping.OriginalKeys.Count > 1 && !editingRemapping.IsAllApps &&
|
||||
if (editingRemapping != null && editingRemapping.Shortcut.Count > 1 && !editingRemapping.IsAllApps &&
|
||||
string.Equals(editingRemapping.AppName, appName, StringComparison.OrdinalIgnoreCase) && isEditingExistingRemapping)
|
||||
{
|
||||
continue;
|
||||
|
||||
@@ -119,7 +119,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<Rectangle Style="{StaticResource ItemDividerStyle}" />
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<ItemsControl VerticalAlignment="Center" ItemsSource="{x:Bind OriginalKeys}">
|
||||
<ItemsControl VerticalAlignment="Center" ItemsSource="{x:Bind Shortcut}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" Spacing="4" />
|
||||
@@ -162,7 +162,10 @@
|
||||
Grid.Column="1"
|
||||
Orientation="Horizontal"
|
||||
Spacing="8">
|
||||
<!-- TO DO: Add ToggleSwitch -->
|
||||
<ToggleSwitch
|
||||
IsOn="{x:Bind IsActive}"
|
||||
Style="{StaticResource RightAlignedCompactToggleSwitchStyle}"
|
||||
Toggled="ToggleSwitch_Toggled" />
|
||||
<Button
|
||||
VerticalAlignment="Center"
|
||||
Content="{ui:FontIcon Glyph=,
|
||||
|
||||
@@ -113,13 +113,13 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
{
|
||||
Type = EditingItem.ItemType.Remapping,
|
||||
Item = remapping,
|
||||
OriginalTriggerKeys = remapping.OriginalKeys.ToList(),
|
||||
OriginalTriggerKeys = remapping.Shortcut.ToList(),
|
||||
AppName = remapping.AppName,
|
||||
IsAllApps = remapping.IsAllApps,
|
||||
};
|
||||
|
||||
UnifiedMappingControl.Reset();
|
||||
UnifiedMappingControl.SetTriggerKeys(remapping.OriginalKeys.ToList());
|
||||
UnifiedMappingControl.SetTriggerKeys(remapping.Shortcut.ToList());
|
||||
UnifiedMappingControl.SetActionType(UnifiedMappingControl.ActionType.KeyOrShortcut);
|
||||
UnifiedMappingControl.SetActionKeys(remapping.RemappedKeys.ToList());
|
||||
UnifiedMappingControl.SetAppSpecific(!remapping.IsAllApps, remapping.AppName);
|
||||
@@ -597,13 +597,19 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
switch (menuFlyoutItem.Tag)
|
||||
{
|
||||
case Remapping remapping:
|
||||
if (RemappingHelper.DeleteRemapping(_mappingService, remapping))
|
||||
|
||||
if (!remapping.IsActive)
|
||||
{
|
||||
SettingsManager.RemoveShortcutKeyMappingFromSettings(remapping.Id);
|
||||
LoadRemappings();
|
||||
}
|
||||
else if (RemappingHelper.DeleteRemapping(_mappingService, remapping))
|
||||
{
|
||||
LoadRemappings();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning($"Failed to delete remapping: {string.Join("+", remapping.OriginalKeys)}");
|
||||
Logger.LogWarning($"Failed to delete remapping: {string.Join("+", remapping.Shortcut)}");
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -656,6 +662,14 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
{
|
||||
if (toggleSwitch.IsOn)
|
||||
{
|
||||
if (shortcut is Remapping remapping)
|
||||
{
|
||||
RemappingHelper.SaveMapping(_mappingService, remapping.Shortcut, remapping.RemappedKeys, remapping.IsAllApps, remapping.AppName, false);
|
||||
shortcut.IsActive = true;
|
||||
SettingsManager.ToggleShortcutKeyMappingActiveState(shortcut.Id);
|
||||
return;
|
||||
}
|
||||
|
||||
bool saved = false;
|
||||
ShortcutKeyMapping shortcutKeyMapping = SettingsManager.EditorSettings.ShortcutSettingsDictionary[shortcut.Id].Shortcut;
|
||||
if (shortcut.Shortcut.Count == 1)
|
||||
@@ -672,16 +686,20 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
if (saved)
|
||||
{
|
||||
shortcut.IsActive = true;
|
||||
_mappingService.SaveSettings();
|
||||
SettingsManager.ToggleShortcutKeyMappingActiveState(shortcut.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
toggleSwitch.IsOn = false;
|
||||
_mappingService.SaveSettings();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (shortcut is Remapping remapping)
|
||||
{
|
||||
shortcut.IsActive = false;
|
||||
RemappingHelper.DeleteRemapping(_mappingService, remapping, false);
|
||||
SettingsManager.ToggleShortcutKeyMappingActiveState(shortcut.Id);
|
||||
return;
|
||||
}
|
||||
|
||||
bool deleted = false;
|
||||
if (shortcut.Shortcut.Count == 1)
|
||||
{
|
||||
@@ -699,11 +717,10 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
|
||||
if (deleted)
|
||||
{
|
||||
shortcut.IsActive = false;
|
||||
SettingsManager.ToggleShortcutKeyMappingActiveState(shortcut.Id);
|
||||
_mappingService.SaveSettings();
|
||||
}
|
||||
|
||||
LoadAllMappings();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -734,36 +751,12 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
|
||||
RemappingList.Clear();
|
||||
|
||||
// Load all single key mappings
|
||||
foreach (var mapping in _mappingService.GetSingleKeyMappings())
|
||||
{
|
||||
string[] targetKeyCodes = mapping.TargetKey.Split(';');
|
||||
var targetKeyNames = new List<string>();
|
||||
|
||||
foreach (var keyCode in targetKeyCodes)
|
||||
{
|
||||
if (int.TryParse(keyCode, out int code))
|
||||
{
|
||||
targetKeyNames.Add(_mappingService.GetKeyDisplayName(code));
|
||||
}
|
||||
}
|
||||
|
||||
RemappingList.Add(new Remapping
|
||||
{
|
||||
OriginalKeys = new List<string> { _mappingService.GetKeyDisplayName(mapping.OriginalKey) },
|
||||
RemappedKeys = targetKeyNames,
|
||||
IsAllApps = true,
|
||||
});
|
||||
}
|
||||
|
||||
// Load all shortcut key mappings
|
||||
foreach (var mapping in _mappingService.GetShortcutMappingsByType(ShortcutOperationType.RemapShortcut))
|
||||
foreach (var shortcutSettings in SettingsManager.GetShortcutSettingsByOperationType(ShortcutOperationType.RemapShortcut))
|
||||
{
|
||||
ShortcutKeyMapping mapping = shortcutSettings.Shortcut;
|
||||
string[] originalKeyCodes = mapping.OriginalKeys.Split(';');
|
||||
string[] targetKeyCodes = mapping.TargetKeys.Split(';');
|
||||
|
||||
var originalKeyNames = new List<string>();
|
||||
var targetKeyNames = new List<string>();
|
||||
var remappedKeyNames = new List<string>();
|
||||
|
||||
foreach (var keyCode in originalKeyCodes)
|
||||
{
|
||||
@@ -773,20 +766,22 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var keyCode in targetKeyCodes)
|
||||
foreach (var remappedKeyCode in mapping.TargetKeys.Split(';'))
|
||||
{
|
||||
if (int.TryParse(keyCode, out int code))
|
||||
if (int.TryParse(remappedKeyCode, out int remappedCode))
|
||||
{
|
||||
targetKeyNames.Add(_mappingService.GetKeyDisplayName(code));
|
||||
remappedKeyNames.Add(_mappingService.GetKeyDisplayName(remappedCode));
|
||||
}
|
||||
}
|
||||
|
||||
RemappingList.Add(new Remapping
|
||||
{
|
||||
OriginalKeys = originalKeyNames,
|
||||
RemappedKeys = targetKeyNames,
|
||||
Shortcut = originalKeyNames,
|
||||
RemappedKeys = remappedKeyNames,
|
||||
IsAllApps = string.IsNullOrEmpty(mapping.TargetApp),
|
||||
AppName = string.IsNullOrEmpty(mapping.TargetApp) ? string.Empty : mapping.TargetApp,
|
||||
Id = shortcutSettings.Id,
|
||||
IsActive = shortcutSettings.IsActive,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
Grid.Column="0"
|
||||
VerticalAlignment="Center"
|
||||
IsEnabled="{x:Bind IsEnabled, Mode=OneWay}"
|
||||
ItemsSource="{x:Bind OriginalKeys}">
|
||||
ItemsSource="{x:Bind Shortcut}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<tkcontrols:WrapPanel
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
_isEditMode = true;
|
||||
_editingRemapping = selectedRemapping;
|
||||
|
||||
RemappingControl.SetOriginalKeys(selectedRemapping.OriginalKeys);
|
||||
RemappingControl.SetOriginalKeys(selectedRemapping.Shortcut);
|
||||
RemappingControl.SetRemappedKeys(selectedRemapping.RemappedKeys);
|
||||
RemappingControl.SetApp(!selectedRemapping.IsAllApps, selectedRemapping.AppName);
|
||||
RemappingControl.SetUpToggleButtonInitialStatus();
|
||||
@@ -290,7 +290,7 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
|
||||
RemappingList.Add(new Remapping
|
||||
{
|
||||
OriginalKeys = new List<string> { _mappingService.GetKeyDisplayName(mapping.OriginalKey) },
|
||||
Shortcut = new List<string> { _mappingService.GetKeyDisplayName(mapping.OriginalKey) },
|
||||
RemappedKeys = targetKeyNames,
|
||||
IsAllApps = true,
|
||||
});
|
||||
@@ -325,7 +325,7 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
|
||||
RemappingList.Add(new Remapping
|
||||
{
|
||||
OriginalKeys = originalKeyNames,
|
||||
Shortcut = originalKeyNames,
|
||||
RemappedKeys = targetKeyNames,
|
||||
IsAllApps = string.IsNullOrEmpty(mapping.TargetApp),
|
||||
AppName = string.IsNullOrEmpty(mapping.TargetApp) ? string.Empty : mapping.TargetApp,
|
||||
|
||||
@@ -87,6 +87,7 @@ namespace KeyboardManagerEditorUI.Settings
|
||||
{
|
||||
EditorSettings settings = new EditorSettings();
|
||||
|
||||
// Handle shortcut mappings (RunProgram, OpenUri, RemapShortcut, RemapText shortcuts)
|
||||
foreach (ShortcutKeyMapping mapping in _mappingService!.GetShortcutMappings())
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
@@ -109,6 +110,38 @@ namespace KeyboardManagerEditorUI.Settings
|
||||
}
|
||||
}
|
||||
|
||||
// Handle single key to key mappings
|
||||
var singleKeyMappings = _mappingService.GetSingleKeyMappings();
|
||||
foreach (var mapping in singleKeyMappings)
|
||||
{
|
||||
// Create a ShortcutKeyMapping representation for single key to key mappings
|
||||
var shortcutMapping = new ShortcutKeyMapping
|
||||
{
|
||||
OperationType = ShortcutOperationType.RemapShortcut,
|
||||
OriginalKeys = mapping.OriginalKey.ToString(CultureInfo.InvariantCulture),
|
||||
TargetKeys = mapping.TargetKey,
|
||||
};
|
||||
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
ShortcutSettings shortcutSettings = new ShortcutSettings
|
||||
{
|
||||
Id = guid,
|
||||
Shortcut = shortcutMapping,
|
||||
IsActive = true,
|
||||
};
|
||||
|
||||
settings.ShortcutSettingsDictionary[guid] = shortcutSettings;
|
||||
|
||||
if (settings.ShortcutsByOperationType.TryGetValue(ShortcutOperationType.RemapShortcut, out List<string>? value))
|
||||
{
|
||||
value.Add(guid);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.ShortcutsByOperationType[ShortcutOperationType.RemapShortcut] = new List<string> { guid };
|
||||
}
|
||||
}
|
||||
|
||||
// Handle single key to text mappings
|
||||
var keyToTextMappings = _mappingService.GetKeyToTextMappings();
|
||||
foreach (var mapping in keyToTextMappings)
|
||||
@@ -117,8 +150,8 @@ namespace KeyboardManagerEditorUI.Settings
|
||||
var shortcutMapping = new ShortcutKeyMapping
|
||||
{
|
||||
OperationType = ShortcutOperationType.RemapText,
|
||||
OriginalKeys = _mappingService.GetKeyDisplayName(mapping.OriginalKey),
|
||||
TargetKeys = _mappingService.GetKeyDisplayName(mapping.OriginalKey),
|
||||
OriginalKeys = mapping.OriginalKey.ToString(CultureInfo.InvariantCulture),
|
||||
TargetKeys = mapping.TargetText,
|
||||
TargetText = mapping.TargetText,
|
||||
};
|
||||
|
||||
@@ -180,6 +213,43 @@ namespace KeyboardManagerEditorUI.Settings
|
||||
}
|
||||
}
|
||||
|
||||
// Handle single key to key mappings
|
||||
var singleKeyMappings = _mappingService.GetSingleKeyMappings();
|
||||
foreach (var mapping in singleKeyMappings)
|
||||
{
|
||||
// Create a ShortcutKeyMapping representation for single key to key mappings
|
||||
var shortcutMapping = new ShortcutKeyMapping
|
||||
{
|
||||
OperationType = ShortcutOperationType.RemapShortcut,
|
||||
OriginalKeys = mapping.OriginalKey.ToString(CultureInfo.InvariantCulture),
|
||||
TargetKeys = mapping.TargetKey,
|
||||
};
|
||||
|
||||
if (!EditorSettings.ShortcutSettingsDictionary.Values.Any(s =>
|
||||
s.Shortcut.OperationType == ShortcutOperationType.RemapShortcut &&
|
||||
s.Shortcut.OriginalKeys == shortcutMapping.OriginalKeys &&
|
||||
s.Shortcut.TargetKeys == shortcutMapping.TargetKeys))
|
||||
{
|
||||
shortcutSettingsChanged = true;
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
ShortcutSettings shortcutSettings = new ShortcutSettings
|
||||
{
|
||||
Id = guid,
|
||||
Shortcut = shortcutMapping,
|
||||
IsActive = true,
|
||||
};
|
||||
EditorSettings.ShortcutSettingsDictionary[guid] = shortcutSettings;
|
||||
if (EditorSettings.ShortcutsByOperationType.TryGetValue(ShortcutOperationType.RemapShortcut, out List<string>? value))
|
||||
{
|
||||
value.Add(guid);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorSettings.ShortcutsByOperationType[ShortcutOperationType.RemapShortcut] = new List<string> { guid };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle single key to text mappings
|
||||
var keyToTextMappings = _mappingService.GetKeyToTextMappings();
|
||||
foreach (var mapping in keyToTextMappings)
|
||||
@@ -231,6 +301,17 @@ namespace KeyboardManagerEditorUI.Settings
|
||||
m.TargetText == shortcutSettings.Shortcut.TargetText);
|
||||
}
|
||||
}
|
||||
else if (shortcutSettings.Shortcut.OperationType == ShortcutOperationType.RemapShortcut &&
|
||||
!string.IsNullOrEmpty(shortcutSettings.Shortcut.OriginalKeys) &&
|
||||
shortcutSettings.Shortcut.OriginalKeys.Split(';').Length == 1)
|
||||
{
|
||||
if (int.TryParse(shortcutSettings.Shortcut.OriginalKeys, out int keyCode))
|
||||
{
|
||||
foundInService = singleKeyMappings.Any(m =>
|
||||
m.OriginalKey == keyCode &&
|
||||
m.TargetKey == shortcutSettings.Shortcut.TargetKeys);
|
||||
}
|
||||
}
|
||||
else if (shortcutKeyMappings.Any(m => m.OriginalKeys == shortcutSettings.Shortcut.OriginalKeys))
|
||||
{
|
||||
foundInService = true;
|
||||
|
||||
Reference in New Issue
Block a user