mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 22:43:31 +08:00
Added localization to default sizes (#8928)
This commit is contained in:
parent
b1a6964e18
commit
11a569b113
@ -54,7 +54,7 @@ namespace ColorPicker.Settings
|
||||
{
|
||||
if (!_loadingColorsHistory)
|
||||
{
|
||||
var settings = _settingsUtils.GetSettings<ColorPickerSettings>(ColorPickerModuleName);
|
||||
var settings = _settingsUtils.GetSettingsOrDefault<ColorPickerSettings>(ColorPickerModuleName);
|
||||
settings.Properties.ColorHistory = ColorHistory.ToList();
|
||||
settings.Save(_settingsUtils);
|
||||
}
|
||||
@ -98,7 +98,7 @@ namespace ColorPicker.Settings
|
||||
defaultColorPickerSettings.Save(_settingsUtils);
|
||||
}
|
||||
|
||||
var settings = _settingsUtils.GetSettings<ColorPickerSettings>(ColorPickerModuleName);
|
||||
var settings = _settingsUtils.GetSettingsOrDefault<ColorPickerSettings>(ColorPickerModuleName);
|
||||
if (settings != null)
|
||||
{
|
||||
ChangeCursor.Value = settings.Properties.ChangeCursor;
|
||||
|
@ -71,7 +71,7 @@ namespace PowerLauncher
|
||||
retryCount++;
|
||||
CreateSettingsIfNotExists();
|
||||
|
||||
var overloadSettings = _settingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||
var overloadSettings = _settingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||
|
||||
var openPowerlauncher = ConvertHotkey(overloadSettings.Properties.OpenPowerLauncher);
|
||||
if (_settings.Hotkey != openPowerlauncher)
|
||||
|
@ -11,6 +11,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
T GetSettings<T>(string powertoy = "", string fileName = "settings.json")
|
||||
where T : ISettingsConfig, new();
|
||||
|
||||
T GetSettingsOrDefault<T>(string powertoy = "", string fileName = "settings.json")
|
||||
where T : ISettingsConfig, new();
|
||||
|
||||
void SaveSettings(string jsonSettings, string powertoy = "", string fileName = "settings.json");
|
||||
|
||||
bool SettingsExists(string powertoy = "", string fileName = "settings.json");
|
||||
|
@ -2,6 +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.
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
@ -20,20 +21,29 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
ImageresizerPngInterlaceOption = new IntProperty();
|
||||
ImageresizerTiffCompressOption = new IntProperty();
|
||||
ImageresizerFileName = new StringProperty("%1 (%2)");
|
||||
|
||||
ImageresizerSizes = new ImageResizerSizes(new ObservableCollection<ImageSize>()
|
||||
{
|
||||
new ImageSize(0, "Small", ResizeFit.Fit, 854, 480, ResizeUnit.Pixel),
|
||||
new ImageSize(1, "Medium", ResizeFit.Fit, 1366, 768, ResizeUnit.Pixel),
|
||||
new ImageSize(2, "Large", ResizeFit.Fit, 1920, 1080, ResizeUnit.Pixel),
|
||||
new ImageSize(3, "Phone", ResizeFit.Fit, 320, 568, ResizeUnit.Pixel),
|
||||
});
|
||||
|
||||
ImageresizerSizes = new ImageResizerSizes();
|
||||
ImageresizerKeepDateModified = new BoolProperty();
|
||||
ImageresizerFallbackEncoder = new StringProperty(new System.Guid("19e4a5aa-5662-4fc5-a0c0-1758028e1057").ToString());
|
||||
ImageresizerCustomSize = new ImageResizerCustomSizeProperty(new ImageSize(4, "custom", ResizeFit.Fit, 1024, 640, ResizeUnit.Pixel));
|
||||
}
|
||||
|
||||
public ImageResizerProperties(Func<string, string> resourceLoader)
|
||||
: this()
|
||||
{
|
||||
if (resourceLoader == null)
|
||||
{
|
||||
throw new NullReferenceException("Resource loader is null");
|
||||
}
|
||||
|
||||
ImageresizerSizes = new ImageResizerSizes(new ObservableCollection<ImageSize>()
|
||||
{
|
||||
new ImageSize(0, resourceLoader("ImageResizer_DefaultSize_Small"), ResizeFit.Fit, 854, 480, ResizeUnit.Pixel),
|
||||
new ImageSize(1, resourceLoader("ImageResizer_DefaultSize_Medium"), ResizeFit.Fit, 1366, 768, ResizeUnit.Pixel),
|
||||
new ImageSize(2, resourceLoader("ImageResizer_DefaultSize_Large"), ResizeFit.Fit, 1920, 1080, ResizeUnit.Pixel),
|
||||
new ImageSize(3, resourceLoader("ImageResizer_DefaultSize_Phone"), ResizeFit.Fit, 320, 568, ResizeUnit.Pixel),
|
||||
});
|
||||
}
|
||||
|
||||
[JsonPropertyName("imageresizer_selectedSizeIndex")]
|
||||
public IntProperty ImageresizerSelectedSizeIndex { get; set; }
|
||||
|
||||
|
@ -2,6 +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.
|
||||
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
@ -22,6 +23,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
Properties = new ImageResizerProperties();
|
||||
}
|
||||
|
||||
public ImageResizerSettings(Func<string, string> resourceLoader)
|
||||
: this()
|
||||
{
|
||||
Properties = new ImageResizerProperties(resourceLoader);
|
||||
}
|
||||
|
||||
public override string ToJsonString()
|
||||
{
|
||||
var options = new JsonSerializerOptions
|
||||
|
@ -52,7 +52,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
if (settingsConfig == null)
|
||||
{
|
||||
T settingsItem = new T();
|
||||
settingsConfig = _settingsUtils.GetSettings<T>(settingsItem.GetModuleName());
|
||||
settingsConfig = _settingsUtils.GetSettingsOrDefault<T>(settingsItem.GetModuleName());
|
||||
}
|
||||
|
||||
return settingsConfig;
|
||||
|
@ -46,37 +46,49 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
_settingsPath.DeleteSettings(powertoy);
|
||||
}
|
||||
|
||||
public T GetSettings<T>(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
where T : ISettingsConfig, new()
|
||||
{
|
||||
if (!SettingsExists(powertoy, fileName))
|
||||
{
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
// Given the file already exists, to deserialize the file and read it's content.
|
||||
T deserializedSettings = GetFile<T>(powertoy, fileName);
|
||||
|
||||
// If the file needs to be modified, to save the new configurations accordingly.
|
||||
if (deserializedSettings.UpgradeSettingsConfiguration())
|
||||
{
|
||||
SaveSettings(deserializedSettings.ToJsonString(), powertoy, fileName);
|
||||
}
|
||||
|
||||
return deserializedSettings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a Deserialized object of the json settings string.
|
||||
/// This function creates a file in the powertoy folder if it does not exist and returns an object with default properties.
|
||||
/// </summary>
|
||||
/// <returns>Deserialized json settings object.</returns>
|
||||
public T GetSettings<T>(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
public T GetSettingsOrDefault<T>(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
where T : ISettingsConfig, new()
|
||||
{
|
||||
if (SettingsExists(powertoy, fileName))
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
// Given the file already exists, to deserialize the file and read it's content.
|
||||
T deserializedSettings = GetFile<T>(powertoy, fileName);
|
||||
return GetSettings<T>(powertoy, fileName);
|
||||
}
|
||||
|
||||
// If the file needs to be modified, to save the new configurations accordingly.
|
||||
if (deserializedSettings.UpgradeSettingsConfiguration())
|
||||
{
|
||||
SaveSettings(deserializedSettings.ToJsonString(), powertoy, fileName);
|
||||
}
|
||||
|
||||
return deserializedSettings;
|
||||
}
|
||||
|
||||
// Catch json deserialization exceptions when the file is corrupt and has an invalid json.
|
||||
// If there are any deserialization issues like in https://github.com/microsoft/PowerToys/issues/7500, log the error and create a new settings.json file.
|
||||
// This is different from the case where we have trailing zeros following a valid json file, which we have handled by trimming the trailing zeros.
|
||||
catch (JsonException ex)
|
||||
{
|
||||
Logger.LogError($"Exception encountered while loading {powertoy} settings.", ex);
|
||||
}
|
||||
// Catch json deserialization exceptions when the file is corrupt and has an invalid json.
|
||||
// If there are any deserialization issues like in https://github.com/microsoft/PowerToys/issues/7500, log the error and create a new settings.json file.
|
||||
// This is different from the case where we have trailing zeros following a valid json file, which we have handled by trimming the trailing zeros.
|
||||
catch (JsonException ex)
|
||||
{
|
||||
Logger.LogError($"Exception encountered while loading {powertoy} settings.", ex);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
Logger.LogInfo($"Settings file {fileName} for {powertoy} was not found.");
|
||||
}
|
||||
|
||||
// If the settings file does not exist or if the file is corrupt, to create a new object with default parameters and save it to a newly created settings file.
|
||||
|
@ -60,7 +60,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
if (_settingsUtils.SettingsExists(ColorPickerSettings.ModuleName))
|
||||
{
|
||||
_colorPickerSettings = _settingsUtils.GetSettings<ColorPickerSettings>(ColorPickerSettings.ModuleName);
|
||||
_colorPickerSettings = _settingsUtils.GetSettingsOrDefault<ColorPickerSettings>(ColorPickerSettings.ModuleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.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)
|
||||
public ImageResizerViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, Func<string, string> resourceLoader)
|
||||
{
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
|
||||
@ -52,7 +52,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
Settings = new ImageResizerSettings();
|
||||
Settings = new ImageResizerSettings(resourceLoader);
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
Settings = _settingsUtils.GetSettings<KeyboardManagerSettings>(PowerToyName);
|
||||
Settings = _settingsUtils.GetSettingsOrDefault<KeyboardManagerSettings>(PowerToyName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -214,7 +214,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
|
||||
if (_settingsUtils.SettingsExists(PowerToyName, fileName))
|
||||
{
|
||||
_profile = _settingsUtils.GetSettings<KeyboardManagerProfile>(PowerToyName, fileName);
|
||||
_profile = _settingsUtils.GetSettingsOrDefault<KeyboardManagerProfile>(PowerToyName, fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
|
||||
if (_settingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
|
||||
{
|
||||
settings = _settingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||
settings = _settingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -42,7 +42,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
|
||||
try
|
||||
{
|
||||
PowerRenameLocalProperties localSettings = _settingsUtils.GetSettings<PowerRenameLocalProperties>(GetSettingsSubPath(), "power-rename-settings.json");
|
||||
PowerRenameLocalProperties localSettings = _settingsUtils.GetSettingsOrDefault<PowerRenameLocalProperties>(GetSettingsSubPath(), "power-rename-settings.json");
|
||||
Settings = new PowerRenameSettings(localSettings);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -36,7 +36,7 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
|
||||
get
|
||||
{
|
||||
T settingsItem = new T();
|
||||
_settingsConfig = _settingsUtils.GetSettings<T>(settingsItem.GetModuleName());
|
||||
_settingsConfig = _settingsUtils.GetSettingsOrDefault<T>(settingsItem.GetModuleName());
|
||||
return _settingsConfig;
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,13 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks
|
||||
where T : ISettingsConfig, new()
|
||||
{
|
||||
var settingsUtils = new Mock<ISettingsUtils>();
|
||||
settingsUtils.Setup(x => x.GetSettings<T>(It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(new T());
|
||||
settingsUtils
|
||||
.Setup(x => x.GetSettingsOrDefault<T>(It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(new T());
|
||||
|
||||
settingsUtils
|
||||
.Setup(x => x.GetSettings<T>(It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(new T());
|
||||
|
||||
return settingsUtils;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ namespace CommonLibTest
|
||||
JsonSchema expectedSchema = JsonSchema.Parse(expectedSchemaText);
|
||||
|
||||
// Act
|
||||
JObject actualSchema = JObject.Parse(settingsUtils.GetSettings<BasePTSettingsTest>(file_name).ToJsonString());
|
||||
JObject actualSchema = JObject.Parse(settingsUtils.GetSettingsOrDefault<BasePTSettingsTest>(file_name).ToJsonString());
|
||||
bool valid = actualSchema.IsValid(expectedSchema);
|
||||
|
||||
// Assert
|
||||
|
@ -30,7 +30,7 @@ namespace CommonLibTest
|
||||
|
||||
// Act
|
||||
settingsUtils.SaveSettings(file_contents_correct_json_content, file_name);
|
||||
BasePTSettingsTest actual_json = settingsUtils.GetSettings<BasePTSettingsTest>(file_name);
|
||||
BasePTSettingsTest actual_json = settingsUtils.GetSettingsOrDefault<BasePTSettingsTest>(file_name);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(expected_json.ToJsonString(), actual_json.ToJsonString());
|
||||
@ -48,7 +48,7 @@ namespace CommonLibTest
|
||||
BasePTSettingsTest expected_json = JsonSerializer.Deserialize<BasePTSettingsTest>(file_contents_correct_json_content);
|
||||
|
||||
settingsUtils.SaveSettings(file_contents_correct_json_content, file_name);
|
||||
BasePTSettingsTest actual_json = settingsUtils.GetSettings<BasePTSettingsTest>(file_name);
|
||||
BasePTSettingsTest actual_json = settingsUtils.GetSettingsOrDefault<BasePTSettingsTest>(file_name);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(expected_json.ToJsonString(), actual_json.ToJsonString());
|
||||
@ -83,7 +83,7 @@ namespace CommonLibTest
|
||||
var mockSettingsUtils = new SettingsUtils(mockFileSystem);
|
||||
|
||||
// Act
|
||||
TestClass settings = mockSettingsUtils.GetSettings<TestClass>(string.Empty);
|
||||
TestClass settings = mockSettingsUtils.GetSettingsOrDefault<TestClass>(string.Empty);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(settings.TestInt, 100);
|
||||
|
@ -29,12 +29,12 @@ namespace ViewModelTests
|
||||
var settingPathMock = new Mock<ISettingsPath>();
|
||||
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object, settingPathMock.Object);
|
||||
ColorPickerSettings originalSettings = mockSettingsUtils.GetSettings<ColorPickerSettings>(ColorPickerSettings.ModuleName);
|
||||
ColorPickerSettings originalSettings = mockSettingsUtils.GetSettingsOrDefault<ColorPickerSettings>(ColorPickerSettings.ModuleName);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettingsOrDefault<GeneralSettings>();
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
// Act
|
||||
|
@ -33,11 +33,11 @@ namespace ViewModelTests
|
||||
|
||||
var fileMock = BackCompatTestProperties.GetModuleIOProvider(version, FancyZonesSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(fileMock.Object, settingPathMock.Object);
|
||||
FancyZonesSettings originalSettings = mockSettingsUtils.GetSettings<FancyZonesSettings>(FancyZonesSettings.ModuleName);
|
||||
FancyZonesSettings originalSettings = mockSettingsUtils.GetSettingsOrDefault<FancyZonesSettings>(FancyZonesSettings.ModuleName);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettingsOrDefault<GeneralSettings>();
|
||||
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
var fancyZonesRepository = new BackCompatTestProperties.MockSettingsRepository<FancyZonesSettings>(mockSettingsUtils);
|
||||
|
@ -38,7 +38,7 @@ namespace ViewModelTests
|
||||
var fileMock = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(fileMock.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettingsOrDefault<GeneralSettings>();
|
||||
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
|
@ -45,17 +45,17 @@ namespace ViewModelTests
|
||||
var fileMock = BackCompatTestProperties.GetModuleIOProvider(version, ImageResizerSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(fileMock.Object, settingPathMock.Object);
|
||||
|
||||
ImageResizerSettings originalSettings = mockSettingsUtils.GetSettings<ImageResizerSettings>(ImageResizerSettings.ModuleName);
|
||||
ImageResizerSettings originalSettings = mockSettingsUtils.GetSettingsOrDefault<ImageResizerSettings>(ImageResizerSettings.ModuleName);
|
||||
|
||||
var mockGeneralFileMock = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralFileMock.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettingsOrDefault<GeneralSettings>();
|
||||
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
// Initialise View Model with test Config files
|
||||
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, generalSettingsRepository, sendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, generalSettingsRepository, sendMockIPCConfigMSG, (string name) => name);
|
||||
|
||||
// Verify that the old settings persisted
|
||||
Assert.AreEqual(originalGeneralSettings.Enabled.ImageResizer, viewModel.IsEnabled);
|
||||
@ -85,7 +85,7 @@ namespace ViewModelTests
|
||||
};
|
||||
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(_mockImgResizerSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(_mockImgResizerSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
|
||||
// act
|
||||
viewModel.IsEnabled = true;
|
||||
@ -98,13 +98,13 @@ namespace ViewModelTests
|
||||
var fileSystemMock = new MockFileSystem();
|
||||
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
|
||||
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
|
||||
// act
|
||||
viewModel.JPEGQualityLevel = 10;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
Assert.AreEqual(10, viewModel.JPEGQualityLevel);
|
||||
}
|
||||
|
||||
@ -115,13 +115,13 @@ namespace ViewModelTests
|
||||
var fileSystemMock = new MockFileSystem();
|
||||
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
|
||||
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
|
||||
// act
|
||||
viewModel.PngInterlaceOption = 10;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
Assert.AreEqual(10, viewModel.PngInterlaceOption);
|
||||
}
|
||||
|
||||
@ -132,13 +132,13 @@ namespace ViewModelTests
|
||||
var fileSystemMock = new MockFileSystem();
|
||||
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
|
||||
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
|
||||
// act
|
||||
viewModel.TiffCompressOption = 10;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
Assert.AreEqual(10, viewModel.TiffCompressOption);
|
||||
}
|
||||
|
||||
@ -149,14 +149,14 @@ namespace ViewModelTests
|
||||
var fileSystemMock = new MockFileSystem();
|
||||
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
|
||||
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
string expectedValue = "%1 (%3)";
|
||||
|
||||
// act
|
||||
viewModel.FileName = expectedValue;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
Assert.AreEqual(expectedValue, viewModel.FileName);
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ namespace ViewModelTests
|
||||
.Verifiable();
|
||||
|
||||
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(settingUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(settingUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
|
||||
// act
|
||||
viewModel.KeepDateModified = true;
|
||||
@ -192,13 +192,13 @@ namespace ViewModelTests
|
||||
var fileSystemMock = new MockFileSystem();
|
||||
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
|
||||
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
|
||||
// act
|
||||
viewModel.Encoder = 3;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
Assert.AreEqual("163bcc30-e2e9-4f0b-961d-a3e9fdb788a3", viewModel.EncoderGuid);
|
||||
Assert.AreEqual(3, viewModel.Encoder);
|
||||
}
|
||||
@ -209,7 +209,7 @@ namespace ViewModelTests
|
||||
// arrange
|
||||
var mockSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ImageResizerSettings>();
|
||||
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
int sizeOfOriginalArray = viewModel.Sizes.Count;
|
||||
|
||||
// act
|
||||
@ -225,7 +225,8 @@ namespace ViewModelTests
|
||||
// arrange
|
||||
var mockSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ImageResizerSettings>();
|
||||
Func<string, int> sendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), sendMockIPCConfigMSG, (string name) => name);
|
||||
viewModel.AddRow();
|
||||
int sizeOfOriginalArray = viewModel.Sizes.Count;
|
||||
ImageSize deleteCandidate = viewModel.Sizes.Where<ImageSize>(x => x.Id == 0).First();
|
||||
|
||||
|
@ -56,11 +56,11 @@ namespace ViewModelTests
|
||||
|
||||
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, PowerLauncherSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object, settingPathMock.Object);
|
||||
PowerLauncherSettings originalSettings = mockSettingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||
PowerLauncherSettings originalSettings = mockSettingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettingsOrDefault<GeneralSettings>();
|
||||
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
|
@ -42,12 +42,12 @@ namespace ViewModelTests
|
||||
var fileMock = BackCompatTestProperties.GetModuleIOProvider(version, PowerPreviewSettings.ModuleName, fileName);
|
||||
|
||||
var mockSettingsUtils = new SettingsUtils(fileMock.Object, settingPathMock.Object);
|
||||
PowerPreviewSettings originalSettings = mockSettingsUtils.GetSettings<PowerPreviewSettings>(PowerPreviewSettings.ModuleName);
|
||||
PowerPreviewSettings originalSettings = mockSettingsUtils.GetSettingsOrDefault<PowerPreviewSettings>(PowerPreviewSettings.ModuleName);
|
||||
var repository = new BackCompatTestProperties.MockSettingsRepository<PowerPreviewSettings>(mockSettingsUtils);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettingsOrDefault<GeneralSettings>();
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
// Initialise View Model with test Config files
|
||||
|
@ -43,12 +43,12 @@ namespace ViewModelTests
|
||||
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, PowerRenameSettings.ModuleName, fileName);
|
||||
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object, settingPathMock.Object);
|
||||
PowerRenameLocalProperties originalSettings = mockSettingsUtils.GetSettings<PowerRenameLocalProperties>(PowerRenameSettings.ModuleName);
|
||||
PowerRenameLocalProperties originalSettings = mockSettingsUtils.GetSettingsOrDefault<PowerRenameLocalProperties>(PowerRenameSettings.ModuleName);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettingsOrDefault<GeneralSettings>();
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
// Initialise View Model with test Config files
|
||||
|
@ -32,11 +32,11 @@ namespace ViewModelTests
|
||||
var settingPathMock = new Mock<ISettingsPath>();
|
||||
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, ShortcutGuideSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object, settingPathMock.Object);
|
||||
ShortcutGuideSettings originalSettings = mockSettingsUtils.GetSettings<ShortcutGuideSettings>(ShortcutGuideSettings.ModuleName);
|
||||
ShortcutGuideSettings originalSettings = mockSettingsUtils.GetSettingsOrDefault<ShortcutGuideSettings>(ShortcutGuideSettings.ModuleName);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettingsOrDefault<GeneralSettings>();
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
var shortcutSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<ShortcutGuideSettings>(mockSettingsUtils);
|
||||
|
||||
|
@ -876,6 +876,18 @@
|
||||
<data name="ColorPicker_ShowColorName.Content" xml:space="preserve">
|
||||
<value>Show color name</value>
|
||||
</data>
|
||||
<data name="ImageResizer_DefaultSize_Large" xml:space="preserve">
|
||||
<value>Large</value>
|
||||
</data>
|
||||
<data name="ImageResizer_DefaultSize_Medium" xml:space="preserve">
|
||||
<value>Medium</value>
|
||||
</data>
|
||||
<data name="ImageResizer_DefaultSize_Phone" xml:space="preserve">
|
||||
<value>Phone</value>
|
||||
</data>
|
||||
<data name="ImageResizer_DefaultSize_Small" xml:space="preserve">
|
||||
<value>Small</value>
|
||||
</data>
|
||||
<data name="ColorPicker_ImageHyperlinkToDocs.NavigateUri" xml:space="preserve">
|
||||
<value>https://aka.ms/PowerToysOverview_ColorPicker</value>
|
||||
<comment>URL. Do not loc</comment>
|
||||
|
@ -22,7 +22,13 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
InitializeComponent();
|
||||
var settingsUtils = new SettingsUtils();
|
||||
ViewModel = new ImageResizerViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage);
|
||||
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
|
||||
Func<string, string> loader = (string name) =>
|
||||
{
|
||||
return resourceLoader.GetString(name);
|
||||
};
|
||||
|
||||
ViewModel = new ImageResizerViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage, loader);
|
||||
DataContext = ViewModel;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user