diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml index c1a3ea97ba..27321f82cc 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml +++ b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml @@ -3,7 +3,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:FancyZonesEditor" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml.cs index 57996ac6fc..344bdeed9a 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/CanvasEditor.xaml.cs @@ -13,18 +13,20 @@ namespace FancyZonesEditor /// public partial class CanvasEditor : UserControl { + private CanvasLayoutModel _model; + public CanvasEditor() { InitializeComponent(); - Loaded += CanvasEditor_Loaded; + Loaded += OnLoaded; } - private void CanvasEditor_Loaded(object sender, RoutedEventArgs e) + private void OnLoaded(object sender, RoutedEventArgs e) { CanvasLayoutModel model = (CanvasLayoutModel)DataContext; if (model != null) { - Model = model; + _model = model; UpdateZoneRects(); model.PropertyChanged += OnModelChanged; @@ -43,17 +45,19 @@ namespace FancyZonesEditor { UIElementCollection previewChildren = Preview.Children; int previewChildrenCount = previewChildren.Count; - while (previewChildrenCount < Model.Zones.Count) + while (previewChildrenCount < _model.Zones.Count) { - CanvasZone zone = new CanvasZone(); - zone.Model = Model; + CanvasZone zone = new CanvasZone + { + Model = _model, + }; Preview.Children.Add(zone); previewChildrenCount++; } for (int i = 0; i < previewChildrenCount; i++) { - Int32Rect rect = Model.Zones[i]; + Int32Rect rect = _model.Zones[i]; CanvasZone zone = previewChildren[i] as CanvasZone; zone.ZoneIndex = i; @@ -63,7 +67,5 @@ namespace FancyZonesEditor zone.MinWidth = rect.Width; } } - - public CanvasLayoutModel Model; } } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/EditorOverlay.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/EditorOverlay.xaml.cs index 146196b68b..26bd9c3079 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/EditorOverlay.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/EditorOverlay.xaml.cs @@ -43,7 +43,7 @@ namespace FancyZonesEditor int i = 0; foreach (FrameworkElement child in previewPanel.Children) { - Point topLeft = child.TransformToAncestor(previewPanel).Transform(default(Point)); + Point topLeft = child.TransformToAncestor(previewPanel).Transform(default); var right = topLeft.X + child.ActualWidth; var bottom = topLeft.Y + child.ActualHeight; @@ -78,15 +78,19 @@ namespace FancyZonesEditor DataContext = null; _editor = null; - _layoutPreview = new LayoutPreview(); - _layoutPreview.IsActualSize = true; - _layoutPreview.Opacity = 0.5; + _layoutPreview = new LayoutPreview + { + IsActualSize = true, + Opacity = 0.5, + }; Content = _layoutPreview; - MainWindow window = new MainWindow(); - window.Owner = this; - window.ShowActivated = true; - window.Topmost = true; + MainWindow window = new MainWindow + { + Owner = this, + ShowActivated = true, + Topmost = true, + }; window.Show(); // window is set to topmost to make sure it shows on top of PowerToys settings page diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs b/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs index f8ef6c257a..ed11e357dd 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs @@ -14,8 +14,7 @@ namespace FancyZonesEditor protected void OnSaveApplyTemplate(object sender, RoutedEventArgs e) { EditorOverlay mainEditor = EditorOverlay.Current; - var model = mainEditor.DataContext as LayoutModel; - if (model != null) + if (mainEditor.DataContext is LayoutModel model) { model.Persist(mainEditor.GetZoneRects()); } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs index 676aa97e0f..84f868f2f5 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/GridEditor.xaml.cs @@ -466,10 +466,12 @@ namespace FancyZonesEditor private void AddDragHandle(Orientation orientation, int index) { - GridResizer resizer = new GridResizer(); - resizer.Orientation = orientation; - resizer.Index = index; - resizer.Model = Model; + GridResizer resizer = new GridResizer + { + Orientation = orientation, + Index = index, + Model = Model + }; resizer.DragDelta += Resizer_DragDelta; if (orientation == Orientation.Vertical) { @@ -537,8 +539,6 @@ namespace FancyZonesEditor private void OnGridDimensionsChanged() { - GridLayoutModel model = Model; - Size actualSize = new Size(ActualWidth, ActualHeight); if (actualSize.Width > 0) { diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/GridZone.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/GridZone.xaml.cs index 760c91f0a6..40583c20ae 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/GridZone.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/GridZone.xaml.cs @@ -258,26 +258,17 @@ namespace FancyZonesEditor private void DoMergeDrag(MouseEventArgs e) { - if (MergeDrag != null) - { - MergeDrag(this, e); - } + MergeDrag?.Invoke(this, e); } private void DoMergeComplete(MouseButtonEventArgs e) { - if (MergeComplete != null) - { - MergeComplete(this, e); - } + MergeComplete?.Invoke(this, e); } private void DoSplit(Orientation orientation, double offset) { - if (Split != null) - { - Split(this, new SplitEventArgs(orientation, offset)); - } + Split?.Invoke(this, new SplitEventArgs(orientation, offset)); } private void FullSplit_Click(object sender, RoutedEventArgs e) @@ -287,10 +278,7 @@ namespace FancyZonesEditor private void DoFullSplit() { - if (FullSplit != null) - { - FullSplit(this, new SplitEventArgs()); - } + FullSplit?.Invoke(this, new SplitEventArgs()); } } } diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/LayoutPreview.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/LayoutPreview.xaml.cs index 3a530acc05..5dea8f92df 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/LayoutPreview.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/LayoutPreview.xaml.cs @@ -89,8 +89,7 @@ namespace FancyZonesEditor } else { - var canvasModel = _model as CanvasLayoutModel; - if (canvasModel != null) + if (_model is CanvasLayoutModel canvasModel) { RenderCanvasPreview(canvasModel); } @@ -102,16 +101,20 @@ namespace FancyZonesEditor Body.RowDefinitions.Clear(); foreach (int percent in grid.RowPercents) { - RowDefinition def = new RowDefinition(); - def.Height = new GridLength(percent, GridUnitType.Star); + RowDefinition def = new RowDefinition + { + Height = new GridLength(percent, GridUnitType.Star), + }; Body.RowDefinitions.Add(def); } Body.ColumnDefinitions.Clear(); foreach (int percent in grid.ColumnPercents) { - ColumnDefinition def = new ColumnDefinition(); - def.Width = new GridLength(percent, GridUnitType.Star); + ColumnDefinition def = new ColumnDefinition + { + Width = new GridLength(percent, GridUnitType.Star), + }; Body.ColumnDefinitions.Add(def); } @@ -167,8 +170,10 @@ namespace FancyZonesEditor Body.RowDefinitions.Clear(); Body.ColumnDefinitions.Clear(); - Viewbox viewbox = new Viewbox(); - viewbox.Stretch = Stretch.Uniform; + Viewbox viewbox = new Viewbox + { + Stretch = Stretch.Uniform, + }; Body.Children.Add(viewbox); Canvas frame = new Canvas(); viewbox.Child = frame; diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs index cfafe52805..54869e71cf 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs @@ -6,9 +6,7 @@ using System; using System.Linq; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; using System.Windows.Input; -using System.Windows.Media; using FancyZonesEditor.Models; using MahApps.Metro.Controls; @@ -20,10 +18,9 @@ namespace FancyZonesEditor public partial class MainWindow : MetroWindow { // TODO: share the constants b/w C# Editor and FancyZoneLib - public static int MAX_ZONES = 40; + public const int MaxZones = 40; private static string _defaultNamePrefix = "Custom Layout "; private bool _editing = false; - private int _wrapPanelItemSize = 262; public MainWindow() { @@ -36,18 +33,7 @@ namespace FancyZonesEditor } } - public int WrapPanelItemSize - { - get - { - return _wrapPanelItemSize; - } - - set - { - _wrapPanelItemSize = value; - } - } + public int WrapPanelItemSize { get; set; } = 262; private void DecrementZones_Click(object sender, RoutedEventArgs e) { @@ -59,7 +45,7 @@ namespace FancyZonesEditor private void IncrementZones_Click(object sender, RoutedEventArgs e) { - if (_settings.ZoneCount < MAX_ZONES) + if (_settings.ZoneCount < MaxZones) { _settings.ZoneCount++; } @@ -119,8 +105,7 @@ namespace FancyZonesEditor string name = customModel.Name; if (name.StartsWith(_defaultNamePrefix)) { - int i; - if (int.TryParse(name.Substring(_defaultNamePrefix.Length), out i)) + if (int.TryParse(name.Substring(_defaultNamePrefix.Length), out int i)) { if (maxCustomIndex < i) { diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/Settings.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/Settings.cs index f28575b5ba..f90fc831d6 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/Settings.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/Settings.cs @@ -43,14 +43,18 @@ namespace FancyZonesEditor _focusModel = new CanvasLayoutModel("Focus", _focusModelId, (int)_workArea.Width, (int)_workArea.Height); DefaultModels.Add(_focusModel); - _columnsModel = new GridLayoutModel("Columns", _columnsModelId); - _columnsModel.Rows = 1; - _columnsModel.RowPercents = new int[1] { _multiplier }; + _columnsModel = new GridLayoutModel("Columns", _columnsModelId) + { + Rows = 1, + RowPercents = new int[1] { _multiplier }, + }; DefaultModels.Add(_columnsModel); - _rowsModel = new GridLayoutModel("Rows", _rowsModelId); - _rowsModel.Columns = 1; - _rowsModel.ColumnPercents = new int[1] { _multiplier }; + _rowsModel = new GridLayoutModel("Rows", _rowsModelId) + { + Columns = 1, + ColumnPercents = new int[1] { _multiplier }, + }; DefaultModels.Add(_rowsModel); _gridModel = new GridLayoutModel("Grid", _gridModelId); @@ -199,8 +203,6 @@ namespace FancyZonesEditor // Update the five default layouts based on the new ZoneCount private void UpdateLayoutModels() { - int previousZoneCount = _focusModel.Zones.Count; - // Update the "Focus" Default Layout _focusModel.Zones.Clear(); @@ -231,15 +233,13 @@ namespace FancyZonesEditor // Update the "Grid" Default Layout int rows = 1; - int cols = 1; - int mergeCount = 0; while (ZoneCount / rows >= rows) { rows++; } rows--; - cols = ZoneCount / rows; + int cols = ZoneCount / rows; if (ZoneCount % rows == 0) { // even grid @@ -247,7 +247,6 @@ namespace FancyZonesEditor else { cols++; - mergeCount = rows - (ZoneCount % rows); } _gridModel.Rows = rows;