mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
adding toggles back to programs
This commit is contained in:
@@ -241,10 +241,10 @@
|
||||
<ColumnDefinition Width="348" />
|
||||
<ColumnDefinition Width="476" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="84" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Rectangle
|
||||
Grid.ColumnSpan="5"
|
||||
Grid.ColumnSpan="4"
|
||||
Height="1"
|
||||
Margin="-16,0,-16,0"
|
||||
HorizontalAlignment="Stretch"
|
||||
@@ -287,21 +287,28 @@
|
||||
</ToolTipService.ToolTip>
|
||||
</FontIcon>
|
||||
</StackPanel>
|
||||
<Button
|
||||
<StackPanel
|
||||
Grid.Column="3"
|
||||
Margin="0,0,4,0"
|
||||
Padding="8,4"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Click="DeleteMapping_Click">
|
||||
<FontIcon
|
||||
FontFamily="{StaticResource SymbolThemeFontFamily}"
|
||||
FontSize="16"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
|
||||
Glyph="" />
|
||||
</Button>
|
||||
Orientation="Horizontal"
|
||||
Spacing="8">
|
||||
<ToggleSwitch
|
||||
IsOn="{x:Bind IsActive}"
|
||||
Toggled="ProgramToggleSwitch_Toggled" />
|
||||
<Button
|
||||
Padding="8,4"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Click="DeleteMapping_Click">
|
||||
<FontIcon
|
||||
FontFamily="{StaticResource SymbolThemeFontFamily}"
|
||||
FontSize="16"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
|
||||
Glyph="" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
|
||||
@@ -411,7 +411,7 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
int originalKey = _mappingService.GetKeyCodeFromName(originalKeys[0]);
|
||||
if (originalKey != 0)
|
||||
{
|
||||
deleted = _mappingService.DeleteSingleKeyToTextMapping(originalKey);
|
||||
deleted = _mappingService.DeleteSingleKeyMapping(originalKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -439,7 +439,7 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
int originalKey = _mappingService.GetKeyCodeFromName(originalKeys[0]);
|
||||
if (originalKey != 0)
|
||||
{
|
||||
deleted = _mappingService.DeleteSingleKeyToTextMapping(originalKey);
|
||||
deleted = _mappingService.DeleteSingleKeyMapping(originalKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -618,9 +618,12 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
case Remapping remapping:
|
||||
if (RemappingHelper.DeleteRemapping(_mappingService, remapping))
|
||||
{
|
||||
_mappingService.SaveSettings();
|
||||
LoadRemappings();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning($"Failed to delete remapping: {string.Join("+", remapping.OriginalKeys)}");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -646,6 +649,10 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
_mappingService.SaveSettings();
|
||||
LoadTextMappings();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning($"Failed to delete text mapping: {string.Join("+", textMapping.Keys)}");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -658,7 +665,7 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
int originalKey = _mappingService.GetKeyCodeFromName(programShortcut.Shortcut[0]);
|
||||
if (originalKey != 0)
|
||||
{
|
||||
deleted = _mappingService.DeleteSingleKeyToTextMapping(originalKey);
|
||||
deleted = _mappingService.DeleteSingleKeyMapping(originalKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -673,6 +680,10 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
SettingsManager.RemoveShortcutKeyMappingFromSettings(programShortcut.Id);
|
||||
LoadProgramShortcuts();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning($"Failed to delete program shortcut: {string.Join("+", programShortcut.Shortcut)}");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -685,7 +696,7 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
int originalKey = _mappingService.GetKeyCodeFromName(urlShortcut.Shortcut[0]);
|
||||
if (originalKey != 0)
|
||||
{
|
||||
deleted = _mappingService.DeleteSingleKeyToTextMapping(originalKey);
|
||||
deleted = _mappingService.DeleteSingleKeyMapping(originalKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -699,9 +710,17 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
_mappingService.SaveSettings();
|
||||
LoadUrlShortcuts();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning($"Failed to delete URL shortcut: {string.Join("+", urlShortcut.Shortcut)}");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
Logger.LogWarning($"Unknown DataContext type for delete: {button.DataContext?.GetType().Name ?? "null"}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -712,6 +731,72 @@ namespace KeyboardManagerEditorUI.Pages
|
||||
|
||||
#endregion
|
||||
|
||||
#region Toggle Switch Handlers
|
||||
|
||||
private void ProgramToggleSwitch_Toggled(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is ToggleSwitch toggleSwitch && toggleSwitch.DataContext is ProgramShortcut shortcut && _mappingService != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (toggleSwitch.IsOn)
|
||||
{
|
||||
bool saved = false;
|
||||
ShortcutKeyMapping shortcutKeyMapping = SettingsManager.EditorSettings.ShortcutSettingsDictionary[shortcut.Id].Shortcut;
|
||||
|
||||
saved = _mappingService.AddShorcutMapping(shortcutKeyMapping);
|
||||
|
||||
if (saved)
|
||||
{
|
||||
shortcut.IsActive = true;
|
||||
_mappingService.SaveSettings();
|
||||
SettingsManager.ToggleShortcutKeyMappingActiveState(shortcut.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
toggleSwitch.IsOn = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool deleted = false;
|
||||
if (shortcut.Shortcut.Count == 1)
|
||||
{
|
||||
int originalKey = _mappingService.GetKeyCodeFromName(shortcut.Shortcut[0]);
|
||||
if (originalKey != 0)
|
||||
{
|
||||
deleted = _mappingService.DeleteSingleKeyToTextMapping(originalKey);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string originalKeys = string.Join(";", shortcut.Shortcut.Select(k => _mappingService.GetKeyCodeFromName(k)));
|
||||
deleted = _mappingService.DeleteShortcutMapping(originalKeys);
|
||||
}
|
||||
|
||||
if (deleted)
|
||||
{
|
||||
shortcut.IsActive = false;
|
||||
SettingsManager.ToggleShortcutKeyMappingActiveState(shortcut.Id);
|
||||
_mappingService.SaveSettings();
|
||||
}
|
||||
else
|
||||
{
|
||||
toggleSwitch.IsOn = true;
|
||||
}
|
||||
|
||||
LoadProgramShortcuts();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError("Error toggling program shortcut active state: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Load Methods
|
||||
|
||||
private void LoadAllMappings()
|
||||
|
||||
Reference in New Issue
Block a user