Merge branch 'master' into users/niels9001/settings-accesbilitynarratorsupportforshortcutcontrol

This commit is contained in:
Niels Laute
2020-10-23 16:16:09 +02:00
committed by GitHub
446 changed files with 7966 additions and 4126 deletions

View File

@@ -2,10 +2,11 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class AppSpecificKeysDataModel : KeysDataModel
{
@@ -24,7 +25,15 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
public bool Compare(AppSpecificKeysDataModel arg)
{
return OriginalKeys.Equals(arg.OriginalKeys) && NewRemapKeys.Equals(arg.NewRemapKeys) && TargetApp.Equals(arg.TargetApp);
if (arg == null)
{
throw new ArgumentNullException(nameof(arg));
}
// Using Ordinal comparison for internal text
return OriginalKeys.Equals(arg.OriginalKeys, StringComparison.Ordinal) &&
NewRemapKeys.Equals(arg.NewRemapKeys, StringComparison.Ordinal) &&
TargetApp.Equals(arg.TargetApp, StringComparison.Ordinal);
}
}
}

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public abstract class BasePTModuleSettings
{

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class BoolProperty
{

View File

@@ -6,7 +6,7 @@ using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class BoolPropertyJsonConverter : JsonConverter<bool>
{

View File

@@ -5,12 +5,34 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public enum ColorRepresentationType
{
/// <summary>
/// Color presentation as hexadecimal color value without the alpha-value (e.g. #0055FF)
/// </summary>
HEX = 0,
/// <summary>
/// Color presentation as RGB color value (red[0..255], green[0..255], blue[0..255])
/// </summary>
RGB = 1,
/// <summary>
/// Color presentation as CMYK color value (cyan[0%..100%], magenta[0%..100%], yellow[0%..100%], black key[0%..100%])
/// </summary>
CMYK = 2,
/// <summary>
/// Color presentation as HSL color value (hue[0°..360°], saturation[0..100%], lightness[0%..100%])
/// </summary>
HSL = 3,
/// <summary>
/// Color presentation as HSV color value (hue[0°..360°], saturation[0%..100%], value[0%..100%])
/// </summary>
HSV = 4,
}
public class ColorPickerProperties
@@ -31,8 +53,6 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
public ColorRepresentationType CopiedColorRepresentation { get; set; }
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
=> JsonSerializer.Serialize(this);
}
}

View File

@@ -2,11 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ColorPickerSettings : BasePTModuleSettings, ISettingsConfig
{
@@ -30,6 +31,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
WriteIndented = true,
};
if (settingsUtils == null)
{
throw new ArgumentNullException(nameof(settingsUtils));
}
settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
}

View File

@@ -2,7 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public static class ConfigDefaults
{

View File

@@ -4,7 +4,7 @@
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
namespace Microsoft.PowerToys.Settings.UI.Library.CustomAction
{
public class CustomActionDataModel
{

View File

@@ -5,7 +5,7 @@
using System;
using System.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
namespace Microsoft.PowerToys.Settings.UI.Library.CustomAction
{
public class CustomNamePolicy : JsonNamingPolicy
{

View File

@@ -2,7 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
namespace Microsoft.PowerToys.Settings.UI.Library.CustomAction
{
public class ModuleCustomAction
{

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
namespace Microsoft.PowerToys.Settings.UI.Library.CustomAction
{
public class SendCustomAction
{
@@ -25,7 +25,8 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.CustomAction
{
PropertyNamingPolicy = new CustomNamePolicy((propertyName) =>
{
return propertyName.Equals("ModuleAction") ? moduleName : propertyName;
// Using Ordinal as this is an internal property name
return propertyName.Equals("ModuleAction", System.StringComparison.Ordinal) ? moduleName : propertyName;
}),
};

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
// Represents the configuration property of the settings that store Double type.
public class DoubleProperty

View File

@@ -8,7 +8,7 @@ using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.Telemetry;
using Microsoft.PowerToys.Telemetry;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class EnabledModules
{

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class FZConfigProperties
{

View File

@@ -3,9 +3,9 @@
// See the LICENSE file in the project root for more information.
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class FancyZonesSettings : BasePTModuleSettings, ISettingsConfig
{

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class FancyZonesSettingsIPCMessage
{

View File

@@ -3,12 +3,13 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class GeneralSettings : ISettingsConfig
{
@@ -53,6 +54,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
[JsonPropertyName("download_updates_automatically")]
public bool AutoDownloadUpdates { get; set; }
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Any error from calling interop code should not prevent the program from loading.")]
public GeneralSettings()
{
Packaged = false;
@@ -66,8 +68,9 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
{
PowertoysVersion = DefaultPowertoysVersion();
}
catch
catch (Exception e)
{
Logger.LogError("Exception encountered when getting PowerToys version", e);
PowertoysVersion = "v0.0.0";
}

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class GeneralSettingsCustomAction
{

View File

@@ -4,7 +4,7 @@
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class GenericProperty<T>
{

View File

@@ -5,7 +5,7 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Microsoft.PowerToys.Settings.UI.Lib.Helpers
namespace Microsoft.PowerToys.Settings.UI.Library.Helpers
{
public class Observable : INotifyPropertyChanged
{

View File

@@ -4,9 +4,9 @@
using System.Text;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class HotkeySettings
{

View File

@@ -3,9 +3,10 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using interop;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public delegate void KeyEvent(int key);
@@ -13,17 +14,19 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
public delegate bool FilterAccessibleKeyboardEvents(int key, UIntPtr extraInfo);
public class HotkeySettingsControlHook
public class HotkeySettingsControlHook : IDisposable
{
private const int WmKeyDown = 0x100;
private const int WmKeyUp = 0x101;
private const int WmSysKeyDown = 0x0104;
private const int WmSysKeyUp = 0x0105;
[SuppressMessage("Usage", "CA2213:Disposable fields should be disposed", Justification = "This class conforms to the IDisposable pattern, and the Dispose and C++ destructor does get called when debugging. Looks like a false positive from FxCop.")]
private KeyboardHook _hook;
private KeyEvent _keyDown;
private KeyEvent _keyUp;
private IsActive _isActive;
private bool disposedValue;
private FilterAccessibleKeyboardEvents _filterKeyboardEvent;
@@ -62,10 +65,24 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
return _filterKeyboardEvent(ev.key, (UIntPtr)ev.dwExtraInfo);
}
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
// Dispose the KeyboardHook object to terminate the hook threads
_hook.Dispose();
}
disposedValue = true;
}
}
public void Dispose()
{
// Dispose the KeyboardHook object to terminate the hook threads
_hook.Dispose();
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

View File

@@ -2,9 +2,9 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public interface ISettingsUtils
{

View File

@@ -6,7 +6,7 @@ using System.Collections.ObjectModel;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ImageResizerProperties
{

View File

@@ -4,9 +4,9 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ImageResizerSettings : BasePTModuleSettings, ISettingsConfig
{

View File

@@ -2,12 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ImageSize : INotifyPropertyChanged
{
@@ -222,6 +223,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
public void Update(ImageSize modifiedSize)
{
if (modifiedSize == null)
{
throw new ArgumentNullException(nameof(modifiedSize));
}
Id = modifiedSize.Id;
Name = modifiedSize.Name;
Fit = modifiedSize.Fit;

View File

@@ -4,7 +4,7 @@
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ImagerResizerKeepDateModified
{

View File

@@ -4,7 +4,7 @@
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ImageResizerCustomSizeProperty
{

View File

@@ -4,7 +4,7 @@
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ImageResizerFallbackEncoder
{

View File

@@ -6,12 +6,17 @@ using System.Collections.ObjectModel;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ImageResizerSizes
{
// Suppressing this warning because removing the setter breaks
// deserialization with System.Text.Json. This affects the UI display.
// See: https://github.com/dotnet/runtime/issues/30258
[JsonPropertyName("value")]
#pragma warning disable CA2227 // Collection properties should be read only
public ObservableCollection<ImageSize> Value { get; set; }
#pragma warning restore CA2227 // Collection properties should be read only
public ImageResizerSizes()
{

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
// Represents the configuration property of the settings that store Integer type.
public class IntProperty

View File

@@ -2,7 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.Settings.UI.Lib.Interface
namespace Microsoft.PowerToys.Settings.UI.Library.Interfaces
{
// Common interface to be implemented by all the objects which get and store settings properties.
public interface ISettingsConfig

View File

@@ -2,7 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.Settings.UI.Lib.Interface
namespace Microsoft.PowerToys.Settings.UI.Library.Interfaces
{
public interface ISettingsRepository<T>
{

View File

@@ -4,7 +4,7 @@
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class KeyboardKeysProperty
{

View File

@@ -4,9 +4,9 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class KeyboardManagerProfile : ISettingsConfig
{

View File

@@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class KeyboardManagerProperties
{

View File

@@ -3,9 +3,9 @@
// See the LICENSE file in the project root for more information.
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class KeyboardManagerSettings : BasePTModuleSettings, ISettingsConfig
{

View File

@@ -6,9 +6,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class KeysDataModel
{

View File

@@ -8,13 +8,14 @@
<Version>$(Version).0</Version>
<Authors>Microsoft Corporation</Authors>
<Product>PowerToys</Product>
<Description>PowerToys Settings UI Lib</Description>
<Description>PowerToys Settings UI Library</Description>
<Copyright>Copyright (C) 2020 Microsoft Corporation</Copyright>
<RepositoryUrl>https://github.com/microsoft/PowerToys</RepositoryUrl>
<RepositoryType>Github</RepositoryType>
<PackageTags>PowerToys</PackageTags>
<NeutralLanguage>en-US</NeutralLanguage>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyName>Microsoft.PowerToys.Settings.UI.Lib</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -41,6 +42,11 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="4.7.2" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
<Version>3.3.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class OutGoingGeneralSettings
{

View File

@@ -4,7 +4,7 @@
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class PowerLauncherProperties
{

View File

@@ -2,11 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class PowerLauncherSettings : BasePTModuleSettings, ISettingsConfig
{
@@ -30,6 +31,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
WriteIndented = true,
};
if (settingsUtils == null)
{
throw new ArgumentNullException(nameof(settingsUtils));
}
settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
}

View File

@@ -8,7 +8,7 @@ using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.Telemetry;
using Microsoft.PowerToys.Telemetry;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class PowerPreviewProperties
{

View File

@@ -3,9 +3,9 @@
// See the LICENSE file in the project root for more information.
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class PowerPreviewSettings : BasePTModuleSettings, ISettingsConfig
{

View File

@@ -3,9 +3,9 @@
// See the LICENSE file in the project root for more information.
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class PowerRenameLocalProperties : ISettingsConfig
{

View File

@@ -4,7 +4,7 @@
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class PowerRenameProperties
{

View File

@@ -2,10 +2,11 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class PowerRenameSettings : BasePTModuleSettings, ISettingsConfig
{
@@ -23,6 +24,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
public PowerRenameSettings(PowerRenameLocalProperties localProperties)
{
if (localProperties == null)
{
throw new ArgumentNullException(nameof(localProperties));
}
Properties = new PowerRenameProperties();
Properties.PersistState.Value = localProperties.PersistState;
Properties.MRUEnabled.Value = localProperties.MRUEnabled;

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class PowerRenameSettingsIPCMessage
{

View File

@@ -6,12 +6,17 @@ using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class RemapKeysDataModel
{
// Suppressing this warning because removing the setter breaks
// deserialization with System.Text.Json. This affects the UI display.
// See: https://github.com/dotnet/runtime/issues/30258
[JsonPropertyName("inProcess")]
#pragma warning disable CA2227 // Collection properties should be read only
public List<KeysDataModel> InProcessRemapKeys { get; set; }
#pragma warning restore CA2227 // Collection properties should be read only
public RemapKeysDataModel()
{

View File

@@ -3,9 +3,9 @@
// See the LICENSE file in the project root for more information.
using System;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
// This Singleton class is a wrapper around the settings configurations that are accessed by viewmodels.
// This class can have only one instance and therefore the settings configurations are common to all.
@@ -20,7 +20,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
private T settingsConfig;
// Suppressing the warning as this is a singleton class and this method is
// necessarily static
#pragma warning disable CA1000 // Do not declare static members on generic types
public static SettingsRepository<T> GetInstance(ISettingsUtils settingsUtils)
#pragma warning restore CA1000 // Do not declare static members on generic types
{
// To ensure that only one instance of Settings Repository is created in a multi-threaded environment.
lock (_SettingsRepoLock)

View File

@@ -3,11 +3,13 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class SettingsUtils : ISettingsUtils
{
@@ -100,6 +102,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
}
// Save settings to a json file.
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "General exceptions will be logged until we can better understand runtime exception scenarios")]
public void SaveSettings(string jsonSettings, string powertoy = DefaultModuleName, string fileName = DefaultFileName)
{
try
@@ -114,8 +117,15 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
_ioProvider.WriteAllText(GetSettingsPath(powertoy, fileName), jsonSettings);
}
}
catch
catch (Exception e)
{
Logger.LogError($"Exception encountered while saving {powertoy} settings.", e);
#if DEBUG
if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
{
throw;
}
#endif
}
}

View File

@@ -4,7 +4,7 @@
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ShortcutGuideProperties
{

View File

@@ -3,9 +3,9 @@
// See the LICENSE file in the project root for more information.
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ShortcutGuideSettings : BasePTModuleSettings, ISettingsConfig
{

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ShortcutGuideSettingsIPCMessage
{

View File

@@ -6,15 +6,22 @@ using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class ShortcutsKeyDataModel
{
// Suppressing these warnings because removing the setter breaks
// deserialization with System.Text.Json. This affects the UI display.
// See: https://github.com/dotnet/runtime/issues/30258
[JsonPropertyName("global")]
#pragma warning disable CA2227 // Collection properties should be read only
public List<KeysDataModel> GlobalRemapShortcuts { get; set; }
#pragma warning restore CA2227 // Collection properties should be read only
[JsonPropertyName("appSpecific")]
#pragma warning disable CA2227 // Collection properties should be read only
public List<AppSpecificKeysDataModel> AppSpecificRemapShortcuts { get; set; }
#pragma warning restore CA2227 // Collection properties should be read only
public ShortcutsKeyDataModel()
{

View File

@@ -4,7 +4,7 @@
using System.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class SndFancyZonesSettings
{

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class SndImageResizerSettings
{

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class SndKeyboardManagerSettings
{

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
// Represents a powertoys module settings setnt to the runner.
public class SndModuleSettings<T>

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class SndPowerPreviewSettings
{

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class SndPowerRenameSettings
{

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class SndShortcutGuideSettings
{

View File

@@ -5,7 +5,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.Lib
namespace Microsoft.PowerToys.Settings.UI.Library
{
// Represents the configuration property of the settings that store string type.
public class StringProperty

View File

@@ -7,9 +7,9 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.PowerToys.Settings.UI.Lib.CustomAction;
using Microsoft.PowerToys.Settings.UI.Library.CustomAction;
namespace Microsoft.PowerToys.Settings.UI.Lib.Utilities
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
{
public static class Helper
{
@@ -92,6 +92,15 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.Utilities
{
// Split up the version strings into int[]
// Example: v10.0.2 -> {10, 0, 2};
if (version1 == null)
{
throw new ArgumentNullException(nameof(version1));
}
else if (version2 == null)
{
throw new ArgumentNullException(nameof(version2));
}
var v1 = version1.Substring(1).Split('.').Select(int.Parse).ToArray();
var v2 = version2.Substring(1).Split('.').Select(int.Parse).ToArray();

View File

@@ -2,7 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.Settings.UI.Lib.Utilities
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
{
public interface IIOProvider
{

View File

@@ -0,0 +1,65 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
{
public static class Logger
{
private static readonly string ApplicationLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\Settings Logs");
static Logger()
{
if (!Directory.Exists(ApplicationLogPath))
{
Directory.CreateDirectory(ApplicationLogPath);
}
var logFilePath = Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
Trace.AutoFlush = true;
}
public static void LogInfo(string message)
{
Log(message, "INFO");
}
public static void LogError(string message, Exception e)
{
Log(
message + Environment.NewLine +
e?.Message + Environment.NewLine +
"Inner exception: " + Environment.NewLine +
e?.InnerException?.Message + Environment.NewLine +
"Stack trace: " + Environment.NewLine +
e?.StackTrace,
"ERROR");
}
private static void Log(string message, string type)
{
Trace.WriteLine(type + ": " + DateTime.Now.TimeOfDay);
Trace.Indent();
Trace.WriteLine(GetCallerInfo());
Trace.WriteLine(message);
Trace.Unindent();
}
private static string GetCallerInfo()
{
StackTrace stackTrace = new StackTrace();
var methodName = stackTrace.GetFrame(3)?.GetMethod();
var className = methodName?.DeclaringType.Name;
return "[Method]: " + methodName?.Name + " [Class]: " + className;
}
}
}

View File

@@ -7,7 +7,7 @@ using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace Microsoft.PowerToys.Settings.UI.Lib.Utilities
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
{
internal static class NativeMethods
{

View File

@@ -4,7 +4,7 @@
using System.IO;
namespace Microsoft.PowerToys.Settings.UI.Lib.Utilities
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
{
public class SystemIOProvider : IIOProvider
{

View File

@@ -3,11 +3,12 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{
public class ColorPickerViewModel : Observable
{
@@ -24,6 +25,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
public ColorPickerViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
{
// Obtain the general PowerToy settings configurations
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
}
GeneralSettingsConfig = settingsRepository.SettingsConfig;
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
@@ -121,8 +127,13 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
private void NotifySettingsChanged()
{
// Using InvariantCulture as this is an IPC message
SendConfigMSG(
string.Format("{{ \"powertoys\": {{ \"{0}\": {1} }} }}", ColorPickerSettings.ModuleName, JsonSerializer.Serialize(_colorPickerSettings)));
string.Format(
CultureInfo.InvariantCulture,
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
ColorPickerSettings.ModuleName,
JsonSerializer.Serialize(_colorPickerSettings)));
}
}
}

View File

@@ -5,7 +5,7 @@
using System;
using System.Windows.Input;
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels.Commands
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands
{
public class ButtonClickCommand : ICommand
{

View File

@@ -5,7 +5,7 @@
using System;
using System.Windows.Input;
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels.Commands
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands
{
public class RelayCommand : ICommand
{

View File

@@ -5,7 +5,7 @@
using System;
using System.Windows.Input;
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels.Commands
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands
{
public class RelayCommand<T> : ICommand
{

View File

@@ -4,12 +4,13 @@
using System;
using System.Drawing;
using System.Globalization;
using System.Runtime.CompilerServices;
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels.Commands;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{
public class FancyZonesViewModel : Observable
{
@@ -28,10 +29,20 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
public FancyZonesViewModel(ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<FancyZonesSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
{
// To obtain the general settings configurations of PowerToys Settings.
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
}
GeneralSettingsConfig = settingsRepository.SettingsConfig;
settingsConfigFileFolder = configFileSubfolder;
// To obtain the settings configurations of Fancy zones.
if (moduleSettingsRepository == null)
{
throw new ArgumentNullException(nameof(moduleSettingsRepository));
}
Settings = moduleSettingsRepository.SettingsConfig;
LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);
@@ -137,7 +148,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_shiftDrag = value;
Settings.Properties.FancyzonesShiftDrag.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -155,7 +166,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_mouseSwitch = value;
Settings.Properties.FancyzonesMouseSwitch.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -178,7 +189,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_overrideSnapHotkeys = value;
Settings.Properties.FancyzonesOverrideSnapHotkeys.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
OnPropertyChanged(nameof(SnapHotkeysCategoryEnabled));
}
}
@@ -197,7 +208,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_moveWindowsAcrossMonitors = value;
Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -215,7 +226,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_moveWindowsBasedOnPosition = value;
Settings.Properties.FancyzonesMoveWindowsBasedOnPosition.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -233,7 +244,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_displayChangemoveWindows = value;
Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -251,7 +262,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_zoneSetChangeMoveWindows = value;
Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -269,7 +280,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_appLastZoneMoveWindows = value;
Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -287,7 +298,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_openWindowOnActiveMonitor = value;
Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -305,7 +316,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_restoreSize = value;
Settings.Properties.FancyzonesRestoreSize.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -323,7 +334,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_useCursorPosEditorStartupScreen = value;
Settings.Properties.UseCursorposEditorStartupscreen.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -341,7 +352,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_showOnAllMonitors = value;
Settings.Properties.FancyzonesShowOnAllMonitors.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -359,7 +370,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_spanZonesAcrossMonitors = value;
Settings.Properties.FancyzonesSpanZonesAcrossMonitors.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -377,11 +388,13 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_makeDraggedWindowTransparent = value;
Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
// For the following setters we use OrdinalIgnoreCase string comparison since
// we expect value to be a hex code.
public string ZoneHighlightColor
{
get
@@ -391,12 +404,15 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
set
{
value = ToRGBHex(value);
if (!value.Equals(_zoneHighlightColor))
// The fallback value is based on ToRGBHex's behavior, which returns
// #FFFFFF if any exceptions are encountered, e.g. from passing in a null value.
// This extra handling is added here to deal with FxCop warnings.
value = (value != null) ? ToRGBHex(value) : "#FFFFFF";
if (!value.Equals(_zoneHighlightColor, StringComparison.OrdinalIgnoreCase))
{
_zoneHighlightColor = value;
Settings.Properties.FancyzonesZoneHighlightColor.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -410,12 +426,15 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
set
{
value = ToRGBHex(value);
// The fallback value is based on ToRGBHex's behavior, which returns
// #FFFFFF if any exceptions are encountered, e.g. from passing in a null value.
// This extra handling is added here to deal with FxCop warnings.
value = (value != null) ? ToRGBHex(value) : "#FFFFFF";
if (!value.Equals(_zoneBorderColor, StringComparison.OrdinalIgnoreCase))
{
_zoneBorderColor = value;
Settings.Properties.FancyzonesBorderColor.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -429,12 +448,15 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
set
{
value = ToRGBHex(value);
if (!value.Equals(_zoneInActiveColor))
// The fallback value is based on ToRGBHex's behavior, which returns
// #FFFFFF if any exceptions are encountered, e.g. from passing in a null value.
// This extra handling is added here to deal with FxCop warnings.
value = (value != null) ? ToRGBHex(value) : "#FFFFFF";
if (!value.Equals(_zoneInActiveColor, StringComparison.OrdinalIgnoreCase))
{
_zoneInActiveColor = value;
Settings.Properties.FancyzonesInActiveColor.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -452,7 +474,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_highlightOpacity = value;
Settings.Properties.FancyzonesHighlightOpacity.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -468,7 +490,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
if (value != _editorHotkey)
{
if (value.IsEmpty())
if (value == null || value.IsEmpty())
{
_editorHotkey = FZConfigProperties.DefaultHotkeyValue;
}
@@ -478,7 +500,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
}
Settings.Properties.FancyzonesEditorHotkey.Value = _editorHotkey;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -496,7 +518,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_excludedApps = value;
Settings.Properties.FancyzonesExcludedApps.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -507,7 +529,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
SendConfigMSG("{\"action\":{\"FancyZones\":{\"action_name\":\"ToggledFZEditor\", \"value\":\"\"}}}");
}
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
OnPropertyChanged(propertyName);
if (SendConfigMSG != null)
@@ -520,13 +542,21 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
private static string ToRGBHex(string color)
{
try
// Using InvariantCulture as these are expected to be hex codes.
bool success = int.TryParse(
color.Replace("#", string.Empty),
System.Globalization.NumberStyles.HexNumber,
CultureInfo.InvariantCulture,
out int argb);
if (success)
{
int argb = int.Parse(color.Replace("#", string.Empty), System.Globalization.NumberStyles.HexNumber);
Color clr = Color.FromArgb(argb);
return "#" + clr.R.ToString("X2") + clr.G.ToString("X2") + clr.B.ToString("X2");
return "#" + clr.R.ToString("X2", CultureInfo.InvariantCulture) +
clr.G.ToString("X2", CultureInfo.InvariantCulture) +
clr.B.ToString("X2", CultureInfo.InvariantCulture);
}
catch (Exception)
else
{
return "#FFFFFF";
}

View File

@@ -3,13 +3,14 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels.Commands;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{
public class GeneralViewModel : Observable
{
@@ -39,6 +40,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
RestartElevatedButtonEventHandler = new ButtonClickCommand(RestartElevated);
// To obtain the general settings configuration of PowerToys if it exists, else to create a new file and return the default configurations.
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
}
GeneralSettingsConfig = settingsRepository.SettingsConfig;
// set the callback functions value to hangle outgoing IPC message.
@@ -48,20 +54,25 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
// set the callback function value to update the UI theme.
UpdateUIThemeCallBack = updateTheme;
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme.ToLower());
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
// Update Settings file folder:
_settingsConfigFileFolder = configFileSubfolder;
switch (GeneralSettingsConfig.Theme.ToLower())
// Using Invariant here as these are internal strings and fxcop
// expects strings to be normalized to uppercase. While the theme names
// are represented in lowercase everywhere else, we'll use uppercase
// normalization for switch statements
switch (GeneralSettingsConfig.Theme.ToUpperInvariant())
{
case "light":
case "LIGHT":
_isLightThemeRadioButtonChecked = true;
break;
case "dark":
case "DARK":
_isDarkThemeRadioButtonChecked = true;
break;
case "system":
case "SYSTEM":
_isSystemThemeRadioButtonChecked = true;
break;
}
@@ -102,7 +113,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
if (_packaged != value)
{
_packaged = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -121,7 +132,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_startup = value;
GeneralSettingsConfig.Startup = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -193,7 +204,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_runElevated = value;
GeneralSettingsConfig.RunElevated = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -220,11 +231,12 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_autoDownloadUpdates = value;
GeneralSettingsConfig.AutoDownloadUpdates = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "This may throw if the XAML page is not initialized in tests (https://github.com/microsoft/PowerToys/pull/2676)")]
public bool IsDarkThemeRadioButtonChecked
{
get
@@ -242,15 +254,17 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
}
catch
catch (Exception e)
{
Logger.LogError("Exception encountered when changing Settings theme", e);
}
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "This may throw if the XAML page is not initialized in tests (https://github.com/microsoft/PowerToys/pull/2676)")]
public bool IsLightThemeRadioButtonChecked
{
get
@@ -268,15 +282,17 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
}
catch
catch (Exception e)
{
Logger.LogError("Exception encountered when changing Settings theme", e);
}
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "This may throw if the XAML page is not initialized in tests (https://github.com/microsoft/PowerToys/pull/2676)")]
public bool IsSystemThemeRadioButtonChecked
{
get
@@ -294,11 +310,12 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
}
catch
catch (Exception e)
{
Logger.LogError("Exception encountered when changing Settings theme", e);
}
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -329,12 +346,12 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
if (_latestAvailableVersion != value)
{
_latestAvailableVersion = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
// Notify UI of property change
OnPropertyChanged(propertyName);

View File

@@ -5,11 +5,14 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{
public class ImageResizerViewModel : Observable
{
@@ -23,19 +26,32 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
private Func<string, int> SendConfigMSG { get; }
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions should not crash the program but will be logged until we can understand common exception scenarios")]
public ImageResizerViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
{
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
// To obtain the general settings configurations of PowerToys.
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
}
GeneralSettingsConfig = settingsRepository.SettingsConfig;
try
{
Settings = _settingsUtils.GetSettings<ImageResizerSettings>(ModuleName);
}
catch
catch (Exception e)
{
Logger.LogError($"Exception encountered while reading {ModuleName} settings.", e);
#if DEBUG
if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
{
throw;
}
#endif
Settings = new ImageResizerSettings();
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
}
@@ -92,13 +108,18 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
}
}
#pragma warning disable CA2227 // Collection properties should be read only
public ObservableCollection<ImageSize> Sizes
#pragma warning restore CA2227 // Collection properties should be read only
{
get
{
return _advancedSizes;
}
// FxCop demands collection properties to be read-only, but this
// setter is used in autogenerated files (ImageResizerPage.g.cs)
// and replacing the setter with its own method will break the file
set
{
SavesImageSizes(value);

View File

@@ -4,17 +4,18 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels.Commands;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{
public class KeyboardManagerViewModel : Observable
{
@@ -41,8 +42,14 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
private Func<List<KeysDataModel>, int> FilterRemapKeysList { get; }
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions should not crash the program but will be logged until we can understand common exception scenarios")]
public KeyboardManagerViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, Func<List<KeysDataModel>, int> filterRemapKeysList)
{
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
}
GeneralSettingsConfig = settingsRepository.SettingsConfig;
// set the callback functions value to hangle outgoing IPC message.
@@ -53,8 +60,20 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
if (_settingsUtils.SettingsExists(PowerToyName))
{
// Todo: Be more resilient while reading and saving settings.
Settings = _settingsUtils.GetSettings<KeyboardManagerSettings>(PowerToyName);
try
{
Settings = _settingsUtils.GetSettings<KeyboardManagerSettings>(PowerToyName);
}
catch (Exception e)
{
Logger.LogError($"Exception encountered while reading {PowerToyName} settings.", e);
#if DEBUG
if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
{
throw;
}
#endif
}
// Load profile.
if (!LoadProfile())
@@ -107,7 +126,22 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
public static List<AppSpecificKeysDataModel> CombineShortcutLists(List<KeysDataModel> globalShortcutList, List<AppSpecificKeysDataModel> appSpecificShortcutList)
{
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = "All Apps" }).Concat(appSpecificShortcutList).ToList();
if (globalShortcutList == null && appSpecificShortcutList == null)
{
return new List<AppSpecificKeysDataModel>();
}
else if (globalShortcutList == null)
{
return appSpecificShortcutList;
}
else if (appSpecificShortcutList == null)
{
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = "All Apps" }).ToList();
}
else
{
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = "All Apps" }).Concat(appSpecificShortcutList).ToList();
}
}
public List<AppSpecificKeysDataModel> RemapShortcuts
@@ -129,28 +163,31 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
public ICommand EditShortcutCommand => _editShortcutCommand ?? (_editShortcutCommand = new RelayCommand(OnEditShortcut));
// Note: FxCop suggests calling ConfigureAwait() for the following methods,
// and calling ConfigureAwait(true) has the same behavior as not explicitly
// calling it (continuations are scheduled on the task-creating thread)
private async void OnRemapKeyboard()
{
await Task.Run(() => OnRemapKeyboardBackground());
await Task.Run(() => OnRemapKeyboardBackground()).ConfigureAwait(true);
}
private async void OnEditShortcut()
{
await Task.Run(() => OnEditShortcutBackground());
await Task.Run(() => OnEditShortcutBackground()).ConfigureAwait(true);
}
private async Task OnRemapKeyboardBackground()
{
Helper.AllowRunnerToForeground();
SendConfigMSG(Helper.GetSerializedCustomAction(PowerToyName, RemapKeyboardActionName, RemapKeyboardActionValue));
await Task.CompletedTask;
await Task.CompletedTask.ConfigureAwait(true);
}
private async Task OnEditShortcutBackground()
{
Helper.AllowRunnerToForeground();
SendConfigMSG(Helper.GetSerializedCustomAction(PowerToyName, EditShortcutActionName, EditShortcutActionValue));
await Task.CompletedTask;
await Task.CompletedTask.ConfigureAwait(true);
}
public void NotifyFileChanged()
@@ -159,6 +196,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
OnPropertyChanged(nameof(RemapShortcuts));
}
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions here (especially mutex errors) should not halt app execution, but they will be logged.")]
public bool LoadProfile()
{
var success = true;
@@ -198,9 +236,10 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
}
}
}
catch (Exception)
catch (Exception e)
{
// Failed to load the configuration.
Logger.LogError($"Exception encountered when loading {PowerToyName} profile", e);
success = false;
}

View File

@@ -3,12 +3,13 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{
public class PowerLauncherViewModel : Observable
{
@@ -29,6 +30,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
// To obtain the general Settings configurations of PowerToys
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
}
GeneralSettingsConfig = settingsRepository.SettingsConfig;
// set the callback functions value to hangle outgoing IPC message.
@@ -36,8 +42,13 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
callback = (PowerLauncherSettings settings) =>
{
// Propagate changes to Power Launcher through IPC
// Using InvariantCulture as this is an IPC message
SendConfigMSG(
string.Format("{{ \"powertoys\": {{ \"{0}\": {1} }} }}", PowerLauncherSettings.ModuleName, JsonSerializer.Serialize(settings)));
string.Format(
CultureInfo.InvariantCulture,
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
PowerLauncherSettings.ModuleName,
JsonSerializer.Serialize(settings)));
};
if (_settingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))

View File

@@ -4,10 +4,10 @@
using System;
using System.Runtime.CompilerServices;
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{
public class PowerPreviewViewModel : Observable
{
@@ -27,10 +27,20 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
_settingsConfigFileFolder = configFileSubfolder;
// To obtain the general Settings configurations of PowerToys
if (generalSettingsRepository == null)
{
throw new ArgumentNullException(nameof(generalSettingsRepository));
}
GeneralSettingsConfig = generalSettingsRepository.SettingsConfig;
// To obtain the PowerPreview settings if it exists.
// If the file does not exist, to create a new one and return the default settings configurations.
if (moduleSettingsRepository == null)
{
throw new ArgumentNullException(nameof(moduleSettingsRepository));
}
Settings = moduleSettingsRepository.SettingsConfig;
// set the callback functions value to hangle outgoing IPC message.

View File

@@ -3,11 +3,14 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.CompilerServices;
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{
public class PowerRenameViewModel : Observable
{
@@ -23,12 +26,18 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
private Func<string, int> SendConfigMSG { get; }
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions should not crash the program but will be logged until we can understand common exception scenarios")]
public PowerRenameViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
{
// Update Settings file folder:
_settingsConfigFileFolder = configFileSubfolder;
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
}
GeneralSettingsConfig = settingsRepository.SettingsConfig;
try
@@ -36,8 +45,15 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
PowerRenameLocalProperties localSettings = _settingsUtils.GetSettings<PowerRenameLocalProperties>(GetSettingsSubPath(), "power-rename-settings.json");
Settings = new PowerRenameSettings(localSettings);
}
catch
catch (Exception e)
{
Logger.LogError($"Exception encountered while reading {ModuleName} settings.", e);
#if DEBUG
if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
{
throw;
}
#endif
PowerRenameLocalProperties localSettings = new PowerRenameLocalProperties();
Settings = new PowerRenameSettings(localSettings);
_settingsUtils.SaveSettings(localSettings.ToJsonString(), GetSettingsSubPath(), "power-rename-settings.json");

View File

@@ -4,10 +4,10 @@
using System;
using System.Runtime.CompilerServices;
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{
public class ShortcutGuideViewModel : Observable
{
@@ -27,10 +27,20 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
_settingsConfigFileFolder = configFileSubfolder;
// To obtain the general PowerToys settings.
if (settingsRepository == null)
{
throw new ArgumentNullException(nameof(settingsRepository));
}
GeneralSettingsConfig = settingsRepository.SettingsConfig;
// To obtain the shortcut guide settings, if the file exists.
// If not, to create a file with the default settings and to return the default configurations.
if (moduleSettingsRepository == null)
{
throw new ArgumentNullException(nameof(moduleSettingsRepository));
}
Settings = moduleSettingsRepository.SettingsConfig;
// set the callback functions value to hangle outgoing IPC message.
@@ -102,7 +112,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
// set theme to dark.
Settings.Properties.Theme.Value = "dark";
_themeIndex = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
if (value == 1)
@@ -110,7 +120,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
// set theme to light.
Settings.Properties.Theme.Value = "light";
_themeIndex = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
if (value == 2)
@@ -118,7 +128,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
// set theme to system default.
Settings.Properties.Theme.Value = "system";
_themeIndex = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -137,7 +147,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_pressTime = value;
Settings.Properties.PressTime.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -155,7 +165,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
_opacity = value;
Settings.Properties.OverlayOpacity.Value = value;
RaisePropertyChanged();
NotifyPropertyChanged();
}
}
}
@@ -165,7 +175,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
return _settingsConfigFileFolder + "\\" + ModuleName;
}
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
OnPropertyChanged(propertyName);
SndShortcutGuideSettings outsettings = new SndShortcutGuideSettings(Settings);

View File

@@ -30,6 +30,12 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
private void WindowsXamlHost_ChildChanged(object sender, EventArgs e)
{
// If sender is null, it could lead to a NullReferenceException. This might occur on restarting as admin (check https://github.com/microsoft/PowerToys/issues/7393 for details)
if (sender == null)
{
return;
}
// Hook up x:Bind source.
WindowsXamlHost windowsXamlHost = sender as WindowsXamlHost;
ShellPage shellPage = windowsXamlHost.GetUwpInternalObject() as ShellPage;

View File

@@ -75,7 +75,7 @@
<ProjectReference Include="..\..\common\interop\interop.vcxproj" />
<ProjectReference Include="..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\Telemetry.csproj" />
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj" />
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Library\Microsoft.PowerToys.Settings.UI.Library.csproj" />
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI\Microsoft.PowerToys.Settings.UI.csproj" />
</ItemGroup>

View File

@@ -1,6 +1,6 @@
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Moq;
using System;

View File

@@ -32,7 +32,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj" />
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Library\Microsoft.PowerToys.Settings.UI.Library.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,4 +1,4 @@
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Moq;
using System;
using System.Collections.Generic;

View File

@@ -1,5 +1,5 @@
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Moq;
using System;

View File

@@ -3,8 +3,8 @@
// See the LICENSE file in the project root for more information.
using System;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Microsoft.PowerToys.Settings.UnitTest;
using Microsoft.VisualStudio.TestTools.UnitTesting;

View File

@@ -2,8 +2,8 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.Interface;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UnitTest
{

View File

@@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CommonLibTest

View File

@@ -6,7 +6,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;

View File

@@ -6,8 +6,8 @@ using System;
using System.IO;
using System.Linq;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Microsoft.PowerToys.Settings.UnitTest;
using Microsoft.VisualStudio.TestTools.UnitTesting;

View File

@@ -5,8 +5,8 @@
using System.Globalization;
using System.IO;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

View File

@@ -8,8 +8,8 @@ using System.Globalization;
using System.IO;
using System.Text.Json;
using CommonLibTest;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

View File

@@ -6,8 +6,8 @@ using System;
using System.Globalization;
using System.IO;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

View File

@@ -7,9 +7,9 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

View File

@@ -4,8 +4,8 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ViewModelTests
@@ -41,6 +41,69 @@ namespace ViewModelTests
Assert.AreEqual(expectedResult.Count, result.Count);
}
[TestMethod]
public void CombineShortcutListsShouldReturnEmptyListWhenBothArgumentsAreNull()
{
// act
var result = KeyboardManagerViewModel.CombineShortcutLists(null, null);
// Assert
var expectedResult = new List<AppSpecificKeysDataModel>();
Assert.AreEqual(expectedResult.Count, result.Count);
}
[TestMethod]
public void CombineShortcutListsShouldReturnListWithOneAppSpecificEntryWhenFirstArgumentIsNullAndSecondArgumentHasOneEntry()
{
// arrange
var secondList = new List<AppSpecificKeysDataModel>();
var entry = new AppSpecificKeysDataModel();
entry.OriginalKeys = "17;65";
entry.NewRemapKeys = "17;86";
entry.TargetApp = "msedge";
secondList.Add(entry);
// act
var result = KeyboardManagerViewModel.CombineShortcutLists(null, secondList);
// Assert
var expectedResult = new List<AppSpecificKeysDataModel>();
var expectedEntry = new AppSpecificKeysDataModel();
expectedEntry.OriginalKeys = entry.OriginalKeys;
expectedEntry.NewRemapKeys = entry.NewRemapKeys;
expectedEntry.TargetApp = entry.TargetApp;
expectedResult.Add(expectedEntry);
Assert.AreEqual(expectedResult.Count, result.Count);
Assert.IsTrue(expectedResult[0].Compare(result[0]));
}
[TestMethod]
public void CombineShortcutListsShouldReturnListWithOneAllAppsEntryWhenFirstArgumentHasOneEntryAndSecondArgumentIsNull()
{
// arrange
var firstList = new List<KeysDataModel>();
var entry = new KeysDataModel();
entry.OriginalKeys = "17;65";
entry.NewRemapKeys = "17;86";
firstList.Add(entry);
// act
var result = KeyboardManagerViewModel.CombineShortcutLists(firstList, null);
// Assert
var expectedResult = new List<AppSpecificKeysDataModel>();
var expectedEntry = new AppSpecificKeysDataModel();
expectedEntry.OriginalKeys = entry.OriginalKeys;
expectedEntry.NewRemapKeys = entry.NewRemapKeys;
expectedEntry.TargetApp = "All Apps";
expectedResult.Add(expectedEntry);
Assert.AreEqual(expectedResult.Count, result.Count);
Assert.IsTrue(expectedResult[0].Compare(result[0]));
}
[TestMethod]
public void CombineShortcutListsShouldReturnListWithOneAllAppsEntryWhenFirstArgumentHasOneEntryAndSecondArgumentIsEmpty()
{

View File

@@ -2,8 +2,8 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Moq;

View File

@@ -5,8 +5,8 @@
using System;
using System.IO;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Some files were not shown because too many files have changed in this diff Show More