mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
[FancyZones Editor] Fix FZ Editor crash on opening custom layout for editing (#10911)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FancyZonesEditor.Models
|
||||
@@ -173,6 +174,53 @@ namespace FancyZonesEditor.Models
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsModelValid()
|
||||
{
|
||||
// Check if rows and columns are valid
|
||||
if (Rows <= 0 || Columns <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if percentage is valid.
|
||||
if (RowPercents.Count != Rows || ColumnPercents.Count != Columns || RowPercents.Exists((x) => (x < 1)) || ColumnPercents.Exists((x) => (x < 1)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if cells map is valid
|
||||
if (CellChildMap.Length != Rows * Columns)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int zoneCount = 0;
|
||||
for (int row = 0; row < Rows; row++)
|
||||
{
|
||||
for (int col = 0; col < Columns; col++)
|
||||
{
|
||||
zoneCount = Math.Max(zoneCount, CellChildMap[row, col]);
|
||||
}
|
||||
}
|
||||
|
||||
zoneCount++;
|
||||
|
||||
if (zoneCount > Rows * Columns)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var rowPrefixSum = GridData.PrefixSum(RowPercents);
|
||||
var colPrefixSum = GridData.PrefixSum(ColumnPercents);
|
||||
|
||||
if (rowPrefixSum[Rows] != GridData.Multiplier || colPrefixSum[Columns] != GridData.Multiplier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void UpdatePreview()
|
||||
{
|
||||
FirePropertyChanged();
|
||||
|
||||
Reference in New Issue
Block a user