[FancyZones Editor] memory leaks crash fix (#12876)
This commit is contained in:
parent
fce3864784
commit
0440a89292
|
@ -6,7 +6,6 @@ using System.Windows;
|
|||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using FancyZonesEditor.Models;
|
||||
using FancyZonesEditor.Utils;
|
||||
|
||||
namespace FancyZonesEditor
|
||||
{
|
||||
|
@ -24,6 +23,7 @@ namespace FancyZonesEditor
|
|||
{
|
||||
InitializeComponent();
|
||||
Loaded += OnLoaded;
|
||||
Unloaded += OnUnloaded;
|
||||
KeyDown += CanvasEditor_KeyDown;
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,15 @@ namespace FancyZonesEditor
|
|||
_model = model;
|
||||
UpdateZoneRects();
|
||||
|
||||
model.PropertyChanged += OnModelChanged;
|
||||
_model.PropertyChanged += OnModelChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUnloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_model != null)
|
||||
{
|
||||
_model.PropertyChanged -= OnModelChanged;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ using System.Windows;
|
|||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using FancyZonesEditor.Models;
|
||||
using FancyZonesEditor.Utils;
|
||||
|
||||
namespace FancyZonesEditor
|
||||
{
|
||||
|
|
|
@ -39,11 +39,12 @@ namespace FancyZonesEditor
|
|||
Loaded += GridEditor_Loaded;
|
||||
Unloaded += GridEditor_Unloaded;
|
||||
gridEditorUniqueId = ++gridEditorUniqueIdCounter;
|
||||
((App)Application.Current).MainWindowSettings.PropertyChanged += ZoneSettings_PropertyChanged;
|
||||
}
|
||||
|
||||
private void GridEditor_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
((App)Application.Current).MainWindowSettings.PropertyChanged += ZoneSettings_PropertyChanged;
|
||||
|
||||
GridLayoutModel model = (GridLayoutModel)DataContext;
|
||||
if (model == null)
|
||||
{
|
||||
|
@ -57,6 +58,18 @@ namespace FancyZonesEditor
|
|||
SetupUI();
|
||||
}
|
||||
|
||||
private void GridEditor_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
((App)Application.Current).MainWindowSettings.PropertyChanged -= ZoneSettings_PropertyChanged;
|
||||
|
||||
if (Model != null)
|
||||
{
|
||||
Model.PropertyChanged -= OnGridDimensionsChanged;
|
||||
}
|
||||
|
||||
gridEditorUniqueId = -1;
|
||||
}
|
||||
|
||||
private void PlaceResizer(GridResizer resizerThumb)
|
||||
{
|
||||
var leftZone = Preview.Children[resizerThumb.LeftReferenceZone];
|
||||
|
@ -174,11 +187,6 @@ namespace FancyZonesEditor
|
|||
}
|
||||
}
|
||||
|
||||
private void GridEditor_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
gridEditorUniqueId = -1;
|
||||
}
|
||||
|
||||
private Size WorkAreaSize()
|
||||
{
|
||||
Rect workingArea = App.Overlay.WorkArea;
|
||||
|
@ -188,7 +196,7 @@ namespace FancyZonesEditor
|
|||
public GridLayoutModel Model
|
||||
{
|
||||
get { return (GridLayoutModel)GetValue(ModelProperty); }
|
||||
set { SetValue(ModelProperty, value); }
|
||||
private set { SetValue(ModelProperty, value); }
|
||||
}
|
||||
|
||||
public Panel PreviewPanel
|
||||
|
|
|
@ -37,7 +37,6 @@ namespace FancyZonesEditor
|
|||
{
|
||||
InitializeComponent();
|
||||
DataContextChanged += LayoutPreview_DataContextChanged;
|
||||
((App)Application.Current).MainWindowSettings.PropertyChanged += ZoneSettings_PropertyChanged;
|
||||
}
|
||||
|
||||
public void UpdatePreview()
|
||||
|
@ -60,7 +59,7 @@ namespace FancyZonesEditor
|
|||
}
|
||||
}
|
||||
|
||||
private void ZoneSettings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
public void ZoneSettings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == PropertyZoneCountID)
|
||||
{
|
||||
|
|
|
@ -232,16 +232,13 @@
|
|||
Margin="16,48,16,16">
|
||||
<StackPanel.Style>
|
||||
<Style TargetType="StackPanel">
|
||||
<Setter Property="Visibility"
|
||||
Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding CustomModels.Count}"
|
||||
Value="0">
|
||||
<Setter Property="Visibility"
|
||||
Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding CustomModelsCount}" Value="0">
|
||||
<Setter Property="Visibility" Value="Visible" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</StackPanel.Style>
|
||||
<controls:PathIcon
|
||||
Foreground="{DynamicResource SecondaryForegroundBrush}"
|
||||
|
|
|
@ -8,7 +8,6 @@ using System.Windows;
|
|||
using System.Windows.Automation;
|
||||
using System.Windows.Automation.Peers;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Forms.Automation;
|
||||
using System.Windows.Input;
|
||||
using FancyZonesEditor.Models;
|
||||
using FancyZonesEditor.Utils;
|
||||
|
@ -290,11 +289,11 @@ namespace FancyZonesEditor
|
|||
|
||||
if (_settings.SelectedModel is GridLayoutModel grid)
|
||||
{
|
||||
_backup = new GridLayoutModel(grid, false);
|
||||
_backup = new GridLayoutModel(grid);
|
||||
}
|
||||
else if (_settings.SelectedModel is CanvasLayoutModel canvas)
|
||||
{
|
||||
_backup = new CanvasLayoutModel(canvas, false);
|
||||
_backup = new CanvasLayoutModel(canvas);
|
||||
}
|
||||
|
||||
await EditLayoutDialog.ShowAsync();
|
||||
|
|
|
@ -52,8 +52,8 @@ namespace FancyZonesEditor.Models
|
|||
{
|
||||
}
|
||||
|
||||
public CanvasLayoutModel(CanvasLayoutModel other, bool enableQuickKeysPropertyChangedSubscribe = true)
|
||||
: base(other, enableQuickKeysPropertyChangedSubscribe)
|
||||
public CanvasLayoutModel(CanvasLayoutModel other)
|
||||
: base(other)
|
||||
{
|
||||
CanvasRect = new Rect(other.CanvasRect.X, other.CanvasRect.Y, other.CanvasRect.Width, other.CanvasRect.Height);
|
||||
|
||||
|
|
|
@ -146,8 +146,8 @@ namespace FancyZonesEditor.Models
|
|||
CellChildMap = cellChildMap;
|
||||
}
|
||||
|
||||
public GridLayoutModel(GridLayoutModel other, bool enableQuickKeysPropertyChangedSubscribe = true)
|
||||
: base(other, enableQuickKeysPropertyChangedSubscribe)
|
||||
public GridLayoutModel(GridLayoutModel other)
|
||||
: base(other)
|
||||
{
|
||||
_rows = other._rows;
|
||||
_cols = other._cols;
|
||||
|
|
|
@ -17,8 +17,6 @@ namespace FancyZonesEditor.Models
|
|||
{
|
||||
_guid = Guid.NewGuid();
|
||||
Type = LayoutType.Custom;
|
||||
|
||||
MainWindowSettingsModel.QuickKeys.PropertyChanged += QuickSwitchKeys_PropertyChanged;
|
||||
}
|
||||
|
||||
protected LayoutModel(string name)
|
||||
|
@ -42,7 +40,7 @@ namespace FancyZonesEditor.Models
|
|||
Type = type;
|
||||
}
|
||||
|
||||
protected LayoutModel(LayoutModel other, bool enableQuickKeysPropertyChangedSubscribe)
|
||||
protected LayoutModel(LayoutModel other)
|
||||
{
|
||||
_guid = other._guid;
|
||||
_name = other._name;
|
||||
|
@ -52,11 +50,6 @@ namespace FancyZonesEditor.Models
|
|||
_sensitivityRadius = other._sensitivityRadius;
|
||||
_zoneCount = other._zoneCount;
|
||||
_quickKey = other._quickKey;
|
||||
|
||||
if (enableQuickKeysPropertyChangedSubscribe)
|
||||
{
|
||||
MainWindowSettingsModel.QuickKeys.PropertyChanged += QuickSwitchKeys_PropertyChanged;
|
||||
}
|
||||
}
|
||||
|
||||
// Name - the display name for this layout model - is also used as the key in the registry
|
||||
|
@ -305,7 +298,7 @@ namespace FancyZonesEditor.Models
|
|||
PersistData();
|
||||
}
|
||||
|
||||
private void QuickSwitchKeys_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
public void QuickSwitchKeys_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
foreach (var pair in MainWindowSettingsModel.QuickKeys.SelectedKeys)
|
||||
{
|
||||
|
|
|
@ -138,10 +138,34 @@ namespace FancyZonesEditor
|
|||
{
|
||||
return _customModels;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
foreach (LayoutModel model in _customModels)
|
||||
{
|
||||
QuickKeys.PropertyChanged -= model.QuickSwitchKeys_PropertyChanged;
|
||||
}
|
||||
|
||||
_customModels.Clear();
|
||||
_customModels = value;
|
||||
|
||||
foreach (LayoutModel model in _customModels)
|
||||
{
|
||||
QuickKeys.PropertyChanged += model.QuickSwitchKeys_PropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ObservableCollection<LayoutModel> _customModels = new ObservableCollection<LayoutModel>();
|
||||
|
||||
public static int CustomModelsCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return _customModels.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public static QuickKeysModel QuickKeys { get; } = new QuickKeysModel();
|
||||
|
||||
public LayoutModel SelectedModel
|
||||
|
|
|
@ -134,12 +134,20 @@ namespace FancyZonesEditor
|
|||
|
||||
public void Show()
|
||||
{
|
||||
var mainWindowSettings = ((App)Application.Current).MainWindowSettings;
|
||||
if (_layoutPreview != null)
|
||||
{
|
||||
mainWindowSettings.PropertyChanged -= _layoutPreview.ZoneSettings_PropertyChanged;
|
||||
}
|
||||
|
||||
_layoutPreview = new LayoutPreview
|
||||
{
|
||||
IsActualSize = true,
|
||||
Opacity = 1,
|
||||
};
|
||||
|
||||
mainWindowSettings.PropertyChanged += _layoutPreview.ZoneSettings_PropertyChanged;
|
||||
|
||||
ShowLayout();
|
||||
OpenMainWindow();
|
||||
}
|
||||
|
@ -160,7 +168,10 @@ namespace FancyZonesEditor
|
|||
|
||||
for (int i = 0; i < DesktopsCount; i++)
|
||||
{
|
||||
Monitors[i].Window.Show();
|
||||
if (!Monitors[i].Window.IsVisible)
|
||||
{
|
||||
Monitors[i].Window.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,13 +229,23 @@ namespace FancyZonesEditor
|
|||
|
||||
public void CloseEditor()
|
||||
{
|
||||
var mainWindowSettings = ((App)Application.Current).MainWindowSettings;
|
||||
|
||||
_editorLayout = null;
|
||||
|
||||
if (_layoutPreview != null)
|
||||
{
|
||||
mainWindowSettings.PropertyChanged -= _layoutPreview.ZoneSettings_PropertyChanged;
|
||||
}
|
||||
|
||||
_layoutPreview = new LayoutPreview
|
||||
{
|
||||
IsActualSize = true,
|
||||
Opacity = 1,
|
||||
};
|
||||
|
||||
mainWindowSettings.PropertyChanged += _layoutPreview.ZoneSettings_PropertyChanged;
|
||||
|
||||
CurrentLayoutWindow.Content = _layoutPreview;
|
||||
|
||||
OpenMainWindow();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
|
@ -758,7 +759,7 @@ namespace FancyZonesEditor.Utils
|
|||
return false;
|
||||
}
|
||||
|
||||
MainWindowSettingsModel.CustomModels.Clear();
|
||||
ObservableCollection<LayoutModel> models = new ObservableCollection<LayoutModel>();
|
||||
bool result = true;
|
||||
|
||||
foreach (var zoneSet in customLayouts)
|
||||
|
@ -793,9 +794,11 @@ namespace FancyZonesEditor.Utils
|
|||
continue;
|
||||
}
|
||||
|
||||
MainWindowSettingsModel.CustomModels.Add(layout);
|
||||
models.Add(layout);
|
||||
}
|
||||
|
||||
MainWindowSettingsModel.CustomModels = models;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,10 +21,6 @@ namespace FancyZonesEditor.ViewModels
|
|||
|
||||
public static double DesktopPreviewMultiplier { get; private set; }
|
||||
|
||||
public RelayCommand AddCommand { get; set; }
|
||||
|
||||
public RelayCommand DeleteCommand { get; set; }
|
||||
|
||||
public RelayCommand<MonitorInfoModel> SelectCommand { get; set; }
|
||||
|
||||
public MonitorViewModel()
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
<Window x:Class="FancyZonesEditor.WindowLayout"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
Title="Window1" Height="450"
|
||||
Width="800"
|
||||
WindowState="Maximized"
|
||||
ShowInTaskbar="False"
|
||||
ResizeMode="NoResize"
|
||||
WindowStyle="None"
|
||||
AllowsTransparency="True"
|
||||
Background="Transparent"
|
||||
Loaded="OnLoaded"
|
||||
>
|
||||
|
||||
|
||||
<Grid x:Name="Body">
|
||||
<Rectangle Fill="White" Opacity="1"/>
|
||||
|
||||
<Grid x:Name="Window1" >
|
||||
<Border BorderThickness="2" BorderBrush="Black">
|
||||
<Grid>
|
||||
<!--
|
||||
<Thumb Background="Red" Height="36" VerticalAlignment="Top"/>
|
||||
<Button Height="36" Width="36" VerticalAlignment="Top" Background="Red" FontFamily="Segoe UI Symbol" FontSize="16" Content="✖" HorizontalAlignment="Right"/>
|
||||
-->
|
||||
<Rectangle Fill="Black" Opacity="1"/>
|
||||
<!--
|
||||
<Grid Width="24" Height="24" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,10,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Rectangle Fill="White" Height="24" Width="2" Margin="-33,0,0,0">
|
||||
<Rectangle.RenderTransform>
|
||||
<RotateTransform Angle="-45"/>
|
||||
</Rectangle.RenderTransform>
|
||||
</Rectangle>
|
||||
<Rectangle Fill="White" Height="24" Width="2" Margin="0,-3,0,0" VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
<Rectangle.RenderTransform>
|
||||
<RotateTransform Angle="45"/>
|
||||
</Rectangle.RenderTransform>
|
||||
</Rectangle>
|
||||
</Grid>
|
||||
-->
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
|
@ -1,24 +0,0 @@
|
|||
// 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.Windows;
|
||||
|
||||
namespace FancyZonesEditor
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for WindowLayout.xaml
|
||||
/// </summary>
|
||||
public partial class WindowLayout : Window
|
||||
{
|
||||
public WindowLayout()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// WindowEditor window = new WindowEditor(); window.Show();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue