Merge branch 'master' of https://github.com/microsoft/PowerToys into microsoft-master

This commit is contained in:
Den Delimarsky
2021-04-07 17:12:51 -07:00
610 changed files with 21033 additions and 18367 deletions

View File

@@ -23,5 +23,16 @@ namespace Microsoft.PowerToys.Settings.UI.Library
// By default JsonSerializer will only serialize the properties in the base class. This can be avoided by passing the object type (more details at https://stackoverflow.com/a/62498888)
return JsonSerializer.Serialize(this, GetType());
}
public override int GetHashCode()
{
return ToJsonString().GetHashCode();
}
public override bool Equals(object obj)
{
var settings = obj as BasePTModuleSettings;
return settings?.ToJsonString() == ToJsonString();
}
}
}

View File

@@ -12,6 +12,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
private string _name;
private string _example;
private bool _isShown;
private bool _canMoveUp = true;
private bool _canMoveDown = true;
public ColorFormatModel(string name, string example, bool isShown)
{
@@ -62,6 +64,34 @@ namespace Microsoft.PowerToys.Settings.UI.Library
}
}
public bool CanMoveUp
{
get
{
return _canMoveUp;
}
set
{
_canMoveUp = value;
OnPropertyChanged();
}
}
public bool CanMoveDown
{
get
{
return _canMoveDown;
}
set
{
_canMoveDown = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = null)

View File

@@ -14,5 +14,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
// Fancy Zones Default Flags.
public static readonly bool DefaultFancyzonesShiftDrag = true;
public static readonly bool DefaultUseCursorposEditorStartupscreen = true;
public static readonly bool DefaultFancyzonesQuickLayoutSwitch = true;
public static readonly bool DefaultFancyzonesFlashZonesOnQuickSwitch = true;
}
}

View File

@@ -24,6 +24,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
FancyzonesAppLastZoneMoveWindows = new BoolProperty();
FancyzonesOpenWindowOnActiveMonitor = new BoolProperty();
FancyzonesRestoreSize = new BoolProperty();
FancyzonesQuickLayoutSwitch = new BoolProperty(ConfigDefaults.DefaultFancyzonesQuickLayoutSwitch);
FancyzonesFlashZonesOnQuickSwitch = new BoolProperty(ConfigDefaults.DefaultFancyzonesFlashZonesOnQuickSwitch);
UseCursorposEditorStartupscreen = new BoolProperty(ConfigDefaults.DefaultUseCursorposEditorStartupscreen);
FancyzonesShowOnAllMonitors = new BoolProperty();
FancyzonesSpanZonesAcrossMonitors = new BoolProperty();
@@ -69,6 +71,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonPropertyName("fancyzones_restoreSize")]
public BoolProperty FancyzonesRestoreSize { get; set; }
[JsonPropertyName("fancyzones_quickLayoutSwitch")]
public BoolProperty FancyzonesQuickLayoutSwitch { get; set; }
[JsonPropertyName("fancyzones_flashZonesOnQuickSwitch")]
public BoolProperty FancyzonesFlashZonesOnQuickSwitch { get; set; }
[JsonPropertyName("use_cursorpos_editor_startupscreen")]
public BoolProperty UseCursorposEditorStartupscreen { get; set; }

View File

@@ -45,7 +45,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
<PackageReference Include="System.Text.Json" Version="5.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
<Version>3.3.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@@ -45,6 +45,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonPropertyName("theme")]
public Theme Theme { get; set; }
[JsonPropertyName("startupPosition")]
public StartupPosition Position { get; set; }
public PowerLauncherProperties()
{
OpenPowerLauncher = new HotkeySettings(false, false, true, false, 32);
@@ -57,6 +60,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
ClearInputOnLaunch = false;
MaximumNumberOfResults = 4;
Theme = Theme.System;
Position = StartupPosition.Cursor;
}
}
}

View File

@@ -54,7 +54,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
throw new FileNotFoundException();
}
// Given the file already exists, to deserialize the file and read it's content.
// Given the file already exists, to deserialize the file and read its content.
T deserializedSettings = GetFile<T>(powertoy, fileName);
// If the file needs to be modified, to save the new configurations accordingly.

View File

@@ -13,6 +13,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
OverlayOpacity = new IntProperty(90);
PressTime = new IntProperty(900);
Theme = new StringProperty("system");
DisabledApps = new StringProperty();
}
[JsonPropertyName("overlay_opacity")]
@@ -23,5 +24,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonPropertyName("theme")]
public StringProperty Theme { get; set; }
[JsonPropertyName("disabled_apps")]
public StringProperty DisabledApps { get; set; }
}
}

View File

@@ -247,11 +247,28 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
ColorFormats.Add(remainingColorFormat);
}
// Reordering colors with buttons: disable first and last buttons
ColorFormats[0].CanMoveUp = false;
ColorFormats[ColorFormats.Count - 1].CanMoveDown = false;
ColorFormats.CollectionChanged += ColorFormats_CollectionChanged;
}
private void ColorFormats_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
// Reordering colors with buttons: update buttons availability depending on order
if (ColorFormats.Count > 0)
{
foreach (var color in ColorFormats)
{
color.CanMoveUp = true;
color.CanMoveDown = true;
}
ColorFormats[0].CanMoveUp = false;
ColorFormats[ColorFormats.Count - 1].CanMoveDown = false;
}
UpdateColorFormats();
ScheduleSavingOfSettings();
}

View File

@@ -71,6 +71,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
_appLastZoneMoveWindows = Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value;
_openWindowOnActiveMonitor = Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value;
_restoreSize = Settings.Properties.FancyzonesRestoreSize.Value;
_quickLayoutSwitch = Settings.Properties.FancyzonesQuickLayoutSwitch.Value;
_flashZonesOnQuickLayoutSwitch = Settings.Properties.FancyzonesFlashZonesOnQuickSwitch.Value;
_useCursorPosEditorStartupScreen = Settings.Properties.UseCursorposEditorStartupscreen.Value;
_showOnAllMonitors = Settings.Properties.FancyzonesShowOnAllMonitors.Value;
_spanZonesAcrossMonitors = Settings.Properties.FancyzonesSpanZonesAcrossMonitors.Value;
@@ -107,6 +109,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
private bool _openWindowOnActiveMonitor;
private bool _spanZonesAcrossMonitors;
private bool _restoreSize;
private bool _quickLayoutSwitch;
private bool _flashZonesOnQuickLayoutSwitch;
private bool _useCursorPosEditorStartupScreen;
private bool _showOnAllMonitors;
private bool _makeDraggedWindowTransparent;
@@ -138,6 +142,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
SendConfigMSG(snd.ToString());
OnPropertyChanged(nameof(IsEnabled));
OnPropertyChanged(nameof(SnapHotkeysCategoryEnabled));
OnPropertyChanged(nameof(QuickSwitchEnabled));
}
}
}
@@ -150,6 +155,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
}
}
public bool QuickSwitchEnabled
{
get
{
return _isEnabled && _quickLayoutSwitch;
}
}
public bool ShiftDrag
{
get
@@ -374,6 +387,43 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
}
}
public bool QuickLayoutSwitch
{
get
{
return _quickLayoutSwitch;
}
set
{
if (value != _quickLayoutSwitch)
{
_quickLayoutSwitch = value;
Settings.Properties.FancyzonesQuickLayoutSwitch.Value = value;
NotifyPropertyChanged();
OnPropertyChanged(nameof(QuickSwitchEnabled));
}
}
}
public bool FlashZonesOnQuickSwitch
{
get
{
return _flashZonesOnQuickLayoutSwitch;
}
set
{
if (value != _flashZonesOnQuickLayoutSwitch)
{
_flashZonesOnQuickLayoutSwitch = value;
Settings.Properties.FancyzonesFlashZonesOnQuickSwitch.Value = value;
NotifyPropertyChanged();
}
}
}
public bool UseCursorPosEditorStartupScreen
{
get

View File

@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
@@ -22,9 +21,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
private bool _isLightThemeRadioButtonChecked;
private bool _isSystemThemeRadioButtonChecked;
private GeneralSettings GeneralSettingsConfig { get; set; }
private bool _isCursorPositionRadioButtonChecked;
private bool _isPrimaryMonitorPositionRadioButtonChecked;
private bool _isFocusPositionRadioButtonChecked;
private readonly ISettingsUtils _settingsUtils;
private GeneralSettings GeneralSettingsConfig { get; set; }
private PowerLauncherSettings settings;
@@ -36,9 +37,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
private Func<string, int> SendConfigMSG { get; }
public PowerLauncherViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, int defaultKeyCode, Func<bool> isDark)
public PowerLauncherViewModel(PowerLauncherSettings settings, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, Func<bool> isDark)
{
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
if (settings == null)
{
throw new ArgumentException("settings argument can not be null");
}
this.settings = settings;
this.isDark = isDark;
// To obtain the general Settings configurations of PowerToys
@@ -51,7 +57,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
// set the callback functions value to hangle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
callback = (PowerLauncherSettings settings) =>
callback = (PowerLauncherSettings s) =>
{
// Propagate changes to Power Launcher through IPC
// Using InvariantCulture as this is an IPC message
@@ -60,22 +66,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
CultureInfo.InvariantCulture,
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
PowerLauncherSettings.ModuleName,
JsonSerializer.Serialize(settings)));
JsonSerializer.Serialize(s)));
};
if (_settingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
{
settings = _settingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
}
else
{
settings = new PowerLauncherSettings();
settings.Properties.OpenPowerLauncher.Alt = true;
settings.Properties.OpenPowerLauncher.Code = defaultKeyCode;
settings.Properties.MaximumNumberOfResults = 4;
callback(settings);
}
switch (settings.Properties.Theme)
{
case Theme.Light:
@@ -89,6 +82,19 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
break;
}
switch (settings.Properties.Position)
{
case StartupPosition.Cursor:
_isCursorPositionRadioButtonChecked = true;
break;
case StartupPosition.PrimaryMonitor:
_isPrimaryMonitorPositionRadioButtonChecked = true;
break;
case StartupPosition.Focus:
_isFocusPositionRadioButtonChecked = true;
break;
}
foreach (var plugin in Plugins)
{
plugin.PropertyChanged += OnPluginInfoChange;
@@ -129,6 +135,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
GeneralSettingsConfig.Enabled.PowerLauncher = value;
OnPropertyChanged(nameof(EnablePowerLauncher));
OnPropertyChanged(nameof(ShowAllPluginsDisabledWarning));
OnPropertyChanged(nameof(ShowPluginsLoadingMessage));
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
SendConfigMSG(outgoing.ToString());
}
@@ -243,6 +250,60 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
}
}
public bool IsCursorPositionRadioButtonChecked
{
get
{
return _isCursorPositionRadioButtonChecked;
}
set
{
if (value == true)
{
settings.Properties.Position = StartupPosition.Cursor;
_isCursorPositionRadioButtonChecked = value;
UpdateSettings();
}
}
}
public bool IsPrimaryMonitorPositionRadioButtonChecked
{
get
{
return _isPrimaryMonitorPositionRadioButtonChecked;
}
set
{
if (value == true)
{
settings.Properties.Position = StartupPosition.PrimaryMonitor;
_isPrimaryMonitorPositionRadioButtonChecked = value;
UpdateSettings();
}
}
}
public bool IsFocusPositionRadioButtonChecked
{
get
{
return _isFocusPositionRadioButtonChecked;
}
set
{
if (value == true)
{
settings.Properties.Position = StartupPosition.Focus;
_isFocusPositionRadioButtonChecked = value;
UpdateSettings();
}
}
}
public HotkeySettings OpenPowerLauncher
{
get
@@ -379,7 +440,17 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
public bool ShowAllPluginsDisabledWarning
{
get => EnablePowerLauncher && Plugins.All(x => x.Disabled);
get => EnablePowerLauncher && Plugins.Any() && Plugins.All(x => x.Disabled);
}
public bool ShowPluginsLoadingMessage
{
get => EnablePowerLauncher && !Plugins.Any();
}
public bool IsUpToDate(PowerLauncherSettings settings)
{
return this.settings.Equals(settings);
}
}
}

View File

@@ -20,6 +20,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
private Func<string, int> SendConfigMSG { get; }
private string _settingsConfigFileFolder = string.Empty;
private string _disabledApps;
public ShortcutGuideViewModel(ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<ShortcutGuideSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
{
@@ -49,6 +50,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
_isEnabled = GeneralSettingsConfig.Enabled.ShortcutGuide;
_pressTime = Settings.Properties.PressTime.Value;
_opacity = Settings.Properties.OverlayOpacity.Value;
_disabledApps = Settings.Properties.DisabledApps.Value;
string theme = Settings.Properties.Theme.Value;
@@ -170,6 +172,24 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
}
}
public string DisabledApps
{
get
{
return _disabledApps;
}
set
{
if (value != _disabledApps)
{
_disabledApps = value;
Settings.Properties.DisabledApps.Value = value;
NotifyPropertyChanged();
}
}
}
public string GetSettingsSubPath()
{
return _settingsConfigFileFolder + "\\" + ModuleName;