mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Adding in sytlecop and fixing issues
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Converters;
|
||||
using System.Windows.Documents;
|
||||
|
||||
namespace FancyZonesEditor.Models
|
||||
{
|
||||
// CanvasLayoutModel
|
||||
// CanvasLayoutModel
|
||||
// Free form Layout Model, which specifies independent zone rects
|
||||
public class CanvasLayoutModel : LayoutModel
|
||||
{
|
||||
@@ -30,7 +27,9 @@ namespace FancyZonesEditor.Models
|
||||
}
|
||||
|
||||
public CanvasLayoutModel(string name, ushort id) : base(name, id) { }
|
||||
|
||||
public CanvasLayoutModel(string name) : base(name) { }
|
||||
|
||||
public CanvasLayoutModel() : base() { }
|
||||
|
||||
// ReferenceWidth - the reference width for the layout rect that all Zones are relative to
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Documents;
|
||||
|
||||
namespace FancyZonesEditor.Models
|
||||
{
|
||||
// GridLayoutModel
|
||||
// GridLayoutModel
|
||||
// Grid-styled Layout Model, which specifies rows, columns, percentage sizes, and row/column spans
|
||||
public class GridLayoutModel : LayoutModel
|
||||
{
|
||||
@@ -52,26 +50,22 @@ namespace FancyZonesEditor.Models
|
||||
}
|
||||
private int _cols = 1;
|
||||
|
||||
// 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
|
||||
// TODO: ideally no setter here - this means moving logic like "split" over to model
|
||||
public int[,] CellChildMap { get { return _cellChildMap; } set { _cellChildMap = value; } }
|
||||
private int[,] _cellChildMap;
|
||||
|
||||
// RowPercents - represents the %age height of each row in the grid
|
||||
public int[] RowPercents { get { return _rowPercents; } set { _rowPercents = value; } }
|
||||
private int[] _rowPercents;
|
||||
|
||||
// ColumnPercents - represents the %age width of each column in the grid
|
||||
public int[] ColumnPercents { get { return _colPercents; } set { _colPercents = value; } }
|
||||
private int[] _colPercents;
|
||||
|
||||
// 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
|
||||
// TODO: do I need FreeZones on the data model? - I think I do
|
||||
public IList<int> FreeZones { get { return _freeZones; } }
|
||||
private IList<int> _freeZones = new List<int>();
|
||||
|
||||
public int[,] CellChildMap { get; set; }
|
||||
|
||||
// RowPercents - represents the %age height of each row in the grid
|
||||
public int[] RowPercents { get; set; }
|
||||
|
||||
// ColumnPercents - represents the %age width of each column in the grid
|
||||
public int[] ColumnPercents { get; set; }
|
||||
|
||||
// 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
|
||||
// TODO: do I need FreeZones on the data model? - I think I do
|
||||
public IList<int> FreeZones { get; } = new List<int>();
|
||||
|
||||
public void Reload(byte[] data)
|
||||
{
|
||||
// Skip version (2 bytes), id (2 bytes), and type (1 bytes)
|
||||
@@ -80,24 +74,24 @@ namespace FancyZonesEditor.Models
|
||||
Rows = data[i++];
|
||||
Columns = data[i++];
|
||||
|
||||
_rowPercents = new int[Rows];
|
||||
RowPercents = new int[Rows];
|
||||
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++)
|
||||
{
|
||||
_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 col = 0; col < Columns; col++)
|
||||
{
|
||||
_cellChildMap[row, col] = data[i++];
|
||||
CellChildMap[row, col] = data[i++];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,10 +145,10 @@ namespace FancyZonesEditor.Models
|
||||
|
||||
int[,] cellChildMap;
|
||||
|
||||
if (_freeZones.Count == 0)
|
||||
if (FreeZones.Count == 0)
|
||||
{
|
||||
// no unused indices -- so we can just use the _cellChildMap as is
|
||||
cellChildMap = _cellChildMap;
|
||||
cellChildMap = CellChildMap;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -167,7 +161,7 @@ namespace FancyZonesEditor.Models
|
||||
{
|
||||
for (int col = 0; col < cols; col++)
|
||||
{
|
||||
int source = _cellChildMap[row, col];
|
||||
int source = CellChildMap[row, col];
|
||||
|
||||
int index = mapping.IndexOf(source);
|
||||
if (index == -1)
|
||||
@@ -196,14 +190,14 @@ namespace FancyZonesEditor.Models
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
// 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.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace FancyZonesEditor.Models
|
||||
@@ -59,7 +57,7 @@ namespace FancyZonesEditor.Models
|
||||
private ushort _id = 0;
|
||||
|
||||
// IsSelected (not-persisted) - tracks whether or not this LayoutModel is selected in the picker
|
||||
// TODO: once we switch to a picker per monitor, we need to move this state to the view
|
||||
// TODO: once we switch to a picker per monitor, we need to move this state to the view
|
||||
public bool IsSelected
|
||||
{
|
||||
get { return _isSelected; }
|
||||
@@ -72,6 +70,7 @@ namespace FancyZonesEditor.Models
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isSelected;
|
||||
|
||||
// implementation of INotifyProeprtyChanged
|
||||
@@ -80,14 +79,13 @@ namespace FancyZonesEditor.Models
|
||||
// FirePropertyChanged -- wrapper that calls INPC.PropertyChanged
|
||||
protected virtual void FirePropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChangedEventHandler handler = PropertyChanged;
|
||||
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
// Removes this Layout from the registry and the loaded CustomModels list
|
||||
public void Delete()
|
||||
{
|
||||
RegistryKey key = Registry.CurrentUser.OpenSubKey(c_registryPath, true);
|
||||
RegistryKey key = Registry.CurrentUser.OpenSubKey(_registryPath, true);
|
||||
if (key != null)
|
||||
{
|
||||
key.DeleteValue(Name);
|
||||
@@ -105,17 +103,17 @@ namespace FancyZonesEditor.Models
|
||||
{
|
||||
s_customModels = new ObservableCollection<LayoutModel>();
|
||||
|
||||
RegistryKey key = Registry.CurrentUser.OpenSubKey(c_registryPath);
|
||||
RegistryKey key = Registry.CurrentUser.OpenSubKey(_registryPath);
|
||||
if (key != null)
|
||||
{
|
||||
foreach (string name in key.GetValueNames())
|
||||
{
|
||||
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];
|
||||
ushort id = (ushort) (data[3]*256 + data[4]);
|
||||
ushort id = (ushort)((data[3] * 256) + data[4]);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
@@ -143,7 +141,7 @@ namespace FancyZonesEditor.Models
|
||||
// Callbacks that the base LayoutModel makes to derived types
|
||||
protected abstract byte[] GetPersistData();
|
||||
public abstract LayoutModel Clone();
|
||||
|
||||
|
||||
// PInvokes to handshake with fancyzones backend
|
||||
internal static class Native
|
||||
{
|
||||
@@ -165,12 +163,12 @@ namespace FancyZonesEditor.Models
|
||||
public void Persist(System.Windows.Int32Rect[] zones)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
public void Apply(System.Windows.Int32Rect[] zones)
|
||||
{
|
||||
{
|
||||
// Persist the zone data back into FZ
|
||||
var module = Native.LoadLibrary("fancyzones.dll");
|
||||
if (module == IntPtr.Zero)
|
||||
@@ -196,16 +194,16 @@ namespace FancyZonesEditor.Models
|
||||
|
||||
var index = i * 4;
|
||||
zoneArray[index] = left;
|
||||
zoneArray[index+1] = top;
|
||||
zoneArray[index+2] = right;
|
||||
zoneArray[index+3] = bottom;
|
||||
zoneArray[index + 1] = top;
|
||||
zoneArray[index + 2] = right;
|
||||
zoneArray[index + 3] = bottom;
|
||||
}
|
||||
|
||||
var persistZoneSet = Marshal.GetDelegateForFunctionPointer<Native.PersistZoneSet>(pfn);
|
||||
persistZoneSet(Settings.UniqueKey, Settings.WorkAreaKey, Settings.Monitor, _id, zoneCount, zoneArray);
|
||||
}
|
||||
|
||||
private static readonly string c_registryPath = Settings.RegistryPath + "\\Layouts";
|
||||
private static readonly string c_fullRegistryPath = Settings.FullRegistryPath + "\\Layouts";
|
||||
private static readonly string _registryPath = Settings.RegistryPath + "\\Layouts";
|
||||
private static readonly string _fullRegistryPath = Settings.FullRegistryPath + "\\Layouts";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using FancyZonesEditor.Models;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using FancyZonesEditor.Models;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace FancyZonesEditor
|
||||
{
|
||||
//
|
||||
// Settings
|
||||
// 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
|
||||
//
|
||||
public class Settings : INotifyPropertyChanged
|
||||
{
|
||||
public bool IsCustomLayoutActive
|
||||
@@ -271,9 +267,9 @@ namespace FancyZonesEditor
|
||||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
@@ -374,8 +370,8 @@ namespace FancyZonesEditor
|
||||
|
||||
// storage for Default Layout Models
|
||||
private IList<LayoutModel> _defaultModels;
|
||||
private CanvasLayoutModel _focusModel;
|
||||
private GridLayoutModel _rowsModel;
|
||||
private CanvasLayoutModel _focusModel;
|
||||
private GridLayoutModel _rowsModel;
|
||||
private GridLayoutModel _columnsModel;
|
||||
private GridLayoutModel _gridModel;
|
||||
private GridLayoutModel _priorityGridModel;
|
||||
@@ -390,7 +386,7 @@ namespace FancyZonesEditor
|
||||
private static readonly ushort c_lastPrefinedId = c_blankCustomModelId;
|
||||
|
||||
// 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, 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, 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, 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;
|
||||
|
||||
Reference in New Issue
Block a user