[FancyZones Editor] Reset layout shortcut key after canceling changes (#12613)

* don't update backup layout quick keys
* cancel changes on closing
This commit is contained in:
Seraphima Zykova 2021-08-05 19:29:54 +03:00 committed by GitHub
parent cc6a8d30b3
commit 35c8130060
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 12 deletions

View File

@ -235,6 +235,8 @@ namespace FancyZonesEditor
private void OnClosing(object sender, EventArgs e)
{
CancelLayoutChanges();
App.FancyZonesEditorIO.SerializeZoneSettings();
App.Overlay.CloseLayoutWindow();
App.Current.Shutdown();
@ -259,11 +261,11 @@ namespace FancyZonesEditor
if (_settings.SelectedModel is GridLayoutModel grid)
{
_backup = new GridLayoutModel(grid);
_backup = new GridLayoutModel(grid, false);
}
else if (_settings.SelectedModel is CanvasLayoutModel canvas)
{
_backup = new CanvasLayoutModel(canvas);
_backup = new CanvasLayoutModel(canvas, false);
}
await EditLayoutDialog.ShowAsync();
@ -354,10 +356,7 @@ namespace FancyZonesEditor
// EditLayout: Cancel changes
private void EditLayoutDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
// restore model properties from settings
_settings.RestoreSelectedModel(_backup);
_backup = null;
CancelLayoutChanges();
Select(_settings.AppliedModel);
}
@ -467,5 +466,14 @@ namespace FancyZonesEditor
TextBox tb = sender as TextBox;
tb.SelectionStart = tb.Text.Length;
}
private void CancelLayoutChanges()
{
if (_backup != null)
{
_settings.RestoreSelectedModel(_backup);
_backup = null;
}
}
}
}

View File

@ -52,8 +52,8 @@ namespace FancyZonesEditor.Models
{
}
public CanvasLayoutModel(CanvasLayoutModel other)
: base(other)
public CanvasLayoutModel(CanvasLayoutModel other, bool enableQuickKeysPropertyChangedSubscribe = true)
: base(other, enableQuickKeysPropertyChangedSubscribe)
{
CanvasRect = new Rect(other.CanvasRect.X, other.CanvasRect.Y, other.CanvasRect.Width, other.CanvasRect.Height);

View File

@ -146,8 +146,8 @@ namespace FancyZonesEditor.Models
CellChildMap = cellChildMap;
}
public GridLayoutModel(GridLayoutModel other)
: base(other)
public GridLayoutModel(GridLayoutModel other, bool enableQuickKeysPropertyChangedSubscribe = true)
: base(other, enableQuickKeysPropertyChangedSubscribe)
{
_rows = other._rows;
_cols = other._cols;

View File

@ -42,7 +42,7 @@ namespace FancyZonesEditor.Models
Type = type;
}
protected LayoutModel(LayoutModel other)
protected LayoutModel(LayoutModel other, bool enableQuickKeysPropertyChangedSubscribe)
{
_guid = other._guid;
_name = other._name;
@ -53,7 +53,10 @@ namespace FancyZonesEditor.Models
_zoneCount = other._zoneCount;
_quickKey = other._quickKey;
MainWindowSettingsModel.QuickKeys.PropertyChanged += QuickSwitchKeys_PropertyChanged;
if (enableQuickKeysPropertyChangedSubscribe)
{
MainWindowSettingsModel.QuickKeys.PropertyChanged += QuickSwitchKeys_PropertyChanged;
}
}
// Name - the display name for this layout model - is also used as the key in the registry