[Settings] Reset Activation Key to Default Value (#26449)

* Add Default Value field to all controls

* Add reset button to Control field

* Improve button
Improve appearance
Add ToolTipService
Add AutomationProperties

* Move Reset button to Shortcut Dialog

* Fix Video Conferencing crash

* Change `Use Default` to `Reset`
This commit is contained in:
Sven 2023-06-20 15:42:04 +02:00 committed by GitHub
parent a883dcc283
commit 46ed52eab6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 127 additions and 78 deletions

View File

@ -12,9 +12,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ColorPickerProperties
{
public HotkeySettings DefaultActivationShortcut => new HotkeySettings(true, false, false, true, 0x43);
public ColorPickerProperties()
{
ActivationShortcut = new HotkeySettings(true, false, false, true, 0x43);
ActivationShortcut = DefaultActivationShortcut;
ChangeCursor = false;
ColorHistoryLimit = 20;
VisibleColorFormats = new Dictionary<string, KeyValuePair<bool, string>>();

View File

@ -11,9 +11,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ColorPickerPropertiesVersion1
{
public HotkeySettings DefaultActivationShortcut => new HotkeySettings(true, false, false, true, 0x43);
public ColorPickerPropertiesVersion1()
{
ActivationShortcut = new HotkeySettings(true, false, false, true, 0x43);
ActivationShortcut = DefaultActivationShortcut;
ChangeCursor = false;
ColorHistory = new List<string>();
ColorHistoryLimit = 20;

View File

@ -10,9 +10,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public class MeasureToolProperties
{
public HotkeySettings DefaultActivationShortcut => new HotkeySettings(true, false, false, true, 0x4D);
public MeasureToolProperties()
{
ActivationShortcut = new HotkeySettings(true, false, false, true, 0x4D);
ActivationShortcut = DefaultActivationShortcut;
UnitsOfMeasure = new IntProperty(0);
PixelTolerance = new IntProperty(30);
ContinuousCapture = false;

View File

@ -8,6 +8,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public class MouseHighlighterProperties
{
public HotkeySettings DefaultActivationShortcut => new HotkeySettings(true, false, false, true, 0x48);
[JsonPropertyName("activation_shortcut")]
public HotkeySettings ActivationShortcut { get; set; }
@ -31,7 +33,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public MouseHighlighterProperties()
{
ActivationShortcut = new HotkeySettings(true, false, false, true, 0x48);
ActivationShortcut = DefaultActivationShortcut;
LeftButtonClickColor = new StringProperty("#FFFF00");
RightButtonClickColor = new StringProperty("#0000FF");
HighlightOpacity = new IntProperty(65);

View File

@ -8,6 +8,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public class MouseJumpProperties
{
public HotkeySettings DefaultActivationShortcut => new HotkeySettings(true, false, false, true, 0x44);
[JsonPropertyName("activation_shortcut")]
public HotkeySettings ActivationShortcut { get; set; }
@ -16,7 +18,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public MouseJumpProperties()
{
ActivationShortcut = new HotkeySettings(true, false, false, true, 0x44);
ActivationShortcut = DefaultActivationShortcut;
ThumbnailSize = new MouseJumpThumbnailSize();
}
}

View File

@ -8,6 +8,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public class MousePointerCrosshairsProperties
{
public HotkeySettings DefaultActivationShortcut => new HotkeySettings(true, false, true, false, 0x50); // Win + Alt + P
[JsonPropertyName("activation_shortcut")]
public HotkeySettings ActivationShortcut { get; set; }
@ -31,7 +33,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public MousePointerCrosshairsProperties()
{
ActivationShortcut = new HotkeySettings(true, false, true, false, 0x50); // Win + Alt + P
ActivationShortcut = DefaultActivationShortcut;
CrosshairsColor = new StringProperty("#FF0000");
CrosshairsOpacity = new IntProperty(75);
CrosshairsRadius = new IntProperty(20);

View File

@ -8,9 +8,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public class PastePlainProperties
{
public HotkeySettings DefaultActivationShortcut => new HotkeySettings(true, true, true, false, 0x56); // Ctrl+Win+Alt+V
public PastePlainProperties()
{
ActivationShortcut = new HotkeySettings(true, true, true, false, 0x56); // Ctrl+Win+Alt+V
ActivationShortcut = DefaultActivationShortcut;
}
public HotkeySettings ActivationShortcut { get; set; }

View File

@ -8,9 +8,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public class PeekProperties
{
public HotkeySettings DefaultActivationShortcut => new HotkeySettings(false, true, false, false, 0x20);
public PeekProperties()
{
ActivationShortcut = new HotkeySettings(false, true, false, false, 0x20);
ActivationShortcut = DefaultActivationShortcut;
AlwaysRunNotElevated = new BoolProperty(true);
CloseAfterLosingFocus = new BoolProperty(false);
}

View File

@ -75,11 +75,17 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonPropertyName("generate_thumbnails_from_files")]
public bool GenerateThumbnailsFromFiles { get; set; }
public HotkeySettings DefaultOpenPowerLauncher => new HotkeySettings(false, false, true, false, 32);
public HotkeySettings DefaultOpenFileLocation => new HotkeySettings();
public HotkeySettings DefaultCopyPathLocation => new HotkeySettings();
public PowerLauncherProperties()
{
OpenPowerLauncher = new HotkeySettings(false, false, true, false, 32);
OpenFileLocation = new HotkeySettings();
CopyPathLocation = new HotkeySettings();
OpenPowerLauncher = DefaultOpenPowerLauncher;
OpenFileLocation = DefaultOpenFileLocation;
CopyPathLocation = DefaultCopyPathLocation;
OpenConsole = new HotkeySettings();
SearchResultPreference = "most_recently_used";
SearchTypePreference = "application_name";

View File

@ -8,9 +8,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public class PowerOcrProperties
{
public HotkeySettings DefaultActivationShortcut => new HotkeySettings(true, false, false, true, 0x54); // Win+Shift+T
public PowerOcrProperties()
{
ActivationShortcut = new HotkeySettings(true, false, false, true, 0x54); // Win+Shift+T
ActivationShortcut = DefaultActivationShortcut;
PreferredLanguage = string.Empty;
}

View File

@ -8,6 +8,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ShortcutGuideProperties
{
public HotkeySettings DefaultOpenShortcutGuide => new HotkeySettings(true, false, false, true, 0xBF);
public ShortcutGuideProperties()
{
OverlayOpacity = new IntProperty(90);
@ -16,7 +18,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
PressTimeForTaskbarIconShortcuts = new IntProperty(900);
Theme = new StringProperty("system");
DisabledApps = new StringProperty();
OpenShortcutGuide = new HotkeySettings(true, false, false, true, 0xBF);
OpenShortcutGuide = DefaultOpenShortcutGuide;
}
[JsonPropertyName("open_shortcutguide")]

View File

@ -9,10 +9,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
public class VideoConferenceConfigProperties
{
public VideoConferenceConfigProperties()
{
this.MuteCameraAndMicrophoneHotkey = new KeyboardKeysProperty(
new HotkeySettings()
public HotkeySettings DefaultMuteCameraAndMicrophoneHotkey => new HotkeySettings()
{
Win = true,
Ctrl = false,
@ -20,10 +17,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
Shift = true,
Key = "Q",
Code = 81,
});
};
this.MuteMicrophoneHotkey = new KeyboardKeysProperty(
new HotkeySettings()
public HotkeySettings DefaultMuteMicrophoneHotkey => new HotkeySettings()
{
Win = true,
Ctrl = false,
@ -31,10 +27,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
Shift = true,
Key = "A",
Code = 65,
});
};
this.PushToTalkMicrophoneHotkey = new KeyboardKeysProperty(
new HotkeySettings()
public HotkeySettings DefaultPushToTalkMicrophoneHotkey => new HotkeySettings()
{
Win = true,
Ctrl = false,
@ -42,10 +37,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
Shift = true,
Key = "I",
Code = 73,
});
};
this.MuteCameraHotkey = new KeyboardKeysProperty(
new HotkeySettings()
public HotkeySettings DefaultMuteCameraHotkey => new HotkeySettings()
{
Win = true,
Ctrl = false,
@ -53,9 +47,16 @@ namespace Microsoft.PowerToys.Settings.UI.Library
Shift = true,
Key = "O",
Code = 79,
});
};
this.PushToReverseEnabled = new BoolProperty(false);
public VideoConferenceConfigProperties()
{
MuteCameraAndMicrophoneHotkey = new KeyboardKeysProperty(DefaultMuteCameraAndMicrophoneHotkey);
MuteMicrophoneHotkey = new KeyboardKeysProperty(DefaultMuteMicrophoneHotkey);
PushToTalkMicrophoneHotkey = new KeyboardKeysProperty(DefaultPushToTalkMicrophoneHotkey);
MuteCameraHotkey = new KeyboardKeysProperty(DefaultMuteCameraHotkey);
PushToReverseEnabled = new BoolProperty(false);
}
[JsonPropertyName("mute_camera_and_microphone_hotkey")]

View File

@ -101,10 +101,12 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
Title = resourceLoader.GetString("Activation_Shortcut_Title"),
Content = c,
PrimaryButtonText = resourceLoader.GetString("Activation_Shortcut_Save"),
SecondaryButtonText = resourceLoader.GetString("Activation_Shortcut_Reset"),
CloseButtonText = resourceLoader.GetString("Activation_Shortcut_Cancel"),
DefaultButton = ContentDialogButton.Primary,
};
shortcutDialog.PrimaryButtonClick += ShortcutDialog_PrimaryButtonClick;
shortcutDialog.SecondaryButtonClick += ShortcutDialog_Reset;
shortcutDialog.Opened += ShortcutDialog_Opened;
shortcutDialog.Closing += ShortcutDialog_Closing;
AutomationProperties.SetName(EditButton, resourceLoader.GetString("Activation_Shortcut_Title"));
@ -355,6 +357,19 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
await shortcutDialog.ShowAsync();
}
private void ShortcutDialog_Reset(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
hotkeySettings = null;
SetValue(HotkeySettingsProperty, hotkeySettings);
PreviewKeysControl.ItemsSource = HotkeySettings.GetKeysList();
lastValidSettings = hotkeySettings;
AutomationProperties.SetHelpText(EditButton, HotkeySettings.ToString());
shortcutDialog.Hide();
}
private void ShortcutDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
if (ComboIsValid(lastValidSettings))

View File

@ -2471,6 +2471,9 @@ From there, simply click on one of the supported files in the File Explorer and
<data name="Activation_Shortcut_Description.Text" xml:space="preserve">
<value>Press a combination of keys to change this shortcut</value>
</data>
<data name="Activation_Shortcut_Reset" xml:space="preserve">
<value>Reset</value>
</data>
<data name="Activation_Shortcut_Save" xml:space="preserve">
<value>Save</value>
</data>

View File

@ -148,7 +148,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (_colorPickerSettings.Properties.ActivationShortcut != value)
{
_colorPickerSettings.Properties.ActivationShortcut = value;
_colorPickerSettings.Properties.ActivationShortcut = value ?? _colorPickerSettings.Properties.DefaultActivationShortcut;
OnPropertyChanged(nameof(ActivationShortcut));
NotifySettingsChanged();
}

View File

@ -209,7 +209,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (Settings.Properties.ActivationShortcut != value)
{
Settings.Properties.ActivationShortcut = value;
Settings.Properties.ActivationShortcut = value ?? Settings.Properties.DefaultActivationShortcut;
NotifyPropertyChanged();

View File

@ -427,7 +427,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (MouseHighlighterSettingsConfig.Properties.ActivationShortcut != value)
{
MouseHighlighterSettingsConfig.Properties.ActivationShortcut = value;
MouseHighlighterSettingsConfig.Properties.ActivationShortcut = value ?? MouseHighlighterSettingsConfig.Properties.DefaultActivationShortcut;
NotifyMouseHighlighterPropertyChanged();
}
}
@ -595,7 +595,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (MouseJumpSettingsConfig.Properties.ActivationShortcut != value)
{
MouseJumpSettingsConfig.Properties.ActivationShortcut = value;
MouseJumpSettingsConfig.Properties.ActivationShortcut = value ?? MouseJumpSettingsConfig.Properties.DefaultActivationShortcut;
NotifyMouseJumpPropertyChanged();
}
}
@ -676,7 +676,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (MousePointerCrosshairsSettingsConfig.Properties.ActivationShortcut != value)
{
MousePointerCrosshairsSettingsConfig.Properties.ActivationShortcut = value;
MousePointerCrosshairsSettingsConfig.Properties.ActivationShortcut = value ?? MousePointerCrosshairsSettingsConfig.Properties.DefaultActivationShortcut;
NotifyMousePointerCrosshairsPropertyChanged();
}
}

View File

@ -126,7 +126,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (_pastePlainSettings.Properties.ActivationShortcut != value)
{
_pastePlainSettings.Properties.ActivationShortcut = value;
_pastePlainSettings.Properties.ActivationShortcut = value ?? _pastePlainSettings.Properties.DefaultActivationShortcut;
OnPropertyChanged(nameof(ActivationShortcut));
OnPropertyChanged(nameof(IsConflictingCopyShortcut));

View File

@ -102,7 +102,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (_peekSettings.Properties.ActivationShortcut != value)
{
_peekSettings.Properties.ActivationShortcut = value;
_peekSettings.Properties.ActivationShortcut = value ?? _peekSettings.Properties.DefaultActivationShortcut;
OnPropertyChanged(nameof(ActivationShortcut));
NotifySettingsChanged();
}

View File

@ -319,7 +319,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (settings.Properties.OpenPowerLauncher != value)
{
settings.Properties.OpenPowerLauncher = value;
settings.Properties.OpenPowerLauncher = value ?? settings.Properties.DefaultOpenPowerLauncher;
UpdateSettings();
}
}
@ -455,7 +455,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (settings.Properties.OpenFileLocation != value)
{
settings.Properties.OpenFileLocation = value;
settings.Properties.OpenFileLocation = value ?? settings.Properties.DefaultOpenFileLocation;
UpdateSettings();
}
}
@ -472,7 +472,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (settings.Properties.CopyPathLocation != value)
{
settings.Properties.CopyPathLocation = value;
settings.Properties.CopyPathLocation = value ?? settings.Properties.DefaultCopyPathLocation;
UpdateSettings();
}
}

View File

@ -158,7 +158,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (_powerOcrSettings.Properties.ActivationShortcut != value)
{
_powerOcrSettings.Properties.ActivationShortcut = value;
_powerOcrSettings.Properties.ActivationShortcut = value ?? _powerOcrSettings.Properties.DefaultActivationShortcut;
OnPropertyChanged(nameof(ActivationShortcut));
_settingsUtils.SaveSettings(_powerOcrSettings.ToJsonString(), PowerOcrSettings.ModuleName);

View File

@ -138,7 +138,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (Settings.Properties.OpenShortcutGuide != value)
{
Settings.Properties.OpenShortcutGuide = value;
Settings.Properties.OpenShortcutGuide = value ?? Settings.Properties.DefaultOpenShortcutGuide;
NotifyPropertyChanged();
}
}

View File

@ -319,8 +319,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (value != _cameraAndMicrophoneMuteHotkey)
{
_cameraAndMicrophoneMuteHotkey = value;
Settings.Properties.MuteCameraAndMicrophoneHotkey.Value = value;
var hotkey = value ?? Settings.Properties.DefaultMuteCameraAndMicrophoneHotkey;
_cameraAndMicrophoneMuteHotkey = hotkey;
Settings.Properties.MuteCameraAndMicrophoneHotkey.Value = hotkey;
RaisePropertyChanged(nameof(CameraAndMicrophoneMuteHotkey));
}
}
@ -337,8 +338,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (value != _microphoneMuteHotkey)
{
_microphoneMuteHotkey = value;
Settings.Properties.MuteMicrophoneHotkey.Value = value;
var hotkey = value ?? Settings.Properties.DefaultMuteMicrophoneHotkey;
_microphoneMuteHotkey = hotkey;
Settings.Properties.MuteMicrophoneHotkey.Value = hotkey;
RaisePropertyChanged(nameof(MicrophoneMuteHotkey));
}
}
@ -355,8 +357,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (value != _microphonePushToTalkHotkey)
{
_microphonePushToTalkHotkey = value;
Settings.Properties.PushToTalkMicrophoneHotkey.Value = value;
var hotkey = value ?? Settings.Properties.DefaultMuteMicrophoneHotkey;
_microphonePushToTalkHotkey = hotkey;
Settings.Properties.PushToTalkMicrophoneHotkey.Value = hotkey;
RaisePropertyChanged(nameof(MicrophonePushToTalkHotkey));
}
}
@ -391,8 +394,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (value != _cameraMuteHotkey)
{
_cameraMuteHotkey = value;
Settings.Properties.MuteCameraHotkey.Value = value;
var hotkey = value ?? Settings.Properties.DefaultMuteCameraHotkey;
_cameraMuteHotkey = hotkey;
Settings.Properties.MuteCameraHotkey.Value = hotkey;
RaisePropertyChanged(nameof(CameraMuteHotkey));
}
}