mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[Settings] Migrated Image Resizer Tests (#5765)
* added MSTest project * Migrated Image Resizer Tests * fixed links * removed exception
This commit is contained in:
@@ -2,15 +2,17 @@
|
||||
// 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.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using Microsoft.PowerToys.Settings.UI.Views;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels.Commands;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
|
||||
{
|
||||
public class ImageResizerViewModel : Observable
|
||||
{
|
||||
@@ -18,7 +20,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
||||
private const string ModuleName = "ImageResizer";
|
||||
|
||||
public ImageResizerViewModel()
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public ImageResizerViewModel(Func<string, int> ipcMSGCallBackFunc)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -42,14 +46,17 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
|
||||
}
|
||||
|
||||
_isEnabled = generalSettings.Enabled.ImageResizer;
|
||||
_advancedSizes = Settings.Properties.ImageresizerSizes.Value;
|
||||
_jpegQualityLevel = Settings.Properties.ImageresizerJpegQualityLevel.Value;
|
||||
_pngInterlaceOption = Settings.Properties.ImageresizerPngInterlaceOption.Value;
|
||||
_tiffCompressOption = Settings.Properties.ImageresizerTiffCompressOption.Value;
|
||||
_fileName = Settings.Properties.ImageresizerFileName.Value;
|
||||
_keepDateModified = Settings.Properties.ImageresizerKeepDateModified.Value;
|
||||
_encoderGuidId = GetEncoderIndex(Settings.Properties.ImageresizerFallbackEncoder.Value);
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
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)
|
||||
@@ -84,7 +91,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
GeneralSettings generalSettings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
|
||||
generalSettings.Enabled.ImageResizer = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(generalSettings);
|
||||
ShellPage.DefaultSndMSGCallback(snd.ToString());
|
||||
SendConfigMSG(snd.ToString());
|
||||
OnPropertyChanged("IsEnabled");
|
||||
}
|
||||
}
|
||||
@@ -99,10 +106,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
||||
set
|
||||
{
|
||||
SettingsUtils.SaveSettings(Settings.Properties.ImageresizerSizes.ToJsonString(), ModuleName, "sizes.json");
|
||||
SavesImageSizes(value);
|
||||
_advancedSizes = value;
|
||||
Settings.Properties.ImageresizerSizes = new ImageResizerSizes(value);
|
||||
SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged("Sizes");
|
||||
}
|
||||
}
|
||||
@@ -219,30 +224,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -250,27 +231,24 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
ImageSize newSize = new ImageSize(maxId + 1);
|
||||
newSize.PropertyChanged += Size_PropertyChanged;
|
||||
imageSizes.Add(newSize);
|
||||
Sizes = imageSizes;
|
||||
OnPropertyChanged("Sizes");
|
||||
_advancedSizes = imageSizes;
|
||||
SavesImageSizes(imageSizes);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
}
|
||||
ImageSize size = _advancedSizes.Where<ImageSize>(x => x.Id == id).First();
|
||||
ObservableCollection<ImageSize> imageSizes = Sizes;
|
||||
imageSizes.Remove(size);
|
||||
|
||||
_advancedSizes = imageSizes;
|
||||
SavesImageSizes(imageSizes);
|
||||
}
|
||||
|
||||
public void SavesImageSizes()
|
||||
public void SavesImageSizes(ObservableCollection<ImageSize> imageSizes)
|
||||
{
|
||||
SettingsUtils.SaveSettings(Settings.Properties.ImageresizerSizes.ToJsonString(), ModuleName, "sizes.json");
|
||||
Settings.Properties.ImageresizerSizes = new ImageResizerSizes(imageSizes);
|
||||
SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
}
|
||||
|
||||
@@ -361,8 +339,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
ImageSize modifiedSize = (ImageSize)sender;
|
||||
ObservableCollection<ImageSize> imageSizes = Sizes;
|
||||
imageSizes.Where<ImageSize>(x => x.Id == modifiedSize.Id).First().Update(modifiedSize);
|
||||
Sizes = imageSizes;
|
||||
OnPropertyChanged("Sizes");
|
||||
_advancedSizes = imageSizes;
|
||||
SavesImageSizes(imageSizes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
// 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.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (SettingsUtils.SettingsFolderExists(Module))
|
||||
{
|
||||
DeleteFolder(Module);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteFolder(string powertoy)
|
||||
{
|
||||
Directory.Delete(Path.Combine(SettingsUtils.LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"), true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IsEnabled_ShouldEnableModule_WhenSuccessful()
|
||||
{
|
||||
// Assert
|
||||
Func<string, int> SendMockIPCConfigMSG = msg =>
|
||||
{
|
||||
OutGoingGeneralSettings snd = JsonSerializer.Deserialize<OutGoingGeneralSettings>(msg);
|
||||
Assert.IsTrue(snd.GeneralSettings.Enabled.ImageResizer);
|
||||
return 0;
|
||||
};
|
||||
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
|
||||
// act
|
||||
viewModel.IsEnabled = true;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void JPEGQualityLevel_ShouldSetValueToTen_WhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
|
||||
// act
|
||||
viewModel.JPEGQualityLevel = 10;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
Assert.AreEqual(10, viewModel.JPEGQualityLevel);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PngInterlaceOption_ShouldSetValueToTen_WhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
|
||||
// act
|
||||
viewModel.PngInterlaceOption = 10;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
Assert.AreEqual(10, viewModel.PngInterlaceOption);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TiffCompressOption_ShouldSetValueToTen_WhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
|
||||
// act
|
||||
viewModel.TiffCompressOption = 10;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
Assert.AreEqual(10, viewModel.TiffCompressOption);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FileName_ShouldUpdateValue_WhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
string expectedValue = "%1 (%3)";
|
||||
|
||||
// act
|
||||
viewModel.FileName = expectedValue;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
Assert.AreEqual(expectedValue, viewModel.FileName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void KeepDateModified_ShouldUpdateValue_WhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
|
||||
// act
|
||||
viewModel.KeepDateModified = true;
|
||||
|
||||
// Assert
|
||||
ImageResizerSettings settings = SettingsUtils.GetSettings<ImageResizerSettings>(Module);
|
||||
Assert.AreEqual(true, settings.Properties.ImageresizerKeepDateModified.Value);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Encoder_ShouldUpdateValue_WhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
|
||||
// act
|
||||
viewModel.Encoder = 3;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
Assert.AreEqual("163bcc30-e2e9-4f0b-961d-a3e9fdb788a3", viewModel.GetEncoderGuid(viewModel.Encoder));
|
||||
Assert.AreEqual(3, viewModel.Encoder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddRow_ShouldAddEmptyImageSize_WhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
int sizeOfOriginalArray = viewModel.Sizes.Count;
|
||||
|
||||
// act
|
||||
viewModel.AddRow();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(viewModel.Sizes.Count, sizeOfOriginalArray + 1);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeleteImageSize_ShouldDeleteImageSize_WhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(SendMockIPCConfigMSG);
|
||||
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));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UpdateWidthAndHeight_ShouldUpateSize_WhenCorrectValuesAreProvided()
|
||||
{
|
||||
// arrange
|
||||
ImageSize imageSize = new ImageSize()
|
||||
{
|
||||
Id = 0,
|
||||
Name = "Test",
|
||||
Fit = (int)ResizeFit.Fit,
|
||||
Width = 30,
|
||||
Height = 30,
|
||||
Unit = (int)ResizeUnit.Pixel,
|
||||
};
|
||||
|
||||
double negativeWidth = -2.0;
|
||||
double negativeHeight = -2.0;
|
||||
|
||||
// Act
|
||||
imageSize.Width = negativeWidth;
|
||||
imageSize.Height = negativeHeight;
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(0, imageSize.Width);
|
||||
Assert.AreEqual(0, imageSize.Height);
|
||||
|
||||
// Act
|
||||
imageSize.Width = 50;
|
||||
imageSize.Height = 50;
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(50, imageSize.Width);
|
||||
Assert.AreEqual(50, imageSize.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,6 @@
|
||||
<Compile Include="Services\NavigationService.cs" />
|
||||
<Compile Include="ViewModels\Commands\ButtonClickCommand.cs" />
|
||||
<Compile Include="ViewModels\FancyZonesViewModel.cs" />
|
||||
<Compile Include="ViewModels\ImageResizerViewModel.cs" />
|
||||
<Compile Include="ViewModels\PowerLauncherViewModel.cs" />
|
||||
<Compile Include="ViewModels\ShellViewModel.cs" />
|
||||
<Compile Include="Views\ColorPickerPage.xaml.cs">
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
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:viewModel="using:Microsoft.PowerToys.Settings.UI.ViewModels"
|
||||
xmlns:CustomControls="using:Microsoft.PowerToys.Settings.UI.Controls"
|
||||
xmlns:models="using:Microsoft.PowerToys.Settings.UI.Lib"
|
||||
xmlns:viewModels="using:Microsoft.PowerToys.Settings.UI.Lib.ViewModels"
|
||||
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"
|
||||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
|
||||
mc:Ignorable="d"
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
|
||||
<Page.Resources>
|
||||
<viewModel:ImageResizerViewModel x:Key="ViewModel"/>
|
||||
<!--<viewModel:ImageResizerViewModel x:Key="ViewModel"/>-->
|
||||
</Page.Resources>
|
||||
|
||||
<Grid RowSpacing="{StaticResource DefaultRowSpacing}">
|
||||
@@ -58,7 +58,7 @@
|
||||
Foreground="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled, Converter={StaticResource ModuleEnabledToForegroundConverter}}"/>
|
||||
|
||||
<ListView x:Name="ImagesSizesListView"
|
||||
ItemsSource="{Binding Sizes, Mode=TwoWay, Source={StaticResource ViewModel}}"
|
||||
ItemsSource="{x:Bind ViewModel.Sizes, Mode=TwoWay}"
|
||||
Padding="0"
|
||||
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}"
|
||||
SelectionMode="None">
|
||||
@@ -146,16 +146,17 @@
|
||||
<ComboBoxItem x:Uid="ImageResizer_Sizes_Units_Percent" />
|
||||
<ComboBoxItem x:Uid="ImageResizer_Sizes_Units_Pixels" />
|
||||
</ComboBox>
|
||||
<Button x:Name="RemoveButton"
|
||||
Background="Transparent"
|
||||
Command = "{Binding DeleteImageSizeEventHandler, Source={StaticResource ViewModel}}"
|
||||
CommandParameter="{Binding Id}"
|
||||
FontFamily="Segoe MDL2 Assets"
|
||||
Height="34"
|
||||
Width="34"
|
||||
Content=""
|
||||
VerticalAlignment="Center"
|
||||
Margin="{StaticResource SmallTopMargin}" UseLayoutRounding="False"/>
|
||||
<Button x:Name="RemoveButton"
|
||||
Background="Transparent"
|
||||
FontFamily="Segoe MDL2 Assets"
|
||||
Height="34"
|
||||
Width="34"
|
||||
Content=""
|
||||
VerticalAlignment="Center"
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
UseLayoutRounding="False"
|
||||
Click="DeleteCustomSize"
|
||||
CommandParameter="{Binding Id}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
@@ -169,8 +170,9 @@
|
||||
Style="{StaticResource AddItemAppBarButtonStyle}"
|
||||
IsEnabled="{x:Bind Mode=TwoWay, Path=ViewModel.IsEnabled}"
|
||||
x:Uid="ImageResizer_AddSizeButton"
|
||||
Click="AddSizeButton_Click"
|
||||
Margin="{StaticResource AddItemButtonMargin}"
|
||||
Command = "{Binding AddImageSizeEventHandler, Source={StaticResource ViewModel}}"
|
||||
|
||||
/>
|
||||
</StackPanel>
|
||||
|
||||
@@ -179,7 +181,7 @@
|
||||
Foreground="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled, Converter={StaticResource ModuleEnabledToForegroundConverter}}"/>
|
||||
|
||||
<ComboBox x:Uid="ImageResizer_FallBackEncoderText"
|
||||
SelectedIndex="{Binding Path=Encoder, Mode=TwoWay, Source={StaticResource ViewModel}}"
|
||||
SelectedIndex="{x:Bind Path=ViewModel.Encoder, Mode=TwoWay}"
|
||||
Width="240"
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}">
|
||||
@@ -194,10 +196,10 @@
|
||||
<TextBlock x:Uid="ImageResizer_Encoding"
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
Foreground="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled, Converter={StaticResource ModuleEnabledToForegroundConverter}}"/>
|
||||
|
||||
|
||||
<muxc:NumberBox Minimum="0"
|
||||
Maximum="100"
|
||||
Value="{ Binding Mode=TwoWay, Path=JPEGQualityLevel, Source={StaticResource ViewModel}}"
|
||||
Value="{x:Bind Mode=TwoWay, Path=ViewModel.JPEGQualityLevel}"
|
||||
Width="240"
|
||||
Margin="{StaticResource HeaderTextTopMargin}"
|
||||
SpinButtonPlacementMode="Compact"
|
||||
@@ -206,7 +208,7 @@
|
||||
/>
|
||||
|
||||
<ComboBox x:Uid="ImageResizer_PNGInterlacing"
|
||||
SelectedIndex="{ Binding Mode=TwoWay, Path=PngInterlaceOption, Source={StaticResource ViewModel}}"
|
||||
SelectedIndex="{x:Bind Mode=TwoWay, Path=ViewModel.PngInterlaceOption}"
|
||||
Width="240"
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}">
|
||||
@@ -216,7 +218,7 @@
|
||||
</ComboBox>
|
||||
|
||||
<ComboBox x:Uid="ImageResizer_TIFFCompression"
|
||||
SelectedIndex="{ Binding Mode=TwoWay, Path=TiffCompressOption, Source={StaticResource ViewModel}}"
|
||||
SelectedIndex="{x:Bind Mode=TwoWay, Path=ViewModel.TiffCompressOption}"
|
||||
Width="240"
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}">
|
||||
@@ -293,7 +295,7 @@
|
||||
<CheckBox x:Uid="ImageResizer_UseOriginalDate"
|
||||
IsEnabled="{x:Bind Mode=OneWay, Path=ViewModel.IsEnabled}"
|
||||
Margin="{StaticResource SmallTopMargin}"
|
||||
IsChecked="{Binding Mode=TwoWay, Path=KeepDateModified, Source={StaticResource ViewModel}}"/>
|
||||
IsChecked="{x:Bind Mode=TwoWay, Path=ViewModel.KeepDateModified}"/>
|
||||
</StackPanel>
|
||||
|
||||
<RelativePanel x:Name="SidePanel"
|
||||
@@ -318,7 +320,7 @@
|
||||
RelativePanel.Below="DescriptionPanel">
|
||||
<Image Source="ms-appx:///Assets/Modules/ImageResizer.png" />
|
||||
</Border>
|
||||
|
||||
|
||||
<StackPanel x:Name="LinksPanel"
|
||||
Margin="0,1,0,0"
|
||||
RelativePanel.Below="AboutImage"
|
||||
|
||||
@@ -2,21 +2,48 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
using System;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib.ViewModels;
|
||||
using Windows.UI.Popups;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
public sealed partial class ImageResizerPage : Page
|
||||
{
|
||||
private ImageResizerViewModel ViewModel { get; set; }
|
||||
public ImageResizerViewModel ViewModel { get; set; }
|
||||
|
||||
public ImageResizerPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
ViewModel = new ImageResizerViewModel();
|
||||
ViewModel = new ImageResizerViewModel(ShellPage.SendDefaultIPCMessage);
|
||||
DataContext = ViewModel;
|
||||
}
|
||||
|
||||
public void DeleteCustomSize(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Button deleteRowButton = (Button)sender;
|
||||
int rowNum = int.Parse(deleteRowButton.CommandParameter.ToString());
|
||||
ViewModel.DeleteImageSize(rowNum);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSizeButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
ViewModel.AddRow();
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user