Browse Source

Implemented PixiEditorSettings into Avalonia project

CPKreuz 1 year ago
parent
commit
104766fe9b

+ 1 - 1
src/PixiEditor.AvaloniaUI/Models/Constants.cs

@@ -10,4 +10,4 @@ internal class Constants
 
     public const string NativeExtensionNoDot = "pixi";
     public const string NativeExtension = "." + NativeExtensionNoDot;
-}
+}

+ 4 - 4
src/PixiEditor.AvaloniaUI/Models/Palettes/LocalPalettesFetcher.cs

@@ -8,7 +8,7 @@ using PixiEditor.AvaloniaUI.Models.IO.PaletteParsers.JascPalFile;
 using PixiEditor.Extensions.CommonApi.Async;
 using PixiEditor.Extensions.CommonApi.Palettes;
 using PixiEditor.Extensions.CommonApi.Palettes.Parsers;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 
 namespace PixiEditor.AvaloniaUI.Models.Palettes;
 
@@ -39,11 +39,11 @@ internal class LocalPalettesFetcher : PaletteListDataSource
         watcher.Created += FileSystemChanged;
 
         watcher.EnableRaisingEvents = true;
-        cachedFavoritePalettes = IPreferences.Current.GetLocalPreference<List<string>>(PreferencesConstants.FavouritePalettes);
+        cachedFavoritePalettes = PixiEditorSettings.FavouritePalettes.AsList();
 
-        IPreferences.Current.AddCallback(PreferencesConstants.FavouritePalettes, updated =>
+        PixiEditorSettings.FavouritePalettes.AddListCallback(updated =>
         {
-            cachedFavoritePalettes = (List<string>)updated;
+            cachedFavoritePalettes = updated;
             cachedPalettes.ForEach(x => x.IsFavourite = cachedFavoritePalettes.Contains(x.Name));
         });
     }

+ 4 - 4
src/PixiEditor.AvaloniaUI/Models/Services/NewsFeed/NewsProvider.cs

@@ -4,7 +4,7 @@ using System.Net;
 using System.Net.Http;
 using System.Threading.Tasks;
 using Newtonsoft.Json;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 using PixiEditor.Platform;
 
 namespace PixiEditor.AvaloniaUI.Models.Services.NewsFeed;
@@ -14,11 +14,11 @@ internal class NewsProvider
     private const int MaxNewsCount = 20;
     private const string FeedUrl = "https://raw.githubusercontent.com/PixiEditor/news-feed/main/";
 
-    private List<int> _lastCheckedIds = new List<int>();
+    private List<int> _lastCheckedIds;
 
     public NewsProvider()
     {
-        _lastCheckedIds = IPreferences.Current.GetPreference(PreferencesConstants.LastCheckedNewsIds, new List<int>());
+        _lastCheckedIds = PixiEditorSettings.LastCheckedNewsIds.AsList();
     }
 
     public async Task<List<News>?> FetchNewsAsync()
@@ -60,6 +60,6 @@ internal class NewsProvider
             }
         }
 
-        IPreferences.Current.UpdatePreference(PreferencesConstants.LastCheckedNewsIds, _lastCheckedIds);
+        PixiEditorSettings.LastCheckedNewsIds.Value = _lastCheckedIds;
     }
 }

+ 7 - 7
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/DebugViewModel.cs

@@ -17,7 +17,7 @@ using PixiEditor.AvaloniaUI.Views;
 using PixiEditor.AvaloniaUI.Views.Dialogs.Debugging;
 using PixiEditor.AvaloniaUI.Views.Dialogs.Debugging.Localization;
 using PixiEditor.Extensions.Common.Localization;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 using PixiEditor.OperatingSystem;
 
 namespace PixiEditor.AvaloniaUI.ViewModels.SubViewModels;
@@ -67,12 +67,12 @@ internal class DebugViewModel : SubViewModel<ViewModelMain>
         }
     }
 
-    public DebugViewModel(ViewModelMain owner, IPreferences preferences)
+    public DebugViewModel(ViewModelMain owner)
         : base(owner)
     {
         SetDebug();
-        preferences.AddCallback<bool>("IsDebugModeEnabled", UpdateDebugMode);
-        UpdateDebugMode(preferences.GetPreference<bool>("IsDebugModeEnabled"));
+        PixiEditorSettings.IsDebugModeEnabled.ValueChanged += UpdateDebugMode;
+        UpdateDebugMode(null, PixiEditorSettings.IsDebugModeEnabled.Value);
     }
 
     public static void OpenFolder(string path)
@@ -218,7 +218,7 @@ internal class DebugViewModel : SubViewModel<ViewModelMain>
     public void ClearRecentDocuments()
     {
         Owner.FileSubViewModel.RecentlyOpened.Clear();
-        IPreferences.Current.UpdateLocalPreference(PreferencesConstants.RecentlyOpened, Array.Empty<object>());
+        PixiEditorSettings.RecentlyOpened.Value = [];
     }
 
     [Command.Debug("PixiEditor.Debug.OpenCommandDebugWindow", "OPEN_CMD_DEBUG_WINDOW", "OPEN_CMD_DEBUG_WINDOW",
@@ -315,9 +315,9 @@ internal class DebugViewModel : SubViewModel<ViewModelMain>
     [Conditional("DEBUG")]
     private static void SetDebug() => IsDebugBuild = true;
 
-    private void UpdateDebugMode(bool setting)
+    private void UpdateDebugMode(Setting<bool> setting, bool value)
     {
-        IsDebugModeEnabled = setting;
+        IsDebugModeEnabled = value;
         UseDebug = IsDebugBuild || IsDebugModeEnabled;
     }
 }

+ 7 - 55
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/DiscordViewModel.cs

@@ -3,7 +3,7 @@ using DiscordRPC;
 using PixiEditor.AvaloniaUI.Helpers;
 using PixiEditor.AvaloniaUI.Models.Controllers;
 using PixiEditor.AvaloniaUI.ViewModels.Document;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 
 namespace PixiEditor.AvaloniaUI.ViewModels.SubViewModels;
 
@@ -32,62 +32,14 @@ internal class DiscordViewModel : SubViewModel<ViewModelMain>, IDisposable
         }
     }
 
-    private bool showDocumentName = IPreferences.Current.GetPreference(nameof(ShowDocumentName), false);
-
-    public bool ShowDocumentName
-    {
-        get => showDocumentName;
-        set
-        {
-            if (showDocumentName != value)
-            {
-                showDocumentName = value;
-                UpdatePresence(currentDocument);
-            }
-        }
-    }
-
-    private bool showDocumentSize = IPreferences.Current.GetPreference(nameof(ShowDocumentSize), true);
-
-    public bool ShowDocumentSize
-    {
-        get => showDocumentSize;
-        set
-        {
-            if (showDocumentSize != value)
-            {
-                showDocumentSize = value;
-                UpdatePresence(currentDocument);
-            }
-        }
-    }
-
-    private bool showLayerCount = IPreferences.Current.GetPreference(nameof(ShowLayerCount), true);
-
-    public bool ShowLayerCount
-    {
-        get => showLayerCount;
-        set
-        {
-            if (showLayerCount != value)
-            {
-                showLayerCount = value;
-                UpdatePresence(currentDocument);
-            }
-        }
-    }
-
     public DiscordViewModel(ViewModelMain owner, string clientId)
         : base(owner)
     {
         Owner.DocumentManagerSubViewModel.ActiveDocumentChanged += DocumentChanged;
         this.clientId = clientId;
 
-        Enabled = IPreferences.Current.GetPreference("EnableRichPresence", true);
-        IPreferences.Current.AddCallback("EnableRichPresence", x => Enabled = (bool)x);
-        IPreferences.Current.AddCallback(nameof(ShowDocumentName), x => ShowDocumentName = (bool)x);
-        IPreferences.Current.AddCallback(nameof(ShowDocumentSize), x => ShowDocumentSize = (bool)x);
-        IPreferences.Current.AddCallback(nameof(ShowLayerCount), x => ShowLayerCount = (bool)x);
+        Enabled = PixiEditorSettings.EnableRichPresence.Value;
+        PixiEditorSettings.EnableRichPresence.ValueChanged += (_, value) => Enabled = value;
         AppDomain.CurrentDomain.ProcessExit += (_, _) => Enabled = false;
     }
 
@@ -118,22 +70,22 @@ internal class DiscordViewModel : SubViewModel<ViewModelMain>, IDisposable
         {
             richPresence.WithTimestamps(new Timestamps(document.OpenedUTC));
 
-            richPresence.Details = ShowDocumentName
+            richPresence.Details = PixiEditorSettings.ShowDocumentName.Value
                 ? $"Editing {document.FileName.Limit(128)}" : "Editing an image";
 
             string state = string.Empty;
 
-            if (ShowDocumentSize)
+            if (PixiEditorSettings.ShowDocumentSize.Value)
             {
                 state = $"{document.Width}x{document.Height}";
             }
 
-            if (ShowDocumentSize && ShowLayerCount)
+            if (PixiEditorSettings.ShowDocumentSize.Value && PixiEditorSettings.ShowLayerCount.Value)
             {
                 state += ", ";
             }
 
-            if (ShowLayerCount)
+            if (PixiEditorSettings.ShowLayerCount.Value)
             {
                 int count = CountLayers(document.StructureRoot);
                 state += count == 1 ? "1 layer" : $"{count} layers";

+ 9 - 13
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/FileViewModel.cs

@@ -21,7 +21,7 @@ using PixiEditor.AvaloniaUI.Views.Dialogs;
 using PixiEditor.AvaloniaUI.Views.Windows;
 using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.Extensions.Common.Localization;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 using PixiEditor.Extensions.Exceptions;
 using PixiEditor.Numerics;
 using PixiEditor.OperatingSystem;
@@ -57,7 +57,7 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
             HasRecent = true;
         }
 
-        IPreferences.Current.AddCallback(PreferencesConstants.MaxOpenedRecently, UpdateMaxRecentlyOpened);
+        PixiEditorSettings.MaxOpenedRecently.ValueChanged += (_, value) => UpdateMaxRecentlyOpened(value);
     }
 
     public void AddRecentlyOpened(string path)
@@ -71,14 +71,14 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
             RecentlyOpened.Insert(0, path);
         }
 
-        int maxCount = IPreferences.Current.GetPreference(PreferencesConstants.MaxOpenedRecently, PreferencesConstants.MaxOpenedRecentlyDefault);
+        int maxCount = PixiEditorSettings.MaxOpenedRecently.Value;
 
         while (RecentlyOpened.Count > maxCount)
         {
             RecentlyOpened.RemoveAt(RecentlyOpened.Count - 1);
         }
 
-        IPreferences.Current.UpdateLocalPreference(PreferencesConstants.RecentlyOpened, RecentlyOpened.Select(x => x.FilePath));
+        PixiEditorSettings.RecentlyOpened.Value = RecentlyOpened.Select(x => x.FilePath);
     }
 
     [Command.Internal("PixiEditor.File.RemoveRecent")]
@@ -90,7 +90,7 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
         }
 
         RecentlyOpened.Remove(path);
-        IPreferences.Current.UpdateLocalPreference(PreferencesConstants.RecentlyOpened, RecentlyOpened.Select(x => x.FilePath));
+        PixiEditorSettings.RecentlyOpened.Value = RecentlyOpened.Select(x => x.FilePath);
     }
 
     private void OpenHelloTherePopup()
@@ -108,7 +108,7 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
         }
         else if ((Owner.DocumentManagerSubViewModel.Documents.Count == 0 && !args.Contains("--crash")) && !args.Contains("--openedInExisting"))
         {
-            if (IPreferences.Current.GetPreference("ShowStartupWindow", true))
+            if (PixiEditorSettings.ShowStartupWindow.Value)
             {
                 OpenHelloTherePopup();
             }
@@ -123,7 +123,7 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
         {
             NoticeDialog.Show("FILE_NOT_FOUND", "FAILED_TO_OPEN_FILE");
             RecentlyOpened.Remove(path);
-            IPreferences.Current.UpdateLocalPreference(PreferencesConstants.RecentlyOpened, RecentlyOpened.Select(x => x.FilePath));
+            PixiEditorSettings.RecentlyOpened.Value = RecentlyOpened.Select(x => x.FilePath);
             return;
         }
 
@@ -399,10 +399,8 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
         }
     }
 
-    private void UpdateMaxRecentlyOpened(object parameter)
+    private void UpdateMaxRecentlyOpened(int newAmount)
     {
-        int newAmount = (int)parameter;
-
         if (newAmount >= RecentlyOpened.Count)
         {
             return;
@@ -420,9 +418,7 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
 
     private List<RecentlyOpenedDocument> GetRecentlyOpenedDocuments()
     {
-        IEnumerable<string> paths = IPreferences.Current.GetLocalPreference(nameof(RecentlyOpened), new JArray()).ToObject<string[]>()
-            .Take(IPreferences.Current.GetPreference(PreferencesConstants.MaxOpenedRecently, 8));
-
+        var paths = PixiEditorSettings.RecentlyOpened.Value.Take(PixiEditorSettings.MaxOpenedRecently.Value);
         List<RecentlyOpenedDocument> documents = new List<RecentlyOpenedDocument>();
 
         foreach (string path in paths)

+ 3 - 3
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/StylusViewModel.cs

@@ -1,7 +1,7 @@
 using PixiEditor.AvaloniaUI.Models.Commands.Attributes.Commands;
 using PixiEditor.AvaloniaUI.ViewModels.Tools;
 using PixiEditor.AvaloniaUI.ViewModels.Tools.Tools;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 
 namespace PixiEditor.AvaloniaUI.ViewModels.SubViewModels;
 
@@ -23,7 +23,7 @@ internal class StylusViewModel : SubViewModel<ViewModelMain>
         {
             if (SetProperty(ref isPenModeEnabled, value))
             {
-                IPreferences.Current.UpdateLocalPreference(nameof(IsPenModeEnabled), value);
+                PixiEditorSettings.IsPenModeEnabled.Value = value;
                 UpdateUseTouchGesture();
             }
         }
@@ -40,7 +40,7 @@ internal class StylusViewModel : SubViewModel<ViewModelMain>
     public StylusViewModel(ViewModelMain owner)
         : base(owner)
     {
-        isPenModeEnabled = IPreferences.Current.GetLocalPreference<bool>(nameof(IsPenModeEnabled));
+        isPenModeEnabled = PixiEditorSettings.IsPenModeEnabled.Value;
         Owner.ToolsSubViewModel.AddPropertyChangedCallback(nameof(ToolsViewModel.ActiveTool), UpdateUseTouchGesture);
 
         UpdateUseTouchGesture();

+ 5 - 6
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/ToolsViewModel.cs

@@ -14,7 +14,7 @@ using PixiEditor.AvaloniaUI.ViewModels.Tools;
 using PixiEditor.AvaloniaUI.ViewModels.Tools.Tools;
 using PixiEditor.AvaloniaUI.ViewModels.Tools.ToolSettings.Toolbars;
 using PixiEditor.DrawingApi.Core.Numerics;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 using PixiEditor.Numerics;
 
 namespace PixiEditor.AvaloniaUI.ViewModels.SubViewModels;
@@ -22,7 +22,7 @@ namespace PixiEditor.AvaloniaUI.ViewModels.SubViewModels;
 [Command.Group("PixiEditor.Tools", "TOOLS")]
 internal class ToolsViewModel : SubViewModel<ViewModelMain>, IToolsHandler
 {
-    private RightClickMode rightClickMode;
+    private RightClickMode rightClickMode = PixiEditorSettings.RightClickMode.As<RightClickMode>();
     public ZoomToolViewModel? ZoomTool => GetTool<ZoomToolViewModel>();
 
     public IToolHandler? LastActionTool { get; private set; }
@@ -34,14 +34,14 @@ internal class ToolsViewModel : SubViewModel<ViewModelMain>, IToolsHandler
         {
             if (SetProperty(ref rightClickMode, value))
             {
-                IPreferences.Current.UpdatePreference(nameof(RightClickMode), value);
+                PixiEditorSettings.RightClickMode.Value = value;
             }
         }
     }
 
     public bool EnableSharedToolbar
     {
-        get => IPreferences.Current.GetPreference<bool>(nameof(EnableSharedToolbar));
+        get => PixiEditorSettings.EnableSharedToolbar.Value;
         set
         {
             if (EnableSharedToolbar == value)
@@ -49,7 +49,7 @@ internal class ToolsViewModel : SubViewModel<ViewModelMain>, IToolsHandler
                 return;
             }
 
-            IPreferences.Current.UpdatePreference(nameof(EnableSharedToolbar), value);
+            PixiEditorSettings.EnableSharedToolbar.Value = value;
             OnPropertyChanged(nameof(EnableSharedToolbar));
         }
     }
@@ -92,7 +92,6 @@ internal class ToolsViewModel : SubViewModel<ViewModelMain>, IToolsHandler
     public ToolsViewModel(ViewModelMain owner)
         : base(owner)
     {
-        rightClickMode = IPreferences.Current.GetPreference<RightClickMode>(nameof(RightClickMode));
     }
 
     public void SetupTools(IServiceProvider services)

+ 6 - 6
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/UpdateViewModel.cs

@@ -11,7 +11,7 @@ using PixiEditor.AvaloniaUI.Models.Commands.Attributes.Commands;
 using PixiEditor.AvaloniaUI.Models.Dialogs;
 using PixiEditor.AvaloniaUI.Views.Dialogs;
 using PixiEditor.Extensions.Common.Localization;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 using PixiEditor.Platform;
 using PixiEditor.UpdateModule;
 
@@ -55,15 +55,15 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
         : base(owner)
     {
         Owner.OnStartupEvent += Owner_OnStartupEvent;
-        IPreferences.Current.AddCallback<string>("UpdateChannel", val =>
+        PixiEditorSettings.UpdateChannel.ValueChanged += (_, value) =>
         {
             string prevChannel = UpdateChecker.Channel.ApiUrl;
-            UpdateChecker.Channel = GetUpdateChannel(val);
+            UpdateChecker.Channel = GetUpdateChannel(value);
             if (prevChannel != UpdateChecker.Channel.ApiUrl)
             {
                 ConditionalUPDATE();
             }
-        });
+        };
         InitUpdateChecker();
     }
 
@@ -217,7 +217,7 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
     [Conditional("UPDATE")]
     private async void ConditionalUPDATE()
     {
-        if (IPreferences.Current.GetPreference("CheckUpdatesOnStartup", true))
+        if (PixiEditorSettings.CheckUpdatesOnStartup.Value)
         {
             try
             {
@@ -247,7 +247,7 @@ internal class UpdateViewModel : SubViewModel<ViewModelMain>
         UpdateChannels.Add(new UpdateChannel(platformName, "", ""));
 #endif
 
-        string updateChannel = IPreferences.Current.GetPreference<string>("UpdateChannel");
+        string updateChannel = PixiEditorSettings.UpdateChannel.Value;
 
         string version = VersionHelpers.GetCurrentAssemblyVersionString();
         UpdateChecker = new UpdateChecker(version, GetUpdateChannel(updateChannel));

+ 2 - 2
src/PixiEditor.AvaloniaUI/ViewModels/Tools/Tools/PenToolViewModel.cs

@@ -8,7 +8,7 @@ using PixiEditor.AvaloniaUI.ViewModels.Tools.ToolSettings.Toolbars;
 using PixiEditor.AvaloniaUI.Views.Overlays.BrushShapeOverlay;
 using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.Extensions.Common.Localization;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 using PixiEditor.Numerics;
 
 namespace PixiEditor.AvaloniaUI.ViewModels.Tools.Tools
@@ -58,7 +58,7 @@ namespace PixiEditor.AvaloniaUI.ViewModels.Tools.Tools
                 setting.Value = 1;
             }
             
-            if (!IPreferences.Current.GetPreference<bool>("EnableSharedToolbar"))
+            if (!PixiEditorSettings.EnableRichPresence.Value)
             {
                 return;
             }

+ 3 - 3
src/PixiEditor.AvaloniaUI/Views/Dialogs/Debugging/Localization/LocalizationDataContext.cs

@@ -16,7 +16,7 @@ using PixiEditor.AvaloniaUI.Models.Dialogs;
 using PixiEditor.AvaloniaUI.ViewModels;
 using PixiEditor.AvaloniaUI.ViewModels.SubViewModels;
 using PixiEditor.Extensions.Common.Localization;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 using PixiEditor.OperatingSystem;
 
 namespace PixiEditor.AvaloniaUI.Views.Dialogs.Debugging.Localization;
@@ -40,7 +40,7 @@ internal class LocalizationDataContext : PixiObservableObject
         {
             if (SetProperty(ref apiKey, value))
             {
-                IPreferences.Current.UpdateLocalPreference("POEditor_API_Key", apiKey);
+                PixiEditorSettings.PoEditorApiKey.Value = value;
             }
         }
     }
@@ -76,7 +76,7 @@ internal class LocalizationDataContext : PixiObservableObject
     public LocalizationDataContext()
     {
         dispatcher = Dispatcher.UIThread;
-        apiKey = IPreferences.Current.GetLocalPreference<string>("POEditor_API_Key");
+        apiKey = PixiEditorSettings.PoEditorApiKey.Value;
         LoadApiKeyCommand = new RelayCommand(LoadApiKey, () => !string.IsNullOrWhiteSpace(apiKey));
         ApplyLanguageCommand =
             new RelayCommand(ApplyLanguage, () => loggedIn && SelectedLanguage != null);

+ 4 - 4
src/PixiEditor.AvaloniaUI/Views/Dialogs/NewFileDialog.cs

@@ -2,15 +2,15 @@
 using Avalonia.Controls;
 using PixiEditor.AvaloniaUI.Models;
 using PixiEditor.AvaloniaUI.Models.Dialogs;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 
 namespace PixiEditor.AvaloniaUI.Views.Dialogs;
 
 internal class NewFileDialog : CustomDialog
 {
-    private int height = IPreferences.Current.GetPreference("DefaultNewFileHeight", Constants.DefaultCanvasSize);
-
-    private int width = IPreferences.Current.GetPreference("DefaultNewFileWidth", Constants.DefaultCanvasSize);
+    private int width = PixiEditorSettings.DefaultNewFileWidth.Value;
+    
+    private int height = PixiEditorSettings.DefaultNewFileHeight.Value;
 
     public int Width
     {

+ 4 - 4
src/PixiEditor.AvaloniaUI/Views/Windows/HelloTherePopup.axaml.cs

@@ -12,7 +12,7 @@ using PixiEditor.AvaloniaUI.Models.Structures;
 using PixiEditor.AvaloniaUI.Models.UserData;
 using PixiEditor.AvaloniaUI.ViewModels.SubViewModels;
 using PixiEditor.AvaloniaUI.Views.Dialogs;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 using PixiEditor.OperatingSystem;
 
 namespace PixiEditor.AvaloniaUI.Views.Windows;
@@ -106,7 +106,7 @@ internal partial class HelloTherePopup : PixiEditorPopup
         RecentlyOpenedEmpty = RecentlyOpened.Count == 0;
         RecentlyOpened.CollectionChanged += RecentlyOpened_CollectionChanged;
 
-        _newsDisabled = IPreferences.Current.GetPreference<bool>(PreferencesConstants.DisableNewsPanel);
+        _newsDisabled = PixiEditorSettings.DisableNewsPanel.Value;
 
         NewsProvider = new NewsProvider();
 
@@ -116,7 +116,7 @@ internal partial class HelloTherePopup : PixiEditorPopup
 
         int newsWidth = 300;
 
-        NewsPanelCollapsed = IPreferences.Current.GetPreference<bool>(PreferencesConstants.NewsPanelCollapsed);
+        NewsPanelCollapsed = PixiEditorSettings.NewsPanelCollapsed.Value;
 
         if (_newsDisabled || NewsPanelCollapsed)
         {
@@ -159,7 +159,7 @@ internal partial class HelloTherePopup : PixiEditorPopup
             Enumerable.Last<ColumnDefinition>(helloTherePopup.grid.ColumnDefinitions).Width = new GridLength(300);
         }
 
-        IPreferences.Current.UpdatePreference(PreferencesConstants.NewsPanelCollapsed, e.NewValue.Value);
+        PixiEditorSettings.NewsPanelCollapsed.Value = e.NewValue.Value;
     }
 
     private void RecentlyOpened_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)

+ 14 - 18
src/PixiEditor.AvaloniaUI/Views/Windows/PalettesBrowser.axaml.cs

@@ -25,7 +25,7 @@ using PixiEditor.AvaloniaUI.Views.Palettes;
 using PixiEditor.Extensions.Common.Localization;
 using PixiEditor.Extensions.CommonApi.Palettes;
 using PixiEditor.Extensions.CommonApi.Palettes.Parsers;
-using PixiEditor.Extensions.CommonApi.UserPreferences;
+using PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
 using PixiEditor.Extensions.CommonApi.Windowing;
 using PixiEditor.OperatingSystem;
 using PaletteColor = PixiEditor.Extensions.CommonApi.Palettes.PaletteColor;
@@ -151,7 +151,7 @@ internal partial class PalettesBrowser : PixiEditorPopup, IPopupWindow
 
     public FilteringSettings Filtering => filteringSettings ??=
         new FilteringSettings(ColorsNumberMode, ColorsNumber, NameFilter, ShowOnlyFavourites,
-            IPreferences.Current.GetLocalPreference<List<string>>(PreferencesConstants.FavouritePalettes, new List<string>()));
+            PixiEditorSettings.FavouritePalettes.AsList());
 
     private char[] separators = new char[] { ' ', ',' };
 
@@ -208,7 +208,7 @@ internal partial class PalettesBrowser : PixiEditorPopup, IPopupWindow
             LocalPalettesFetcher.CacheUpdated -= LocalCacheRefreshed;
         };
 
-        IPreferences.Current.AddCallback(PreferencesConstants.FavouritePalettes, OnFavouritePalettesChanged);
+        PixiEditorSettings.FavouritePalettes.ValueChanged += OnFavouritePalettesChanged;
     }
 
     public async Task<bool?> ShowDialog()
@@ -246,10 +246,9 @@ internal partial class PalettesBrowser : PixiEditorPopup, IPopupWindow
         return palette != null && palette.Source.GetType() == typeof(LocalPalettesFetcher);
     }
 
-    private void OnFavouritePalettesChanged(object obj)
+    private void OnFavouritePalettesChanged(Setting<IEnumerable<string>> setting, IEnumerable<string> value)
     {
-        Filtering.Favourites =
-            IPreferences.Current.GetLocalPreference<List<string>>(PreferencesConstants.FavouritePalettes);
+        Filtering.Favourites = PixiEditorSettings.FavouritePalettes.AsList();
     }
 
     public static PalettesBrowser Open()
@@ -354,7 +353,7 @@ internal partial class PalettesBrowser : PixiEditorPopup, IPopupWindow
     private async void ToggleFavourite(Palette palette)
     {
         palette.IsFavourite = !palette.IsFavourite;
-        var favouritePalettes = IPreferences.Current.GetLocalPreference(PreferencesConstants.FavouritePalettes, new List<string>());
+        var favouritePalettes = PixiEditorSettings.FavouritePalettes.AsList();
 
         if (palette.IsFavourite && !favouritePalettes.Contains(palette.Name))
         {
@@ -365,13 +364,13 @@ internal partial class PalettesBrowser : PixiEditorPopup, IPopupWindow
             favouritePalettes.RemoveAll(x => x == palette.Name);
         }
 
-        IPreferences.Current.UpdateLocalPreference(PreferencesConstants.FavouritePalettes, favouritePalettes);
+        PixiEditorSettings.FavouritePalettes.Value = favouritePalettes;
         await UpdatePaletteList();
     }
 
     private bool IsPaletteFavourite(string name)
     {
-        var favouritePalettes = IPreferences.Current.GetLocalPreference(PreferencesConstants.FavouritePalettes, new List<string>());
+        var favouritePalettes = PixiEditorSettings.FavouritePalettes.AsList();
         return favouritePalettes.Contains(name);
     }
 
@@ -392,12 +391,11 @@ internal partial class PalettesBrowser : PixiEditorPopup, IPopupWindow
 
     private static void RemoveFavouritePalette(Palette palette)
     {
-        var favouritePalettes =
-            IPreferences.Current.GetLocalPreference<List<string>>(PreferencesConstants.FavouritePalettes);
-        if (favouritePalettes != null && favouritePalettes.Contains(palette.Name))
+        var favouritePalettes = PixiEditorSettings.FavouritePalettes.AsList();
+        if (favouritePalettes.Contains(palette.Name))
         {
             favouritePalettes.Remove(palette.Name);
-            IPreferences.Current.UpdateLocalPreference(PreferencesConstants.FavouritePalettes, favouritePalettes);
+            PixiEditorSettings.FavouritePalettes.Value = favouritePalettes;
         }
     }
 
@@ -630,9 +628,7 @@ internal partial class PalettesBrowser : PixiEditorPopup, IPopupWindow
 
     private static void UpdateRenamedFavourite(string old, string newName)
     {
-        var favourites = IPreferences.Current.GetLocalPreference(
-            PreferencesConstants.FavouritePalettes,
-            new List<string>());
+        var favourites = PixiEditorSettings.FavouritePalettes.AsList();
 
         if (favourites.Contains(old))
         {
@@ -640,7 +636,7 @@ internal partial class PalettesBrowser : PixiEditorPopup, IPopupWindow
             favourites.Add(newName);
         }
 
-        IPreferences.Current.UpdateLocalPreference(PreferencesConstants.FavouritePalettes, favourites);
+        PixiEditorSettings.FavouritePalettes.Value = favourites;
     }
 
     private void BrowseOnLospec_OnClick(object sender, RoutedEventArgs e)
@@ -682,6 +678,6 @@ internal partial class PalettesBrowser : PixiEditorPopup, IPopupWindow
     protected override void OnClosing(WindowClosingEventArgs e)
     {
         base.OnClosing(e);
-        IPreferences.Current.RemoveCallback(PreferencesConstants.FavouritePalettes, OnFavouritePalettesChanged);
+        PixiEditorSettings.FavouritePalettes.ValueChanged -= OnFavouritePalettesChanged;
     }
 }

+ 1 - 1
src/PixiEditor.AvaloniaUI/Views/Windows/Settings/DiscordRichPresencePreview.axaml

@@ -59,7 +59,7 @@
                             <StackPanel Orientation="Vertical">
                                 <TextBlock FontWeight="Bold" FontSize="12" Foreground="White" Margin="0,0,0,10" Text="PLAYING A GAME"/>
                                 <StackPanel Orientation="Horizontal">
-                                    <Image Source="/Images/PixiEditorLogo.png" Height="60"/>
+                                    <!-- <Image Source="/Images/PixiEditorLogo.png" Height="60"/> -->
                                     <StackPanel Margin="15,0,0,0" VerticalAlignment="Center">
                                         <TextBlock Foreground="White" FontSize="12" FontWeight="SemiBold">PixiEditor</TextBlock>
                                         <TextBlock Foreground="White" FontSize="12" 

+ 57 - 0
src/PixiEditor.Extensions.CommonApi/UserPreferences/Settings/PixiEditorSettings.cs

@@ -0,0 +1,57 @@
+namespace PixiEditor.Extensions.CommonApi.UserPreferences.Settings;
+
+public static class PixiEditorSettings
+{
+    // TODO: Subdivide this into different classes
+    
+    public static LocalSetting<IEnumerable<string>> FavouritePalettes { get; } = new(nameof(FavouritePalettes));
+    
+    public static LocalSetting<IEnumerable<string>> RecentlyOpened { get; } = new(nameof(RecentlyOpened));
+    public static SyncedSetting<int> MaxOpenedRecently { get; } = new(nameof(MaxOpenedRecently), 8);
+
+    public static SyncedSetting<bool> ShowStartupWindow { get; } = new(nameof(ShowStartupWindow), true);
+
+    public static SyncedSetting<bool> DisableNewsPanel { get; } = new(nameof(DisableNewsPanel));
+    public static SyncedSetting<bool> NewsPanelCollapsed { get; } = new(nameof(NewsPanelCollapsed));
+
+    public static SyncedSetting<int> DefaultNewFileWidth { get; } = new(nameof(DefaultNewFileWidth), 64);
+
+    public static SyncedSetting<int> DefaultNewFileHeight { get; } = new(nameof(DefaultNewFileHeight));
+    
+    public static SyncedSetting<IEnumerable<int>> LastCheckedNewsIds { get; } = new(nameof(LastCheckedNewsIds));
+    
+    // Update
+
+    public static SyncedSetting<bool> CheckUpdatesOnStartup { get; } = new(nameof(CheckUpdatesOnStartup), true);
+
+    public static SyncedSetting<string> UpdateChannel { get; } = new(nameof(UpdateChannel));
+
+    // Local
+
+    public static LocalSetting<string> PoEditorApiKey { get; } = new("POEditor_API_Key");
+
+    // Discord
+
+    public static SyncedSetting<bool> EnableRichPresence { get; } = new(nameof(EnableRichPresence));
+
+    public static SyncedSetting<bool> ShowDocumentName { get; } = new(nameof(ShowDocumentName));
+
+    public static SyncedSetting<bool> ShowDocumentSize { get; } = new(nameof(ShowDocumentSize), true);
+    
+    public static SyncedSetting<bool> ShowLayerCount { get; } = new(nameof(ShowLayerCount), true);
+    
+    // Tools
+
+    public static SyncedSetting<bool> EnableSharedToolbar { get; } = new(nameof(EnableSharedToolbar));
+    
+    // TODO: Use RightClickMode
+    public static SyncedSetting<object> RightClickMode { get; } = new(nameof(RightClickMode));
+    
+    // Debug
+
+    public static SyncedSetting<bool> IsDebugModeEnabled { get; } = new(nameof(IsDebugModeEnabled));
+    
+    // Pen
+
+    public static SyncedSetting<bool> IsPenModeEnabled { get; } = new(nameof(IsPenModeEnabled));
+}