mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 10:16:24 +02:00
[ColorPicker]Custom color formats (#22141)
* [ColorPicker] Development: custom color formats, first steps * ColorPicker development of custom format handling. * Custom color format developmnet. Added common helper class for format string Fixed settings loading Added numbering if default name exists (My format (1)) * Custom color format implementation. Extended the colorPicker settings with the format string Updated the color to string conversion * Custom color format in color picker, development. Adding edit, delete buttons. Implement functionality Re-arranging settings panel (newly created formats at the top) Implementing details (valid parameters, more format elements, more types) * Minor commit * Development color picker custom formats. "Last" steps. Replacing hard coded english strings with resources, polishing. * Adding help to the format edit dialog. * Undoing changes unwillingly commited in Host module * Fixing bug unable to delete a custom format after renaming it - use the colorformat object as reference (and not the name) Modifying the default custom formula Removing unnecessary using directives * Udating the default user defined color format * Removing unnecessary using directive * ColorPicker Implementing custom color formats: adding custom formats to the default format selection (dropdown box). * Fix binding of name and example * Custom color formats, implemented steps: vorwarts compatibility loading settings. Fixed UI as requested (removed one settings panel, added button to the first panel) * Minor change in the UI: description modified * ColorPicker Custom Color Formats develepoment. Added conversion from old predefined formats to customizable formats. Extended default settings (in case settings file is deleted/corrupted). Minor fixes. * Fixing color format parameters. Implementing 3 different Saturation calculations, 2 Hue calculations and 2 Lightness calculations (depending color format) * Color Picker: New/Edit Color format. Fixing bug when cancelling addition/edit * ColorPicker. Updating help section, available parameters * Fix spellchecker * Remove the MinWidth so that scrollviewers can be drawn * ColorPicker bugfix: Not allowing to delete the last color format.
This commit is contained in:
@@ -96,6 +96,50 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
return newSettingsItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a Deserialized object of the json settings string.
|
||||
/// This function creates a file in the powertoy folder if it does not exist and returns an object with default properties.
|
||||
/// </summary>
|
||||
/// <returns>Deserialized json settings object.</returns>
|
||||
public T GetSettingsOrDefault<T, T2>(string powertoy = DefaultModuleName, string fileName = DefaultFileName, Func<object, object> settingsUpgrader = null)
|
||||
where T : ISettingsConfig, new()
|
||||
where T2 : ISettingsConfig, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
return GetSettings<T>(powertoy, fileName);
|
||||
}
|
||||
|
||||
// Catch json deserialization exceptions when the file is corrupt and has an invalid json.
|
||||
// If there are any deserialization issues like in https://github.com/microsoft/PowerToys/issues/7500, log the error and create a new settings.json file.
|
||||
// This is different from the case where we have trailing zeros following a valid json file, which we have handled by trimming the trailing zeros.
|
||||
catch (JsonException ex)
|
||||
{
|
||||
Logger.LogError($"Exception encountered while loading {powertoy} settings.", ex);
|
||||
|
||||
// try to deserialize to the old format, which is presented in T2
|
||||
try
|
||||
{
|
||||
T2 oldSettings = GetSettings<T2>(powertoy, fileName);
|
||||
T newSettings = (T)settingsUpgrader(oldSettings);
|
||||
return newSettings;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// do nothing, the problem wasn't that the settings was stored in the previous format, continue with the default settings
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
Logger.LogInfo($"Settings file {fileName} for {powertoy} was not found.");
|
||||
}
|
||||
|
||||
// If the settings file does not exist or if the file is corrupt, to create a new object with default parameters and save it to a newly created settings file.
|
||||
T newSettingsItem = new T();
|
||||
SaveSettings(newSettingsItem.ToJsonString(), powertoy, fileName);
|
||||
return newSettingsItem;
|
||||
}
|
||||
|
||||
// Given the powerToy folder name and filename to be accessed, this function deserializes and returns the file.
|
||||
private T GetFile<T>(string powertoyFolderName = DefaultModuleName, string fileName = DefaultFileName)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user