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
This commit is contained in:
Lavius Motileng
2020-04-26 17:34:03 -07:00
committed by GitHub
parent 4946daeea4
commit 8f2a33dcaa
38 changed files with 1431 additions and 110 deletions

View File

@@ -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; }

View File

@@ -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; }

View File

@@ -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")]

View File

@@ -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<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),
});
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,
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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<ImageSize> Value { get; set; }
public ImageresizerSizes()
{
this.Value = new ObservableCollection<ImageSize>();
}
public ImageresizerSizes(ObservableCollection<ImageSize> value)
{
Value = value;
}
public string ToJsonString()
{
var options = new JsonSerializerOptions
{
WriteIndented = true,
};
return JsonSerializer.Serialize(this, options);
}
}
}

View File

@@ -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; }

View File

@@ -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);
}
}
}
}

View File

@@ -18,7 +18,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
{
properties = new PowerPreviewProperties();
version = "1";
name = "_unset_";
name = "File Explorer";
}
public PowerPreviewSettings(string ptName)

View File

@@ -81,4 +81,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
}
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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; }