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:
parent
4946daeea4
commit
8f2a33dcaa
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
187
src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageSize.cs
Normal file
187
src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageSize.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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; }
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
|||
{
|
||||
properties = new PowerPreviewProperties();
|
||||
version = "1";
|
||||
name = "_unset_";
|
||||
name = "File Explorer";
|
||||
}
|
||||
|
||||
public PowerPreviewSettings(string ptName)
|
||||
|
|
|
@ -81,4 +81,4 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
|||
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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; }
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -154,7 +154,7 @@
|
|||
<comment>Navigation view item name for FancyZones</comment>
|
||||
</data>
|
||||
<data name="Shell_ImageResizer.Content" xml:space="preserve">
|
||||
<value>Image Resizer [Not Functional]</value>
|
||||
<value>Image Resizer</value>
|
||||
<comment>Navigation view item name for Image Resizer</comment>
|
||||
</data>
|
||||
<data name="Shell_KeyboardManager.Content" xml:space="preserve">
|
||||
|
@ -425,4 +425,103 @@
|
|||
<data name="ShortcutGuide_OverlayOpacity.Header" xml:space="preserve">
|
||||
<value>Opacity of the Shortcut Guide's overlay background (%)</value>
|
||||
</data>
|
||||
<data name="ImageResizer_CustomSizes.Text" xml:space="preserve">
|
||||
<value>Image Sizes</value>
|
||||
</data>
|
||||
<data name="ImageResizer_Description.Text" xml:space="preserve">
|
||||
<value>Lets you resize images by right-clicking.</value>
|
||||
</data>
|
||||
<data name="ImageResizer_EnableGroupSettingsHeader.Text" xml:space="preserve">
|
||||
<value>Enable</value>
|
||||
</data>
|
||||
<data name="ImageResizer_EnableToggle.Header" xml:space="preserve">
|
||||
<value>Enable Image Resizer</value>
|
||||
</data>
|
||||
<data name="ImageResizer_AddSizeButton.Label" xml:space="preserve">
|
||||
<value>Add Size</value>
|
||||
</data>
|
||||
<data name="ImageResizer_SaveSizeButton.Label" xml:space="preserve">
|
||||
<value>Save Sizes</value>
|
||||
</data>
|
||||
<data name="ImageResizer_Encoding.Text" xml:space="preserve">
|
||||
<value>JPEG Quality level</value>
|
||||
</data>
|
||||
<data name="ImageResizer_PNGInterlacing.Header" xml:space="preserve">
|
||||
<value>PNG interlacing</value>
|
||||
</data>
|
||||
<data name="ImageResizer_TIFFCompression.Header" xml:space="preserve">
|
||||
<value>TIFF Compression</value>
|
||||
</data>
|
||||
<data name="File.Text" xml:space="preserve">
|
||||
<value>File</value>
|
||||
</data>
|
||||
<data name="Default.Content" xml:space="preserve">
|
||||
<value>Default</value>
|
||||
</data>
|
||||
<data name="ImageResizer_ENCODER_TIFF_CCITT3.Content" xml:space="preserve">
|
||||
<value>CCITT3</value>
|
||||
</data>
|
||||
<data name="ImageResizer_ENCODER_TIFF_CCITT4.Content" xml:space="preserve">
|
||||
<value>CCITT4</value>
|
||||
</data>
|
||||
<data name="ImageResizer_ENCODER_TIFF_Default.Content" xml:space="preserve">
|
||||
<value>Default</value>
|
||||
</data>
|
||||
<data name="ImageResizer_ENCODER_TIFF_LZW.Content" xml:space="preserve">
|
||||
<value>LZW</value>
|
||||
</data>
|
||||
<data name="ImageResizer_ENCODER_TIFF_None.Content" xml:space="preserve">
|
||||
<value>None</value>
|
||||
</data>
|
||||
<data name="ImageResizer_ENCODER_TIFF_RLE.Content" xml:space="preserve">
|
||||
<value>RLE</value>
|
||||
</data>
|
||||
<data name="ImageResizer_ENCODER_TIFF_Zip.Content" xml:space="preserve">
|
||||
<value>Zip</value>
|
||||
</data>
|
||||
<data name="ImageResizer_FallbackEncoder_BMP.Content" xml:space="preserve">
|
||||
<value>BMP Encoder</value>
|
||||
</data>
|
||||
<data name="ImageResizer_FallbackEncoder_GIF.Content" xml:space="preserve">
|
||||
<value>GIF Encoder</value>
|
||||
</data>
|
||||
<data name="ImageResizer_FallbackEncoder_JPEG.Content" xml:space="preserve">
|
||||
<value>JPEG Encoder</value>
|
||||
</data>
|
||||
<data name="ImageResizer_FallbackEncoder_PNG.Content" xml:space="preserve">
|
||||
<value>PNG Encoder</value>
|
||||
</data>
|
||||
<data name="ImageResizer_FallbackEncoder_TIFF.Content" xml:space="preserve">
|
||||
<value>TIFF Encoder</value>
|
||||
</data>
|
||||
<data name="ImageResizer_FallbackEncoder_WMPhoto.Content" xml:space="preserve">
|
||||
<value>WMPhoto Encoder</value>
|
||||
</data>
|
||||
<data name="ImageResizer_Sizes_Fit_Fill.Content" xml:space="preserve">
|
||||
<value>Fill</value>
|
||||
</data>
|
||||
<data name="ImageResizer_Sizes_Fit_Fit.Content" xml:space="preserve">
|
||||
<value>Fit</value>
|
||||
</data>
|
||||
<data name="ImageResizer_Sizes_Fit_Stretch.Content" xml:space="preserve">
|
||||
<value>Stretch</value>
|
||||
</data>
|
||||
<data name="ImageResizer_Sizes_Units_CM.Content" xml:space="preserve">
|
||||
<value>Centimeters</value>
|
||||
</data>
|
||||
<data name="ImageResizer_Sizes_Units_Inches.Content" xml:space="preserve">
|
||||
<value>Inches</value>
|
||||
</data>
|
||||
<data name="ImageResizer_Sizes_Units_Percent.Content" xml:space="preserve">
|
||||
<value>Percent</value>
|
||||
</data>
|
||||
<data name="ImageResizer_Sizes_Units_Pixels.Content" xml:space="preserve">
|
||||
<value>Pixels</value>
|
||||
</data>
|
||||
<data name="Off.Content" xml:space="preserve">
|
||||
<value>Off</value>
|
||||
</data>
|
||||
<data name="On.Content" xml:space="preserve">
|
||||
<value>On</value>
|
||||
</data>
|
||||
</root>
|
|
@ -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<ImageResizerSettings>(ModuleName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Settings = new ImageResizerSettings();
|
||||
SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
}
|
||||
|
||||
GeneralSettings generalSettings;
|
||||
|
||||
try
|
||||
{
|
||||
generalSettings = SettingsUtils.GetSettings<GeneralSettings>(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<ImageSize> _advancedSizes = new ObservableCollection<ImageSize>();
|
||||
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<GeneralSettings>(string.Empty);
|
||||
generalSettings.Enabled.ImageResizer = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(generalSettings);
|
||||
ShellPage.DefaultSndMSGCallback(snd.ToString());
|
||||
OnPropertyChanged("IsEnabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<ImageSize> 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<int>(DeleteImageSize);
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand AddImageSizeEventHandler
|
||||
{
|
||||
get
|
||||
{
|
||||
return new RelayCommand(AddRow);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddRow()
|
||||
{
|
||||
ObservableCollection<ImageSize> 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<ImageSize>(x => x.Id == id).First();
|
||||
ObservableCollection<ImageSize> 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<ImageSize> imageSizes = Sizes;
|
||||
imageSizes.Where<ImageSize>(x => x.Id == modifiedSize.Id).First().Update(modifiedSize);
|
||||
Sizes = imageSizes;
|
||||
OnPropertyChanged("Sizes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -81,9 +81,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||
GeneralSettings generalSettings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
|
||||
generalSettings.Enabled.ShortcutGuide = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(generalSettings);
|
||||
|
||||
ShellPage.DefaultSndMSGCallback(snd.ToString());
|
||||
RaisePropertyChanged();
|
||||
OnPropertyChanged("IsEnabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}">
|
||||
|
||||
<Page.Resources>
|
||||
<viewModel:ImageResizerViewModel x:Key="ViewModel"/>
|
||||
</Page.Resources>
|
||||
|
||||
<Grid ColumnSpacing="{StaticResource DefaultColumnSpacing}" RowSpacing="{StaticResource DefaultRowSpacing}">
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="LayoutVisualStates">
|
||||
|
@ -40,107 +45,182 @@
|
|||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Vertical">
|
||||
<TextBlock Text="Lets you resize images by right-clicking."
|
||||
<StackPanel Orientation="Vertical" x:Name="ImageResizerView">
|
||||
|
||||
<TextBlock x:Uid="ImageResizer_Description"
|
||||
TextWrapping="Wrap"/>
|
||||
|
||||
<ToggleSwitch Header="Enable Image Resizer"
|
||||
IsOn="True"
|
||||
Margin="{StaticResource SmallTopMargin}" />
|
||||
|
||||
<TextBlock Text="Sizes"
|
||||
<TextBlock x:Uid="ImageResizer_EnableGroupSettingsHeader"
|
||||
Style="{StaticResource SettingsGroupTitleStyle}"/>
|
||||
|
||||
<!-- TO DO: Don't know if a listview with these items is the best solution here. Maybe a data grid is better? -->
|
||||
<!--<ListView Margin="{StaticResource SmallTopMargin}" Padding="-12,0,0,0" SelectionMode="None" ItemsSource="{x:Bind Sizes, Mode=OneWay}">
|
||||
<!--x:Uid="ImageResizer_EnableToggle"-->
|
||||
<ToggleSwitch IsOn="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}"
|
||||
Margin="{StaticResource SmallTopMargin}" />
|
||||
|
||||
<TextBlock x:Uid="ImageResizer_CustomSizes"
|
||||
Style="{StaticResource SettingsGroupTitleStyle}"/>
|
||||
|
||||
|
||||
<ListView x:Name="ImagesSizesListView"
|
||||
ItemsSource="{Binding Sizes, Mode=TwoWay, Source={StaticResource ViewModel}}"
|
||||
Padding="0"
|
||||
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}"
|
||||
Margin="0"
|
||||
>
|
||||
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="ListViewItem">
|
||||
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
|
||||
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
|
||||
<Setter Property="Background" Value="{ThemeResource ListViewItemBackground}"/>
|
||||
<Setter Property="Foreground" Value="{ThemeResource ListViewItemForeground}"/>
|
||||
<Setter Property="TabNavigation" Value="Local"/>
|
||||
<Setter Property="IsHoldingEnabled" Value="True"/>
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
<Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}"/>
|
||||
<Setter Property="MinHeight" Value="0"/>
|
||||
<Setter Property="AllowDrop" Value="False"/>
|
||||
<Setter Property="UseSystemFocusVisuals" Value="True"/>
|
||||
<Setter Property="FocusVisualMargin" Value="0"/>
|
||||
<Setter Property="FocusVisualPrimaryBrush" Value="{ThemeResource ListViewItemFocusVisualPrimaryBrush}"/>
|
||||
<Setter Property="FocusVisualPrimaryThickness" Value="2"/>
|
||||
<Setter Property="FocusVisualSecondaryBrush" Value="{ThemeResource ListViewItemFocusVisualSecondaryBrush}"/>
|
||||
<Setter Property="FocusVisualSecondaryThickness" Value="1"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListViewItem">
|
||||
<ListViewItemPresenter CheckBrush="{ThemeResource ListViewItemCheckBrush}" ContentMargin="{TemplateBinding Padding}" CheckMode="{ThemeResource ListViewItemCheckMode}" ContentTransitions="{TemplateBinding ContentTransitions}" CheckBoxBrush="{ThemeResource ListViewItemCheckBoxBrush}" DragForeground="{ThemeResource ListViewItemDragForeground}" DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}" DragBackground="{ThemeResource ListViewItemDragBackground}" DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}" FocusVisualPrimaryBrush="{TemplateBinding FocusVisualPrimaryBrush}" FocusVisualSecondaryThickness="{TemplateBinding FocusVisualSecondaryThickness}" FocusBorderBrush="{ThemeResource ListViewItemFocusBorderBrush}" FocusVisualMargin="{TemplateBinding FocusVisualMargin}" FocusVisualPrimaryThickness="{TemplateBinding FocusVisualPrimaryThickness}" FocusSecondaryBorderBrush="{ThemeResource ListViewItemFocusSecondaryBorderBrush}" FocusVisualSecondaryBrush="{TemplateBinding FocusVisualSecondaryBrush}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Control.IsTemplateFocusTarget="True" PointerOverForeground="{ThemeResource ListViewItemForegroundPointerOver}" PressedBackground="{ThemeResource ListViewItemBackgroundPressed}" PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackground}" PointerOverBackground="{ThemeResource ListViewItemBackgroundPointerOver}" ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}" SelectedPressedBackground="{ThemeResource ListViewItemBackgroundSelectedPressed}" SelectionCheckMarkVisualEnabled="{ThemeResource ListViewItemSelectionCheckMarkVisualEnabled}" SelectedForeground="{ThemeResource ListViewItemForegroundSelected}" SelectedPointerOverBackground="{ThemeResource ListViewItemBackgroundSelectedPointerOver}" SelectedBackground="{ThemeResource ListViewItemBackgroundSelected}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
</ListView.ItemContainerStyle>
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:DataType="local:ResizeSize">
|
||||
<StackPanel Orientation="Horizontal" Spacing="4">
|
||||
<TextBox Text="{x:Bind Title}" Width="68"/>
|
||||
<ComboBox SelectedIndex="1" Width="88">
|
||||
<ComboBoxItem>Fill</ComboBoxItem>
|
||||
<ComboBoxItem>Fit</ComboBoxItem>
|
||||
<ComboBoxItem>Stretch</ComboBoxItem>
|
||||
<DataTemplate x:Name="SingleLineDataTemplate" x:DataType="models:ImageSize" >
|
||||
<StackPanel Orientation="Horizontal" Padding="0" Spacing="4">
|
||||
<TextBox Text="{x:Bind Path=Name, Mode=TwoWay}"
|
||||
Width="90"
|
||||
Height="35"
|
||||
Margin="{StaticResource SmallTopMargin}"/>
|
||||
|
||||
<ComboBox SelectedIndex="{x:Bind Path=Fit, Mode=TwoWay}"
|
||||
Width="90"
|
||||
Height="35"
|
||||
Margin="{StaticResource SmallTopMargin}">
|
||||
<ComboBoxItem x:Uid="ImageResizer_Sizes_Fit_Fill" />
|
||||
<ComboBoxItem x:Uid="ImageResizer_Sizes_Fit_Fit" />
|
||||
<ComboBoxItem x:Uid="ImageResizer_Sizes_Fit_Stretch" />
|
||||
</ComboBox>
|
||||
<muxc:NumberBox Value="{x:Bind Width}"/>
|
||||
<TextBlock Text="x" FontWeight="SemiBold" Margin="0,4,0,0"/>
|
||||
<muxc:NumberBox Value="{x:Bind Height}"/>
|
||||
<ComboBox SelectedIndex="3">
|
||||
<ComboBoxItem>Centimeters</ComboBoxItem>
|
||||
<ComboBoxItem>Inches</ComboBoxItem>
|
||||
<ComboBoxItem>Percent</ComboBoxItem>
|
||||
<ComboBoxItem>Pixels</ComboBoxItem>
|
||||
|
||||
<muxc:NumberBox Value="{x:Bind Path=Width, Mode=TwoWay}"
|
||||
Width="68"
|
||||
Height="34"
|
||||
Margin="{StaticResource SmallTopMargin}"/>
|
||||
|
||||
<TextBlock Text="x"
|
||||
FontWeight="SemiBold"
|
||||
TextAlignment="Center"
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
Width="25"
|
||||
Height="35"/>
|
||||
|
||||
<muxc:NumberBox Value="{x:Bind Path=Height, Mode=TwoWay}"
|
||||
Width="68"
|
||||
Height="34"
|
||||
Margin="{StaticResource SmallTopMargin}"/>
|
||||
|
||||
<ComboBox SelectedIndex="{Binding Path=Unit, Mode=TwoWay}"
|
||||
Width="90"
|
||||
Height="35"
|
||||
Margin="{StaticResource SmallTopMargin}">
|
||||
<ComboBoxItem x:Uid="ImageResizer_Sizes_Units_CM" />
|
||||
<ComboBoxItem x:Uid="ImageResizer_Sizes_Units_Inches" />
|
||||
<ComboBoxItem x:Uid="ImageResizer_Sizes_Units_Percent" />
|
||||
<ComboBoxItem x:Uid="ImageResizer_Sizes_Units_Pixels" />
|
||||
</ComboBox>
|
||||
<Button x:Name="RemoveButton" Background="Transparent" Click="RemoveButton_Click">
|
||||
<Button.Content>
|
||||
<FontIcon Opacity="0.8" Glyph=""/>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<AppBarButton x:Name="RemoveButton"
|
||||
Background="Transparent"
|
||||
Command = "{Binding DeleteImageSizeEventHandler, Source={StaticResource ViewModel}}"
|
||||
CommandParameter="{Binding Id}"
|
||||
Icon="Delete"
|
||||
Width="52"
|
||||
Height="32"
|
||||
Margin="{StaticResource SmallTopMargin}" Padding="0,0,50,100" UseLayoutRounding="False"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>-->
|
||||
</ListView>
|
||||
|
||||
<Button x:Name="AddSizeButton" Content="Add new size" Margin="{StaticResource SmallTopMargin}"/>
|
||||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<AppBarButton Icon="Add"
|
||||
x:Name="AddSizeButton"
|
||||
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}"
|
||||
Label="Add Size"
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
Command = "{Binding AddImageSizeEventHandler, Source={StaticResource ViewModel}}"
|
||||
/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Text="Encoding"
|
||||
Style="{StaticResource SettingsGroupTitleStyle}"/>
|
||||
|
||||
<ComboBox Header="Fallback encoder"
|
||||
SelectedIndex="1"
|
||||
SelectedIndex="{Binding Path=Encoder, Mode=TwoWay, Source={StaticResource ViewModel}}"
|
||||
MinWidth="240"
|
||||
Margin="{StaticResource SmallTopMargin}">
|
||||
<ComboBoxItem>BMP Encoder</ComboBoxItem>
|
||||
<ComboBoxItem>GIF Encoder</ComboBoxItem>
|
||||
<ComboBoxItem>JPEG Encoder</ComboBoxItem>
|
||||
<ComboBoxItem>PNG Encoder</ComboBoxItem>
|
||||
<ComboBoxItem>TIFF Encoder</ComboBoxItem>
|
||||
<ComboBoxItem>WMPhoto Encoder</ComboBoxItem>
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}">
|
||||
<ComboBoxItem x:Uid="ImageResizer_FallbackEncoder_PNG" />
|
||||
<ComboBoxItem x:Uid="ImageResizer_FallbackEncoder_BMP" />
|
||||
<ComboBoxItem x:Uid="ImageResizer_FallbackEncoder_JPEG" />
|
||||
<ComboBoxItem x:Uid="ImageResizer_FallbackEncoder_TIFF" />
|
||||
<ComboBoxItem x:Uid="ImageResizer_FallbackEncoder_WMPhoto" />
|
||||
<ComboBoxItem x:Uid="ImageResizer_FallbackEncoder_GIF" />
|
||||
</ComboBox>
|
||||
|
||||
|
||||
<muxc:NumberBox Header="JPEG Quality level"
|
||||
Minimum="0"
|
||||
Maximum="100"
|
||||
Value="90"
|
||||
Value="{ Binding Mode=TwoWay, Path=JPEGQualityLevel, Source={StaticResource ViewModel}}"
|
||||
MinWidth="240"
|
||||
SpinButtonPlacementMode="Inline"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="{StaticResource SmallTopMargin}" />
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}"/>
|
||||
|
||||
<ComboBox Header="PNG interlacing"
|
||||
SelectedIndex="0"
|
||||
SelectedIndex="{ Binding Mode=TwoWay, Path=PngInterlaceOption, Source={StaticResource ViewModel}}"
|
||||
MinWidth="240"
|
||||
Margin="{StaticResource SmallTopMargin}">
|
||||
<ComboBoxItem>Default</ComboBoxItem>
|
||||
<ComboBoxItem>On</ComboBoxItem>
|
||||
<ComboBoxItem>Off</ComboBoxItem>
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}">
|
||||
<ComboBoxItem x:Uid="Default"/>
|
||||
<ComboBoxItem x:Uid="On"/>
|
||||
<ComboBoxItem x:Uid="Off"/>
|
||||
</ComboBox>
|
||||
|
||||
<ComboBox Header="TIFF Compression"
|
||||
SelectedIndex="0"
|
||||
SelectedIndex="{ Binding Mode=TwoWay, Path=TiffCompressOption, Source={StaticResource ViewModel}}"
|
||||
MinWidth="240"
|
||||
Margin="{StaticResource SmallTopMargin}">
|
||||
<ComboBoxItem>Default</ComboBoxItem>
|
||||
<ComboBoxItem>None</ComboBoxItem>
|
||||
<ComboBoxItem>CCITT3</ComboBoxItem>
|
||||
<ComboBoxItem>CCITT4</ComboBoxItem>
|
||||
<ComboBoxItem>LZW</ComboBoxItem>
|
||||
<ComboBoxItem>RLE</ComboBoxItem>
|
||||
<ComboBoxItem>Zip</ComboBoxItem>
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}">
|
||||
<ComboBoxItem x:Uid="ImageResizer_ENCODER_TIFF_Default"/>
|
||||
<ComboBoxItem x:Uid="ImageResizer_ENCODER_TIFF_None"/>
|
||||
<ComboBoxItem x:Uid="ImageResizer_ENCODER_TIFF_CCITT3"/>
|
||||
<ComboBoxItem x:Uid="ImageResizer_ENCODER_TIFF_CCITT4"/>
|
||||
<ComboBoxItem x:Uid="ImageResizer_ENCODER_TIFF_LZW"/>
|
||||
<ComboBoxItem x:Uid="ImageResizer_ENCODER_TIFF_RLE"/>
|
||||
<ComboBoxItem x:Uid="ImageResizer_ENCODER_TIFF_Zip"/>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Text="File"
|
||||
Style="{StaticResource SettingsGroupTitleStyle}"/>
|
||||
|
||||
|
||||
<TextBox Header="Filename format"
|
||||
Text="%1 (%2)"
|
||||
HorizontalAlignment="Left"
|
||||
MinWidth="240"
|
||||
Margin="{StaticResource SmallTopMargin}"/>
|
||||
|
||||
<TextBlock Text="The following parameters can be used:"
|
||||
Margin="{StaticResource SmallTopBottomMargin}"/>
|
||||
Margin="{StaticResource SmallTopBottomMargin}"/>
|
||||
|
||||
<TextBlock FontSize="12">
|
||||
<Run FontWeight="Bold">%1</Run>
|
||||
|
@ -167,11 +247,20 @@
|
|||
<Run> - Actual width</Run>
|
||||
</TextBlock>
|
||||
|
||||
<CheckBox Content="Use original date modified"
|
||||
<TextBox Header="Filename format"
|
||||
Text="{ Binding Mode=TwoWay, Path=FileName, Source={StaticResource ViewModel}}"
|
||||
HorizontalAlignment="Left"
|
||||
MinWidth="240"
|
||||
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}"
|
||||
Margin="{StaticResource SmallTopMargin}"/>
|
||||
|
||||
<CheckBox Content="Use original date modified"
|
||||
IsEnabled="{ Binding Mode=TwoWay, Path=IsEnabled, Source={StaticResource ViewModel}}"
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
IsChecked="{Binding Mode=TwoWay, Path=KeepDateModified, Source={StaticResource ViewModel}}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
<StackPanel
|
||||
x:Name="SidePanel"
|
||||
Orientation="Vertical"
|
||||
HorizontalAlignment="Left"
|
||||
|
@ -179,19 +268,26 @@
|
|||
Grid.Column="1">
|
||||
|
||||
<TextBlock
|
||||
Text="About this feature"
|
||||
x:Uid="About_This_Feature"
|
||||
Style="{StaticResource SettingsGroupTitleStyle}"
|
||||
Margin="{StaticResource XSmallBottomMargin}"/>
|
||||
|
||||
<HyperlinkButton Content="Module overview"/>
|
||||
<HyperlinkButton
|
||||
x:Uid="Module_overview"
|
||||
NavigateUri="https://github.com/microsoft/PowerToys/blob/master/src/modules/imageresizer/README.md"/>
|
||||
|
||||
<HyperlinkButton x:Uid="Give_Feedback"
|
||||
NavigateUri="https://github.com/microsoft/PowerToys/issues"/>
|
||||
|
||||
<TextBlock
|
||||
Text="Attribution"
|
||||
x:Uid="AttributionTitle"
|
||||
Style="{StaticResource SettingsGroupTitleStyle}" />
|
||||
|
||||
<HyperlinkButton
|
||||
Content="Brice Lams's Image Resizer"
|
||||
Content="Brice Lambson"
|
||||
NavigateUri="https://github.com/bricelam/ImageResizer/" />
|
||||
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
</Page>
|
|
@ -9,11 +9,12 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
|||
{
|
||||
public sealed partial class ImageResizerPage : Page
|
||||
{
|
||||
public ImageResizerViewModel ViewModel { get; } = new ImageResizerViewModel();
|
||||
public ImageResizerViewModel ViewModel { get; set; }
|
||||
|
||||
public ImageResizerPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
ViewModel = new ImageResizerViewModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,8 @@
|
|||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel Orientation="Vertical">
|
||||
<TextBlock x:Uid="PowerLauncher_Description" Style="{StaticResource BodyTextBlockStyle}"
|
||||
<TextBlock x:Uid="PowerLauncher_Description"
|
||||
Style="{StaticResource BodyTextBlockStyle}"
|
||||
TextWrapping="Wrap"/>
|
||||
|
||||
<ToggleSwitch x:Uid="PowerLauncher_EnablePowerLauncher"
|
||||
|
|
|
@ -119,6 +119,7 @@
|
|||
<SDKReference Include="TestPlatform.Universal, Version=$(UnitTestPlatformVersion)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ViewModelTests\ImageResizer.cs" />
|
||||
<Compile Include="ModelsTests\BasePTModuleSettingsTest.cs" />
|
||||
<Compile Include="ModelsTests\BasePTSettingsTest.cs" />
|
||||
<Compile Include="ModelsTests\SettingsUtilsTests.cs" />
|
||||
|
@ -126,8 +127,8 @@
|
|||
<Compile Include="UnitTestApp.xaml.cs">
|
||||
<DependentUpon>UnitTestApp.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ViewModelTests\ShortcutGuide.cs" />
|
||||
<Compile Include="ViewModelTests\PowerLauncherViewModelTest.cs" />
|
||||
<Compile Include="ViewModelTests\ShortcutGuideViewModelTest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="UnitTestApp.xaml">
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using Microsoft.PowerToys.Settings.UnitTest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Schema;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UnitTest
|
||||
namespace CommonLibTest
|
||||
{
|
||||
[TestClass]
|
||||
public class BasePTModuleSettingsTest
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using Microsoft.PowerToys.Settings.UnitTest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
@ -7,7 +8,7 @@ using System.Linq;
|
|||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UnitTest
|
||||
namespace CommonLibTest
|
||||
{
|
||||
[TestClass]
|
||||
public class SettingsUtilsTests
|
||||
|
|
|
@ -0,0 +1,214 @@
|
|||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
using Microsoft.PowerToys.Settings.UI.Views;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ViewModelTests
|
||||
{
|
||||
[TestClass]
|
||||
public class ImageResizer
|
||||
{
|
||||
public const string Module = "ImageResizer";
|
||||
[TestInitialize]
|
||||
public void Setup()
|
||||
{
|
||||
// initialize creation of test settings file.
|
||||
// Test base path:
|
||||
// C:\Users\<user name>\AppData\Local\Packages\08e1807b-8b6d-4bfa-adc4-79c64aae8e78_9abkseg265h2m\LocalState\Microsoft\PowerToys\
|
||||
GeneralSettings generalSettings = new GeneralSettings();
|
||||
ImageResizerSettings imageResizer = new ImageResizerSettings();
|
||||
|
||||
SettingsUtils.SaveSettings(generalSettings.ToJsonString());
|
||||
SettingsUtils.SaveSettings(imageResizer.ToJsonString(), imageResizer.Name);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void CleanUp()
|
||||
{
|
||||
// delete folder created.
|
||||
string generalSettings_file_name = string.Empty;
|
||||
if (SettingsUtils.SettingsFolderExists(generalSettings_file_name))
|
||||
{
|
||||
DeleteFolder(generalSettings_file_name);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteFolder(string powertoy)
|
||||
{
|
||||
Directory.Delete(Path.Combine(SettingsUtils.LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"), true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IsEnabled_ShouldEnableModule_WhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel();
|
||||
|
||||
// Assert
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
||||
Assert.IsTrue(snd.GeneralSettings.Enabled.ImageResizer);
|
||||
};
|
||||
|
||||
// act
|
||||
viewModel.IsEnabled = true;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void JPEGQualityLevel_ShouldSetValueToTen_WhenSuccefull()
|
||||
{
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel();
|
||||
|
||||
// act
|
||||
viewModel.JPEGQualityLevel = 10;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel();
|
||||
Assert.AreEqual(10, viewModel.JPEGQualityLevel);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PngInterlaceOption_ShouldSetValueToTen_WhenSuccefull()
|
||||
{
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel();
|
||||
|
||||
// act
|
||||
viewModel.PngInterlaceOption = 10;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel();
|
||||
Assert.AreEqual(10, viewModel.PngInterlaceOption);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TiffCompressOption_ShouldSetValueToTen_WhenSuccefull()
|
||||
{
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel();
|
||||
|
||||
// act
|
||||
viewModel.TiffCompressOption = 10;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel();
|
||||
Assert.AreEqual(10, viewModel.TiffCompressOption);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FileName_ShouldUpdateValue_WhenSuccefull()
|
||||
{
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel();
|
||||
string exptectedValue = "%1 (%3)";
|
||||
|
||||
// act
|
||||
viewModel.FileName = exptectedValue;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel();
|
||||
Assert.AreEqual(exptectedValue, viewModel.FileName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FileName_ShouldNOTUpdateValue_WhenNameIsInValid ()
|
||||
{
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel();
|
||||
string[] invalidNames =
|
||||
{
|
||||
string.Empty,
|
||||
" ", // no name.
|
||||
"%1", // single name value.
|
||||
"%7 (%5)", // name max index exceeded.
|
||||
"%8 (%8)", // name max index exceeded.
|
||||
"%5 (%3 )", // name contains extra spaces.
|
||||
"%5 (%3)", // name contains extra spaces.
|
||||
"%5 ( %3)", // name contains extra spaces.
|
||||
"% 5 ( %3)", // name contains extra spaces.
|
||||
"%5 (% 3)", // name contains extra spaces.
|
||||
"%5 ( %3 )", // name contains extra spaces.
|
||||
};
|
||||
|
||||
// act and Assert
|
||||
foreach (string invalidName in invalidNames)
|
||||
{
|
||||
viewModel = new ImageResizerViewModel();
|
||||
viewModel.FileName = invalidName;
|
||||
Assert.AreNotEqual(invalidName, viewModel.FileName);
|
||||
|
||||
ImageResizerSettings settings = SettingsUtils.GetSettings<ImageResizerSettings>(Module);
|
||||
Assert.AreNotEqual(invalidName, settings.Properties.ImageresizerFileName.Value);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void KeepDateModified_ShouldUpdateValue_WhenSuccefull()
|
||||
{
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel();
|
||||
|
||||
// act
|
||||
viewModel.KeepDateModified = true;
|
||||
|
||||
// Assert
|
||||
ImageResizerSettings settings = SettingsUtils.GetSettings<ImageResizerSettings>(Module);
|
||||
Assert.AreEqual(true, settings.Properties.ImageresizerKeepDateModified.Value);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void Encoder_ShouldUpdateValue_WhenSuccefull()
|
||||
{
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel();
|
||||
|
||||
// act
|
||||
viewModel.Encoder = 3;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel();
|
||||
Assert.AreEqual("163bcc30-e2e9-4f0b-961d-a3e9fdb788a3", viewModel.GetEncoderGuid(viewModel.Encoder));
|
||||
Assert.AreEqual(3, viewModel.Encoder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddRow_ShouldAddEmptyImageSize_WhenSuccefull()
|
||||
{
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel();
|
||||
int sizeOfOriginalArray = viewModel.Sizes.Count;
|
||||
|
||||
// act
|
||||
viewModel.AddRow();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(viewModel.Sizes.Count, sizeOfOriginalArray + 1);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeleteImageSize_ShouldDeleteImageSize_WhenSuccefull()
|
||||
{
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel();
|
||||
int sizeOfOriginalArray = viewModel.Sizes.Count;
|
||||
ImageSize deleteCandidate = viewModel.Sizes.Where<ImageSize>(x => x.Id == 0).First();
|
||||
|
||||
// act
|
||||
viewModel.DeleteImageSize(0);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(viewModel.Sizes.Count, sizeOfOriginalArray - 1);
|
||||
Assert.IsFalse(viewModel.Sizes.Contains(deleteCandidate));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,10 +8,10 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UnitTest.ViewModelTests
|
||||
namespace ViewModelTests
|
||||
{
|
||||
[TestClass]
|
||||
public class PowerLauncherViewModelTest
|
||||
public class PowerLauncher
|
||||
{
|
||||
class PowerLauncherSettingsMock : PowerLauncherSettings
|
||||
{
|
||||
|
|
|
@ -10,10 +10,10 @@ using System.IO;
|
|||
using System.Text.Json;
|
||||
using Windows.UI.Popups;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UnitTest.ViewModelTests
|
||||
namespace ViewModelTests
|
||||
{
|
||||
[TestClass]
|
||||
public class ShortcutGuideViewModelTest
|
||||
public class ShortcutGuide
|
||||
{
|
||||
[TestInitialize]
|
||||
public void Setup()
|
||||
|
@ -28,6 +28,22 @@ namespace Microsoft.PowerToys.Settings.UnitTest.ViewModelTests
|
|||
SettingsUtils.SaveSettings(shortcutGuide.ToJsonString(), shortcutGuide.Name);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void CleanUp()
|
||||
{
|
||||
// delete folder created.
|
||||
string file_name = "\\test";
|
||||
if (SettingsUtils.SettingsFolderExists(file_name))
|
||||
{
|
||||
DeleteFolder(file_name);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteFolder(string powertoy)
|
||||
{
|
||||
Directory.Delete(Path.Combine(SettingsUtils.LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"), true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IsEnabled_ShouldEnableModule_WhenSuccessful()
|
||||
{
|
||||
|
@ -39,7 +55,7 @@ namespace Microsoft.PowerToys.Settings.UnitTest.ViewModelTests
|
|||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
||||
Assert.IsTrue(snd.general.Enabled.ShortcutGuide);
|
||||
Assert.IsTrue(snd.GeneralSettings.Enabled.ShortcutGuide);
|
||||
};
|
||||
|
||||
// Act
|
||||
|
@ -56,9 +72,8 @@ namespace Microsoft.PowerToys.Settings.UnitTest.ViewModelTests
|
|||
// Initilize mock function of sending IPC message.
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
SndModuleSettings<ShortcutGuideSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<ShortcutGuideSettings>>(msg);
|
||||
Assert.AreEqual("dark", snd.powertoys.Properties.Theme.Value);
|
||||
Assert.AreEqual("hey", msg);
|
||||
ShortcutGuideSettingsIPCMessage snd = JsonSerializer.Deserialize<ShortcutGuideSettingsIPCMessage>(msg);
|
||||
Assert.AreEqual("dark", snd.Powertoys.ShortcutGuide.Properties.Theme.Value);
|
||||
};
|
||||
|
||||
// Act
|
||||
|
@ -75,9 +90,8 @@ namespace Microsoft.PowerToys.Settings.UnitTest.ViewModelTests
|
|||
// Initilize mock function of sending IPC message.
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
SndModuleSettings<ShortcutGuideSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<ShortcutGuideSettings>>(msg);
|
||||
// https://stackoverflow.com/questions/59198417/deserialization-of-reference-types-without-parameterless-constructor-is-not-supp
|
||||
Assert.AreEqual(100, snd.powertoys.Properties.PressTime.Value);
|
||||
ShortcutGuideSettingsIPCMessage snd = JsonSerializer.Deserialize<ShortcutGuideSettingsIPCMessage>(msg);
|
||||
Assert.AreEqual(100, snd.Powertoys.ShortcutGuide.Properties.PressTime.Value);
|
||||
};
|
||||
|
||||
// Act
|
||||
|
@ -94,14 +108,13 @@ namespace Microsoft.PowerToys.Settings.UnitTest.ViewModelTests
|
|||
// Initilize mock function of sending IPC message.
|
||||
ShellPage.DefaultSndMSGCallback = msg =>
|
||||
{
|
||||
SndModuleSettings<ShortcutGuideSettings> snd = JsonSerializer.Deserialize<SndModuleSettings<ShortcutGuideSettings>>(msg);
|
||||
ShortcutGuideSettingsIPCMessage snd = JsonSerializer.Deserialize<ShortcutGuideSettingsIPCMessage>(msg);
|
||||
// Serialisation not working as expected in the test project:
|
||||
// https://stackoverflow.com/questions/59198417/deserialization-of-reference-types-without-parameterless-constructor-is-not-supp
|
||||
Assert.AreEqual(100, snd.powertoys.Properties.OverlayOpacity.Value);
|
||||
Assert.AreEqual(100, snd.Powertoys.ShortcutGuide.Properties.OverlayOpacity.Value);
|
||||
};
|
||||
|
||||
// Act
|
||||
viewModel.OverlayOpacity = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) Brice Lambson
|
||||
// The Brice Lambson licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
|
||||
// ShowAdvancedCommand = new RelayCommand(ShowAdvanced);
|
||||
|
||||
using System.Windows.Input;
|
||||
using GalaSoft.MvvmLight;
|
||||
|
@ -32,7 +33,6 @@ namespace ImageResizer.ViewModels
|
|||
|
||||
ResizeCommand = new RelayCommand(Resize);
|
||||
CancelCommand = new RelayCommand(Cancel);
|
||||
ShowAdvancedCommand = new RelayCommand(ShowAdvanced);
|
||||
}
|
||||
|
||||
public Settings Settings { get; }
|
||||
|
@ -51,8 +51,5 @@ namespace ImageResizer.ViewModels
|
|||
|
||||
public void Cancel()
|
||||
=> _mainView.Close();
|
||||
|
||||
public void ShowAdvanced()
|
||||
=> _mainView.ShowAdvanced(new AdvancedViewModel(Settings));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) Brice Lambson
|
||||
// The Brice Lambson licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
|
||||
// void ShowAdvanced(AdvancedViewModel viewModel);
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ImageResizer.ViewModels;
|
||||
|
@ -11,8 +12,6 @@ namespace ImageResizer.Views
|
|||
{
|
||||
void Close();
|
||||
|
||||
void ShowAdvanced(AdvancedViewModel viewModel);
|
||||
|
||||
IEnumerable<string> OpenPictureFiles();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,11 +129,13 @@
|
|||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<!--
|
||||
<TextBlock VerticalAlignment="Center">
|
||||
<Hyperlink Command="{Binding ShowAdvancedCommand}">
|
||||
<Run Text="{x:Static p:Resources.Input_ShowAdvanced}"/>
|
||||
</Hyperlink>
|
||||
</TextBlock>
|
||||
-->
|
||||
<Button Grid.Column="1"
|
||||
Height="23"
|
||||
MinWidth="75"
|
||||
|
|
|
@ -39,9 +39,10 @@ namespace ImageResizer.Views
|
|||
return openFileDialog.FileNames;
|
||||
}
|
||||
|
||||
/*
|
||||
public void ShowAdvanced(AdvancedViewModel viewModel)
|
||||
=> viewModel.Close(new AdvancedWindow(viewModel).ShowDialog() == true);
|
||||
|
||||
*/
|
||||
void IMainView.Close()
|
||||
=> Dispatcher.Invoke((Action)Close);
|
||||
}
|
||||
|
|
|
@ -129,6 +129,7 @@ void send_message_to_powertoys_runner(const std::wstring& msg)
|
|||
{
|
||||
if (g_message_pipe != nullptr)
|
||||
{
|
||||
MessageBox(g_main_wnd, msg.c_str(), L"From Webview", MB_OK);
|
||||
g_message_pipe->send(msg);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue