New editor UX toggle

This commit is contained in:
Niels Laute
2026-02-18 18:01:46 +01:00
parent d0608db26d
commit b46c76ade0
5 changed files with 327 additions and 213 deletions

View File

@@ -32,6 +32,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public HotkeySettings ToggleShortcut { get; set; }
[JsonPropertyName("useNewEditor")]
public bool UseNewEditor { get; set; }
public string ToJsonString()
{
return JsonSerializer.Serialize(this);

View File

@@ -15,219 +15,264 @@
mc:Ignorable="d">
<local:NavigablePage.Resources>
<tkconverters:CollectionVisibilityConverter x:Key="CollectionVisibilityConverter" />
<Style x:Name="KeysListViewContainerStyle" TargetType="ListViewItem">
<Setter Property="IsTabStop" Value="False" />
</Style>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<LinearGradientBrush x:Key="CardGradient2Brush" StartPoint="0,0" EndPoint="0.5, 1">
<GradientStop Offset="0" Color="#38C8AEC4" />
<GradientStop Offset="1" Color="#383286EE" />
</LinearGradientBrush>
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<LinearGradientBrush x:Key="CardGradient2Brush" StartPoint="0,0" EndPoint="1, 1">
<GradientStop Offset="0.0" Color="#FFF6F9FF" />
<GradientStop Offset="0.4" Color="#FFEFF5FF" />
<GradientStop Offset="0.7" Color="#FFF7FAFD" />
<GradientStop Offset="1.0" Color="#FFF5F8FA" />
</LinearGradientBrush>
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<SolidColorBrush x:Key="CardGradient2Brush" Color="Transparent" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<DataTemplate x:Key="OriginalKeyTemplate" x:DataType="x:String">
<ptcontrols:KeyVisual
Padding="8"
Content="{Binding}"
CornerRadius="{StaticResource ControlCornerRadius}" />
</DataTemplate>
<tkconverters:CollectionVisibilityConverter x:Key="CollectionVisibilityConverter" />
<Style x:Name="KeysListViewContainerStyle" TargetType="ListViewItem">
<Setter Property="IsTabStop" Value="False" />
</Style>
<DataTemplate x:Key="RemappedKeyTemplate" x:DataType="x:String">
<ptcontrols:KeyVisual
Padding="8"
Content="{Binding}"
CornerRadius="{StaticResource ControlCornerRadius}"
Style="{StaticResource AccentKeyVisualStyle}" />
</DataTemplate>
<DataTemplate x:Key="OriginalKeyTemplate" x:DataType="x:String">
<ptcontrols:KeyVisual
Padding="8"
Content="{Binding}"
CornerRadius="{StaticResource ControlCornerRadius}" />
</DataTemplate>
<!--<DataTemplate x:Name="KeysListViewTemplate" x:DataType="Lib:KeysDataModel">
<StackPanel
Name="KeyboardManager_RemappedKeysListItem"
x:Uid="KeyboardManager_RemappedKeysListItem"
Orientation="Horizontal"
Height="56">
</StackPanel>
</DataTemplate>-->
<!--<DataTemplate x:Name="ShortcutKeysListViewTemplate" x:DataType="Lib:AppSpecificKeysDataModel">
<StackPanel
Name="KeyboardManager_RemappedShortcutsListItem"
x:Uid="KeyboardManager_RemappedShortcutsListItem"
Orientation="Horizontal"
Height="56">
</DataTemplate>-->
<DataTemplate x:Key="RemappedKeyTemplate" x:DataType="x:String">
<ptcontrols:KeyVisual
Padding="8"
Content="{Binding}"
CornerRadius="{StaticResource ControlCornerRadius}"
Style="{StaticResource AccentKeyVisualStyle}" />
</DataTemplate>
</ResourceDictionary>
</local:NavigablePage.Resources>
<controls:SettingsPageControl x:Uid="KeyboardManager" ModuleImageSource="ms-appx:///Assets/Settings/Modules/KBM.png">
<controls:SettingsPageControl.ModuleContent>
<StackPanel ChildrenTransitions="{StaticResource SettingsCardsAnimations}" Orientation="Vertical">
<controls:GPOInfoControl ShowWarning="{x:Bind ViewModel.IsEnabledGpoConfigured, Mode=OneWay}">
<tkcontrols:SettingsCard
<tkcontrols:SettingsExpander
Name="KeyboardManagerEnableToggle"
x:Uid="KeyboardManager_EnableToggle"
HeaderIcon="{ui:BitmapIcon Source=/Assets/Settings/Icons/KeyboardManager.png}">
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.Enabled, Mode=TwoWay}" />
<tkcontrols:SettingsCard.Description>
<tkcontrols:SettingsExpander.Description>
<HyperlinkButton NavigateUri="https://aka.ms/powerToysCannotRemapKeys">
<TextBlock x:Uid="KBM_KeysCannotBeRemapped" FontWeight="SemiBold" />
</HyperlinkButton>
</tkcontrols:SettingsCard.Description>
</tkcontrols:SettingsCard>
</tkcontrols:SettingsExpander.Description>
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard Name="ToggleShortcut" x:Uid="KeyboardManager_Toggle_Shortcut">
<controls:ShortcutControl MinWidth="{StaticResource SettingActionControlMinWidth}" HotkeySettings="{x:Bind Path=ViewModel.ToggleShortcut, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
</tkcontrols:SettingsExpander.Items>
</tkcontrols:SettingsExpander>
</controls:GPOInfoControl>
<tkcontrols:SettingsCard
Name="ToggleShortcut"
x:Uid="KeyboardManager_Toggle_Shortcut"
HeaderIcon="{ui:FontIcon Glyph=&#xEDA7;}">
<controls:ShortcutControl MinWidth="{StaticResource SettingActionControlMinWidth}" HotkeySettings="{x:Bind Path=ViewModel.ToggleShortcut, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SwitchPresenter TargetType="x:Boolean" Value="{x:Bind ViewModel.UseNewEditor, Mode=OneWay}">
<tkcontrols:Case Value="False">
<StackPanel Orientation="Vertical">
<tkcontrols:SettingsCard
x:Uid="KeyboardManager_TryNewExperience"
MinHeight="64"
Margin="0,0,0,24"
Background="{ThemeResource CardGradient2Brush}"
HeaderIcon="{ui:FontIcon Glyph=&#xF133;}"
IsEnabled="{x:Bind ViewModel.Enabled, Mode=OneWay}">
<ToggleSwitch IsOn="{x:Bind ViewModel.UseNewEditor, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<controls:SettingsGroup x:Uid="KeyboardManager_Keys" IsEnabled="{x:Bind ViewModel.Enabled, Mode=OneWay}">
<tkcontrols:SettingsCard
Name="KeyboardManagerRemapKeyboardButton"
x:Uid="KeyboardManager_RemapKeyboardButton"
ActionIcon="{ui:FontIcon Glyph=&#xE8A7;}"
Command="{Binding Path=RemapKeyboardCommand}"
HeaderIcon="{ui:FontIcon Glyph=&#xE92E;}"
IsClickEnabled="True" />
<controls:SettingsGroup x:Uid="KeyboardManager_Keys" IsEnabled="{x:Bind ViewModel.Enabled, Mode=OneWay}">
<tkcontrols:SettingsCard
Name="KeyboardManagerRemapKeyboardButton"
x:Uid="KeyboardManager_RemapKeyboardButton"
ActionIcon="{ui:FontIcon Glyph=&#xE8A7;}"
Command="{Binding Path=RemapKeyboardCommand}"
HeaderIcon="{ui:FontIcon Glyph=&#xE92E;}"
IsClickEnabled="True" />
<ListView
x:Name="RemapKeysList"
x:Uid="RemapKeysList"
IsSwipeEnabled="False"
ItemsSource="{x:Bind Path=ViewModel.RemapKeys, Mode=OneWay}"
SelectionMode="None"
Visibility="{x:Bind Path=ViewModel.RemapKeys, Mode=OneWay, Converter={StaticResource CollectionVisibilityConverter}}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="Lib:KeysDataModel">
<tkcontrols:SettingsCard ContentAlignment="Left">
<StackPanel Orientation="Horizontal">
<ItemsControl
IsTabStop="False"
ItemTemplate="{StaticResource OriginalKeyTemplate}"
ItemsSource="{x:Bind GetMappedOriginalKeys()}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<ptcontrols:IsEnabledTextBlock
x:Uid="To"
Margin="8,0,8,0"
VerticalAlignment="Center"
Style="{StaticResource SecondaryIsEnabledTextBlockStyle}" />
<ItemsControl
Name="KeyboardManager_RemappedTo"
x:Uid="KeyboardManager_RemappedTo"
IsTabStop="False"
ItemTemplate="{StaticResource RemappedKeyTemplate}"
ItemsSource="{x:Bind GetMappedNewRemapKeys(50)}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</tkcontrols:SettingsCard>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</controls:SettingsGroup>
<ListView
x:Name="RemapKeysList"
x:Uid="RemapKeysList"
IsSwipeEnabled="False"
ItemsSource="{x:Bind Path=ViewModel.RemapKeys, Mode=OneWay}"
SelectionMode="None"
Visibility="{x:Bind Path=ViewModel.RemapKeys, Mode=OneWay, Converter={StaticResource CollectionVisibilityConverter}}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="Lib:KeysDataModel">
<tkcontrols:SettingsCard ContentAlignment="Left">
<StackPanel Orientation="Horizontal">
<ItemsControl
IsTabStop="False"
ItemTemplate="{StaticResource OriginalKeyTemplate}"
ItemsSource="{x:Bind GetMappedOriginalKeys()}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<ptcontrols:IsEnabledTextBlock
x:Uid="To"
Margin="8,0,8,0"
VerticalAlignment="Center"
Style="{StaticResource SecondaryIsEnabledTextBlockStyle}" />
<ItemsControl
Name="KeyboardManager_RemappedTo"
x:Uid="KeyboardManager_RemappedTo"
IsTabStop="False"
ItemTemplate="{StaticResource RemappedKeyTemplate}"
ItemsSource="{x:Bind GetMappedNewRemapKeys(50)}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</tkcontrols:SettingsCard>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</controls:SettingsGroup>
<controls:SettingsGroup x:Uid="KeyboardManager_Shortcuts" IsEnabled="{x:Bind ViewModel.Enabled, Mode=OneWay}">
<tkcontrols:SettingsCard
Name="KeyboardManagerRemapShortcutsButton"
x:Uid="KeyboardManager_RemapShortcutsButton"
ActionIcon="{ui:FontIcon Glyph=&#xE8A7;}"
Command="{Binding Path=EditShortcutCommand}"
HeaderIcon="{ui:FontIcon Glyph=&#xE713;}"
IsClickEnabled="True" />
<controls:SettingsGroup x:Uid="KeyboardManager_Shortcuts" IsEnabled="{x:Bind ViewModel.Enabled, Mode=OneWay}">
<tkcontrols:SettingsCard
Name="KeyboardManagerRemapShortcutsButton"
x:Uid="KeyboardManager_RemapShortcutsButton"
ActionIcon="{ui:FontIcon Glyph=&#xE8A7;}"
Command="{Binding Path=EditShortcutCommand}"
HeaderIcon="{ui:FontIcon Glyph=&#xE713;}"
IsClickEnabled="True" />
<ListView
x:Name="RemapShortcutsList"
x:Uid="RemapShortcutsList"
IsSwipeEnabled="False"
ItemsSource="{x:Bind Path=ViewModel.RemapShortcuts, Mode=OneWay}"
SelectionMode="None"
Visibility="{x:Bind Path=ViewModel.RemapShortcuts, Mode=OneWay, Converter={StaticResource CollectionVisibilityConverter}}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="Lib:AppSpecificKeysDataModel">
<ListView
x:Name="RemapShortcutsList"
x:Uid="RemapShortcutsList"
IsSwipeEnabled="False"
ItemsSource="{x:Bind Path=ViewModel.RemapShortcuts, Mode=OneWay}"
SelectionMode="None"
Visibility="{x:Bind Path=ViewModel.RemapShortcuts, Mode=OneWay, Converter={StaticResource CollectionVisibilityConverter}}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="Lib:AppSpecificKeysDataModel">
<tkcontrols:SettingsCard>
<tkcontrols:SettingsCard.Description>
<StackPanel Orientation="Horizontal">
<ItemsControl
IsTabStop="False"
ItemTemplate="{StaticResource OriginalKeyTemplate}"
ItemsSource="{x:Bind GetMappedOriginalKeysWithoutChord()}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<tkcontrols:SettingsCard>
<tkcontrols:SettingsCard.Description>
<StackPanel Orientation="Horizontal">
<ItemsControl
IsTabStop="False"
ItemTemplate="{StaticResource OriginalKeyTemplate}"
ItemsSource="{x:Bind GetMappedOriginalKeysWithoutChord()}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<TextBlock
Padding="6,0,6,6"
VerticalAlignment="Bottom"
Text=","
Visibility="{x:Bind Path=HasChord, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}" />
<TextBlock
Padding="6,0,6,6"
VerticalAlignment="Bottom"
Text=","
Visibility="{x:Bind Path=HasChord, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}" />
<ItemsControl
IsTabStop="False"
ItemTemplate="{StaticResource OriginalKeyTemplate}"
ItemsSource="{x:Bind GetMappedOriginalKeysOnlyChord()}"
Visibility="{x:Bind Path=HasChord, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<ItemsControl
IsTabStop="False"
ItemTemplate="{StaticResource OriginalKeyTemplate}"
ItemsSource="{x:Bind GetMappedOriginalKeysOnlyChord()}"
Visibility="{x:Bind Path=HasChord, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<ptcontrols:IsEnabledTextBlock
x:Uid="To"
Margin="8,0,8,0"
VerticalAlignment="Center"
Style="{StaticResource SecondaryIsEnabledTextBlockStyle}"
Visibility="{x:Bind Path=IsOpenUriOrIsRunProgram, Mode=OneWay, Converter={StaticResource ReverseBoolToVisibilityConverter}}" />
<ptcontrols:IsEnabledTextBlock
x:Uid="To"
Margin="8,0,8,0"
VerticalAlignment="Center"
Style="{StaticResource SecondaryIsEnabledTextBlockStyle}"
Visibility="{x:Bind Path=IsOpenUriOrIsRunProgram, Mode=OneWay, Converter={StaticResource ReverseBoolToVisibilityConverter}}" />
<ptcontrols:IsEnabledTextBlock
x:Uid="Starts"
Margin="8,0,8,0"
VerticalAlignment="Center"
Style="{StaticResource SecondaryIsEnabledTextBlockStyle}"
Visibility="{x:Bind Path=IsOpenUriOrIsRunProgram, Mode=OneWay}" />
<ptcontrols:IsEnabledTextBlock
x:Uid="Starts"
Margin="8,0,8,0"
VerticalAlignment="Center"
Style="{StaticResource SecondaryIsEnabledTextBlockStyle}"
Visibility="{x:Bind Path=IsOpenUriOrIsRunProgram, Mode=OneWay}" />
<ItemsControl
Name="KeyboardManager_RemappedTo"
x:Uid="KeyboardManager_RemappedTo"
IsTabStop="False"
ItemTemplate="{StaticResource RemappedKeyTemplate}"
ItemsSource="{x:Bind GetMappedNewRemapKeys(50)}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<Border
Margin="16,0,0,0"
Padding="12,4,12,6"
VerticalAlignment="Center"
CornerRadius="12">
<Border.Background>
<SolidColorBrush Opacity="0.3" Color="{ThemeResource SystemAccentColor}" />
</Border.Background>
<TextBlock Text="{x:Bind TargetApp}" />
</Border>
<ItemsControl
Name="KeyboardManager_RemappedTo"
x:Uid="KeyboardManager_RemappedTo"
IsTabStop="False"
ItemTemplate="{StaticResource RemappedKeyTemplate}"
ItemsSource="{x:Bind GetMappedNewRemapKeys(50)}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<Border
Margin="16,0,0,0"
Padding="12,4,12,6"
VerticalAlignment="Center"
CornerRadius="12">
<Border.Background>
<SolidColorBrush Opacity="0.3" Color="{ThemeResource SystemAccentColor}" />
</Border.Background>
<TextBlock Text="{x:Bind TargetApp}" />
</Border>
</StackPanel>
</tkcontrols:SettingsCard.Description>
</tkcontrols:SettingsCard>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</controls:SettingsGroup>
</StackPanel>
</tkcontrols:SettingsCard.Description>
</tkcontrols:SettingsCard>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</controls:SettingsGroup>
</StackPanel>
</tkcontrols:Case>
<tkcontrols:Case Value="True">
<controls:SettingsGroup x:Uid="KeyboardManager_Editor" IsEnabled="{x:Bind ViewModel.Enabled, Mode=OneWay}">
<StackPanel Orientation="Vertical" Spacing="16">
<tkcontrols:SettingsExpander
x:Uid="KeyboardManager_OpenNewEditor"
HeaderIcon="{ui:FontIcon Glyph=&#xEB3C;}"
IsEnabled="{x:Bind ViewModel.Enabled, Mode=OneWay}"
IsExpanded="True">
<Button
x:Uid="KeyboardManager_LaunchEditor_Button"
Command="{Binding Path=OpenNewEditorCommand}"
Style="{StaticResource AccentButtonStyle}" />
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard Name="KBMEditorShortcut" x:Uid="KeyboardManager_Editor_Shortcut">
<controls:ShortcutControl MinWidth="{StaticResource SettingActionControlMinWidth}" />
</tkcontrols:SettingsCard>
</tkcontrols:SettingsExpander.Items>
</tkcontrols:SettingsExpander>
<HyperlinkButton
x:Uid="KeyboardManager_GoBackClassic"
Padding="0"
Click="GoBackClassic_Click"
FontSize="12"
FontWeight="SemiBold" />
</StackPanel>
</controls:SettingsGroup>
</tkcontrols:Case>
</tkcontrols:SwitchPresenter>
</StackPanel>
</controls:SettingsPageControl.ModuleContent>
<controls:SettingsPageControl.PrimaryLinks>

View File

@@ -91,5 +91,10 @@ namespace Microsoft.PowerToys.Settings.UI.Views
{
ViewModel.RefreshEnabledState();
}
private void GoBackClassic_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
ViewModel.UseNewEditor = false;
}
}
}

View File

@@ -557,6 +557,10 @@ opera.exe</value>
<data name="KeyboardManager_RemapKeyboardButton.Header" xml:space="preserve">
<value>Remap a key</value>
<comment>Keyboard Manager remap keyboard button content</comment>
</data>
<data name="KeyboardManager_Editor.Header" xml:space="preserve">
<value>Editor</value>
<comment>Keyboard Manager new editor header</comment>
</data>
<data name="KeyboardManager_Keys.Header" xml:space="preserve">
<value>Keys</value>
@@ -571,9 +575,29 @@ opera.exe</value>
<comment>Keyboard Manager remap keyboard header</comment>
</data>
<data name="KeyboardManager_All_Apps_Description" xml:space="preserve">
<value>All Apps</value>
<value>All apps</value>
<comment>Should be the same as EditShortcuts_AllApps from keyboard manager editor</comment>
</data>
<data name="KeyboardManager_TryNewExperience.Header" xml:space="preserve">
<value>Try the new editor</value>
<comment>Keyboard Manager toggle to switch to the new unified editor</comment>
</data>
<data name="KeyboardManager_TryNewExperience.Description" xml:space="preserve">
<value>Switch to the new editor experience. You can turn this off at any time.</value>
<comment>Description for the new experience toggle</comment>
</data>
<data name="KeyboardManager_OpenNewEditor.Header" xml:space="preserve">
<value>Editor</value>
<comment>Keyboard Manager button to open the new unified editor</comment>
</data>
<data name="KeyboardManager_OpenNewEditor.Description" xml:space="preserve">
<value>Set and manage your remappings</value>
<comment>Description for the new editor button</comment>
</data>
<data name="KeyboardManager_GoBackClassic.Content" xml:space="preserve">
<value>Switch back to the classic editor experience</value>
<comment>Keyboard Manager link to switch back to the classic editor UI</comment>
</data>
<data name="Shortcut.Header" xml:space="preserve">
<value>Shortcut</value>
</data>
@@ -1877,12 +1901,18 @@ Made with 💗 by Microsoft and the PowerToys community.</value>
<value>Customize the shortcut to activate this module</value>
</data>
<data name="KeyboardManager_Toggle_Shortcut.Header" xml:space="preserve">
<value>Toggle shortcut</value>
<value>Shortcut</value>
</data>
<data name="KeyboardManager_Toggle_Shortcut.Description" xml:space="preserve">
<value>Use a shortcut to toggle this module on or off (note that the Settings UI will not update)</value>
<value>Enable or disable this module (Note: the Settings UI will not update)</value>
</data>
<data name="PasteAsPlainText_Shortcut.Header" xml:space="preserve">
<data name="KeyboardManager_Editor_Shortcut.Header" xml:space="preserve">
<value>Editor shortcut</value>
</data>
<data name="KeyboardManager_LaunchEditor_Button.Content" xml:space="preserve">
<value>Open editor</value>
</data>
<data name="PasteAsPlainText_Shortcut.Header" xml:space="preserve">
<value>Paste as plain text directly</value>
</data>
<data name="AdvancedPasteUI_Actions.Header" xml:space="preserve">

View File

@@ -21,7 +21,6 @@ using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
using Microsoft.PowerToys.Settings.UI.SerializationContext;
using Microsoft.PowerToys.Settings.Utilities;
using Microsoft.Win32;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
@@ -57,6 +56,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private ICommand _remapKeyboardCommand;
private ICommand _editShortcutCommand;
private ICommand _openNewEditorCommand;
private KeyboardManagerProfile _profile;
private Func<string, int> SendConfigMSG { get; }
@@ -201,6 +201,20 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public bool UseNewEditor
{
get => Settings.Properties.UseNewEditor;
set
{
if (Settings.Properties.UseNewEditor != value)
{
Settings.Properties.UseNewEditor = value;
OnPropertyChanged(nameof(UseNewEditor));
NotifySettingsChanged();
}
}
}
private void NotifySettingsChanged()
{
// Using InvariantCulture as this is an IPC message
@@ -262,6 +276,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
public ICommand EditShortcutCommand => _editShortcutCommand ?? (_editShortcutCommand = new RelayCommand(OnEditShortcut));
public ICommand OpenNewEditorCommand => _openNewEditorCommand ?? (_openNewEditorCommand = new RelayCommand(OnOpenNewEditor));
public void OnRemapKeyboard()
{
OpenEditor((int)KeyboardManagerEditorType.KeyEditor);
@@ -272,6 +288,11 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
OpenEditor((int)KeyboardManagerEditorType.ShortcutEditor);
}
public void OnOpenNewEditor()
{
OpenNewEditor();
}
private static void BringProcessToFront(Process process)
{
if (process == null)
@@ -305,32 +326,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
return;
}
// Launch the new editor if:
// 1. the experimentation toggle is enabled in the settings
// 2. the new WinUI3 editor is enabled in the registry. The registry value does not exist by default and is only used for development purposes
string editorPath = KeyboardManagerEditorPath;
try
{
// Check if the experimentation toggle is enabled in the settings
var settingsUtils = SettingsUtils.Default;
bool isExperimentationEnabled = SettingsRepository<GeneralSettings>.GetInstance(settingsUtils).SettingsConfig.EnableExperimentation;
// Only read the registry value if the experimentation toggle is enabled
if (isExperimentationEnabled)
{
editorPath = KeyboardManagerEditorUIPath;
}
}
catch (Exception e)
{
// Fall back to the default editor path if any exception occurs
Logger.LogError("Failed to launch the new WinUI3 Editor", e);
}
string path = Path.Combine(Environment.CurrentDirectory, editorPath);
string path = Path.Combine(Environment.CurrentDirectory, KeyboardManagerEditorPath);
Logger.LogInfo($"Starting {ModuleName} editor from {path}");
// InvariantCulture: type represents the KeyboardManagerEditorType enum va
// InvariantCulture: type represents the KeyboardManagerEditorType enum value
ProcessStartInfo startInfo = new ProcessStartInfo(path);
startInfo.UseShellExecute = true; // LOAD BEARING
startInfo.Arguments = $"{type.ToString(CultureInfo.InvariantCulture)} {Environment.ProcessId}";
@@ -343,6 +342,38 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
private void OpenNewEditor()
{
try
{
if (editor != null && editor.HasExited)
{
Logger.LogInfo($"Previous instance of {ModuleName} editor exited");
editor = null;
}
if (editor != null)
{
Logger.LogInfo($"The {ModuleName} editor instance {editor.Id} exists. Bringing the process to the front");
BringProcessToFront(editor);
return;
}
string path = Path.Combine(Environment.CurrentDirectory, KeyboardManagerEditorUIPath);
Logger.LogInfo($"Starting {ModuleName} new editor from {path}");
ProcessStartInfo startInfo = new ProcessStartInfo(path);
startInfo.UseShellExecute = true; // LOAD BEARING
startInfo.Arguments = $"{Environment.ProcessId}";
System.Environment.SetEnvironmentVariable("MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY", null);
editor = Process.Start(startInfo);
}
catch (Exception e)
{
Logger.LogError($"Exception encountered when opening the new {ModuleName} editor", e);
}
}
public void NotifyFileChanged()
{
OnPropertyChanged(nameof(RemapKeys));