From 8f2a33dcaacb5a164a1d9f03ed15e1389295ec10 Mon Sep 17 00:00:00 2001 From: Lavius Motileng <58791731+laviusmotileng-ms@users.noreply.github.com> Date: Sun, 26 Apr 2020 17:34:03 -0700 Subject: [PATCH] Added Image Resizer Settings (#2324) * added image resizer settings * updated string resource and binding * added tests and removed sett advanced settings from image resizer * fixed string resource spacing * moved conbo box strings to string resource * updated name of contributor * Capitalized size names * updated fallback encoder and sizers configs * removed interence between settings | used static resource binding * fixed build error --- .../BoolProperty.cs | 5 + .../DoubleProperty.cs | 5 + .../EnabledModules.cs | 2 +- .../ImageResizerProperties.cs | 112 ++++++ .../ImageResizerSettings.cs | 40 ++ .../ImageSize.cs | 187 +++++++++ .../ImageresizerCustomSizeProperty.cs | 24 ++ .../ImageresizerFallbackEncoder.cs | 19 + .../ImageresizerKeepDateModified.cs | 19 + .../ImageresizerSizes.cs | 39 ++ .../IntProperty.cs | 5 + .../OutGoingGeneralSettings.cs | 9 +- .../PowerPreviewSettings.cs | 2 +- .../SettingsUtils.cs | 2 +- .../ShortcutGuideSettingsIPCMessage.cs | 33 ++ .../SndImageResizerSettings.cs | 29 ++ .../SndModuleSettings.cs | 7 +- .../SndShortcutGuideSettings.cs | 7 +- .../StringProperty.cs | 5 + .../MainWindow.xaml.cs | 1 + .../Strings/en-us/Resources.resw | 101 ++++- .../ViewModels/ImageResizerViewModel.cs | 361 ++++++++++++++++++ .../ViewModels/PowerPreviewViewModel.cs | 2 +- .../ViewModels/ShortcutGuideViewModel.cs | 3 +- .../Views/ImageResizerPage.xaml | 236 ++++++++---- .../Views/ImageResizerPage.xaml.cs | 3 +- .../Views/PowerLauncherPage.xaml | 3 +- ...crosoft.PowerToys.Settings.UnitTest.csproj | 3 +- .../ModelsTests/BasePTModuleSettingsTest.cs | 3 +- .../ModelsTests/SettingsUtilsTests.cs | 3 +- .../ViewModelTests/ImageResizer.cs | 214 +++++++++++ .../PowerLauncherViewModelTest.cs | 4 +- ...GuideViewModelTest.cs => ShortcutGuide.cs} | 39 +- .../ui/ViewModels/InputViewModel.cs | 5 +- .../imageresizer/ui/Views/IMainView.cs | 3 +- .../imageresizer/ui/Views/InputPage.xaml | 2 + .../imageresizer/ui/Views/MainWindow.xaml.cs | 3 +- src/settings/main.cpp | 1 + 38 files changed, 1431 insertions(+), 110 deletions(-) create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageResizerProperties.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageResizerSettings.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageSize.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerCustomSizeProperty.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerFallbackEncoder.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerKeepDateModified.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerSizes.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/ShortcutGuideSettingsIPCMessage.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UI.Lib/SndImageResizerSettings.cs create mode 100644 src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/ImageResizer.cs rename src/core/Microsoft.PowerToys.Settings.UnitTest/ViewModelTests/{ShortcutGuideViewModelTest.cs => ShortcutGuide.cs} (70%) diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/BoolProperty.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/BoolProperty.cs index ca630919a..c3b2611f8 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/BoolProperty.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/BoolProperty.cs @@ -17,6 +17,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib this.Value = false; } + public BoolProperty(bool value) + { + Value = value; + } + [JsonPropertyName("value")] public bool Value { get; set; } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/DoubleProperty.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/DoubleProperty.cs index 662d18a18..c953ffae6 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/DoubleProperty.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/DoubleProperty.cs @@ -16,6 +16,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib this.Value = 0.0; } + public DoubleProperty(double value) + { + Value = value; + } + // Gets or sets the double value of the settings configuration. [JsonPropertyName("value")] public double Value { get; set; } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/EnabledModules.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/EnabledModules.cs index 549c89023..2c0a788a9 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/EnabledModules.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/EnabledModules.cs @@ -21,7 +21,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib [JsonPropertyName("FancyZones")] public bool FancyZones { get; set; } - [JsonPropertyName("ImageResizer")] + [JsonPropertyName("Image Resizer")] public bool ImageResizer { get; set; } [JsonPropertyName("File Explorer Preview")] diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageResizerProperties.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageResizerProperties.cs new file mode 100644 index 000000000..3b39a3a72 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageResizerProperties.cs @@ -0,0 +1,112 @@ +// 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.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + public class ImageResizerProperties + { + public ImageResizerProperties() + { + ImageresizerSelectedSizeIndex = new IntProperty(0); + ImageresizerShrinkOnly = new BoolProperty(false); + ImageresizerReplace = new BoolProperty(false); + ImageresizerIgnoreOrientation = new BoolProperty(true); + ImageresizerJpegQualityLevel = new IntProperty(90); + ImageresizerPngInterlaceOption = new IntProperty(); + ImageresizerTiffCompressOption = new IntProperty(); + ImageresizerFileName = new StringProperty("%1 (%2)"); + + ImageresizerSizes = new ImageresizerSizes(new ObservableCollection() + { + 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), + }); + + 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)); + } + + [JsonPropertyName("imageresizer_selectedSizeIndex")] + public IntProperty ImageresizerSelectedSizeIndex { get; set; } + + [JsonPropertyName("imageresizer_shrinkOnly")] + public BoolProperty ImageresizerShrinkOnly { get; set; } + + [JsonPropertyName("imageresizer_replace")] + public BoolProperty ImageresizerReplace { get; set; } + + [JsonPropertyName("imageresizer_ignoreOrientation")] + public BoolProperty ImageresizerIgnoreOrientation { get; set; } + + [JsonPropertyName("imageresizer_jpegQualityLevel")] + public IntProperty ImageresizerJpegQualityLevel { get; set; } + + [JsonPropertyName("imageresizer_pngInterlaceOption")] + public IntProperty ImageresizerPngInterlaceOption { get; set; } + + [JsonPropertyName("imageresizer_tiffCompressOption")] + public IntProperty ImageresizerTiffCompressOption { get; set; } + + [JsonPropertyName("imageresizer_fileName")] + public StringProperty ImageresizerFileName { get; set; } + + [JsonPropertyName("imageresizer_sizes")] + public ImageresizerSizes ImageresizerSizes { get; set; } + + [JsonPropertyName("imageresizer_keepDateModified")] + public BoolProperty ImageresizerKeepDateModified { get; set; } + + [JsonPropertyName("imageresizer_fallbackEncoder")] + public StringProperty ImageresizerFallbackEncoder { get; set; } + + [JsonPropertyName("imageresizer_customSize")] + public ImageresizerCustomSizeProperty ImageresizerCustomSize { get; set; } + + public string ToJsonString() + { + return JsonSerializer.Serialize(this); + } + } + + public enum ResizeFit + { + Fill = 0, + Fit = 1, + Stretch = 2, + } + + public enum ResizeUnit + { + Centimeter = 0, + Inch = 1, + Percent = 2, + Pixel = 3, + } + + public enum PngInterlaceOption + { + Default = 0, + On = 1, + Off = 2, + } + + public enum TiffCompressOption + { + Default = 0, + None = 1, + Ccitt3 = 2, + Ccitt4 = 3, + Lzw = 4, + Rle = 5, + Zip = 6, + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageResizerSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageResizerSettings.cs new file mode 100644 index 000000000..1591cbbdb --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageResizerSettings.cs @@ -0,0 +1,40 @@ +// 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.Collections.Generic; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + public class ImageResizerSettings + { + [JsonPropertyName("version")] + public string Version { get; set; } + + [JsonPropertyName("name")] + public string Name { get; set; } + + [JsonPropertyName("properties")] + public ImageResizerProperties Properties { get; set; } + + public ImageResizerSettings() + { + this.Version = "1"; + this.Name = "Image Resizer"; + this.Properties = new ImageResizerProperties(); + } + + public string ToJsonString() + { + var options = new JsonSerializerOptions + { + WriteIndented = true, + }; + return JsonSerializer.Serialize(this, options); + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageSize.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageSize.cs new file mode 100644 index 000000000..491973b13 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageSize.cs @@ -0,0 +1,187 @@ +// 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.Collections.Generic; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + public class ImageSize : INotifyPropertyChanged + { + public ImageSize(int id) + { + Id = id; + Name = string.Empty; + Fit = (int)ResizeFit.Fit; + Width = 0; + Height = 0; + Unit = (int)ResizeUnit.Pixel; + } + + public ImageSize() + { + Id = 0; + Name = string.Empty; + Fit = (int)ResizeFit.Fit; + Width = 0; + Height = 0; + Unit = (int)ResizeUnit.Pixel; + } + + public ImageSize(int id, string name, ResizeFit fit, double width, double height, ResizeUnit unit) + { + Id = id; + Name = name; + Fit = (int)fit; + Width = width; + Height = height; + Unit = (int)unit; + } + + private int _id; + private string _name; + private int _fit; + private double _height; + private double _width; + private int _unit; + + public int Id + { + get + { + return _id; + } + + set + { + if (_id != value) + { + _id = value; + OnPropertyChanged(); + } + } + } + + [JsonPropertyName("name")] + public string Name + { + get + { + return _name; + } + + set + { + if (_name != value) + { + _name = value; + OnPropertyChanged(); + } + } + } + + [JsonPropertyName("fit")] + public int Fit + { + get + { + return _fit; + } + + set + { + if (_fit != value) + { + _fit = value; + OnPropertyChanged(); + } + } + } + + [JsonPropertyName("width")] + public double Width + { + get + { + return _width; + } + + set + { + if (_width != value) + { + _width = value; + OnPropertyChanged(); + } + } + } + + [JsonPropertyName("height")] + public double Height + { + get + { + return _height; + } + + set + { + if (_height != value) + { + _height = value; + OnPropertyChanged(); + } + } + } + + [JsonPropertyName("unit")] + public int Unit + { + get + { + return _unit; + } + + set + { + if (_unit != value) + { + _unit = value; + OnPropertyChanged(); + } + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + public void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + var handler = PropertyChanged; + if (handler != null) + { + handler(this, new PropertyChangedEventArgs(propertyName)); + } + } + + public void Update(ImageSize modifiedSize) + { + Id = modifiedSize.Id; + Name = modifiedSize.Name; + Fit = modifiedSize.Fit; + Width = modifiedSize.Width; + Height = modifiedSize.Height; + Unit = modifiedSize.Unit; + } + + public string ToJsonString() + { + return JsonSerializer.Serialize(this); + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerCustomSizeProperty.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerCustomSizeProperty.cs new file mode 100644 index 000000000..dab6f3ad4 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerCustomSizeProperty.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + + public class ImageresizerCustomSizeProperty + { + [JsonPropertyName("value")] + public ImageSize Value { get; set; } + + public ImageresizerCustomSizeProperty() + { + this.Value = new ImageSize(); + } + + public ImageresizerCustomSizeProperty(ImageSize value) + { + Value = value; + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerFallbackEncoder.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerFallbackEncoder.cs new file mode 100644 index 000000000..5c8b785d2 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerFallbackEncoder.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + + public class ImageresizerFallbackEncoder + { + [JsonPropertyName("value")] + public string Value { get; set; } + + public ImageresizerFallbackEncoder() + { + this.Value = string.Empty; + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerKeepDateModified.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerKeepDateModified.cs new file mode 100644 index 000000000..b807eff01 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerKeepDateModified.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + + public class ImageresizerKeepDateModified + { + [JsonPropertyName("value")] + public bool Value { get; set; } + + public ImageresizerKeepDateModified() + { + this.Value = false; + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerSizes.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerSizes.cs new file mode 100644 index 000000000..3d18b1171 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerSizes.cs @@ -0,0 +1,39 @@ +// 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.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + + public class ImageresizerSizes + { + [JsonPropertyName("value")] + public ObservableCollection Value { get; set; } + + public ImageresizerSizes() + { + this.Value = new ObservableCollection(); + } + + public ImageresizerSizes(ObservableCollection value) + { + Value = value; + } + + public string ToJsonString() + { + var options = new JsonSerializerOptions + { + WriteIndented = true, + }; + return JsonSerializer.Serialize(this, options); + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/IntProperty.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/IntProperty.cs index 911503016..8706806da 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/IntProperty.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/IntProperty.cs @@ -15,6 +15,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib this.Value = 0; } + public IntProperty(int value) + { + Value = value; + } + // Gets or sets the integer value of the settings configuration. [JsonPropertyName("value")] public int Value { get; set; } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/OutGoingGeneralSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/OutGoingGeneralSettings.cs index 4a94d7977..c99d24dbe 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/OutGoingGeneralSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/OutGoingGeneralSettings.cs @@ -3,21 +3,22 @@ // See the LICENSE file in the project root for more information. using System.Text.Json; +using System.Text.Json.Serialization; namespace Microsoft.PowerToys.Settings.UI.Lib { public class OutGoingGeneralSettings { - public GeneralSettings general { get; set; } + [JsonPropertyName("general")] + public GeneralSettings GeneralSettings { get; set; } public OutGoingGeneralSettings() { - general = null; } public OutGoingGeneralSettings(GeneralSettings generalSettings) { - general = generalSettings; + GeneralSettings = generalSettings; } public override string ToString() @@ -25,4 +26,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib return JsonSerializer.Serialize(this); } } -} +} \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs index e36d9a805..3a1678d3f 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/PowerPreviewSettings.cs @@ -18,7 +18,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib { properties = new PowerPreviewProperties(); version = "1"; - name = "_unset_"; + name = "File Explorer"; } public PowerPreviewSettings(string ptName) diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs index abc6c1cd9..210cf800f 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs @@ -81,4 +81,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); } } -} +} \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/ShortcutGuideSettingsIPCMessage.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ShortcutGuideSettingsIPCMessage.cs new file mode 100644 index 000000000..714e04277 --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/ShortcutGuideSettingsIPCMessage.cs @@ -0,0 +1,33 @@ +// 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.Collections.Generic; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + public class ShortcutGuideSettingsIPCMessage + { + [JsonPropertyName("powertoys")] + public SndShortcutGuideSettings Powertoys { get; set; } + + public ShortcutGuideSettingsIPCMessage() + { + + } + + public ShortcutGuideSettingsIPCMessage(SndShortcutGuideSettings settings) + { + this.Powertoys = settings; + } + + public string ToJsonString() + { + return JsonSerializer.Serialize(this); + } + } +} \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndImageResizerSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndImageResizerSettings.cs new file mode 100644 index 000000000..c49011d8e --- /dev/null +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndImageResizerSettings.cs @@ -0,0 +1,29 @@ +// 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.Collections.Generic; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Microsoft.PowerToys.Settings.UI.Lib +{ + + public class SndImageResizerSettings + { + [JsonPropertyName("Image Resizer")] + public ImageResizerSettings ImageResizer { get; set; } + + public SndImageResizerSettings(ImageResizerSettings settings) + { + this.ImageResizer = settings; + } + + public string ToJsonString() + { + return JsonSerializer.Serialize(this); + } + } +} diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs index 440208e30..ef067090b 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndModuleSettings.cs @@ -13,6 +13,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib { public T powertoys { get; set; } + public SndModuleSettings() + { + + } + public SndModuleSettings(T settings) { this.powertoys = settings; @@ -23,4 +28,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib return JsonSerializer.Serialize(this); } } -} +} \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndShortcutGuideSettings.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndShortcutGuideSettings.cs index 2b75e2aef..45685b74d 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndShortcutGuideSettings.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SndShortcutGuideSettings.cs @@ -12,6 +12,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib [JsonPropertyName("Shortcut Guide")] public ShortcutGuideSettings ShortcutGuide { get; set; } + public SndShortcutGuideSettings() + { + + } + public SndShortcutGuideSettings(ShortcutGuideSettings settings) { this.ShortcutGuide = settings; @@ -22,4 +27,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib return JsonSerializer.Serialize(this); } } -} +} \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/StringProperty.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/StringProperty.cs index fac463d70..372e450aa 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/StringProperty.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/StringProperty.cs @@ -18,6 +18,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib this.Value = string.Empty; } + public StringProperty(string value) + { + Value = value; + } + // Gets or sets the integer value of the settings configuration. [JsonPropertyName("value")] public string Value { get; set; } diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs b/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs index 96176fb0a..03705b632 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs @@ -6,6 +6,7 @@ using System; using System.Windows; using Microsoft.PowerToys.Settings.UI.Views; using Microsoft.Toolkit.Wpf.UI.XamlHost; +using Windows.UI.Popups; namespace Microsoft.PowerToys.Settings.UI.Runner { diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw b/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw index d7ffa2fdb..47dd086c9 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw +++ b/src/core/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw @@ -154,7 +154,7 @@ Navigation view item name for FancyZones - Image Resizer [Not Functional] + Image Resizer Navigation view item name for Image Resizer @@ -425,4 +425,103 @@ Opacity of the Shortcut Guide's overlay background (%) + + Image Sizes + + + Lets you resize images by right-clicking. + + + Enable + + + Enable Image Resizer + + + Add Size + + + Save Sizes + + + JPEG Quality level + + + PNG interlacing + + + TIFF Compression + + + File + + + Default + + + CCITT3 + + + CCITT4 + + + Default + + + LZW + + + None + + + RLE + + + Zip + + + BMP Encoder + + + GIF Encoder + + + JPEG Encoder + + + PNG Encoder + + + TIFF Encoder + + + WMPhoto Encoder + + + Fill + + + Fit + + + Stretch + + + Centimeters + + + Inches + + + Percent + + + Pixels + + + Off + + + On + \ No newline at end of file diff --git a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/ImageResizerViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/ImageResizerViewModel.cs index 623c348c7..4601e8ff4 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/ImageResizerViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/ImageResizerViewModel.cs @@ -2,14 +2,375 @@ // 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.Collections.ObjectModel; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Linq; +using System.Text.RegularExpressions; +using System.Windows.Input; using Microsoft.PowerToys.Settings.UI.Helpers; +using Microsoft.PowerToys.Settings.UI.Lib; +using Microsoft.PowerToys.Settings.UI.Views; +using Windows.UI.Popups; namespace Microsoft.PowerToys.Settings.UI.ViewModels { public class ImageResizerViewModel : Observable { + private ImageResizerSettings Settings { get; set; } + + private const string ModuleName = "ImageResizer"; + public ImageResizerViewModel() { + try + { + Settings = SettingsUtils.GetSettings(ModuleName); + } + catch + { + Settings = new ImageResizerSettings(); + SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); + } + + GeneralSettings generalSettings; + + try + { + generalSettings = SettingsUtils.GetSettings(string.Empty); + } + catch + { + generalSettings = new GeneralSettings(); + SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty); + } + + this._isEnabled = generalSettings.Enabled.ImageResizer; + this._advancedSizes = Settings.Properties.ImageresizerSizes.Value; + this._jpegQualityLevel = Settings.Properties.ImageresizerJpegQualityLevel.Value; + this._pngInterlaceOption = Settings.Properties.ImageresizerPngInterlaceOption.Value; + this._tiffCompressOption = Settings.Properties.ImageresizerTiffCompressOption.Value; + this._fileName = Settings.Properties.ImageresizerFileName.Value; + this._keepDateModified = Settings.Properties.ImageresizerKeepDateModified.Value; + this._encoderGuidId = GetEncoderIndex(Settings.Properties.ImageresizerFallbackEncoder.Value); + + int i = 0; + foreach (ImageSize size in _advancedSizes) + { + size.Id = i; + i++; + size.PropertyChanged += Size_PropertyChanged; + } + } + + private bool _isEnabled = false; + private ObservableCollection _advancedSizes = new ObservableCollection(); + private int _jpegQualityLevel = 0; + private int _pngInterlaceOption; + private int _tiffCompressOption; + private string _fileName; + private bool _keepDateModified; + private int _encoderGuidId = 0; + + public bool IsEnabled + { + get + { + return _isEnabled; + } + + set + { + if (value != _isEnabled) + { + _isEnabled = value; + GeneralSettings generalSettings = SettingsUtils.GetSettings(string.Empty); + generalSettings.Enabled.ImageResizer = value; + OutGoingGeneralSettings snd = new OutGoingGeneralSettings(generalSettings); + ShellPage.DefaultSndMSGCallback(snd.ToString()); + OnPropertyChanged("IsEnabled"); + } + } + } + + public ObservableCollection Sizes + { + get + { + return _advancedSizes; + } + + set + { + SettingsUtils.SaveSettings(Settings.Properties.ImageresizerSizes.ToJsonString(), ModuleName, "sizes.json"); + _advancedSizes = value; + Settings.Properties.ImageresizerSizes = new ImageresizerSizes(value); + SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); + OnPropertyChanged("Sizes"); + } + } + + public int JPEGQualityLevel + { + get + { + return _jpegQualityLevel; + } + + set + { + if (_jpegQualityLevel != value) + { + _jpegQualityLevel = value; + Settings.Properties.ImageresizerJpegQualityLevel.Value = value; + SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); + OnPropertyChanged("JPEGQualityLevel"); + } + } + } + + public int PngInterlaceOption + { + get + { + return _pngInterlaceOption; + } + + set + { + if (_pngInterlaceOption != value) + { + _pngInterlaceOption = value; + Settings.Properties.ImageresizerPngInterlaceOption.Value = value; + SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); + OnPropertyChanged("PngInterlaceOption"); + } + } + } + + public int TiffCompressOption + { + get + { + return _tiffCompressOption; + } + + set + { + if (_tiffCompressOption != value) + { + _tiffCompressOption = value; + Settings.Properties.ImageresizerTiffCompressOption.Value = value; + SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); + OnPropertyChanged("TiffCompressOption"); + } + } + } + + public string FileName + { + get + { + return _fileName; + } + + set + { + var regex = @"[%]{1}[1-6]{1} [(]{1}[%]{1}[1-6]{1}[)]{1}"; + Match match = Regex.Match(value.Trim(), regex); + + if (!string.IsNullOrWhiteSpace(value) && match.Success) + { + _fileName = value; + Settings.Properties.ImageresizerFileName.Value = value; + SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); + OnPropertyChanged("FileName"); + } + } + } + + public bool KeepDateModified + { + get + { + return _keepDateModified; + } + + set + { + _keepDateModified = value; + Settings.Properties.ImageresizerKeepDateModified.Value = value; + SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); + OnPropertyChanged("KeepDateModified"); + } + } + + public int Encoder + { + get + { + return _encoderGuidId; + } + + set + { + if (_encoderGuidId != value) + { + _encoderGuidId = value; + SettingsUtils.SaveSettings(Settings.Properties.ImageresizerSizes.ToJsonString(), ModuleName, "sizes.json"); + Settings.Properties.ImageresizerFallbackEncoder.Value = GetEncoderGuid(value); + SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); + OnPropertyChanged("Encoder"); + } + } + } + + public ICommand SaveSizesEventHandler + { + get + { + return new RelayCommand(SavesImageSizes); + } + } + + public ICommand DeleteImageSizeEventHandler + { + get + { + return new RelayCommand(DeleteImageSize); + } + } + + public ICommand AddImageSizeEventHandler + { + get + { + return new RelayCommand(AddRow); + } + } + + public void AddRow() + { + ObservableCollection imageSizes = Sizes; + ImageSize maxSize = imageSizes.OrderBy(x => x.Id).Last(); + ImageSize newSize = new ImageSize(maxSize.Id + 1); + newSize.PropertyChanged += Size_PropertyChanged; + imageSizes.Add(newSize); + Sizes = imageSizes; + OnPropertyChanged("Sizes"); + } + + public void DeleteImageSize(int id) + { + try + { + ImageSize size = Sizes.Where(x => x.Id == id).First(); + ObservableCollection imageSizes = Sizes; + imageSizes.Remove(size); + Sizes = imageSizes; + OnPropertyChanged("Sizes"); + } + catch + { + } + } + + public void SavesImageSizes() + { + SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName); + } + + public string GetEncoderGuid(int value) + { + // PNG Encoder guid + if (value == 0) + { + return "1b7cfaf4-713f-473c-bbcd-6137425faeaf"; + } + + // Bitmap Encoder guid + else if (value == 1) + { + return "0af1d87e-fcfe-4188-bdeb-a7906471cbe3"; + } + + // JPEG Encoder guid + else if (value == 2) + { + return "19e4a5aa-5662-4fc5-a0c0-1758028e1057"; + } + + // Tiff encoder guid. + else if (value == 3) + { + return "163bcc30-e2e9-4f0b-961d-a3e9fdb788a3"; + } + + // Tiff encoder guid. + else if (value == 4) + { + return "57a37caa-367a-4540-916b-f183c5093a4b"; + } + + // Gif encoder guid. + else if (value == 5) + { + return "1f8a5601-7d4d-4cbd-9c82-1bc8d4eeb9a5"; + } + + return null; + } + + public int GetEncoderIndex(string guid) + { + // PNG Encoder guid + if (guid == "1b7cfaf4-713f-473c-bbcd-6137425faeaf") + { + return 0; + } + + // Bitmap Encoder guid + else if (guid == "0af1d87e-fcfe-4188-bdeb-a7906471cbe3") + { + return 1; + } + + // JPEG Encoder guid + else if (guid == "19e4a5aa-5662-4fc5-a0c0-1758028e1057") + { + return 2; + } + + // Tiff encoder guid. + else if (guid == "163bcc30-e2e9-4f0b-961d-a3e9fdb788a3") + { + return 3; + } + + // Tiff encoder guid. + else if (guid == "57a37caa-367a-4540-916b-f183c5093a4b") + { + return 4; + } + + // Gif encoder guid. + else if (guid == "1f8a5601-7d4d-4cbd-9c82-1bc8d4eeb9a5") + { + return 5; + } + + return -1; + } + + public void Size_PropertyChanged(object sender, PropertyChangedEventArgs e) + { + ImageSize modifiedSize = (ImageSize)sender; + ObservableCollection imageSizes = Sizes; + imageSizes.Where(x => x.Id == modifiedSize.Id).First().Update(modifiedSize); + Sizes = imageSizes; + OnPropertyChanged("Sizes"); } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs index b8014c7a5..9e88b0dbe 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/PowerPreviewViewModel.cs @@ -11,7 +11,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { public class PowerPreviewViewModel : Observable { - private const string ModuleName = "File Explorer Preview"; + private const string ModuleName = "File Explorer"; private PowerPreviewSettings Settings { get; set; } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/ShortcutGuideViewModel.cs b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/ShortcutGuideViewModel.cs index 8674767d3..36bef415e 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/ShortcutGuideViewModel.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI/ViewModels/ShortcutGuideViewModel.cs @@ -81,9 +81,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels GeneralSettings generalSettings = SettingsUtils.GetSettings(string.Empty); generalSettings.Enabled.ShortcutGuide = value; OutGoingGeneralSettings snd = new OutGoingGeneralSettings(generalSettings); - ShellPage.DefaultSndMSGCallback(snd.ToString()); - RaisePropertyChanged(); + OnPropertyChanged("IsEnabled"); } } } diff --git a/src/core/Microsoft.PowerToys.Settings.UI/Views/ImageResizerPage.xaml b/src/core/Microsoft.PowerToys.Settings.UI/Views/ImageResizerPage.xaml index c6a7fb977..345138a10 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI/Views/ImageResizerPage.xaml +++ b/src/core/Microsoft.PowerToys.Settings.UI/Views/ImageResizerPage.xaml @@ -2,13 +2,18 @@ x:Class="Microsoft.PowerToys.Settings.UI.Views.ImageResizerPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="using:Microsoft.PowerToys.Settings.UI.Views" + xmlns:viewModel="using:Microsoft.PowerToys.Settings.UI.ViewModels" + xmlns:models="using:Microsoft.PowerToys.Settings.UI.Lib" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:muxc="using:Microsoft.UI.Xaml.Controls" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> + + + + @@ -40,107 +45,182 @@ - - + + - - - - - + + + + + + + + + + + - - - - - Fill - Fit - Stretch + + + + + + + + - - - - - Centimeters - Inches - Percent - Pixels + + + + + + + + + + + + - + - --> + -