Files
PowerToys/src/modules/imageresizer/ui/ViewModels/AdvancedViewModel.cs
Jeremy Sinclair eadcf4b120 [Analyzers] Update .editorconfig with rules to relax IDE errors (#36095)
* [Analyzers] Remove duplicate pascal case style from .editorconfig

* [Analyzers] Configured severity for individual IDE and CA rules showing as errors in VS

Set severity for IDE0005, IDE0008, IDE0016, IDE0018, IDE0019, IDE0021, IDE0022, IDE0023, IDE0025, IDE0027, IDE0028, IDE0029, IDE0031, IDE0032, IDE0034, IDE0036, IDE0039, IDE0042, IDE0044, IDE0045, IDE0046, IDE0047, IDE0057, IDE0051, IDE0052, IDE0054, IDE0055, IDE0056, IDE0057, IDE0059, IDE0060, IDE0061, IDE0063, IDE0071, IDE0073, IDE0074, IDE0075, IDE0077, IDE0078, IDE0083, IDE0090, IDE0100, IDE0130, IDE160, IDE180, IDE0200, IDE0240, IDE0250, IDE0251, IDE0260, IDE0270, IDE0290, IDE0300, IDE0301, IDE0305, IDE1005, IDE1006, CA1859, CA2022, CA2263

* [Analyzers] Fix mismatched analyzer descriptions

* [Analyzers] Fix misspelling

* Update .editorconfig

Made the following style rules `silent` instead of `suggestion`: 
- Use explicit type instead of 'var'
- Use expression body for ...
- Use block-scoped namespace

* [Analyzers] Set IDE0290 to silent

* [Analyzers] Remove IDE1006 configuration from .editorconfig in favor of making exclusions for the few entries

* [Analyzers][Indexer] Add IDE1006 suppressions

* [Analyzers][Peek] Add IDE1006 suppression

* [Analyzers][MWB] Add IDE1006 suppression.

* [Analyzers][Plugins] Add IDE1006 suppression

* [Analyzers][ImageResizer] Suppress IDE0073 to retain original copyright

* [Analyzers] Remove IDE0073 severity change in .editorconfig

---------

Co-authored-by: Ani <115020168+drawbyperpetual@users.noreply.github.com>
2024-12-04 12:58:36 -05:00

90 lines
3.0 KiB
C#

#pragma warning disable IDE0073
// 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/
#pragma warning restore IDE0073
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using ImageResizer.Helpers;
using ImageResizer.Models;
using ImageResizer.Properties;
namespace ImageResizer.ViewModels
{
public class AdvancedViewModel : Observable
{
private static Dictionary<Guid, string> InitEncoderMap()
{
var bmpCodec = new BmpBitmapEncoder().CodecInfo;
var gifCodec = new GifBitmapEncoder().CodecInfo;
var jpegCodec = new JpegBitmapEncoder().CodecInfo;
var pngCodec = new PngBitmapEncoder().CodecInfo;
var tiffCodec = new TiffBitmapEncoder().CodecInfo;
var wmpCodec = new WmpBitmapEncoder().CodecInfo;
return new Dictionary<Guid, string>
{
[bmpCodec.ContainerFormat] = bmpCodec.FriendlyName,
[gifCodec.ContainerFormat] = gifCodec.FriendlyName,
[jpegCodec.ContainerFormat] = jpegCodec.FriendlyName,
[pngCodec.ContainerFormat] = pngCodec.FriendlyName,
[tiffCodec.ContainerFormat] = tiffCodec.FriendlyName,
[wmpCodec.ContainerFormat] = wmpCodec.FriendlyName,
};
}
public AdvancedViewModel(Settings settings)
{
RemoveSizeCommand = new RelayCommand<ResizeSize>(RemoveSize);
AddSizeCommand = new RelayCommand(AddSize);
Settings = settings;
}
public static IDictionary<Guid, string> EncoderMap { get; } = InitEncoderMap();
public Settings Settings { get; }
public static string Version
=> typeof(AdvancedViewModel).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion;
public static IEnumerable<Guid> Encoders => EncoderMap.Keys;
public ICommand RemoveSizeCommand { get; }
public ICommand AddSizeCommand { get; }
public void RemoveSize(ResizeSize size)
=> Settings.Sizes.Remove(size);
public void AddSize()
=> Settings.Sizes.Add(new ResizeSize());
public void Close(bool accepted)
{
if (accepted)
{
Settings.Save();
return;
}
var selectedSizeIndex = Settings.SelectedSizeIndex;
var shrinkOnly = Settings.ShrinkOnly;
var replace = Settings.Replace;
var ignoreOrientation = Settings.IgnoreOrientation;
Settings.Reload();
Settings.SelectedSizeIndex = selectedSizeIndex;
Settings.ShrinkOnly = shrinkOnly;
Settings.Replace = replace;
Settings.IgnoreOrientation = ignoreOrientation;
}
}
}