IPreferences.cs 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. namespace PixiEditor.Extensions.CommonApi.UserPreferences;
  2. public interface IPreferences
  3. {
  4. public static IPreferences Current { get; private set; }
  5. /// <summary>
  6. /// Saves the preferences to be stored permanently.
  7. /// </summary>
  8. public void Save();
  9. /// <summary>
  10. /// Adds a callback that will be executed when the setting called <paramref name="name"/> changes.
  11. /// </summary>
  12. /// <param name="name">The name of the setting</param>
  13. /// <param name="action">The action that will be executed when the setting changes</param>
  14. public void AddCallback(string name, Action<string, object> action);
  15. /// <summary>
  16. /// Adds a callback that will be executed when the setting called <paramref name="name"/> changes.
  17. /// </summary>
  18. /// <typeparam name="T">The <see cref="Type"/> of the setting</typeparam>
  19. /// <param name="name">The name of the setting</param>
  20. /// <param name="action">The action that will be executed when the setting changes</param>
  21. public void AddCallback<T>(string name, Action<string, T> action);
  22. public void RemoveCallback(string name, Action<string, object> action);
  23. public void RemoveCallback<T>(string name, Action<string, T> action);
  24. /// <summary>
  25. /// Initializes the preferences.
  26. /// </summary>
  27. public void Init();
  28. /// <summary>
  29. /// Initializes the preferences using the <paramref name="path"/> and <paramref name="localPath"/>
  30. /// </summary>
  31. public void Init(string path, string localPath);
  32. /// <summary>
  33. /// Updates a user preference and calls all added callbacks.
  34. /// </summary>
  35. /// <typeparam name="T">The <see cref="Type"/> of the setting</typeparam>
  36. /// <param name="name">The name of the setting.</param>
  37. /// <param name="value">The new value.</param>
  38. public void UpdatePreference<T>(string name, T value);
  39. /// <summary>
  40. /// Updates a editor setting and calls all added callbacks.
  41. /// </summary>
  42. /// <typeparam name="T">The <see cref="Type"/> of the setting</typeparam>
  43. /// <param name="name">The name of the setting</param>
  44. /// <param name="value">The new value</param>
  45. public void UpdateLocalPreference<T>(string name, T value);
  46. #nullable enable
  47. /// <summary>
  48. /// Reads the user preference that is called <paramref name="name"/>, if the setting does not exist the default of <typeparamref name="T"/> will be used
  49. /// </summary>
  50. /// <typeparam name="T">The <see cref="Type"/> of the setting</typeparam>
  51. /// <param name="name">The name of the setting</param>
  52. /// <returns>The setting or the default of <typeparamref name="T"/> if it has not been set yet</returns>
  53. public T? GetPreference<T>(string name);
  54. /// <summary>
  55. /// Reads the user preference that is called <paramref name="name"/>, if the setting does not exist the default of <paramref name="fallbackValue"/> will be used
  56. /// </summary>
  57. /// <typeparam name="T">The <see cref="Type"/> of the setting</typeparam>
  58. /// <param name="name">The name of the setting</param>
  59. /// <returns>The setting or the <paramref name="fallbackValue"/> if it has not been set yet</returns>
  60. public T? GetPreference<T>(string name, T? fallbackValue);
  61. /// <summary>
  62. /// Reads the editor setting that is called <paramref name="name"/>, if the setting does not exist the deafult of <typeparamref name="T"/> will be used
  63. /// </summary>
  64. /// <typeparam name="T">The <see cref="Type"/> of the setting</typeparam>
  65. /// <param name="name">The name of the setting</param>
  66. /// <returns>The editor setting or the default of <typeparamref name="T"/> if it has not been set yet</returns>
  67. public T? GetLocalPreference<T>(string name);
  68. /// <summary>
  69. /// Reads the editor setting that is called <paramref name="name"/>, if the setting does not exist the <paramref name="fallbackValue"/> will be used
  70. /// </summary>
  71. /// <typeparam name="T">The <see cref="Type"/> of the setting</typeparam>
  72. /// <param name="name">The name of the setting</param>
  73. /// <returns>The editor setting or the <paramref name="fallbackValue"/> if it has not been set yet</returns>
  74. public T? GetLocalPreference<T>(string name, T? fallbackValue);
  75. protected static void SetAsCurrent(IPreferences provider)
  76. {
  77. Current = provider;
  78. }
  79. }