Skip to content

Commit 6443128

Browse files
committed
Refactor EditSizesDialog initialization logic
Refactored the initialization and size management logic in EditSizesDialog: - Removed automatic selection of Windows full icon sizes during construction. - Improved duplicate size detection using a custom comparer. - Adjusted size insertion logic to maintain descending order. - Moved Windows full icon size selection to occur after size loading.
1 parent a9a0f13 commit 6443128

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

Simple Icon File Maker/Simple Icon File Maker/Views/EditSizesDialog.xaml.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ public sealed partial class EditSizesDialog : ContentDialog
1616
public EditSizesDialog()
1717
{
1818
InitializeComponent();
19-
20-
SelectTheseIcons(IconSize.GetWindowsSizesFull());
2119
}
2220

2321
private void CheckBox_Tapped(object sender, TappedRoutedEventArgs e)
@@ -29,12 +27,14 @@ private void AddNewSizeButton_Tapped(object sender, TappedRoutedEventArgs e)
2927
{
3028
IconSize newSize = new((int)NewSizeNumberBox.Value);
3129

32-
if (IconSizes.Contains(newSize))
30+
// Check if a size with this SideLength already exists (ignore IsSelected state)
31+
IconSideComparer comparer = new();
32+
if (IconSizes.Any(size => comparer.Equals(size, newSize)))
3333
return;
3434

3535
NewSizeNumberBox.Value = double.NaN;
3636

37-
// insert into IconSizes in the right size order
37+
// insert into IconSizes in the right size order (largest first)
3838
for (int i = 0; i < IconSizes.Count; i++)
3939
{
4040
if (IconSizes[i].SideLength < newSize.SideLength)
@@ -43,6 +43,9 @@ private void AddNewSizeButton_Tapped(object sender, TappedRoutedEventArgs e)
4343
return;
4444
}
4545
}
46+
47+
// If we get here, the new size is the smallest, so add it at the end
48+
IconSizes.Add(newSize);
4649
}
4750

4851
private void SelectTheseIcons(IconSize[] iconSizesToSelect)
@@ -72,5 +75,7 @@ private async void ContentDialog_Loaded(object sender, RoutedEventArgs e)
7275

7376
foreach (IconSize size in loadedSizes)
7477
IconSizes.Add(size);
78+
79+
SelectTheseIcons(IconSize.GetWindowsSizesFull());
7580
}
7681
}

0 commit comments

Comments
 (0)