mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
Implement canceling edits in FZE, fix crashes related to canceling. (#1610)
* Implemented proper canceling for CanvasEditor * Implemented proper canceling for GridEditor * Possible fix for a crash in my implementation of canceling * Fixed a crash in FZE/Grid editor
This commit is contained in:
@@ -55,6 +55,12 @@ namespace FancyZonesEditor
|
|||||||
previewChildrenCount++;
|
previewChildrenCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (previewChildrenCount > _model.Zones.Count)
|
||||||
|
{
|
||||||
|
Preview.Children.RemoveAt(previewChildrenCount - 1);
|
||||||
|
previewChildrenCount--;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < previewChildrenCount; i++)
|
for (int i = 0; i < previewChildrenCount; i++)
|
||||||
{
|
{
|
||||||
Int32Rect rect = _model.Zones[i];
|
Int32Rect rect = _model.Zones[i];
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace FancyZonesEditor
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_model = EditorOverlay.Current.DataContext as CanvasLayoutModel;
|
_model = EditorOverlay.Current.DataContext as CanvasLayoutModel;
|
||||||
|
_stashedModel = (CanvasLayoutModel)_model.Clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAddZone(object sender, RoutedEventArgs e)
|
private void OnAddZone(object sender, RoutedEventArgs e)
|
||||||
@@ -24,7 +25,14 @@ namespace FancyZonesEditor
|
|||||||
_offset += 100;
|
_offset += 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected new void OnCancel(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnCancel(sender, e);
|
||||||
|
_stashedModel.RestoreTo(_model);
|
||||||
|
}
|
||||||
|
|
||||||
private int _offset = 100;
|
private int _offset = 100;
|
||||||
private CanvasLayoutModel _model;
|
private CanvasLayoutModel _model;
|
||||||
|
private CanvasLayoutModel _stashedModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,16 @@ namespace FancyZonesEditor
|
|||||||
{
|
{
|
||||||
public static readonly DependencyProperty ModelProperty = DependencyProperty.Register("Model", typeof(GridLayoutModel), typeof(GridEditor), new PropertyMetadata(null, OnGridDimensionsChanged));
|
public static readonly DependencyProperty ModelProperty = DependencyProperty.Register("Model", typeof(GridLayoutModel), typeof(GridEditor), new PropertyMetadata(null, OnGridDimensionsChanged));
|
||||||
|
|
||||||
|
private static int gridEditorUniqueIdCounter = 0;
|
||||||
|
|
||||||
|
private int gridEditorUniqueId;
|
||||||
|
|
||||||
public GridEditor()
|
public GridEditor()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Loaded += GridEditor_Loaded;
|
Loaded += GridEditor_Loaded;
|
||||||
((App)Application.Current).ZoneSettings.PropertyChanged += ZoneSettings_PropertyChanged;
|
((App)Application.Current).ZoneSettings.PropertyChanged += ZoneSettings_PropertyChanged;
|
||||||
|
gridEditorUniqueId = ++gridEditorUniqueIdCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GridEditor_Loaded(object sender, RoutedEventArgs e)
|
private void GridEditor_Loaded(object sender, RoutedEventArgs e)
|
||||||
@@ -73,7 +78,9 @@ namespace FancyZonesEditor
|
|||||||
private void ZoneSettings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
private void ZoneSettings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
Size actualSize = new Size(ActualWidth, ActualHeight);
|
Size actualSize = new Size(ActualWidth, ActualHeight);
|
||||||
if (actualSize.Width > 0)
|
|
||||||
|
// Only enter if this is the newest instance
|
||||||
|
if (actualSize.Width > 0 && gridEditorUniqueId == gridEditorUniqueIdCounter)
|
||||||
{
|
{
|
||||||
ArrangeGridRects(actualSize);
|
ArrangeGridRects(actualSize);
|
||||||
}
|
}
|
||||||
@@ -495,7 +502,8 @@ namespace FancyZonesEditor
|
|||||||
|
|
||||||
private void OnGridDimensionsChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
private void OnGridDimensionsChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if ((e.PropertyName == "Rows") || (e.PropertyName == "Columns"))
|
// Only enter if this is the newest instance
|
||||||
|
if (((e.PropertyName == "Rows") || (e.PropertyName == "Columns")) && gridEditorUniqueId == gridEditorUniqueIdCounter)
|
||||||
{
|
{
|
||||||
OnGridDimensionsChanged();
|
OnGridDimensionsChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.Windows;
|
||||||
|
using FancyZonesEditor.Models;
|
||||||
|
|
||||||
namespace FancyZonesEditor
|
namespace FancyZonesEditor
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -12,6 +15,16 @@ namespace FancyZonesEditor
|
|||||||
public GridEditorWindow()
|
public GridEditorWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_stashedModel = (GridLayoutModel)(EditorOverlay.Current.DataContext as GridLayoutModel).Clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected new void OnCancel(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnCancel(sender, e);
|
||||||
|
GridLayoutModel model = EditorOverlay.Current.DataContext as GridLayoutModel;
|
||||||
|
_stashedModel.RestoreTo(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
private GridLayoutModel _stashedModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,15 @@ namespace FancyZonesEditor.Models
|
|||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RestoreTo(CanvasLayoutModel other)
|
||||||
|
{
|
||||||
|
other.Zones.Clear();
|
||||||
|
foreach (Int32Rect zone in Zones)
|
||||||
|
{
|
||||||
|
other.Zones.Add(zone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// PersistData
|
// PersistData
|
||||||
// Implements the LayoutModel.PersistData abstract method
|
// Implements the LayoutModel.PersistData abstract method
|
||||||
protected override void PersistData()
|
protected override void PersistData()
|
||||||
|
|||||||
@@ -131,6 +131,12 @@ namespace FancyZonesEditor.Models
|
|||||||
public override LayoutModel Clone()
|
public override LayoutModel Clone()
|
||||||
{
|
{
|
||||||
GridLayoutModel layout = new GridLayoutModel(Name);
|
GridLayoutModel layout = new GridLayoutModel(Name);
|
||||||
|
RestoreTo(layout);
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RestoreTo(GridLayoutModel layout)
|
||||||
|
{
|
||||||
int rows = Rows;
|
int rows = Rows;
|
||||||
int cols = Columns;
|
int cols = Columns;
|
||||||
|
|
||||||
@@ -163,8 +169,6 @@ namespace FancyZonesEditor.Models
|
|||||||
}
|
}
|
||||||
|
|
||||||
layout.ColumnPercents = colPercents;
|
layout.ColumnPercents = colPercents;
|
||||||
|
|
||||||
return layout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PersistData
|
// PersistData
|
||||||
|
|||||||
Reference in New Issue
Block a user