mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
[ColorPicker]Fix format name duplicates (#22565)
* ColorPicker fix format name duplicates * ColorPicker: extend settings-loading with security code which skips color formats with empty name or duplicate names * Spell checker fix, typo, sorry
This commit is contained in:
@@ -234,13 +234,20 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
{
|
{
|
||||||
foreach (var storedColorFormat in _colorPickerSettings.Properties.VisibleColorFormats)
|
foreach (var storedColorFormat in _colorPickerSettings.Properties.VisibleColorFormats)
|
||||||
{
|
{
|
||||||
|
// skip entries with empty name or duplicated name, it should never occur
|
||||||
|
string storedName = storedColorFormat.Key;
|
||||||
|
if (storedName == string.Empty || ColorFormats.Count(x => x.Name.ToUpperInvariant().Equals(storedName.ToUpperInvariant(), StringComparison.Ordinal)) > 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
string format = storedColorFormat.Value.Value;
|
string format = storedColorFormat.Value.Value;
|
||||||
if (format == string.Empty)
|
if (format == string.Empty)
|
||||||
{
|
{
|
||||||
format = ColorFormatHelper.GetDefaultFormat(storedColorFormat.Key);
|
format = ColorFormatHelper.GetDefaultFormat(storedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorFormatModel customColorFormat = new ColorFormatModel(storedColorFormat.Key, format, storedColorFormat.Value.Key);
|
ColorFormatModel customColorFormat = new ColorFormatModel(storedName, format, storedColorFormat.Value.Key);
|
||||||
customColorFormat.PropertyChanged += ColorFormat_PropertyChanged;
|
customColorFormat.PropertyChanged += ColorFormat_PropertyChanged;
|
||||||
ColorFormats.Add(customColorFormat);
|
ColorFormats.Add(customColorFormat);
|
||||||
}
|
}
|
||||||
@@ -400,7 +407,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
colorFormatModel.IsValid = ColorFormats.Count(x => x.Name.ToUpperInvariant().Equals(colorFormatModel.Name.ToUpperInvariant(), StringComparison.Ordinal)) < 2;
|
colorFormatModel.IsValid = ColorFormats.Count(x => x.Name.ToUpperInvariant().Equals(colorFormatModel.Name.ToUpperInvariant(), StringComparison.Ordinal))
|
||||||
|
< (colorFormatModel.IsNew ? 1 : 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user