mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 06:29:44 +08:00
fixed a bunch of infos
This commit is contained in:
parent
151a937c10
commit
63cb5ab883
@ -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">
|
||||
<Grid>
|
||||
|
@ -13,18 +13,20 @@ namespace FancyZonesEditor
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user