mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 20:54:59 +00:00
code_review: PR #1092
- Remove `SourceGit.ViewModels.Preference.FixFontFamilyName` (it is not necessary any more) - Use `string.Join` instead of `StringBuilder` to make the logic more clear Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
b9b684a83d
commit
9560496c7b
2 changed files with 14 additions and 50 deletions
|
@ -181,8 +181,8 @@ namespace SourceGit
|
||||||
app._fontsOverrides = null;
|
app._fontsOverrides = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultFont = ProcessFontString(defaultFont);
|
defaultFont = FixFontFamilyName(defaultFont);
|
||||||
monospaceFont = ProcessFontString(monospaceFont);
|
monospaceFont = FixFontFamilyName(monospaceFont);
|
||||||
|
|
||||||
var resDic = new ResourceDictionary();
|
var resDic = new ResourceDictionary();
|
||||||
if (!string.IsNullOrEmpty(defaultFont))
|
if (!string.IsNullOrEmpty(defaultFont))
|
||||||
|
@ -440,26 +440,22 @@ namespace SourceGit
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ProcessFontString(string input)
|
private static string FixFontFamilyName(string input)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(input)) return string.Empty;
|
if (string.IsNullOrEmpty(input))
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
var parts = input.Split(',');
|
var parts = input.Split(',');
|
||||||
var result = new StringBuilder();
|
var trimmed = new List<string>();
|
||||||
var isFirst = true;
|
|
||||||
|
|
||||||
foreach (var part in parts)
|
foreach (var part in parts)
|
||||||
{
|
{
|
||||||
var trimmed = part.Trim();
|
var t = part.Trim();
|
||||||
if (!string.IsNullOrEmpty(trimmed))
|
if (!string.IsNullOrEmpty(t))
|
||||||
{
|
trimmed.Add(t);
|
||||||
if (!isFirst) result.Append(',');
|
|
||||||
result.Append(trimmed);
|
|
||||||
isFirst = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.ToString();
|
return trimmed.Count > 0 ? string.Join(',', trimmed) : string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryLaunchAsCoreEditor(IClassicDesktopStyleApplicationLifetime desktop)
|
private bool TryLaunchAsCoreEditor(IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using Avalonia.Collections;
|
using Avalonia.Collections;
|
||||||
|
@ -66,9 +65,8 @@ namespace SourceGit.ViewModels
|
||||||
get => _defaultFontFamily;
|
get => _defaultFontFamily;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
var name = FixFontFamilyName(value);
|
if (SetProperty(ref _defaultFontFamily, value) && !_isLoading)
|
||||||
if (SetProperty(ref _defaultFontFamily, name) && !_isLoading)
|
App.SetFonts(value, _monospaceFontFamily, _onlyUseMonoFontInEditor);
|
||||||
App.SetFonts(_defaultFontFamily, _monospaceFontFamily, _onlyUseMonoFontInEditor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,9 +75,8 @@ namespace SourceGit.ViewModels
|
||||||
get => _monospaceFontFamily;
|
get => _monospaceFontFamily;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
var name = FixFontFamilyName(value);
|
if (SetProperty(ref _monospaceFontFamily, value) && !_isLoading)
|
||||||
if (SetProperty(ref _monospaceFontFamily, name) && !_isLoading)
|
App.SetFonts(_defaultFontFamily, value, _onlyUseMonoFontInEditor);
|
||||||
App.SetFonts(_defaultFontFamily, _monospaceFontFamily, _onlyUseMonoFontInEditor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,35 +617,6 @@ namespace SourceGit.ViewModels
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string FixFontFamilyName(string name)
|
|
||||||
{
|
|
||||||
var trimmed = name.Trim();
|
|
||||||
if (string.IsNullOrEmpty(trimmed))
|
|
||||||
return string.Empty;
|
|
||||||
|
|
||||||
var builder = new StringBuilder();
|
|
||||||
var lastIsSpace = false;
|
|
||||||
for (int i = 0; i < trimmed.Length; i++)
|
|
||||||
{
|
|
||||||
var c = trimmed[i];
|
|
||||||
if (char.IsWhiteSpace(c))
|
|
||||||
{
|
|
||||||
if (lastIsSpace)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
lastIsSpace = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lastIsSpace = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.Append(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Preferences _instance = null;
|
private static Preferences _instance = null;
|
||||||
private static bool _isLoading = false;
|
private static bool _isLoading = false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue