diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs b/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs index 3d480996cf33..185b0aeb41a6 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs @@ -23,6 +23,9 @@ protected void OnSaveApplyTemplate(object sender, RoutedEventArgs e) } model.Persist(); + + MainWindowSettingsModel settings = ((App)Application.Current).MainWindowSettings; + settings.SetAppliedModel(model); } App.FancyZonesEditorIO.SerializeZoneSettings(); diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml b/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml index 8301b9d02c03..d8516621d445 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml +++ b/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml @@ -447,7 +447,8 @@ + Foreground="{DynamicResource PrimaryForegroundBrush}" + Visibility="{Binding Path=Type, Converter={StaticResource LayoutTypeTemplateToVisibilityConverter}}" /> diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs b/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs index 528257adf323..abdf99273ff2 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs @@ -286,33 +286,23 @@ private void NewLayoutDialog_PrimaryButtonClick(ModernWpf.Controls.ContentDialog if (GridLayoutRadioButton.IsChecked == true) { - // 1:1 Copy from MainWindowSettingsModel, so probably needs to be refactored / combined. - int multiplier = 10000; - int zoneCount = 3; - - GridLayoutModel columnsModel = new GridLayoutModel(LayoutNameText.Text, LayoutType.Columns) + GridLayoutModel gridModel = new GridLayoutModel(LayoutNameText.Text, LayoutType.Columns) { Rows = 1, - RowPercents = new List(1) { multiplier }, + RowPercents = new List(1) { GridLayoutModel.GridMultiplier }, }; - - columnsModel.CellChildMap = new int[1, zoneCount]; - columnsModel.Columns = zoneCount; - columnsModel.ColumnPercents = new List(zoneCount); - - for (int i = 0; i < 3; i++) - { - columnsModel.CellChildMap[0, i] = i; - columnsModel.ColumnPercents.Add(((multiplier * (i + 1)) / zoneCount) - ((multiplier * i) / zoneCount)); - } - - selectedLayoutModel = columnsModel; + selectedLayoutModel = gridModel; } else { - selectedLayoutModel = new CanvasLayoutModel(LayoutNameText.Text, LayoutType.Blank); + selectedLayoutModel = new CanvasLayoutModel(LayoutNameText.Text, LayoutType.Custom) + { + TemplateZoneCount = 0, + }; } + selectedLayoutModel.InitTemplateZones(); + App.Overlay.CurrentDataContext = selectedLayoutModel; var mainEditor = App.Overlay; Hide(); diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/GridLayoutModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/GridLayoutModel.cs index 7716cc135f4a..cb7d781bda2b 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/GridLayoutModel.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/GridLayoutModel.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation +// 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. @@ -14,7 +14,7 @@ public class GridLayoutModel : LayoutModel // Non-localizable strings public const string ModelTypeID = "grid"; - private const int _multiplier = 10000; + public const int GridMultiplier = 10000; // hard coded data for all the "Priority Grid" configurations that are unique to "Grid" private static readonly byte[][] _priorityData = new byte[][] @@ -78,10 +78,10 @@ public int Columns public int[,] CellChildMap { get; set; } // RowPercents - represents the %age height of each row in the grid - public List RowPercents { get; set; } + public List RowPercents { get; set; } = new List(); // ColumnPercents - represents the %age width of each column in the grid - public List ColumnPercents { get; set; } + public List ColumnPercents { get; set; } = new List(); // ShowSpacing - flag if free space between cells should be presented public bool ShowSpacing @@ -170,13 +170,11 @@ public GridLayoutModel(GridLayoutModel other) } } - RowPercents = new List(_rows); for (int row = 0; row < _rows; row++) { RowPercents.Add(other.RowPercents[row]); } - ColumnPercents = new List(_cols); for (int col = 0; col < _cols; col++) { ColumnPercents.Add(other.ColumnPercents[col]); @@ -306,7 +304,7 @@ private void InitRows() // Note: This is NOT equal to _multiplier / ZoneCount and is done like this to make // the sum of all RowPercents exactly (_multiplier). - RowPercents.Add(((_multiplier * (i + 1)) / TemplateZoneCount) - ((_multiplier * i) / TemplateZoneCount)); + RowPercents.Add(((GridMultiplier * (i + 1)) / TemplateZoneCount) - ((GridMultiplier * i) / TemplateZoneCount)); } _rows = TemplateZoneCount; @@ -323,7 +321,7 @@ private void InitColumns() // Note: This is NOT equal to _multiplier / ZoneCount and is done like this to make // the sum of all RowPercents exactly (_multiplier). - ColumnPercents.Add(((_multiplier * (i + 1)) / TemplateZoneCount) - ((_multiplier * i) / TemplateZoneCount)); + ColumnPercents.Add(((GridMultiplier * (i + 1)) / TemplateZoneCount) - ((GridMultiplier * i) / TemplateZoneCount)); } _cols = TemplateZoneCount; @@ -356,12 +354,12 @@ private void InitGrid() // done like this to make the sum of all RowPercents exactly (_multiplier). for (int row = 0; row < rows; row++) { - RowPercents.Add(((_multiplier * (row + 1)) / rows) - ((_multiplier * row) / rows)); + RowPercents.Add(((GridMultiplier * (row + 1)) / rows) - ((GridMultiplier * row) / rows)); } for (int col = 0; col < cols; col++) { - ColumnPercents.Add(((_multiplier * (col + 1)) / cols) - ((_multiplier * col) / cols)); + ColumnPercents.Add(((GridMultiplier * (col + 1)) / cols) - ((GridMultiplier * col) / cols)); } int index = 0; diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs index 076002bdabee..0e5108923ad4 100644 --- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs +++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs @@ -42,8 +42,6 @@ private enum DeviceIdParts public static readonly string RegistryPath = "SOFTWARE\\SuperFancyZones"; public static readonly string FullRegistryPath = "HKEY_CURRENT_USER\\" + RegistryPath; - private const int _multiplier = 10000; - public bool IsCustomLayoutActive { get @@ -71,7 +69,7 @@ public MainWindowSettingsModel() _columnsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Columns, LayoutType.Columns) { Rows = 1, - RowPercents = new List(1) { _multiplier }, + RowPercents = new List(1) { GridLayoutModel.GridMultiplier }, }; _columnsModel.InitTemplateZones(); DefaultModels.Add(_columnsModel); @@ -79,7 +77,7 @@ public MainWindowSettingsModel() _rowsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Rows, LayoutType.Rows) { Columns = 1, - ColumnPercents = new List(1) { _multiplier }, + ColumnPercents = new List(1) { GridLayoutModel.GridMultiplier }, }; _rowsModel.InitTemplateZones(); DefaultModels.Add(_rowsModel);