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