mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
fixed a bunch more
This commit is contained in:
@@ -19,7 +19,7 @@ namespace FancyZonesEditor
|
||||
public CanvasZone()
|
||||
{
|
||||
InitializeComponent();
|
||||
Canvas.SetZIndex(this, c_zIndex++);
|
||||
Panel.SetZIndex(this, _zIndex++);
|
||||
}
|
||||
|
||||
public CanvasLayoutModel Model;
|
||||
@@ -66,9 +66,9 @@ namespace FancyZonesEditor
|
||||
}
|
||||
else if (xDelta > 0)
|
||||
{
|
||||
if ((rect.Width - (int)xDelta) < c_minZoneWidth)
|
||||
if ((rect.Width - (int)xDelta) < _minZoneWidth)
|
||||
{
|
||||
xDelta = rect.Width - c_minZoneWidth;
|
||||
xDelta = rect.Width - _minZoneWidth;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,9 +81,9 @@ namespace FancyZonesEditor
|
||||
}
|
||||
else if (yDelta > 0)
|
||||
{
|
||||
if ((rect.Height - (int)yDelta) < c_minZoneHeight)
|
||||
if ((rect.Height - (int)yDelta) < _minZoneHeight)
|
||||
{
|
||||
yDelta = rect.Height - c_minZoneHeight;
|
||||
yDelta = rect.Height - _minZoneHeight;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,9 +107,9 @@ namespace FancyZonesEditor
|
||||
{
|
||||
int newWidth = rect.Width + (int)xDelta;
|
||||
|
||||
if (newWidth < c_minZoneWidth)
|
||||
if (newWidth < _minZoneWidth)
|
||||
{
|
||||
newWidth = c_minZoneWidth;
|
||||
newWidth = _minZoneWidth;
|
||||
}
|
||||
else if (newWidth > (_settings.WorkArea.Width - rect.X))
|
||||
{
|
||||
@@ -123,9 +123,9 @@ namespace FancyZonesEditor
|
||||
{
|
||||
int newHeight = rect.Height + (int)yDelta;
|
||||
|
||||
if (newHeight < c_minZoneHeight)
|
||||
if (newHeight < _minZoneHeight)
|
||||
{
|
||||
newHeight = c_minZoneHeight;
|
||||
newHeight = _minZoneHeight;
|
||||
}
|
||||
else if (newHeight > (_settings.WorkArea.Height - rect.Y))
|
||||
{
|
||||
@@ -138,13 +138,13 @@ namespace FancyZonesEditor
|
||||
Model.Zones[ZoneIndex] = rect;
|
||||
}
|
||||
|
||||
private static int c_zIndex = 0;
|
||||
private static int c_minZoneWidth = 64;
|
||||
private static int c_minZoneHeight = 72;
|
||||
private static int _zIndex = 0;
|
||||
private static int _minZoneWidth = 64;
|
||||
private static int _minZoneHeight = 72;
|
||||
|
||||
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
|
||||
{
|
||||
Canvas.SetZIndex(this, c_zIndex++);
|
||||
Panel.SetZIndex(this, _zIndex++);
|
||||
base.OnPreviewMouseDown(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,21 +14,21 @@ namespace FancyZonesEditor
|
||||
/// </summary>
|
||||
public partial class EditorOverlay : Window
|
||||
{
|
||||
public static EditorOverlay Current { get; set; }
|
||||
|
||||
public Int32Rect[] GetZoneRects()
|
||||
{
|
||||
// TODO: the ideal here is that the ArrangeRects logic is entirely inside the model, so we don't have to walk the UIElement children to get the rect info
|
||||
Panel previewPanel = null;
|
||||
|
||||
Panel previewPanel;
|
||||
if (_editor != null)
|
||||
{
|
||||
GridEditor gridEditor = _editor as GridEditor;
|
||||
if (gridEditor != null)
|
||||
if (_editor is GridEditor gridEditor)
|
||||
{
|
||||
previewPanel = gridEditor.PreviewPanel;
|
||||
}
|
||||
else
|
||||
{
|
||||
//CanvasEditor
|
||||
// CanvasEditor
|
||||
previewPanel = ((CanvasEditor)_editor).Preview;
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ namespace FancyZonesEditor
|
||||
int i = 0;
|
||||
foreach (FrameworkElement child in previewPanel.Children)
|
||||
{
|
||||
Point topLeft = child.TransformToAncestor(previewPanel).Transform(new Point());
|
||||
Point topLeft = child.TransformToAncestor(previewPanel).Transform(default(Point));
|
||||
|
||||
var right = topLeft.X + child.ActualWidth;
|
||||
var bottom = topLeft.Y + child.ActualHeight;
|
||||
@@ -57,8 +57,6 @@ namespace FancyZonesEditor
|
||||
return zones;
|
||||
}
|
||||
|
||||
public static EditorOverlay Current;
|
||||
|
||||
public EditorOverlay()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
@@ -14,14 +14,14 @@ namespace FancyZonesEditor
|
||||
protected void OnSaveApplyTemplate(object sender, RoutedEventArgs e)
|
||||
{
|
||||
EditorOverlay mainEditor = EditorOverlay.Current;
|
||||
LayoutModel model = mainEditor.DataContext as LayoutModel;
|
||||
var model = mainEditor.DataContext as LayoutModel;
|
||||
if (model != null)
|
||||
{
|
||||
model.Persist(mainEditor.GetZoneRects());
|
||||
}
|
||||
|
||||
_choosing = true;
|
||||
this.Close();
|
||||
Close();
|
||||
EditorOverlay.Current.Close();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace FancyZonesEditor
|
||||
protected void OnCancel(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_choosing = true;
|
||||
this.Close();
|
||||
Close();
|
||||
EditorOverlay.Current.ShowLayoutPicker();
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@
|
||||
<DependentUpon>EditorOverlay.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Converters\ModelToVisibilityConverter.xaml.cs" />
|
||||
<Compile Include="Native.cs" />
|
||||
<Compile Include="RowColInfo.cs" />
|
||||
<Compile Include="GridEditorWindow.xaml.cs">
|
||||
<DependentUpon>GridEditorWindow.xaml</DependentUpon>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// 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.
|
||||
|
||||
// This file is used by Code Analysis to maintain SuppressMessage
|
||||
|
||||
@@ -343,8 +343,9 @@ namespace FancyZonesEditor
|
||||
|
||||
model.Columns++;
|
||||
}
|
||||
else // Horizontal
|
||||
else
|
||||
{
|
||||
// Horizontal
|
||||
if (splitee.HorizontalSnapPoints != null)
|
||||
{
|
||||
offset += Canvas.GetTop(splitee);
|
||||
@@ -553,7 +554,7 @@ namespace FancyZonesEditor
|
||||
return;
|
||||
}
|
||||
|
||||
Settings settings = ((App)(Application.Current)).ZoneSettings;
|
||||
Settings settings = ((App)Application.Current).ZoneSettings;
|
||||
int spacing = settings.Spacing;
|
||||
int gutter = settings.Spacing;
|
||||
|
||||
@@ -566,14 +567,14 @@ namespace FancyZonesEditor
|
||||
double top = gutter;
|
||||
for (int row = 0; row < rows; row++)
|
||||
{
|
||||
double cellHeight = _rowInfo[row].SetExtent(top, totalHeight);
|
||||
double cellHeight = _rowInfo[row].Recalculate(top, totalHeight);
|
||||
top += cellHeight + spacing;
|
||||
}
|
||||
|
||||
double left = gutter;
|
||||
for (int col = 0; col < cols; col++)
|
||||
{
|
||||
double cellWidth = _colInfo[col].SetExtent(left, totalWidth);
|
||||
double cellWidth = _colInfo[col].Recalculate(left, totalWidth);
|
||||
left += cellWidth + spacing;
|
||||
}
|
||||
|
||||
@@ -861,7 +862,7 @@ namespace FancyZonesEditor
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
base.OnPreviewMouseMove(e);
|
||||
OnPreviewMouseMove(e);
|
||||
}
|
||||
|
||||
private void ClearSelection()
|
||||
|
||||
@@ -19,6 +19,25 @@ namespace FancyZonesEditor
|
||||
{
|
||||
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(GridZone), new PropertyMetadata(false, OnSelectionChanged));
|
||||
|
||||
public event SplitEventHandler Split;
|
||||
|
||||
public event SplitEventHandler FullSplit;
|
||||
|
||||
public event MouseEventHandler MergeDrag;
|
||||
|
||||
public event MouseButtonEventHandler MergeComplete;
|
||||
|
||||
public double[] VerticalSnapPoints { get; set; }
|
||||
|
||||
public double[] HorizontalSnapPoints { get; set; }
|
||||
|
||||
private Rectangle _splitter;
|
||||
private bool _switchOrientation = false;
|
||||
private Point _lastPos = new Point(-1, -1);
|
||||
private Point _mouseDownPos = new Point(-1, -1);
|
||||
private bool _inMergeDrag = false;
|
||||
private Orientation _splitOrientation;
|
||||
|
||||
private static void OnSelectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
((GridZone)d).OnSelectionChanged();
|
||||
@@ -35,15 +54,14 @@ namespace FancyZonesEditor
|
||||
set { SetValue(IsSelectedProperty, value); }
|
||||
}
|
||||
|
||||
public double[] VerticalSnapPoints;
|
||||
public double[] HorizontalSnapPoints;
|
||||
|
||||
public GridZone()
|
||||
{
|
||||
InitializeComponent();
|
||||
OnSelectionChanged();
|
||||
_splitter = new Rectangle();
|
||||
_splitter.Fill = Brushes.DarkGray;
|
||||
_splitter = new Rectangle
|
||||
{
|
||||
Fill = Brushes.DarkGray,
|
||||
};
|
||||
Body.Children.Add(_splitter);
|
||||
|
||||
((App)Application.Current).ZoneSettings.PropertyChanged += ZoneSettings_PropertyChanged;
|
||||
@@ -169,8 +187,9 @@ namespace FancyZonesEditor
|
||||
}
|
||||
}
|
||||
}
|
||||
else // horizontal split
|
||||
else
|
||||
{
|
||||
// horizontal split
|
||||
if (HorizontalSnapPoints != null)
|
||||
{
|
||||
int thickness = SplitterThickness;
|
||||
@@ -237,21 +256,6 @@ namespace FancyZonesEditor
|
||||
base.OnMouseUp(e);
|
||||
}
|
||||
|
||||
public event SplitEventHandler Split;
|
||||
|
||||
public event SplitEventHandler FullSplit;
|
||||
|
||||
public event MouseEventHandler MergeDrag;
|
||||
|
||||
public event MouseButtonEventHandler MergeComplete;
|
||||
|
||||
private Rectangle _splitter;
|
||||
private bool _switchOrientation = false;
|
||||
private Point _lastPos = new Point(-1,-1);
|
||||
private Point _mouseDownPos = new Point(-1,-1);
|
||||
private bool _inMergeDrag = false;
|
||||
private Orientation _splitOrientation;
|
||||
|
||||
private void DoMergeDrag(MouseEventArgs e)
|
||||
{
|
||||
if (MergeDrag != null)
|
||||
|
||||
@@ -83,14 +83,13 @@ namespace FancyZonesEditor
|
||||
|
||||
Body.Children.Clear();
|
||||
|
||||
GridLayoutModel gridModel = _model as GridLayoutModel;
|
||||
if (gridModel != null)
|
||||
if (_model is GridLayoutModel gridModel)
|
||||
{
|
||||
RenderGridPreview(gridModel);
|
||||
}
|
||||
else
|
||||
{
|
||||
CanvasLayoutModel canvasModel = _model as CanvasLayoutModel;
|
||||
var canvasModel = _model as CanvasLayoutModel;
|
||||
if (canvasModel != null)
|
||||
{
|
||||
RenderCanvasPreview(canvasModel);
|
||||
@@ -126,7 +125,7 @@ namespace FancyZonesEditor
|
||||
{
|
||||
for (int col = 0; col < grid.Columns; col++)
|
||||
{
|
||||
int childIndex = grid.CellChildMap[row,col];
|
||||
int childIndex = grid.CellChildMap[row, col];
|
||||
if (!visited.Contains(childIndex))
|
||||
{
|
||||
visited.Add(childIndex);
|
||||
@@ -135,7 +134,7 @@ namespace FancyZonesEditor
|
||||
Grid.SetColumn(rect, col);
|
||||
int span = 1;
|
||||
int walk = row + 1;
|
||||
while ((walk < grid.Rows) && grid.CellChildMap[walk,col] == childIndex)
|
||||
while ((walk < grid.Rows) && grid.CellChildMap[walk, col] == childIndex)
|
||||
{
|
||||
span++;
|
||||
walk++;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace FancyZonesEditor
|
||||
public static int MAX_ZONES = 40;
|
||||
private static string _defaultNamePrefix = "Custom Layout ";
|
||||
private bool _editing = false;
|
||||
private int _WrapPanelItemSize = 262;
|
||||
private int _wrapPanelItemSize = 262;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
@@ -31,8 +31,8 @@ namespace FancyZonesEditor
|
||||
DataContext = _settings;
|
||||
if (_settings.WorkArea.Height < 900)
|
||||
{
|
||||
this.SizeToContent = SizeToContent.WidthAndHeight;
|
||||
this.WrapPanelItemSize = 180;
|
||||
SizeToContent = SizeToContent.WidthAndHeight;
|
||||
WrapPanelItemSize = 180;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,12 +40,12 @@ namespace FancyZonesEditor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _WrapPanelItemSize;
|
||||
return _wrapPanelItemSize;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_WrapPanelItemSize = value;
|
||||
_wrapPanelItemSize = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace FancyZonesEditor
|
||||
{
|
||||
WindowLayout window = new WindowLayout();
|
||||
window.Show();
|
||||
this.Close();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void LayoutItem_Click(object sender, MouseButtonEventArgs e)
|
||||
@@ -81,30 +81,26 @@ namespace FancyZonesEditor
|
||||
|
||||
private void Select(LayoutModel newSelection)
|
||||
{
|
||||
LayoutModel currentSelection = EditorOverlay.Current.DataContext as LayoutModel;
|
||||
|
||||
if (currentSelection != null)
|
||||
if (EditorOverlay.Current.DataContext is LayoutModel currentSelection)
|
||||
{
|
||||
currentSelection.IsSelected = false;
|
||||
}
|
||||
|
||||
newSelection.IsSelected = true;
|
||||
|
||||
EditorOverlay.Current.DataContext = newSelection;
|
||||
}
|
||||
|
||||
private void EditLayout_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
EditorOverlay mainEditor = EditorOverlay.Current;
|
||||
LayoutModel model = mainEditor.DataContext as LayoutModel;
|
||||
if (model == null)
|
||||
if (!(mainEditor.DataContext is LayoutModel model))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
model.IsSelected = false;
|
||||
_editing = true;
|
||||
this.Close();
|
||||
Close();
|
||||
|
||||
bool isPredefinedLayout = Settings.IsPredefinedLayout(model);
|
||||
|
||||
@@ -124,7 +120,7 @@ namespace FancyZonesEditor
|
||||
if (name.StartsWith(_defaultNamePrefix))
|
||||
{
|
||||
int i;
|
||||
if (Int32.TryParse(name.Substring(_defaultNamePrefix.Length), out i))
|
||||
if (int.TryParse(name.Substring(_defaultNamePrefix.Length), out i))
|
||||
{
|
||||
if (maxCustomIndex < i)
|
||||
{
|
||||
@@ -157,8 +153,7 @@ namespace FancyZonesEditor
|
||||
private void Apply_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
EditorOverlay mainEditor = EditorOverlay.Current;
|
||||
LayoutModel model = mainEditor.DataContext as LayoutModel;
|
||||
if (model != null)
|
||||
if (mainEditor.DataContext is LayoutModel model)
|
||||
{
|
||||
if (model is GridLayoutModel)
|
||||
{
|
||||
@@ -169,7 +164,7 @@ namespace FancyZonesEditor
|
||||
model.Apply((model as CanvasLayoutModel).Zones.ToArray());
|
||||
}
|
||||
|
||||
this.Close();
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
27
src/modules/fancyzones/editor/FancyZonesEditor/Native.cs
Normal file
27
src/modules/fancyzones/editor/FancyZonesEditor/Native.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
// 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.Runtime.InteropServices;
|
||||
|
||||
namespace FancyZonesEditor
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,16 @@ namespace FancyZonesEditor
|
||||
{
|
||||
public class RowColInfo
|
||||
{
|
||||
private const int _multiplier = 10000;
|
||||
|
||||
public double Extent { get; set; }
|
||||
|
||||
public double Start { get; set; }
|
||||
|
||||
public double End { get; set; }
|
||||
|
||||
public int Percent { get; set; }
|
||||
|
||||
public RowColInfo(int percent)
|
||||
{
|
||||
Percent = percent;
|
||||
@@ -13,15 +23,13 @@ namespace FancyZonesEditor
|
||||
|
||||
public RowColInfo(int index, int count)
|
||||
{
|
||||
Percent = (c_multiplier / count) + ((index == 0) ? (c_multiplier % count) : 0);
|
||||
Percent = (_multiplier / count) + ((index == 0) ? (_multiplier % count) : 0);
|
||||
}
|
||||
|
||||
private const int c_multiplier = 10000;
|
||||
|
||||
public double SetExtent(double start, double totalExtent)
|
||||
public double Recalculate(double start, double totalExtent)
|
||||
{
|
||||
Start = start;
|
||||
Extent = totalExtent * Percent / c_multiplier;
|
||||
Extent = totalExtent * Percent / _multiplier;
|
||||
End = Start + Extent;
|
||||
return Extent;
|
||||
}
|
||||
@@ -35,10 +43,5 @@ namespace FancyZonesEditor
|
||||
info[1] = new RowColInfo(Percent - newPercent);
|
||||
return info;
|
||||
}
|
||||
|
||||
public int Percent;
|
||||
public double Extent;
|
||||
public double Start;
|
||||
public double End;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user