mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
fixed a bunch more
This commit is contained in:
@@ -107,18 +107,18 @@ namespace FancyZonesEditor.Models
|
||||
// Initialize this CanvasLayoutModel based on the given persistence data
|
||||
// Skip version (2 bytes), id (2 bytes), and type (1 bytes)
|
||||
int i = 5;
|
||||
_referenceWidth = data[i++] * 256 + data[i++];
|
||||
_referenceHeight = data[i++] * 256 + data[i++];
|
||||
_referenceWidth = (data[i++] * 256) + data[i++];
|
||||
_referenceHeight = (data[i++] * 256) + data[i++];
|
||||
|
||||
int count = data[i++];
|
||||
|
||||
while (count-- > 0)
|
||||
{
|
||||
Zones.Add(new Int32Rect(
|
||||
data[i++] * 256 + data[i++],
|
||||
data[i++] * 256 + data[i++],
|
||||
data[i++] * 256 + data[i++],
|
||||
data[i++] * 256 + data[i++]));
|
||||
(data[i++] * 256) + data[i++],
|
||||
(data[i++] * 256) + data[i++],
|
||||
(data[i++] * 256) + data[i++],
|
||||
(data[i++] * 256) + data[i++]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,11 +127,13 @@ namespace FancyZonesEditor.Models
|
||||
// Clones the data from this CanvasLayoutModel to a new CanvasLayoutModel
|
||||
public override LayoutModel Clone()
|
||||
{
|
||||
CanvasLayoutModel layout = new CanvasLayoutModel(Name);
|
||||
layout.ReferenceHeight = ReferenceHeight;
|
||||
layout.ReferenceWidth = ReferenceWidth;
|
||||
CanvasLayoutModel layout = new CanvasLayoutModel(Name)
|
||||
{
|
||||
ReferenceHeight = ReferenceHeight,
|
||||
ReferenceWidth = ReferenceWidth,
|
||||
};
|
||||
|
||||
foreach(Int32Rect zone in Zones)
|
||||
foreach (Int32Rect zone in Zones)
|
||||
{
|
||||
layout.Zones.Add(zone);
|
||||
}
|
||||
|
||||
@@ -10,29 +10,7 @@ namespace FancyZonesEditor.Models
|
||||
// Grid-styled Layout Model, which specifies rows, columns, percentage sizes, and row/column spans
|
||||
public class GridLayoutModel : LayoutModel
|
||||
{
|
||||
public GridLayoutModel()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public GridLayoutModel(string name)
|
||||
: base(name)
|
||||
{
|
||||
}
|
||||
|
||||
public GridLayoutModel(string name, ushort id)
|
||||
: base(name, id)
|
||||
{
|
||||
}
|
||||
|
||||
public GridLayoutModel(ushort version, string name, ushort id, byte[] data)
|
||||
: base(name, id)
|
||||
{
|
||||
if (version == c_latestVersion)
|
||||
{
|
||||
Reload(data);
|
||||
}
|
||||
}
|
||||
private static ushort _latestVersion = 0;
|
||||
|
||||
// Rows - number of rows in the Grid
|
||||
public int Rows
|
||||
@@ -90,6 +68,30 @@ namespace FancyZonesEditor.Models
|
||||
// TODO: do I need FreeZones on the data model? - I think I do
|
||||
public IList<int> FreeZones { get; } = new List<int>();
|
||||
|
||||
public GridLayoutModel()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public GridLayoutModel(string name)
|
||||
: base(name)
|
||||
{
|
||||
}
|
||||
|
||||
public GridLayoutModel(string name, ushort id)
|
||||
: base(name, id)
|
||||
{
|
||||
}
|
||||
|
||||
public GridLayoutModel(ushort version, string name, ushort id, byte[] data)
|
||||
: base(name, id)
|
||||
{
|
||||
if (version == _latestVersion)
|
||||
{
|
||||
Reload(data);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reload(byte[] data)
|
||||
{
|
||||
// Skip version (2 bytes), id (2 bytes), and type (1 bytes)
|
||||
@@ -207,8 +209,8 @@ namespace FancyZonesEditor.Models
|
||||
int i = 0;
|
||||
|
||||
// Common persisted values between all layout types
|
||||
data[i++] = (byte)(c_latestVersion / 256);
|
||||
data[i++] = (byte)(c_latestVersion % 256);
|
||||
data[i++] = (byte)(_latestVersion / 256);
|
||||
data[i++] = (byte)(_latestVersion % 256);
|
||||
data[i++] = 0; // LayoutModelType: 0 == GridLayoutModel
|
||||
data[i++] = (byte)(Id / 256);
|
||||
data[i++] = (byte)(Id % 256);
|
||||
@@ -241,7 +243,5 @@ namespace FancyZonesEditor.Models
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private static ushort c_latestVersion = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ namespace FancyZonesEditor.Models
|
||||
// Manages common properties and base persistence
|
||||
public abstract class LayoutModel : INotifyPropertyChanged
|
||||
{
|
||||
private static readonly string _registryPath = Settings.RegistryPath + "\\Layouts";
|
||||
private static readonly string _fullRegistryPath = Settings.FullRegistryPath + "\\Layouts";
|
||||
|
||||
protected LayoutModel()
|
||||
{
|
||||
}
|
||||
@@ -24,7 +27,7 @@ namespace FancyZonesEditor.Models
|
||||
Name = name;
|
||||
}
|
||||
|
||||
protected LayoutModel(string name, ushort id)
|
||||
protected LayoutModel(string name, ushort id)
|
||||
: this(name)
|
||||
{
|
||||
_id = id;
|
||||
@@ -58,7 +61,7 @@ namespace FancyZonesEditor.Models
|
||||
{
|
||||
if (_id == 0)
|
||||
{
|
||||
_id = ++s_maxId;
|
||||
_id = ++_maxId;
|
||||
}
|
||||
|
||||
return _id;
|
||||
@@ -106,17 +109,17 @@ namespace FancyZonesEditor.Models
|
||||
key.DeleteValue(Name);
|
||||
}
|
||||
|
||||
int i = s_customModels.IndexOf(this);
|
||||
int i = _customModels.IndexOf(this);
|
||||
if (i != -1)
|
||||
{
|
||||
s_customModels.RemoveAt(i);
|
||||
_customModels.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Loads all the Layouts persisted under the Layouts key in the registry
|
||||
public static ObservableCollection<LayoutModel> LoadCustomModels()
|
||||
{
|
||||
s_customModels = new ObservableCollection<LayoutModel>();
|
||||
_customModels = new ObservableCollection<LayoutModel>();
|
||||
|
||||
RegistryKey key = Registry.CurrentUser.OpenSubKey(_registryPath);
|
||||
if (key != null)
|
||||
@@ -138,46 +141,28 @@ namespace FancyZonesEditor.Models
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
if (s_maxId < id)
|
||||
if (_maxId < id)
|
||||
{
|
||||
s_maxId = id;
|
||||
_maxId = id;
|
||||
}
|
||||
|
||||
s_customModels.Add(model);
|
||||
_customModels.Add(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return s_customModels;
|
||||
return _customModels;
|
||||
}
|
||||
|
||||
private static ObservableCollection<LayoutModel> s_customModels = null;
|
||||
private static ObservableCollection<LayoutModel> _customModels = null;
|
||||
|
||||
private static ushort s_maxId = 0;
|
||||
private static ushort _maxId = 0;
|
||||
|
||||
// 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
|
||||
{
|
||||
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
|
||||
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName);
|
||||
|
||||
[DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
|
||||
public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
|
||||
|
||||
internal delegate int PersistZoneSet(
|
||||
[MarshalAs(UnmanagedType.LPWStr)] string activeKey,
|
||||
[MarshalAs(UnmanagedType.LPWStr)] string resolutionKey,
|
||||
uint monitor,
|
||||
ushort layoutId,
|
||||
int zoneCount,
|
||||
[MarshalAs(UnmanagedType.LPArray)] int[] zoneArray);
|
||||
}
|
||||
|
||||
public void Persist(System.Windows.Int32Rect[] zones)
|
||||
{
|
||||
// Persist the editor data
|
||||
@@ -220,8 +205,5 @@ namespace FancyZonesEditor.Models
|
||||
var persistZoneSet = Marshal.GetDelegateForFunctionPointer<Native.PersistZoneSet>(pfn);
|
||||
persistZoneSet(Settings.UniqueKey, Settings.WorkAreaKey, Settings.Monitor, _id, zoneCount, zoneArray);
|
||||
}
|
||||
|
||||
private static readonly string _registryPath = Settings.RegistryPath + "\\Layouts";
|
||||
private static readonly string _fullRegistryPath = Settings.FullRegistryPath + "\\Layouts";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,25 +39,25 @@ namespace FancyZonesEditor
|
||||
ParseCommandLineArgs();
|
||||
|
||||
// Initialize the five default layout models: Focus, Columns, Rows, Grid, and PriorityGrid
|
||||
_defaultModels = new List<LayoutModel>(5);
|
||||
DefaultModels = new List<LayoutModel>(5);
|
||||
_focusModel = new CanvasLayoutModel("Focus", _focusModelId, (int)_workArea.Width, (int)_workArea.Height);
|
||||
_defaultModels.Add(_focusModel);
|
||||
DefaultModels.Add(_focusModel);
|
||||
|
||||
_columnsModel = new GridLayoutModel("Columns", _columnsModelId);
|
||||
_columnsModel.Rows = 1;
|
||||
_columnsModel.RowPercents = new int[1] { c_multiplier };
|
||||
_defaultModels.Add(_columnsModel);
|
||||
_columnsModel.RowPercents = new int[1] { _multiplier };
|
||||
DefaultModels.Add(_columnsModel);
|
||||
|
||||
_rowsModel = new GridLayoutModel("Rows", _rowsModelId);
|
||||
_rowsModel.Columns = 1;
|
||||
_rowsModel.ColumnPercents = new int[1] { c_multiplier };
|
||||
_defaultModels.Add(_rowsModel);
|
||||
_rowsModel.ColumnPercents = new int[1] { _multiplier };
|
||||
DefaultModels.Add(_rowsModel);
|
||||
|
||||
_gridModel = new GridLayoutModel("Grid", _gridModelId);
|
||||
_defaultModels.Add(_gridModel);
|
||||
DefaultModels.Add(_gridModel);
|
||||
|
||||
_priorityGridModel = new GridLayoutModel("Priority Grid", _priorityGridModelId);
|
||||
_defaultModels.Add(_priorityGridModel);
|
||||
DefaultModels.Add(_priorityGridModel);
|
||||
|
||||
_blankCustomModel = new CanvasLayoutModel("Create new custom", _blankCustomModelId, (int)_workArea.Width, (int)_workArea.Height);
|
||||
|
||||
@@ -226,7 +226,7 @@ namespace FancyZonesEditor
|
||||
{
|
||||
_rowsModel.CellChildMap[i, 0] = i;
|
||||
_columnsModel.CellChildMap[0, i] = i;
|
||||
_rowsModel.RowPercents[i] = c_multiplier / ZoneCount; // _columnsModel is sharing the same array
|
||||
_rowsModel.RowPercents[i] = _multiplier / ZoneCount; // _columnsModel is sharing the same array
|
||||
}
|
||||
|
||||
// Update the "Grid" Default Layout
|
||||
@@ -258,12 +258,12 @@ namespace FancyZonesEditor
|
||||
|
||||
for (int row = 0; row < rows; row++)
|
||||
{
|
||||
_gridModel.RowPercents[row] = c_multiplier / rows;
|
||||
_gridModel.RowPercents[row] = _multiplier / rows;
|
||||
}
|
||||
|
||||
for (int col = 0; col < cols; col++)
|
||||
{
|
||||
_gridModel.ColumnPercents[col] = c_multiplier / cols;
|
||||
_gridModel.ColumnPercents[col] = _multiplier / cols;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
@@ -297,10 +297,10 @@ namespace FancyZonesEditor
|
||||
|
||||
private void ParseCommandLineArgs()
|
||||
{
|
||||
_workArea = System.Windows.SystemParameters.WorkArea;
|
||||
_workArea = SystemParameters.WorkArea;
|
||||
Monitor = 0;
|
||||
_uniqueRegistryPath = FullRegistryPath;
|
||||
UniqueKey = "";
|
||||
UniqueKey = string.Empty;
|
||||
Dpi = 1;
|
||||
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
@@ -345,10 +345,7 @@ namespace FancyZonesEditor
|
||||
}
|
||||
}
|
||||
|
||||
public IList<LayoutModel> DefaultModels
|
||||
{
|
||||
get { return _defaultModels; }
|
||||
}
|
||||
public IList<LayoutModel> DefaultModels { get; }
|
||||
|
||||
public ObservableCollection<LayoutModel> CustomModels
|
||||
{
|
||||
@@ -383,8 +380,6 @@ namespace FancyZonesEditor
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
// storage for Default Layout Models
|
||||
private IList<LayoutModel> _defaultModels;
|
||||
private CanvasLayoutModel _focusModel;
|
||||
private GridLayoutModel _rowsModel;
|
||||
private GridLayoutModel _columnsModel;
|
||||
@@ -416,6 +411,6 @@ 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, 5, 6, 7, 8, 9, 10 },
|
||||
};
|
||||
|
||||
private const int c_multiplier = 10000;
|
||||
private const int _multiplier = 10000;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user