mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-30 13:51:53 +08:00
refactor: json serialization
* move all converters to `App.JsonCodeGen.cs` * use `ColorConverter` instead of parsing colors manually
This commit is contained in:
@@ -28,35 +28,30 @@ namespace SourceGit.ViewModels
|
||||
set;
|
||||
} = WindowState.Normal;
|
||||
|
||||
[JsonConverter(typeof(GridLengthConverter))]
|
||||
public GridLength RepositorySidebarWidth
|
||||
{
|
||||
get => _repositorySidebarWidth;
|
||||
set => SetProperty(ref _repositorySidebarWidth, value);
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(GridLengthConverter))]
|
||||
public GridLength WorkingCopyLeftWidth
|
||||
{
|
||||
get => _workingCopyLeftWidth;
|
||||
set => SetProperty(ref _workingCopyLeftWidth, value);
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(GridLengthConverter))]
|
||||
public GridLength StashesLeftWidth
|
||||
{
|
||||
get => _stashesLeftWidth;
|
||||
set => SetProperty(ref _stashesLeftWidth, value);
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(GridLengthConverter))]
|
||||
public GridLength CommitDetailChangesLeftWidth
|
||||
{
|
||||
get => _commitDetailChangesLeftWidth;
|
||||
set => SetProperty(ref _commitDetailChangesLeftWidth, value);
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(GridLengthConverter))]
|
||||
public GridLength CommitDetailFilesLeftWidth
|
||||
{
|
||||
get => _commitDetailFilesLeftWidth;
|
||||
@@ -69,18 +64,4 @@ namespace SourceGit.ViewModels
|
||||
private GridLength _commitDetailChangesLeftWidth = new GridLength(256, GridUnitType.Pixel);
|
||||
private GridLength _commitDetailFilesLeftWidth = new GridLength(256, GridUnitType.Pixel);
|
||||
}
|
||||
|
||||
public class GridLengthConverter : JsonConverter<GridLength>
|
||||
{
|
||||
public override GridLength Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var size = reader.GetDouble();
|
||||
return new GridLength(size, GridUnitType.Pixel);
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, GridLength value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteNumberValue(value.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,14 +80,12 @@ namespace SourceGit.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(FontFamilyConverter))]
|
||||
public FontFamily DefaultFont
|
||||
{
|
||||
get => _defaultFont;
|
||||
set => SetProperty(ref _defaultFont, value);
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(FontFamilyConverter))]
|
||||
public FontFamily MonospaceFont
|
||||
{
|
||||
get => _monospaceFont;
|
||||
@@ -517,18 +515,4 @@ namespace SourceGit.ViewModels
|
||||
|
||||
private AvaloniaList<RepositoryNode> _repositoryNodes = new AvaloniaList<RepositoryNode>();
|
||||
}
|
||||
|
||||
public class FontFamilyConverter : JsonConverter<FontFamily>
|
||||
{
|
||||
public override FontFamily Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var name = reader.GetString();
|
||||
return new FontFamily(name);
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, FontFamily value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user