Skip to content

Commit f6e747e

Browse files
[FZ Editor] Small fixes and refactoring. (#9236)
* new layout creation refactoring * "Save and apply" applies the layout * number of zones header hide
1 parent e7904b6 commit f6e747e

5 files changed

Lines changed: 24 additions & 34 deletions

File tree

src/modules/fancyzones/editor/FancyZonesEditor/EditorWindow.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ protected void OnSaveApplyTemplate(object sender, RoutedEventArgs e)
2323
}
2424

2525
model.Persist();
26+
27+
MainWindowSettingsModel settings = ((App)Application.Current).MainWindowSettings;
28+
settings.SetAppliedModel(model);
2629
}
2730

2831
App.FancyZonesEditorIO.SerializeZoneSettings();

src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@
447447
<TextBlock x:Name="numberOfZonesHeader"
448448
Text="{x:Static props:Resources.NumberOfZones}"
449449
Margin="0,16,0,0"
450-
Foreground="{DynamicResource PrimaryForegroundBrush}" />
450+
Foreground="{DynamicResource PrimaryForegroundBrush}"
451+
Visibility="{Binding Path=Type, Converter={StaticResource LayoutTypeTemplateToVisibilityConverter}}" />
451452
<StackPanel Margin="0,6,0,0"
452453
Orientation="Horizontal"
453454
Visibility="{Binding Path=Type, Converter={StaticResource LayoutTypeTemplateToVisibilityConverter}}">

src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -286,33 +286,23 @@ private void NewLayoutDialog_PrimaryButtonClick(ModernWpf.Controls.ContentDialog
286286

287287
if (GridLayoutRadioButton.IsChecked == true)
288288
{
289-
// 1:1 Copy from MainWindowSettingsModel, so probably needs to be refactored / combined.
290-
int multiplier = 10000;
291-
int zoneCount = 3;
292-
293-
GridLayoutModel columnsModel = new GridLayoutModel(LayoutNameText.Text, LayoutType.Columns)
289+
GridLayoutModel gridModel = new GridLayoutModel(LayoutNameText.Text, LayoutType.Columns)
294290
{
295291
Rows = 1,
296-
RowPercents = new List<int>(1) { multiplier },
292+
RowPercents = new List<int>(1) { GridLayoutModel.GridMultiplier },
297293
};
298-
299-
columnsModel.CellChildMap = new int[1, zoneCount];
300-
columnsModel.Columns = zoneCount;
301-
columnsModel.ColumnPercents = new List<int>(zoneCount);
302-
303-
for (int i = 0; i < 3; i++)
304-
{
305-
columnsModel.CellChildMap[0, i] = i;
306-
columnsModel.ColumnPercents.Add(((multiplier * (i + 1)) / zoneCount) - ((multiplier * i) / zoneCount));
307-
}
308-
309-
selectedLayoutModel = columnsModel;
294+
selectedLayoutModel = gridModel;
310295
}
311296
else
312297
{
313-
selectedLayoutModel = new CanvasLayoutModel(LayoutNameText.Text, LayoutType.Blank);
298+
selectedLayoutModel = new CanvasLayoutModel(LayoutNameText.Text, LayoutType.Custom)
299+
{
300+
TemplateZoneCount = 0,
301+
};
314302
}
315303

304+
selectedLayoutModel.InitTemplateZones();
305+
316306
App.Overlay.CurrentDataContext = selectedLayoutModel;
317307
var mainEditor = App.Overlay;
318308
Hide();

src/modules/fancyzones/editor/FancyZonesEditor/Models/GridLayoutModel.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation
1+
// Copyright (c) Microsoft Corporation
22
// The Microsoft Corporation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

@@ -14,7 +14,7 @@ public class GridLayoutModel : LayoutModel
1414
// Non-localizable strings
1515
public const string ModelTypeID = "grid";
1616

17-
private const int _multiplier = 10000;
17+
public const int GridMultiplier = 10000;
1818

1919
// hard coded data for all the "Priority Grid" configurations that are unique to "Grid"
2020
private static readonly byte[][] _priorityData = new byte[][]
@@ -78,10 +78,10 @@ public int Columns
7878
public int[,] CellChildMap { get; set; }
7979

8080
// RowPercents - represents the %age height of each row in the grid
81-
public List<int> RowPercents { get; set; }
81+
public List<int> RowPercents { get; set; } = new List<int>();
8282

8383
// ColumnPercents - represents the %age width of each column in the grid
84-
public List<int> ColumnPercents { get; set; }
84+
public List<int> ColumnPercents { get; set; } = new List<int>();
8585

8686
// ShowSpacing - flag if free space between cells should be presented
8787
public bool ShowSpacing
@@ -170,13 +170,11 @@ public GridLayoutModel(GridLayoutModel other)
170170
}
171171
}
172172

173-
RowPercents = new List<int>(_rows);
174173
for (int row = 0; row < _rows; row++)
175174
{
176175
RowPercents.Add(other.RowPercents[row]);
177176
}
178177

179-
ColumnPercents = new List<int>(_cols);
180178
for (int col = 0; col < _cols; col++)
181179
{
182180
ColumnPercents.Add(other.ColumnPercents[col]);
@@ -306,7 +304,7 @@ private void InitRows()
306304

307305
// Note: This is NOT equal to _multiplier / ZoneCount and is done like this to make
308306
// the sum of all RowPercents exactly (_multiplier).
309-
RowPercents.Add(((_multiplier * (i + 1)) / TemplateZoneCount) - ((_multiplier * i) / TemplateZoneCount));
307+
RowPercents.Add(((GridMultiplier * (i + 1)) / TemplateZoneCount) - ((GridMultiplier * i) / TemplateZoneCount));
310308
}
311309

312310
_rows = TemplateZoneCount;
@@ -323,7 +321,7 @@ private void InitColumns()
323321

324322
// Note: This is NOT equal to _multiplier / ZoneCount and is done like this to make
325323
// the sum of all RowPercents exactly (_multiplier).
326-
ColumnPercents.Add(((_multiplier * (i + 1)) / TemplateZoneCount) - ((_multiplier * i) / TemplateZoneCount));
324+
ColumnPercents.Add(((GridMultiplier * (i + 1)) / TemplateZoneCount) - ((GridMultiplier * i) / TemplateZoneCount));
327325
}
328326

329327
_cols = TemplateZoneCount;
@@ -356,12 +354,12 @@ private void InitGrid()
356354
// done like this to make the sum of all RowPercents exactly (_multiplier).
357355
for (int row = 0; row < rows; row++)
358356
{
359-
RowPercents.Add(((_multiplier * (row + 1)) / rows) - ((_multiplier * row) / rows));
357+
RowPercents.Add(((GridMultiplier * (row + 1)) / rows) - ((GridMultiplier * row) / rows));
360358
}
361359

362360
for (int col = 0; col < cols; col++)
363361
{
364-
ColumnPercents.Add(((_multiplier * (col + 1)) / cols) - ((_multiplier * col) / cols));
362+
ColumnPercents.Add(((GridMultiplier * (col + 1)) / cols) - ((GridMultiplier * col) / cols));
365363
}
366364

367365
int index = 0;

src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ private enum DeviceIdParts
4242
public static readonly string RegistryPath = "SOFTWARE\\SuperFancyZones";
4343
public static readonly string FullRegistryPath = "HKEY_CURRENT_USER\\" + RegistryPath;
4444

45-
private const int _multiplier = 10000;
46-
4745
public bool IsCustomLayoutActive
4846
{
4947
get
@@ -71,15 +69,15 @@ public MainWindowSettingsModel()
7169
_columnsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Columns, LayoutType.Columns)
7270
{
7371
Rows = 1,
74-
RowPercents = new List<int>(1) { _multiplier },
72+
RowPercents = new List<int>(1) { GridLayoutModel.GridMultiplier },
7573
};
7674
_columnsModel.InitTemplateZones();
7775
DefaultModels.Add(_columnsModel);
7876

7977
_rowsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Rows, LayoutType.Rows)
8078
{
8179
Columns = 1,
82-
ColumnPercents = new List<int>(1) { _multiplier },
80+
ColumnPercents = new List<int>(1) { GridLayoutModel.GridMultiplier },
8381
};
8482
_rowsModel.InitTemplateZones();
8583
DefaultModels.Add(_rowsModel);

0 commit comments

Comments
 (0)