diff --git a/PowerToys.sln b/PowerToys.sln index 1e9d13ae8e..a0612a81a8 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -135,11 +135,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KeyboardManager", "src\modu EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "imageresizer", "imageresizer", "{6C7F47CC-2151-44A3-A546-41C70025132C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageResizerUI", "src\modules\imageresizer\ui\ImageResizerUI.csproj", "{2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageResizerUI", "src\modules\imageresizer\ui\ImageResizerUI.csproj", "{2BE46397-4DFA-414C-9BD4-41E4BBF8CB34}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImageResizerExt", "src\modules\imageresizer\dll\ImageResizerExt.vcxproj", "{0B43679E-EDFA-4DA0-AD30-F4628B308B1B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageResizerUITest", "src\modules\imageresizer\tests\ImageResizerUITest.csproj", "{E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageResizerUITest", "src\modules\imageresizer\tests\ImageResizerUITest.csproj", "{E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KeyboardManagerUI", "src\modules\keyboardmanager\ui\KeyboardManagerUI.vcxproj", "{EAF23649-EF6E-478B-980E-81FAD96CCA2A}" EndProject diff --git a/installer/PowerToysSetup/Product.wxs b/installer/PowerToysSetup/Product.wxs index 8a1d14882e..8954644cfe 100644 --- a/installer/PowerToysSetup/Product.wxs +++ b/installer/PowerToysSetup/Product.wxs @@ -492,14 +492,11 @@ - - - - - - - + + + + diff --git a/src/modules/imageresizer/tests/App.config b/src/modules/imageresizer/tests/App.config deleted file mode 100644 index 2a2d449901..0000000000 --- a/src/modules/imageresizer/tests/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/src/modules/imageresizer/tests/ImageResizerUITest.csproj b/src/modules/imageresizer/tests/ImageResizerUITest.csproj index ae869833b1..f853c44e78 100644 --- a/src/modules/imageresizer/tests/ImageResizerUITest.csproj +++ b/src/modules/imageresizer/tests/ImageResizerUITest.csproj @@ -1,114 +1,44 @@ - - - + - + - ImageResizerUITest - Microsoft Corp. - Copyright (C) 2020 Microsoft Corp. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Debug - x64 + netcoreapp3.1 {E0CC7526-D85E-43AC-844F-D5DF0D2F5AB8} Library Properties ImageResizer ImageResizer.Test - v4.7.2 - 512 - - + Microsoft Corp. + Copyright (C) 2020 Microsoft Corp. + $(Version).0 + $(SolutionDir)$(Platform)\$(Configuration)\modules\ImageResizer\$(AssemblyName)\ + ..\..\..\codeAnalysis\Rules.ruleset + x64 + + + + x64 true $(SolutionDir)$(Platform)\$(Configuration)\obj\$(AssemblyName)\ - - true - full - false - $(SolutionDir)$(Platform)\$(Configuration)\modules\ImageResizer\$(AssemblyName)\ - DEBUG;TRACE - prompt - 4 - false - ..\..\..\codeAnalysis\Rules.ruleset + + + x64 - - pdbonly - true - $(SolutionDir)$(Platform)\$(Configuration)\modules\ImageResizer\$(AssemblyName)\ - TRACE - prompt - 4 - false - ..\..\..\codeAnalysis\Rules.ruleset + + x64 + - - - - - - - {2be46397-4dfa-414c-9bd4-41e4bbf8cb34} - ImageResizerUI - + StyleCop.json - - .editorconfig - - - Designer - - - GlobalSuppressions.cs - - - Code - - - - - - - - - - - + @@ -131,33 +61,18 @@ - - 3.3.0 - runtime; build; native; contentfiles; analyzers; buildtransitive + all - - 4.14.5 - - - 1.1.118 - runtime; build; native; contentfiles; analyzers; buildtransitive + + + all - - 4.5.0 - - - 2.4.1 - - - 2.4.3 - runtime; build; native; contentfiles; analyzers; buildtransitive + + + all - - - - \ No newline at end of file diff --git a/src/modules/imageresizer/ui/App.config b/src/modules/imageresizer/ui/App.config deleted file mode 100644 index 2a2d449901..0000000000 --- a/src/modules/imageresizer/ui/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/src/modules/imageresizer/ui/App.xaml b/src/modules/imageresizer/ui/App.xaml index 22503f2c11..092f74ea24 100644 --- a/src/modules/imageresizer/ui/App.xaml +++ b/src/modules/imageresizer/ui/App.xaml @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:m="clr-namespace:ImageResizer.Models" - xmlns:sys="clr-namespace:System;assembly=mscorlib" + xmlns:sys="clr-namespace:System;assembly=System.Runtime" xmlns:v="clr-namespace:ImageResizer.Views"> diff --git a/src/modules/imageresizer/ui/App.xaml.cs b/src/modules/imageresizer/ui/App.xaml.cs index 02b7ecc3cb..1d6fba2cd5 100644 --- a/src/modules/imageresizer/ui/App.xaml.cs +++ b/src/modules/imageresizer/ui/App.xaml.cs @@ -5,7 +5,6 @@ using System; using System.Text; using System.Windows; -using GalaSoft.MvvmLight.Threading; using ImageResizer.Models; using ImageResizer.Properties; using ImageResizer.Utilities; @@ -19,7 +18,6 @@ namespace ImageResizer static App() { Console.InputEncoding = Encoding.Unicode; - DispatcherHelper.Initialize(); } protected override void OnStartup(StartupEventArgs e) diff --git a/src/modules/imageresizer/ui/Helpers/Observable.cs b/src/modules/imageresizer/ui/Helpers/Observable.cs new file mode 100644 index 0000000000..f631ca0ab3 --- /dev/null +++ b/src/modules/imageresizer/ui/Helpers/Observable.cs @@ -0,0 +1,27 @@ +// 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.ComponentModel; +using System.Runtime.CompilerServices; + +namespace ImageResizer.Helpers +{ + public class Observable : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + + protected void Set(ref T storage, T value, [CallerMemberName] string propertyName = null) + { + if (Equals(storage, value)) + { + return; + } + + storage = value; + OnPropertyChanged(propertyName); + } + + protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +} diff --git a/src/modules/imageresizer/ui/Helpers/RelayCommand.cs b/src/modules/imageresizer/ui/Helpers/RelayCommand.cs new file mode 100644 index 0000000000..39843ff837 --- /dev/null +++ b/src/modules/imageresizer/ui/Helpers/RelayCommand.cs @@ -0,0 +1,61 @@ +// 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.Windows.Input; + +namespace ImageResizer.Helpers +{ + public class RelayCommand : ICommand + { + private readonly Action _execute; + private readonly Func _canExecute; + + public event EventHandler CanExecuteChanged; + + public RelayCommand(Action execute) + : this(execute, null) + { + } + + public RelayCommand(Action execute, Func canExecute) + { + _execute = execute ?? throw new ArgumentNullException(nameof(execute)); + _canExecute = canExecute; + } + + public bool CanExecute(object parameter) => _canExecute == null || _canExecute(); + + public void Execute(object parameter) => _execute(); + + public void OnCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty); + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "abstract T and abstract")] + public class RelayCommand : ICommand + { + private readonly Action execute; + + private readonly Func canExecute; + + public event EventHandler CanExecuteChanged; + + public RelayCommand(Action execute) + : this(execute, null) + { + } + + public RelayCommand(Action execute, Func canExecute) + { + this.execute = execute ?? throw new ArgumentNullException(nameof(execute)); + this.canExecute = canExecute; + } + + public bool CanExecute(object parameter) => canExecute == null || canExecute((T)parameter); + + public void Execute(object parameter) => execute((T)parameter); + + public void OnCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty); + } +} diff --git a/src/modules/imageresizer/ui/ImageResizerUI.csproj b/src/modules/imageresizer/ui/ImageResizerUI.csproj index 84fd5a84dc..e94aa10651 100644 --- a/src/modules/imageresizer/ui/ImageResizerUI.csproj +++ b/src/modules/imageresizer/ui/ImageResizerUI.csproj @@ -1,193 +1,60 @@ - - - + - + ImageResizer Microsoft Corp. Copyright (C) 2019 Microsoft Corp. + ..\..\..\codeAnalysis\Rules.ruleset + $(SolutionDir)$(Platform)\$(Configuration)\modules\ImageResizer + false + false + true + x64 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - Debug - x64 + x64 {2BE46397-4DFA-414C-9BD4-41E4BBF8CB34} WinExe ImageResizer ImageResizer - v4.7.2 - 512 + netcoreapp3.1 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - - true $(SolutionDir)$(Platform)\$(Configuration)\obj\$(AssemblyName)\ - - x64 - true - full - false - $(SolutionDir)$(Platform)\$(Configuration)\modules\ImageResizer - DEBUG;TRACE - prompt - 4 - false - ..\..\..\codeAnalysis\Rules.ruleset - - - x64 - pdbonly - true - $(SolutionDir)$(Platform)\$(Configuration)\modules\ImageResizer - TRACE - prompt - 4 - false - ..\..\..\codeAnalysis\Rules.ruleset - + Resources\ImageResizer.ico + en-US + + + true + true + x64 + + + true + false + x64 + + - - - - - - + - - MSBuild:Compile - Designer - - - GlobalSuppressions.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - AdvancedWindow.xaml - - - - - ProgressPage.xaml - - - - ResultsPage.xaml - - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - MSBuild:Compile - Designer - - - App.xaml - Code - - - InputPage.xaml - - - MainWindow.xaml - Code - - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - - - - - Code - - - True - True - Resources.resx - - + PublicResXFileCodeGenerator Resources.Designer.cs Designer - + - - - @@ -195,31 +62,23 @@ - - 3.3.0 - runtime; build; native; contentfiles; analyzers; buildtransitive + all - - 5.4.1.1 - - - 12.0.3 - - - 1.1.118 - runtime; build; native; contentfiles; analyzers; buildtransitive + + + all - - {f055103b-f80b-4d0c-bf48-057c55620033} - interop - + + + + + True + True + Resources.resx + - - - $(TargetFrameworkSDKToolsDirectory)$(Platform)\ - \ No newline at end of file diff --git a/src/modules/imageresizer/ui/Models/ResizeSize.cs b/src/modules/imageresizer/ui/Models/ResizeSize.cs index f9d1145b65..bfc6aef1d2 100644 --- a/src/modules/imageresizer/ui/Models/ResizeSize.cs +++ b/src/modules/imageresizer/ui/Models/ResizeSize.cs @@ -4,14 +4,14 @@ using System.Collections.Generic; using System.Diagnostics; -using GalaSoft.MvvmLight; +using ImageResizer.Helpers; using ImageResizer.Properties; using Newtonsoft.Json; namespace ImageResizer.Models { [JsonObject(MemberSerialization.OptIn)] - public class ResizeSize : ObservableObject + public class ResizeSize : Observable { private static readonly IDictionary _tokens = new Dictionary { @@ -45,7 +45,7 @@ namespace ImageResizer.Models public virtual string Name { get => _name; - set => Set(nameof(Name), ref _name, ReplaceTokens(value)); + set => Set(ref _name, ReplaceTokens(value)); } [JsonProperty(PropertyName = "fit")] @@ -54,7 +54,8 @@ namespace ImageResizer.Models get => _fit; set { - if (Set(nameof(Fit), ref _fit, value)) + Set(ref _fit, value); + if (!Equals(_fit, value)) { UpdateShowHeight(); } @@ -65,14 +66,14 @@ namespace ImageResizer.Models public double Width { get => _width; - set => Set(nameof(Width), ref _width, value); + set => Set(ref _width, value); } [JsonProperty(PropertyName = "height")] public double Height { get => _height; - set => Set(nameof(Height), ref _height, value); + set => Set(ref _height, value); } public bool ShowHeight @@ -87,7 +88,8 @@ namespace ImageResizer.Models get => _unit; set { - if (Set(nameof(Unit), ref _unit, value)) + Set(ref _unit, value); + if (!Equals(_unit, value)) { UpdateShowHeight(); } @@ -113,7 +115,6 @@ namespace ImageResizer.Models private void UpdateShowHeight() => Set( - nameof(ShowHeight), ref _showHeight, Fit == ResizeFit.Stretch || Unit != ResizeUnit.Percent); diff --git a/src/modules/imageresizer/ui/Properties/Settings.cs b/src/modules/imageresizer/ui/Properties/Settings.cs index ffb0f44146..e2d73a7fe5 100644 --- a/src/modules/imageresizer/ui/Properties/Settings.cs +++ b/src/modules/imageresizer/ui/Properties/Settings.cs @@ -2,6 +2,7 @@ // 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/ +using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -65,14 +66,14 @@ namespace ImageResizer.Properties public string FileNameFormat => _fileNameFormat ?? (_fileNameFormat = FileName - .Replace("{", "{{") - .Replace("}", "}}") - .Replace("%1", "{0}") - .Replace("%2", "{1}") - .Replace("%3", "{2}") - .Replace("%4", "{3}") - .Replace("%5", "{4}") - .Replace("%6", "{5}")); + .Replace("{", "{{", StringComparison.OrdinalIgnoreCase) + .Replace("}", "}}", StringComparison.OrdinalIgnoreCase) + .Replace("%1", "{0}", StringComparison.OrdinalIgnoreCase) + .Replace("%2", "{1}", StringComparison.OrdinalIgnoreCase) + .Replace("%3", "{2}", StringComparison.OrdinalIgnoreCase) + .Replace("%4", "{3}", StringComparison.OrdinalIgnoreCase) + .Replace("%5", "{4}", StringComparison.OrdinalIgnoreCase) + .Replace("%6", "{5}", StringComparison.OrdinalIgnoreCase)); public ResizeSize SelectedSize { diff --git a/src/modules/imageresizer/ui/ViewModels/AdvancedViewModel.cs b/src/modules/imageresizer/ui/ViewModels/AdvancedViewModel.cs index 8348a667c6..db2b726060 100644 --- a/src/modules/imageresizer/ui/ViewModels/AdvancedViewModel.cs +++ b/src/modules/imageresizer/ui/ViewModels/AdvancedViewModel.cs @@ -7,14 +7,13 @@ using System.Collections.Generic; using System.Reflection; using System.Windows.Input; using System.Windows.Media.Imaging; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; +using ImageResizer.Helpers; using ImageResizer.Models; using ImageResizer.Properties; namespace ImageResizer.ViewModels { - public class AdvancedViewModel : ViewModelBase + public class AdvancedViewModel : Observable { private static Dictionary InitEncoderMap() { diff --git a/src/modules/imageresizer/ui/ViewModels/InputViewModel.cs b/src/modules/imageresizer/ui/ViewModels/InputViewModel.cs index e863b5e8c4..6913e67867 100644 --- a/src/modules/imageresizer/ui/ViewModels/InputViewModel.cs +++ b/src/modules/imageresizer/ui/ViewModels/InputViewModel.cs @@ -4,15 +4,14 @@ // ShowAdvancedCommand = new RelayCommand(ShowAdvanced); using System.Windows.Input; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; +using ImageResizer.Helpers; using ImageResizer.Models; using ImageResizer.Properties; using ImageResizer.Views; namespace ImageResizer.ViewModels { - public class InputViewModel : ViewModelBase + public class InputViewModel : Observable { private readonly ResizeBatch _batch; private readonly MainViewModel _mainViewModel; diff --git a/src/modules/imageresizer/ui/ViewModels/MainViewModel.cs b/src/modules/imageresizer/ui/ViewModels/MainViewModel.cs index a11f047161..8f335e4b1d 100644 --- a/src/modules/imageresizer/ui/ViewModels/MainViewModel.cs +++ b/src/modules/imageresizer/ui/ViewModels/MainViewModel.cs @@ -4,15 +4,14 @@ using System.Collections.Generic; using System.Windows.Input; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; +using ImageResizer.Helpers; using ImageResizer.Models; using ImageResizer.Properties; using ImageResizer.Views; namespace ImageResizer.ViewModels { - public class MainViewModel : ViewModelBase + public class MainViewModel : Observable { private readonly Settings _settings; private readonly ResizeBatch _batch; @@ -32,13 +31,13 @@ namespace ImageResizer.ViewModels public object CurrentPage { get => _currentPage; - set => Set(nameof(CurrentPage), ref _currentPage, value); + set => Set(ref _currentPage, value); } public double Progress { get => _progress; - set => Set(nameof(Progress), ref _progress, value); + set => Set(ref _progress, value); } public void Load(IMainView view) diff --git a/src/modules/imageresizer/ui/ViewModels/ProgressViewModel.cs b/src/modules/imageresizer/ui/ViewModels/ProgressViewModel.cs index 7763eb961e..826041fc0a 100644 --- a/src/modules/imageresizer/ui/ViewModels/ProgressViewModel.cs +++ b/src/modules/imageresizer/ui/ViewModels/ProgressViewModel.cs @@ -8,14 +8,13 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows.Input; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; +using ImageResizer.Helpers; using ImageResizer.Models; using ImageResizer.Views; namespace ImageResizer.ViewModels { - public class ProgressViewModel : ViewModelBase, IDisposable + public class ProgressViewModel : Observable, IDisposable { private readonly MainViewModel _mainViewModel; private readonly ResizeBatch _batch; @@ -43,13 +42,13 @@ namespace ImageResizer.ViewModels public double Progress { get => _progress; - set => Set(nameof(Progress), ref _progress, value); + set => Set(ref _progress, value); } public TimeSpan TimeRemaining { get => _timeRemaining; - set => Set(nameof(TimeRemaining), ref _timeRemaining, value); + set => Set(ref _timeRemaining, value); } public ICommand StartCommand { get; } diff --git a/src/modules/imageresizer/ui/ViewModels/ResultsViewModel.cs b/src/modules/imageresizer/ui/ViewModels/ResultsViewModel.cs index a15e57747d..39c49f8aa5 100644 --- a/src/modules/imageresizer/ui/ViewModels/ResultsViewModel.cs +++ b/src/modules/imageresizer/ui/ViewModels/ResultsViewModel.cs @@ -4,14 +4,13 @@ using System.Collections.Generic; using System.Windows.Input; -using GalaSoft.MvvmLight; -using GalaSoft.MvvmLight.Command; +using ImageResizer.Helpers; using ImageResizer.Models; using ImageResizer.Views; namespace ImageResizer.ViewModels { - public class ResultsViewModel : ViewModelBase + public class ResultsViewModel : Observable { private readonly IMainView _mainView; diff --git a/src/modules/imageresizer/ui/Views/MainWindow.xaml b/src/modules/imageresizer/ui/Views/MainWindow.xaml index 466136a2c2..243e89048c 100644 --- a/src/modules/imageresizer/ui/Views/MainWindow.xaml +++ b/src/modules/imageresizer/ui/Views/MainWindow.xaml @@ -1,7 +1,7 @@  - - - - - + + + + + diff --git a/src/modules/imageresizer/ui/Views/ProgressPage.xaml b/src/modules/imageresizer/ui/Views/ProgressPage.xaml index 72735f2c79..525969c91d 100644 --- a/src/modules/imageresizer/ui/Views/ProgressPage.xaml +++ b/src/modules/imageresizer/ui/Views/ProgressPage.xaml @@ -1,7 +1,7 @@  @@ -10,11 +10,11 @@ - - - - - + + + + +