- 
                Notifications
    
You must be signed in to change notification settings  - Fork 706
 
Refactor Application Settings and Support for Packaged/Unpackaged Mode #1924 #2014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            ghost1372
  wants to merge
  21
  commits into
  microsoft:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
ghost1372:AppSettings
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from 15 commits
      Commits
    
    
            Show all changes
          
          
            21 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      9a9ae94
              
                Implemented new settings system
              
              
                ghost1372 d5b5b9c
              
                Replace Old Settings with New Settings
              
              
                ghost1372 8def68c
              
                Remove Old Settings
              
              
                ghost1372 c42d4d0
              
                Rename Settings to SettingsHelper
              
              
                ghost1372 ec0bacf
              
                Remove unused codes
              
              
                ghost1372 51c3447
              
                Fix ScratchPadPage
              
              
                ghost1372 b3da70f
              
                Update MainWindow.xaml.cs
              
              
                ghost1372 5bf1266
              
                use Try/Catch in Get methods
              
              
                ghost1372 181fc43
              
                Make ListExtensions More Generic
              
              
                ghost1372 40e76e0
              
                Add Common Methods for Favorites and RecentlyVisited to Simplify Thei…
              
              
                ghost1372 7f04f89
              
                Remove Unsued Vector Wrapper
              
              
                ghost1372 d8c7891
              
                Remove ScratchPadXaml Setting
              
              
                ghost1372 9bcced4
              
                Update WinUIGallery/Helpers/SettingsHelper/Providers/JsonSettingsProv…
              
              
                ghost1372 b14fbb0
              
                Update WinUIGallery/Helpers/SettingsHelper/Providers/ApplicationDataS…
              
              
                ghost1372 b5a7e56
              
                Merge branch 'main' into AppSettings
              
              
                niels9001 0e36b3f
              
                Merge branch 'main' into AppSettings
              
              
                ghost1372 e523217
              
                Rename ListExtensions methods for clarity
              
              
                ghost1372 425e96e
              
                Use product name for settings folder path
              
              
                ghost1372 0361951
              
                Refactor Get<T>: restrict try/catch to JSON deserialization only
              
              
                ghost1372 1982f07
              
                Add one-time migration for Favorites and RecentlyVisited from old Set…
              
              
                ghost1372 90a12b8
              
                Merge branch 'main' into AppSettings
              
              
                ghost1372 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              This file was deleted.
      
      Oops, something went wrong.
      
    
  
        
          
          
            34 changes: 34 additions & 0 deletions
          
          34 
        
  WinUIGallery/Helpers/SettingsHelper/Internals/ListExtensions.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using System.Collections.Generic; | ||
| 
     | 
||
| namespace WinUIGallery.Helpers; | ||
| 
     | 
||
| internal static class ListExtensions | ||
| { | ||
| public static void AddToFirst<T>(this List<T> list, T item, int? maxSize = null) | ||
| { | ||
| if (item == null || (item is string data && string.IsNullOrWhiteSpace(data))) | ||
| return; | ||
| 
     | 
||
| list.Remove(item); | ||
| list.Insert(0, item); | ||
| 
     | 
||
| if (maxSize.HasValue && maxSize.Value > 0 && list.Count > maxSize.Value) | ||
| { | ||
| list.RemoveRange(maxSize.Value, list.Count - maxSize.Value); | ||
| } | ||
| } | ||
| 
     | 
||
| public static void AddToLast<T>(this List<T> list, T item, int? maxSize = null) | ||
| { | ||
| if (item == null || (item is string data && string.IsNullOrWhiteSpace(data))) | ||
| return; | ||
| 
     | 
||
| list.Remove(item); | ||
| list.Add(item); | ||
| 
     | 
||
| if (maxSize.HasValue && maxSize.Value > 0 && list.Count > maxSize.Value) | ||
| { | ||
| list.RemoveRange(0, list.Count - maxSize.Value); | ||
| } | ||
| } | ||
| } | ||
        
          
          
            11 changes: 11 additions & 0 deletions
          
          11 
        
  WinUIGallery/Helpers/SettingsHelper/Internals/SettingsJsonContext.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| using System.Collections.Generic; | ||
| using System.Text.Json.Serialization; | ||
| 
     | 
||
| namespace WinUIGallery.Helpers; | ||
| 
     | 
||
| [JsonSourceGenerationOptions(WriteIndented = true, GenerationMode = JsonSourceGenerationMode.Metadata)] | ||
| [JsonSerializable(typeof(Dictionary<string, System.Text.Json.JsonElement>))] | ||
| [JsonSerializable(typeof(SettingsHelper))] | ||
| internal partial class SettingsJsonContext : JsonSerializerContext | ||
| { | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using System.ComponentModel; | ||
| using System.Runtime.CompilerServices; | ||
| 
     | 
||
| namespace WinUIGallery.Helpers; | ||
| 
     | 
||
| public partial class ObservableSettings : INotifyPropertyChanged | ||
                
      
                  ghost1372 marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| { | ||
| private readonly ISettingsProvider provider; | ||
| 
     | 
||
| public ObservableSettings(ISettingsProvider provider) | ||
| { | ||
| this.provider = provider; | ||
| } | ||
| 
     | 
||
| public event PropertyChangedEventHandler PropertyChanged; | ||
| 
     | 
||
| protected bool Set<T>(T value, [CallerMemberName] string propertyName = null) | ||
| { | ||
| if (provider.Contains(propertyName)) | ||
| { | ||
| var currentValue = provider.Get<T>(propertyName); | ||
| if (Equals(currentValue, value)) | ||
| return false; | ||
| } | ||
| 
     | 
||
| provider.Set(propertyName, value); | ||
| PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
| return true; | ||
| } | ||
| 
     | 
||
| protected T Get<T>([CallerMemberName] string propertyName = null) | ||
| { | ||
| return provider.Get<T>(propertyName); | ||
| } | ||
| 
     | 
||
| protected T GetOrCreateDefault<T>(T defaultValue, [CallerMemberName] string propertyName = null) | ||
| { | ||
| if (!provider.Contains(propertyName)) | ||
| Set(defaultValue, propertyName); | ||
| 
     | 
||
| return Get<T>(propertyName); | ||
| } | ||
| } | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.