Adding in sytlecop and fixing issues

This commit is contained in:
Clint Rutkas
2019-12-12 12:13:31 -08:00
parent f2400ee089
commit 826858c170
20 changed files with 181 additions and 265 deletions

View File

@@ -12,7 +12,9 @@ Global
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|Any CPU.ActiveCfg = Debug|x64 {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|Any CPU.ActiveCfg = Debug|x64
{5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|Any CPU.ActiveCfg = Release|x64 {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|Any CPU.Build.0 = Debug|x64
{5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|Any CPU.ActiveCfg = Debug|x64
{5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|Any CPU.Build.0 = Debug|x64
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -1,10 +1,8 @@
using FancyZonesEditor; // 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;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using FancyZonesEditor.Models; using FancyZonesEditor.Models;
@@ -16,8 +14,10 @@ namespace FancyZonesEditor
public partial class App : Application public partial class App : Application
{ {
public Settings ZoneSettings { get { return _settings; } } public Settings ZoneSettings { get { return _settings; } }
private Settings _settings; private Settings _settings;
private ushort _idInitial = 0; private ushort _idInitial = 0;
public App() public App()
{ {
_settings = new Settings(); _settings = new Settings();

View File

@@ -1,17 +1,9 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Linq; // See the LICENSE file in the project root for more information.
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FancyZonesEditor.Models; using FancyZonesEditor.Models;
namespace FancyZonesEditor namespace FancyZonesEditor

View File

@@ -1,17 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Linq; // See the LICENSE file in the project root for more information.
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MahApps.Metro.Controls;
using FancyZonesEditor.Models; using FancyZonesEditor.Models;
namespace FancyZonesEditor namespace FancyZonesEditor
@@ -24,16 +15,16 @@ namespace FancyZonesEditor
public CanvasEditorWindow() public CanvasEditorWindow()
{ {
InitializeComponent(); InitializeComponent();
Model = EditorOverlay.Current.DataContext as CanvasLayoutModel; _model = EditorOverlay.Current.DataContext as CanvasLayoutModel;
} }
private void OnAddZone(object sender, RoutedEventArgs e) private void OnAddZone(object sender, RoutedEventArgs e)
{ {
Model.AddZone(new Int32Rect(_offset, _offset, (int) (Model.ReferenceWidth * 0.6), (int) (Model.ReferenceHeight * 0.6))); _model.AddZone(new Int32Rect(_offset, _offset, (int)(_model.ReferenceWidth * 0.6), (int)(_model.ReferenceHeight * 0.6)));
_offset += 100; _offset += 100;
} }
private int _offset = 100; private int _offset = 100;
private CanvasLayoutModel Model; private CanvasLayoutModel _model;
} }
} }

View File

@@ -1,17 +1,11 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Linq; // See the LICENSE file in the project root for more information.
using System.Text;
using System.Threading.Tasks; using System;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FancyZonesEditor.Models; using FancyZonesEditor.Models;
namespace FancyZonesEditor namespace FancyZonesEditor
@@ -20,7 +14,6 @@ namespace FancyZonesEditor
/// Once you've "Committ"ed the starter grid, then the Zones within the grid come to life for you to be able to further subdivide them /// Once you've "Committ"ed the starter grid, then the Zones within the grid come to life for you to be able to further subdivide them
/// using splitters /// using splitters
/// </summary> /// </summary>
public partial class CanvasZone : UserControl public partial class CanvasZone : UserControl
{ {
public CanvasZone() public CanvasZone()
@@ -53,8 +46,8 @@ namespace FancyZonesEditor
yDelta = Math.Min(yDelta, _settings.WorkArea.Height - rect.Height - rect.Y); yDelta = Math.Min(yDelta, _settings.WorkArea.Height - rect.Height - rect.Y);
} }
rect.X += (int) xDelta; rect.X += (int)xDelta;
rect.Y += (int) yDelta; rect.Y += (int)yDelta;
Canvas.SetLeft(this, rect.X); Canvas.SetLeft(this, rect.X);
Canvas.SetTop(this, rect.Y); Canvas.SetTop(this, rect.Y);
@@ -112,7 +105,7 @@ namespace FancyZonesEditor
Int32Rect rect = Model.Zones[ZoneIndex]; Int32Rect rect = Model.Zones[ZoneIndex];
if (xDelta != 0) if (xDelta != 0)
{ {
int newWidth = rect.Width + (int) xDelta; int newWidth = rect.Width + (int)xDelta;
if (newWidth < c_minZoneWidth) if (newWidth < c_minZoneWidth)
{ {
@@ -120,7 +113,7 @@ namespace FancyZonesEditor
} }
else if (newWidth > (_settings.WorkArea.Width - rect.X)) else if (newWidth > (_settings.WorkArea.Width - rect.X))
{ {
newWidth = (int) _settings.WorkArea.Width - rect.X; newWidth = (int)_settings.WorkArea.Width - rect.X;
} }
MinWidth = rect.Width = newWidth; MinWidth = rect.Width = newWidth;
} }

View File

@@ -1,4 +1,8 @@
using FancyZonesEditor.Models; // 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 FancyZonesEditor.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View File

@@ -1,16 +1,9 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Linq; // See the LICENSE file in the project root for more information.
using System.Text;
using System.Threading.Tasks; using System;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using FancyZonesEditor.Models; using FancyZonesEditor.Models;
using MahApps.Metro.Controls; using MahApps.Metro.Controls;

View File

@@ -1,20 +1,14 @@
using System; // 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.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FancyZonesEditor.Models; using FancyZonesEditor.Models;
namespace FancyZonesEditor namespace FancyZonesEditor
{ {
/// <summary> /// <summary>
@@ -639,9 +633,11 @@ namespace FancyZonesEditor
break; break;
} }
} }
if (startCol != -1) if (startCol != -1)
{ {
Canvas.SetTop(resizer, _rowInfo[row].End + (spacing / 2) - 24); // hard coding this as (resizer.ActualHeight / 2) will still evaluate to 0 here ... a layout hasn't yet happened // hard coding this as (resizer.ActualHeight / 2) will still evaluate to 0 here ... a layout hasn't yet happened
Canvas.SetTop(resizer, _rowInfo[row].End + (spacing / 2) - 24);
Canvas.SetLeft(resizer, (_colInfo[endCol].End + _colInfo[startCol].Start) / 2); Canvas.SetLeft(resizer, (_colInfo[endCol].End + _colInfo[startCol].Start) / 2);
} }
else else
@@ -842,6 +838,7 @@ namespace FancyZonesEditor
e.Handled = true; e.Handled = true;
} }
base.OnPreviewMouseMove(e); base.OnPreviewMouseMove(e);
} }
@@ -849,7 +846,7 @@ namespace FancyZonesEditor
{ {
foreach (UIElement zone in Preview.Children) foreach (UIElement zone in Preview.Children)
{ {
((GridZone) zone).IsSelected = false; ((GridZone)zone).IsSelected = false;
} }
} }

View File

@@ -1,18 +1,6 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Linq; // See the LICENSE file in the project root for more information.
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using FancyZonesEditor.Models;
using MahApps.Metro.Controls;
namespace FancyZonesEditor namespace FancyZonesEditor
{ {

View File

@@ -1,18 +1,11 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Linq; // See the LICENSE file in the project root for more information.
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FancyZonesEditor.Models; using FancyZonesEditor.Models;
namespace FancyZonesEditor namespace FancyZonesEditor
@@ -45,18 +38,17 @@ namespace FancyZonesEditor
} }
else else
{ {
body.RenderTransform = c_rotateTransform; body.RenderTransform = _rotateTransform;
body.Cursor = Cursors.SizeNS; body.Cursor = Cursors.SizeNS;
} }
} }
} }
private static RotateTransform c_rotateTransform = new RotateTransform(90, 24, 24); private static RotateTransform _rotateTransform = new RotateTransform(90, 24, 24);
public int Index; public int Index;
public LayoutModel Model; public LayoutModel Model;
private Orientation _orientation; private Orientation _orientation;
} }
} }

View File

@@ -1,16 +1,12 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Linq; // See the LICENSE file in the project root for more information.
using System.Text;
using System.Threading.Tasks; using System;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
namespace FancyZonesEditor namespace FancyZonesEditor
@@ -19,7 +15,6 @@ namespace FancyZonesEditor
/// Once you've "Committ"ed the starter grid, then the Zones within the grid come to life for you to be able to further subdivide them /// Once you've "Committ"ed the starter grid, then the Zones within the grid come to life for you to be able to further subdivide them
/// using splitters /// using splitters
/// </summary> /// </summary>
public partial class GridZone : UserControl public partial class GridZone : UserControl
{ {
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(GridZone), new PropertyMetadata(false, OnSelectionChanged)); public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(GridZone), new PropertyMetadata(false, OnSelectionChanged));
@@ -28,6 +23,7 @@ namespace FancyZonesEditor
{ {
((GridZone)d).OnSelectionChanged(); ((GridZone)d).OnSelectionChanged();
} }
private void OnSelectionChanged() private void OnSelectionChanged()
{ {
Background = IsSelected ? Brushes.SteelBlue : Brushes.LightGray; Background = IsSelected ? Brushes.SteelBlue : Brushes.LightGray;
@@ -53,7 +49,7 @@ namespace FancyZonesEditor
_splitter.Fill = Brushes.DarkGray; _splitter.Fill = Brushes.DarkGray;
Body.Children.Add(_splitter); Body.Children.Add(_splitter);
((App) Application.Current).ZoneSettings.PropertyChanged += ZoneSettings_PropertyChanged; ((App)Application.Current).ZoneSettings.PropertyChanged += ZoneSettings_PropertyChanged;
} }
private void ZoneSettings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) private void ZoneSettings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
@@ -67,6 +63,7 @@ namespace FancyZonesEditor
} }
} }
} }
protected override Size ArrangeOverride(Size size) protected override Size ArrangeOverride(Size size)
{ {
_splitOrientation = (size.Width > size.Height) ? Orientation.Vertical : Orientation.Horizontal; _splitOrientation = (size.Width > size.Height) ? Orientation.Vertical : Orientation.Horizontal;
@@ -90,42 +87,40 @@ namespace FancyZonesEditor
private void UpdateSplitter() private void UpdateSplitter()
{ {
int thickness = SplitterThickness;
if (IsVerticalSplit) if (IsVerticalSplit)
{ {
double bodyWidth = Body.ActualWidth; double bodyWidth = Body.ActualWidth;
double pos = _lastPos.X - thickness/2; double pos = _lastPos.X - (SplitterThickness / 2);
if (pos < 0) if (pos < 0)
{ {
pos = 0; pos = 0;
} }
else if (pos > (bodyWidth - thickness)) else if (pos > (bodyWidth - SplitterThickness))
{ {
pos = bodyWidth - thickness; pos = bodyWidth - SplitterThickness;
} }
Canvas.SetLeft(_splitter, pos); Canvas.SetLeft(_splitter, pos);
Canvas.SetTop(_splitter, 0); Canvas.SetTop(_splitter, 0);
_splitter.MinWidth = thickness; _splitter.MinWidth = SplitterThickness;
_splitter.MinHeight = Body.ActualHeight; _splitter.MinHeight = Body.ActualHeight;
} }
else else
{ {
double bodyHeight = Body.ActualHeight; double bodyHeight = Body.ActualHeight;
double pos = _lastPos.Y - thickness / 2; double pos = _lastPos.Y - (SplitterThickness / 2);
if (pos < 0) if (pos < 0)
{ {
pos = 0; pos = 0;
} }
else if (pos > (bodyHeight - thickness)) else if (pos > (bodyHeight - SplitterThickness))
{ {
pos = bodyHeight - thickness; pos = bodyHeight - SplitterThickness;
} }
Canvas.SetLeft(_splitter, 0); Canvas.SetLeft(_splitter, 0);
Canvas.SetTop(_splitter, pos); Canvas.SetTop(_splitter, pos);
_splitter.MinWidth = Body.ActualWidth; _splitter.MinWidth = Body.ActualWidth;
_splitter.MinHeight = thickness; _splitter.MinHeight = SplitterThickness;
} }
} }

View File

@@ -1,18 +1,13 @@
using FancyZonesEditor.Models; // Copyright (c) Microsoft Corporation
using System; // 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.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using FancyZonesEditor.Models;
namespace FancyZonesEditor namespace FancyZonesEditor
{ {
@@ -116,7 +111,7 @@ namespace FancyZonesEditor
Body.ColumnDefinitions.Add(def); Body.ColumnDefinitions.Add(def);
} }
Settings settings = ((App) Application.Current).ZoneSettings; Settings settings = ((App)Application.Current).ZoneSettings;
int divisor = IsActualSize ? 2 : 20; int divisor = IsActualSize ? 2 : 20;
Thickness margin = new Thickness(settings.ShowSpacing ? settings.Spacing / divisor : 0); Thickness margin = new Thickness(settings.ShowSpacing ? settings.Spacing / divisor : 0);

View File

@@ -1,18 +1,14 @@
// 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;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FancyZonesEditor.Models; using FancyZonesEditor.Models;
using MahApps.Metro.Controls; using MahApps.Metro.Controls;
@@ -25,6 +21,9 @@ namespace FancyZonesEditor
{ {
// TODO: share the constants b/w C# Editor and FancyZoneLib // TODO: share the constants b/w C# Editor and FancyZoneLib
public static int MAX_ZONES = 40; public static int MAX_ZONES = 40;
private static string _defaultNamePrefix = "Custom Layout ";
private bool _editing = false;
private int _WrapPanelItemSize = 262;
public MainWindow() public MainWindow()
{ {
@@ -37,7 +36,6 @@ namespace FancyZonesEditor
} }
} }
private int _WrapPanelItemSize = 262;
public int WrapPanelItemSize public int WrapPanelItemSize
{ {
get get
@@ -95,9 +93,6 @@ namespace FancyZonesEditor
EditorOverlay.Current.DataContext = newSelection; EditorOverlay.Current.DataContext = newSelection;
} }
private static string c_defaultNamePrefix = "Custom Layout ";
private bool _editing = false;
private void EditLayout_Click(object sender, RoutedEventArgs e) private void EditLayout_Click(object sender, RoutedEventArgs e)
{ {
EditorOverlay mainEditor = EditorOverlay.Current; EditorOverlay mainEditor = EditorOverlay.Current;
@@ -125,10 +120,10 @@ namespace FancyZonesEditor
foreach (LayoutModel customModel in _settings.CustomModels) foreach (LayoutModel customModel in _settings.CustomModels)
{ {
string name = customModel.Name; string name = customModel.Name;
if (name.StartsWith(c_defaultNamePrefix)) if (name.StartsWith(_defaultNamePrefix))
{ {
int i; int i;
if (Int32.TryParse(name.Substring(c_defaultNamePrefix.Length), out i)) if (Int32.TryParse(name.Substring(_defaultNamePrefix.Length), out i))
{ {
if (maxCustomIndex < i) if (maxCustomIndex < i)
{ {
@@ -137,7 +132,7 @@ namespace FancyZonesEditor
} }
} }
} }
model.Name = c_defaultNamePrefix + (++maxCustomIndex); model.Name = _defaultNamePrefix + (++maxCustomIndex);
} }
mainEditor.Edit(); mainEditor.Edit();

View File

@@ -1,12 +1,9 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections; // 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.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Converters;
using System.Windows.Documents;
namespace FancyZonesEditor.Models namespace FancyZonesEditor.Models
{ {
@@ -30,7 +27,9 @@ namespace FancyZonesEditor.Models
} }
public CanvasLayoutModel(string name, ushort id) : base(name, id) { } public CanvasLayoutModel(string name, ushort id) : base(name, id) { }
public CanvasLayoutModel(string name) : base(name) { } public CanvasLayoutModel(string name) : base(name) { }
public CanvasLayoutModel() : base() { } public CanvasLayoutModel() : base() { }
// ReferenceWidth - the reference width for the layout rect that all Zones are relative to // ReferenceWidth - the reference width for the layout rect that all Zones are relative to

View File

@@ -1,10 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections; // 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.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
namespace FancyZonesEditor.Models namespace FancyZonesEditor.Models
{ {
@@ -55,22 +53,18 @@ namespace FancyZonesEditor.Models
// CellChildMap - represents which "children" belong in which grid cells; // CellChildMap - represents which "children" belong in which grid cells;
// shows spanning children by the same index appearing in adjacent cells // shows spanning children by the same index appearing in adjacent cells
// TODO: ideally no setter here - this means moving logic like "split" over to model // TODO: ideally no setter here - this means moving logic like "split" over to model
public int[,] CellChildMap { get { return _cellChildMap; } set { _cellChildMap = value; } } public int[,] CellChildMap { get; set; }
private int[,] _cellChildMap;
// RowPercents - represents the %age height of each row in the grid // RowPercents - represents the %age height of each row in the grid
public int[] RowPercents { get { return _rowPercents; } set { _rowPercents = value; } } public int[] RowPercents { get; set; }
private int[] _rowPercents;
// ColumnPercents - represents the %age width of each column in the grid // ColumnPercents - represents the %age width of each column in the grid
public int[] ColumnPercents { get { return _colPercents; } set { _colPercents = value; } } public int[] ColumnPercents { get; set; }
private int[] _colPercents;
// FreeZones (not persisted) - used to keep track of child indices that are no longer in use in the CellChildMap, // FreeZones (not persisted) - used to keep track of child indices that are no longer in use in the CellChildMap,
// making them candidates for re-use when it's needed to add another child // making them candidates for re-use when it's needed to add another child
// TODO: do I need FreeZones on the data model? - I think I do // TODO: do I need FreeZones on the data model? - I think I do
public IList<int> FreeZones { get { return _freeZones; } } public IList<int> FreeZones { get; } = new List<int>();
private IList<int> _freeZones = new List<int>();
public void Reload(byte[] data) public void Reload(byte[] data)
{ {
@@ -80,24 +74,24 @@ namespace FancyZonesEditor.Models
Rows = data[i++]; Rows = data[i++];
Columns = data[i++]; Columns = data[i++];
_rowPercents = new int[Rows]; RowPercents = new int[Rows];
for (int row = 0; row < Rows; row++) for (int row = 0; row < Rows; row++)
{ {
_rowPercents[row] = data[i++]*256 + data[i++]; RowPercents[row] = (data[i++] * 256) + data[i++];
} }
_colPercents = new int[Columns]; ColumnPercents = new int[Columns];
for (int col = 0; col < Columns; col++) for (int col = 0; col < Columns; col++)
{ {
_colPercents[col] = data[i++]*256 + data[i++]; ColumnPercents[col] = (data[i++] * 256) + data[i++];
} }
_cellChildMap = new int[Rows, Columns]; CellChildMap = new int[Rows, Columns];
for (int row = 0; row < Rows; row++) for (int row = 0; row < Rows; row++)
{ {
for (int col = 0; col < Columns; col++) for (int col = 0; col < Columns; col++)
{ {
_cellChildMap[row, col] = data[i++]; CellChildMap[row, col] = data[i++];
} }
} }
} }
@@ -151,10 +145,10 @@ namespace FancyZonesEditor.Models
int[,] cellChildMap; int[,] cellChildMap;
if (_freeZones.Count == 0) if (FreeZones.Count == 0)
{ {
// no unused indices -- so we can just use the _cellChildMap as is // no unused indices -- so we can just use the _cellChildMap as is
cellChildMap = _cellChildMap; cellChildMap = CellChildMap;
} }
else else
{ {
@@ -167,7 +161,7 @@ namespace FancyZonesEditor.Models
{ {
for (int col = 0; col < cols; col++) for (int col = 0; col < cols; col++)
{ {
int source = _cellChildMap[row, col]; int source = CellChildMap[row, col];
int index = mapping.IndexOf(source); int index = mapping.IndexOf(source);
if (index == -1) if (index == -1)
@@ -196,14 +190,14 @@ namespace FancyZonesEditor.Models
for (int row = 0; row < Rows; row++) for (int row = 0; row < Rows; row++)
{ {
int rowPercent = _rowPercents[row]; int rowPercent = RowPercents[row];
data[i++] = (byte)(rowPercent / 256); data[i++] = (byte)(rowPercent / 256);
data[i++] = (byte)(rowPercent % 256); data[i++] = (byte)(rowPercent % 256);
} }
for (int col = 0; col < Columns; col++) for (int col = 0; col < Columns; col++)
{ {
int colPercent = _colPercents[col]; int colPercent = ColumnPercents[col];
data[i++] = (byte)(colPercent / 256); data[i++] = (byte)(colPercent / 256);
data[i++] = (byte)(colPercent % 256); data[i++] = (byte)(colPercent % 256);
} }

View File

@@ -1,13 +1,11 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Collections.Generic; // See the LICENSE file in the project root for more information.
using System.Collections.ObjectModel;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32; using Microsoft.Win32;
namespace FancyZonesEditor.Models namespace FancyZonesEditor.Models
@@ -72,6 +70,7 @@ namespace FancyZonesEditor.Models
} }
} }
} }
private bool _isSelected; private bool _isSelected;
// implementation of INotifyProeprtyChanged // implementation of INotifyProeprtyChanged
@@ -80,14 +79,13 @@ namespace FancyZonesEditor.Models
// FirePropertyChanged -- wrapper that calls INPC.PropertyChanged // FirePropertyChanged -- wrapper that calls INPC.PropertyChanged
protected virtual void FirePropertyChanged(string propertyName) protected virtual void FirePropertyChanged(string propertyName)
{ {
PropertyChangedEventHandler handler = PropertyChanged; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
} }
// Removes this Layout from the registry and the loaded CustomModels list // Removes this Layout from the registry and the loaded CustomModels list
public void Delete() public void Delete()
{ {
RegistryKey key = Registry.CurrentUser.OpenSubKey(c_registryPath, true); RegistryKey key = Registry.CurrentUser.OpenSubKey(_registryPath, true);
if (key != null) if (key != null)
{ {
key.DeleteValue(Name); key.DeleteValue(Name);
@@ -105,17 +103,17 @@ namespace FancyZonesEditor.Models
{ {
s_customModels = new ObservableCollection<LayoutModel>(); s_customModels = new ObservableCollection<LayoutModel>();
RegistryKey key = Registry.CurrentUser.OpenSubKey(c_registryPath); RegistryKey key = Registry.CurrentUser.OpenSubKey(_registryPath);
if (key != null) if (key != null)
{ {
foreach (string name in key.GetValueNames()) foreach (string name in key.GetValueNames())
{ {
LayoutModel model = null; LayoutModel model = null;
byte[] data = (byte[])Registry.GetValue(c_fullRegistryPath, name, null); byte[] data = (byte[])Registry.GetValue(_fullRegistryPath, name, null);
ushort version = (ushort) (data[0]*256 + data[1]); ushort version = (ushort)(data[0] * 256 + data[1]);
byte type = data[2]; byte type = data[2];
ushort id = (ushort) (data[3]*256 + data[4]); ushort id = (ushort)((data[3] * 256) + data[4]);
switch (type) switch (type)
{ {
@@ -165,7 +163,7 @@ namespace FancyZonesEditor.Models
public void Persist(System.Windows.Int32Rect[] zones) public void Persist(System.Windows.Int32Rect[] zones)
{ {
// Persist the editor data // Persist the editor data
Registry.SetValue(c_fullRegistryPath, Name, GetPersistData(), Microsoft.Win32.RegistryValueKind.Binary); Registry.SetValue(_fullRegistryPath, Name, GetPersistData(), Microsoft.Win32.RegistryValueKind.Binary);
Apply(zones); Apply(zones);
} }
@@ -196,16 +194,16 @@ namespace FancyZonesEditor.Models
var index = i * 4; var index = i * 4;
zoneArray[index] = left; zoneArray[index] = left;
zoneArray[index+1] = top; zoneArray[index + 1] = top;
zoneArray[index+2] = right; zoneArray[index + 2] = right;
zoneArray[index+3] = bottom; zoneArray[index + 3] = bottom;
} }
var persistZoneSet = Marshal.GetDelegateForFunctionPointer<Native.PersistZoneSet>(pfn); var persistZoneSet = Marshal.GetDelegateForFunctionPointer<Native.PersistZoneSet>(pfn);
persistZoneSet(Settings.UniqueKey, Settings.WorkAreaKey, Settings.Monitor, _id, zoneCount, zoneArray); persistZoneSet(Settings.UniqueKey, Settings.WorkAreaKey, Settings.Monitor, _id, zoneCount, zoneArray);
} }
private static readonly string c_registryPath = Settings.RegistryPath + "\\Layouts"; private static readonly string _registryPath = Settings.RegistryPath + "\\Layouts";
private static readonly string c_fullRegistryPath = Settings.FullRegistryPath + "\\Layouts"; private static readonly string _fullRegistryPath = Settings.FullRegistryPath + "\\Layouts";
} }
} }

View File

@@ -1,25 +1,21 @@
using System; // 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.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Collections;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization; using System.Globalization;
using FancyZonesEditor.Models;
using System.Windows.Documents;
using System.Windows; using System.Windows;
using System.Windows.Controls; using FancyZonesEditor.Models;
using Microsoft.Win32; using Microsoft.Win32;
namespace FancyZonesEditor namespace FancyZonesEditor
{ {
//
// Settings // Settings
// These are the configuration settings used by the rest of the editor // These are the configuration settings used by the rest of the editor
// Other UIs in the editor will subscribe to change events on the properties to stay up to date as these properties change // Other UIs in the editor will subscribe to change events on the properties to stay up to date as these properties change
//
public class Settings : INotifyPropertyChanged public class Settings : INotifyPropertyChanged
{ {
public bool IsCustomLayoutActive public bool IsCustomLayoutActive
@@ -271,9 +267,9 @@ namespace FancyZonesEditor
} }
// Update the "Priority Grid" Default Layout // Update the "Priority Grid" Default Layout
if (ZoneCount <= s_priorityData.Length) if (ZoneCount <= _priorityData.Length)
{ {
_priorityGridModel.Reload(s_priorityData[ZoneCount - 1]); _priorityGridModel.Reload(_priorityData[ZoneCount - 1]);
} }
else else
{ {
@@ -390,7 +386,7 @@ namespace FancyZonesEditor
private static readonly ushort c_lastPrefinedId = c_blankCustomModelId; private static readonly ushort c_lastPrefinedId = c_blankCustomModelId;
// hard coded data for all the "Priority Grid" configurations that are unique to "Grid" // hard coded data for all the "Priority Grid" configurations that are unique to "Grid"
private static byte[][] s_priorityData = new byte[][] private static byte[][] _priorityData = new byte[][]
{ {
new byte[] { 0, 0, 0, 0, 0, 1, 1, 39, 16, 39, 16, 0 }, new byte[] { 0, 0, 0, 0, 0, 1, 1, 39, 16, 39, 16, 0 },
new byte[] { 0, 0, 0, 0, 0, 1, 2, 39, 16, 26, 11, 13, 5, 0, 1 }, new byte[] { 0, 0, 0, 0, 0, 1, 2, 39, 16, 26, 11, 13, 5, 0, 1 },
@@ -402,7 +398,7 @@ namespace FancyZonesEditor
new byte[] { 0, 0, 0, 0, 0, 3, 4, 13, 5, 13, 6, 13, 5, 9, 196, 9, 196, 9, 196, 9, 196, 0, 1, 2, 3, 4, 1, 2, 5, 6, 1, 2, 7 }, new byte[] { 0, 0, 0, 0, 0, 3, 4, 13, 5, 13, 6, 13, 5, 9, 196, 9, 196, 9, 196, 9, 196, 0, 1, 2, 3, 4, 1, 2, 5, 6, 1, 2, 7 },
new byte[] { 0, 0, 0, 0, 0, 3, 4, 13, 5, 13, 6, 13, 5, 9, 196, 9, 196, 9, 196, 9, 196, 0, 1, 2, 3, 4, 1, 2, 5, 6, 1, 7, 8 }, new byte[] { 0, 0, 0, 0, 0, 3, 4, 13, 5, 13, 6, 13, 5, 9, 196, 9, 196, 9, 196, 9, 196, 0, 1, 2, 3, 4, 1, 2, 5, 6, 1, 7, 8 },
new byte[] { 0, 0, 0, 0, 0, 3, 4, 13, 5, 13, 6, 13, 5, 9, 196, 9, 196, 9, 196, 9, 196, 0, 1, 2, 3, 4, 1, 5, 6, 7, 1, 8, 9 }, new byte[] { 0, 0, 0, 0, 0, 3, 4, 13, 5, 13, 6, 13, 5, 9, 196, 9, 196, 9, 196, 9, 196, 0, 1, 2, 3, 4, 1, 5, 6, 7, 1, 8, 9 },
new byte[] { 0, 0, 0, 0, 0, 3, 4, 13, 5, 13, 6, 13, 5, 9, 196, 9, 196, 9, 196, 9, 196, 0, 1, 2, 3, 4, 1, 5, 6, 7, 8, 9, 10 } new byte[] { 0, 0, 0, 0, 0, 3, 4, 13, 5, 13, 6, 13, 5, 9, 196, 9, 196, 9, 196, 9, 196, 0, 1, 2, 3, 4, 1, 5, 6, 7, 8, 9, 10 },
}; };
private const int c_multiplier = 10000; private const int c_multiplier = 10000;

View File

@@ -1,6 +1,8 @@
using System.Reflection; // Copyright (c) Microsoft Corporation
using System.Resources; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Runtime.CompilerServices; // See the LICENSE file in the project root for more information.
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows; using System.Windows;

View File

@@ -1,8 +1,6 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Linq; // See the LICENSE file in the project root for more information.
using System.Text;
using System.Threading.Tasks;
namespace FancyZonesEditor namespace FancyZonesEditor
{ {

View File

@@ -1,16 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Linq; // See the LICENSE file in the project root for more information.
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace FancyZonesEditor namespace FancyZonesEditor
{ {