Merge pull request #8121 from microsoft/dev/crutkas/FxCop_fzEditor_pass1

Dev/crutkas/fx cop fz editor pass1
This commit is contained in:
Clint Rutkas
2020-11-19 14:50:33 -08:00
committed by GitHub
14 changed files with 38 additions and 37 deletions

View File

@@ -7,7 +7,6 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.IO.Abstractions;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
@@ -42,8 +41,6 @@ namespace FancyZonesEditor
private const string CrashReportDynamicAssemblyTag = "dynamic assembly doesn't have location"; private const string CrashReportDynamicAssemblyTag = "dynamic assembly doesn't have location";
private const string CrashReportLocationNullTag = "location is null or empty"; private const string CrashReportLocationNullTag = "location is null or empty";
private readonly IFileSystem _fileSystem = new FileSystem();
public MainWindowSettingsModel MainWindowSettings { get; } public MainWindowSettingsModel MainWindowSettings { get; }
public static FancyZonesEditorIO FancyZonesEditorIO { get; private set; } public static FancyZonesEditorIO FancyZonesEditorIO { get; private set; }
@@ -60,7 +57,7 @@ namespace FancyZonesEditor
} }
} }
private static bool _debugMode = false; private static bool _debugMode;
[Conditional("DEBUG")] [Conditional("DEBUG")]
private void DebugModeCheck() private void DebugModeCheck()

View File

@@ -271,7 +271,7 @@ namespace FancyZonesEditor
Model.Zones[ZoneIndex] = rect; Model.Zones[ZoneIndex] = rect;
} }
private static int zIndex = 0; private static int zIndex;
private const int MinZoneWidth = 64; private const int MinZoneWidth = 64;
private const int MinZoneHeight = 72; private const int MinZoneHeight = 72;

View File

@@ -152,7 +152,7 @@
<Compile Include="Models\LayoutModel.cs" /> <Compile Include="Models\LayoutModel.cs" />
<Compile Include="Models\MainWindowSettingsModel.cs" /> <Compile Include="Models\MainWindowSettingsModel.cs" />
<Compile Include="Converters\ModelToVisibilityConverter.xaml.cs" /> <Compile Include="Converters\ModelToVisibilityConverter.xaml.cs" />
<Compile Include="Native.cs" /> <Compile Include="NativeMethods.cs" />
<Compile Include="RowColInfo.cs" /> <Compile Include="RowColInfo.cs" />
<Compile Include="GridEditorWindow.xaml.cs"> <Compile Include="GridEditorWindow.xaml.cs">
<DependentUpon>GridEditorWindow.xaml</DependentUpon> <DependentUpon>GridEditorWindow.xaml</DependentUpon>

View File

@@ -48,6 +48,16 @@ namespace FancyZonesEditor
public void CalcAdjacentZones(int index, int size, List<RowColInfo> info, Func<int, bool> indexCmpr) public void CalcAdjacentZones(int index, int size, List<RowColInfo> info, Func<int, bool> indexCmpr)
{ {
if (info == null)
{
throw new ArgumentNullException(nameof(info));
}
if (indexCmpr == null)
{
throw new ArgumentNullException(nameof(indexCmpr));
}
int ind = index; int ind = index;
while (ind > 0 && indexCmpr(ind)) while (ind > 0 && indexCmpr(ind))
{ {

View File

@@ -24,7 +24,7 @@ namespace FancyZonesEditor
public static readonly DependencyProperty ModelProperty = DependencyProperty.Register(ObjectDependencyID, typeof(GridLayoutModel), typeof(GridEditor), new PropertyMetadata(null, OnGridDimensionsChanged)); public static readonly DependencyProperty ModelProperty = DependencyProperty.Register(ObjectDependencyID, typeof(GridLayoutModel), typeof(GridEditor), new PropertyMetadata(null, OnGridDimensionsChanged));
private static int gridEditorUniqueIdCounter = 0; private static int gridEditorUniqueIdCounter;
private int gridEditorUniqueId; private int gridEditorUniqueId;

View File

@@ -37,10 +37,10 @@ namespace FancyZonesEditor
public double[] HorizontalSnapPoints { get; set; } public double[] HorizontalSnapPoints { get; set; }
private readonly Rectangle _splitter; private readonly Rectangle _splitter;
private bool _switchOrientation = false; private bool _switchOrientation;
private Point _lastPos = new Point(-1, -1); private Point _lastPos = new Point(-1, -1);
private Point _mouseDownPos = new Point(-1, -1); private Point _mouseDownPos = new Point(-1, -1);
private bool _inMergeDrag = false; private bool _inMergeDrag;
private Orientation _splitOrientation; private Orientation _splitOrientation;
private static void OnSelectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) private static void OnSelectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

View File

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
using System.Globalization;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
@@ -50,6 +51,7 @@ namespace FancyZonesEditor.Utils
{ {
float dpi = Dpi != 0 ? Dpi : 96f; float dpi = Dpi != 0 ? Dpi : 96f;
double scaleFactor = 96f / dpi; double scaleFactor = 96f / dpi;
return Math.Round(coordinate * scaleFactor); return Math.Round(coordinate * scaleFactor);
} }
@@ -57,23 +59,17 @@ namespace FancyZonesEditor.Utils
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.Append("ID: "); sb.AppendFormat(CultureInfo.InvariantCulture, "ID: {0}{1}", Id, Environment.NewLine);
sb.AppendLine(Id); sb.AppendFormat(CultureInfo.InvariantCulture, "DPI: {0}{1}", Dpi, Environment.NewLine);
sb.Append("DPI: "); sb.AppendFormat(CultureInfo.InvariantCulture, "Is primary: {0}{1}", Primary, Environment.NewLine);
sb.AppendLine(Dpi.ToString());
sb.Append("Is primary: ");
sb.AppendLine(Primary.ToString());
string workArea = string.Format("({0}, {1}, {2}, {3})", WorkAreaRect.X, WorkAreaRect.Y, WorkAreaRect.Width, WorkAreaRect.Height); string workArea = string.Format(CultureInfo.InvariantCulture, "({0}, {1}, {2}, {3})", WorkAreaRect.X, WorkAreaRect.Y, WorkAreaRect.Width, WorkAreaRect.Height);
string bounds = string.Format("({0}, {1}, {2}, {3})", UnscaledBounds.X, UnscaledBounds.Y, UnscaledBounds.Width, UnscaledBounds.Height); string bounds = string.Format(CultureInfo.InvariantCulture, "({0}, {1}, {2}, {3})", UnscaledBounds.X, UnscaledBounds.Y, UnscaledBounds.Width, UnscaledBounds.Height);
string scaledBounds = string.Format("({0}, {1}, {2}, {3})", ScaledBounds.X, ScaledBounds.Y, ScaledBounds.Width, ScaledBounds.Height); string scaledBounds = string.Format(CultureInfo.InvariantCulture, "({0}, {1}, {2}, {3})", ScaledBounds.X, ScaledBounds.Y, ScaledBounds.Width, ScaledBounds.Height);
sb.Append("Work area: "); sb.AppendFormat(CultureInfo.InvariantCulture, "Work area: {0}{1}", workArea, Environment.NewLine);
sb.AppendLine(workArea); sb.AppendFormat(CultureInfo.InvariantCulture, "Unscaled bounds: {0}{1}", bounds, Environment.NewLine);
sb.Append("Unscaled bounds: "); sb.AppendFormat(CultureInfo.InvariantCulture, "Scaled bounds: {0}{1}", scaledBounds, Environment.NewLine);
sb.AppendLine(bounds);
sb.Append("Scaled bounds: ");
sb.AppendLine(scaledBounds);
return sb.ToString(); return sb.ToString();
} }

View File

@@ -78,7 +78,7 @@ namespace FancyZonesEditor.Models
{ {
get get
{ {
return "{" + Guid.ToString().ToUpper() + "}"; return "{" + Guid.ToString().ToUpperInvariant() + "}";
} }
} }
@@ -185,7 +185,7 @@ namespace FancyZonesEditor.Models
return _customModels; return _customModels;
} }
private static ObservableCollection<LayoutModel> _customModels = null; private static ObservableCollection<LayoutModel> _customModels;
private static List<string> _deletedCustomModels = new List<string>(); private static List<string> _deletedCustomModels = new List<string>();
private static List<JsonElement> _createdCustomLayouts = new List<JsonElement>(); private static List<JsonElement> _createdCustomLayouts = new List<JsonElement>();

View File

@@ -40,8 +40,6 @@ namespace FancyZonesEditor
public const ushort _blankCustomModelId = 0xFFFA; public const ushort _blankCustomModelId = 0xFFFA;
public const ushort _lastDefinedId = _blankCustomModelId; public const ushort _lastDefinedId = _blankCustomModelId;
private const int MaxNegativeSpacing = -10;
// Non-localizable strings // Non-localizable strings
public static readonly string RegistryPath = "SOFTWARE\\SuperFancyZones"; public static readonly string RegistryPath = "SOFTWARE\\SuperFancyZones";
public static readonly string FullRegistryPath = "HKEY_CURRENT_USER\\" + RegistryPath; public static readonly string FullRegistryPath = "HKEY_CURRENT_USER\\" + RegistryPath;
@@ -394,7 +392,7 @@ namespace FancyZonesEditor
{ {
foreach (LayoutModel model in MainWindowSettingsModel.CustomModels) foreach (LayoutModel model in MainWindowSettingsModel.CustomModels)
{ {
if ("{" + model.Guid.ToString().ToUpper() + "}" == currentApplied.ZonesetUuid.ToUpper()) if ("{" + model.Guid.ToString().ToUpperInvariant() + "}" == currentApplied.ZonesetUuid.ToUpperInvariant())
{ {
// found match // found match
foundModel = model; foundModel = model;

View File

@@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
namespace FancyZonesEditor namespace FancyZonesEditor
{ {
// PInvokes to handshake with fancyzones backend // PInvokes to handshake with fancyzones backend
internal static class Native internal static class NativeMethods
{ {
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)] [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName); public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName);

View File

@@ -115,7 +115,7 @@ namespace FancyZonesEditor
} }
} }
private int _currentDesktop = 0; private int _currentDesktop;
public bool SpanZonesAcrossMonitors public bool SpanZonesAcrossMonitors
{ {

View File

@@ -381,7 +381,7 @@ namespace FancyZonesEditor.Utils
string uuid = current.GetProperty(UuidJsonTag).GetString(); string uuid = current.GetProperty(UuidJsonTag).GetString();
var info = current.GetProperty(InfoJsonTag); var info = current.GetProperty(InfoJsonTag);
if (type.Equals(GridJsonTag)) if (type.Equals(GridJsonTag, StringComparison.OrdinalIgnoreCase))
{ {
bool error = false; bool error = false;
@@ -453,13 +453,13 @@ namespace FancyZonesEditor.Utils
if (error) if (error)
{ {
App.ShowExceptionMessageBox(string.Format(Properties.Resources.Error_Layout_Malformed_Data, name)); App.ShowExceptionMessageBox(string.Format(Properties.Resources.Error_Layout_Malformed_Data, name));
deleted.Add(Guid.Parse(uuid).ToString().ToUpper()); deleted.Add(Guid.Parse(uuid).ToString().ToUpperInvariant());
continue; continue;
} }
custom.Add(new GridLayoutModel(uuid, name, LayoutType.Custom, rows, columns, rowsPercentage, columnsPercentage, cellChildMap)); custom.Add(new GridLayoutModel(uuid, name, LayoutType.Custom, rows, columns, rowsPercentage, columnsPercentage, cellChildMap));
} }
else if (type.Equals(CanvasJsonTag)) else if (type.Equals(CanvasJsonTag, StringComparison.OrdinalIgnoreCase))
{ {
int workAreaWidth = info.GetProperty(RefWidthJsonTag).GetInt32(); int workAreaWidth = info.GetProperty(RefWidthJsonTag).GetInt32();
int workAreaHeight = info.GetProperty(RefHeightJsonTag).GetInt32(); int workAreaHeight = info.GetProperty(RefHeightJsonTag).GetInt32();
@@ -493,7 +493,7 @@ namespace FancyZonesEditor.Utils
if (error) if (error)
{ {
App.ShowExceptionMessageBox(string.Format(Properties.Resources.Error_Layout_Malformed_Data, name)); App.ShowExceptionMessageBox(string.Format(Properties.Resources.Error_Layout_Malformed_Data, name));
deleted.Add(Guid.Parse(uuid).ToString().ToUpper()); deleted.Add(Guid.Parse(uuid).ToString().ToUpperInvariant());
continue; continue;
} }

View File

@@ -22,7 +22,7 @@ namespace FancyZonesEditor.Utils
{ {
if (execute == null) if (execute == null)
{ {
throw new ArgumentNullException("execute"); throw new ArgumentNullException(nameof(execute));
} }
_execute = execute; _execute = execute;

View File

@@ -22,7 +22,7 @@ namespace FancyZonesEditor.Utils
{ {
if (execute == null) if (execute == null)
{ {
throw new ArgumentNullException("execute"); throw new ArgumentNullException(nameof(execute));
} }
_execute = execute; _execute = execute;