mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-19 06:53:26 +08:00
[ColorPicker][Settings]Fix duplicate name crash and cleanup (#28713)
This commit is contained in:
parent
8d5aa9fe6c
commit
b24ae12c5a
@ -162,7 +162,7 @@
|
||||
x:Uid="ColorFormatDialog"
|
||||
IsPrimaryButtonEnabled="{Binding IsValid, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
PrimaryButtonStyle="{ThemeResource AccentButtonStyle}"
|
||||
SecondaryButtonClick="ColorFormatDialog_CancelButtonClick">
|
||||
Closed="ColorFormatDialog_Closed">
|
||||
<ContentDialog.DataContext>
|
||||
<models:ColorFormatModel />
|
||||
</ContentDialog.DataContext>
|
||||
|
@ -112,7 +112,6 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
ColorFormatModel colorFormat = ColorFormatDialog.DataContext as ColorFormatModel;
|
||||
string oldName = ((KeyValuePair<string, string>)ColorFormatDialog.Tag).Key;
|
||||
ViewModel.UpdateColorFormat(oldName, colorFormat);
|
||||
ColorFormatDialog.Hide();
|
||||
}
|
||||
|
||||
private async void NewFormatClick(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
||||
@ -127,19 +126,6 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
await ColorFormatDialog.ShowAsync();
|
||||
}
|
||||
|
||||
private void ColorFormatDialog_CancelButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
||||
{
|
||||
if (ColorFormatDialog.Tag is KeyValuePair<string, string>)
|
||||
{
|
||||
ColorFormatModel modifiedColorFormat = ColorFormatDialog.DataContext as ColorFormatModel;
|
||||
KeyValuePair<string, string> oldProperties = (KeyValuePair<string, string>)ColorFormatDialog.Tag;
|
||||
modifiedColorFormat.Name = oldProperties.Key;
|
||||
modifiedColorFormat.Format = oldProperties.Value;
|
||||
}
|
||||
|
||||
ColorFormatDialog.Hide();
|
||||
}
|
||||
|
||||
private async void EditButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
||||
{
|
||||
SettingsCard btn = sender as SettingsCard;
|
||||
@ -162,5 +148,16 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
ViewModel.RefreshEnabledState();
|
||||
}
|
||||
|
||||
private void ColorFormatDialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args)
|
||||
{
|
||||
if (args.Result != ContentDialogResult.Primary && ColorFormatDialog.Tag is KeyValuePair<string, string>)
|
||||
{
|
||||
ColorFormatModel modifiedColorFormat = ColorFormatDialog.DataContext as ColorFormatModel;
|
||||
KeyValuePair<string, string> oldProperties = (KeyValuePair<string, string>)ColorFormatDialog.Tag;
|
||||
modifiedColorFormat.Name = oldProperties.Key;
|
||||
modifiedColorFormat.Format = oldProperties.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -300,13 +300,16 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
||||
UpdateColorFormats();
|
||||
UpdateColorFormatPreview();
|
||||
ScheduleSavingOfSettings();
|
||||
}
|
||||
|
||||
private void ColorFormat_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
UpdateColorFormats();
|
||||
ScheduleSavingOfSettings();
|
||||
// Remaining properties are handled by the collection and by the dialog
|
||||
if (e.PropertyName == nameof(ColorFormatModel.IsShown))
|
||||
{
|
||||
UpdateColorFormats();
|
||||
ScheduleSavingOfSettings();
|
||||
}
|
||||
}
|
||||
|
||||
private void ScheduleSavingOfSettings()
|
||||
@ -437,6 +440,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
SelectedColorRepresentationValue = colorFormat.Name; // name might be changed by the user
|
||||
}
|
||||
|
||||
UpdateColorFormats();
|
||||
UpdateColorFormatPreview();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user