From fa3a3b2dad50de23d8b97b531bdb0a099c9bd263 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 30 May 2024 15:13:59 +0800 Subject: [PATCH] refactor: code cleanup --- src/Converters/BoolConverters.cs | 9 ++-- src/Converters/StringConverters.cs | 2 +- src/Converters/WindowStateConverters.cs | 14 ------ src/Resources/Styles.axaml | 6 +++ src/ViewModels/AssumeUnchangedManager.cs | 4 +- src/ViewModels/Clone.cs | 4 +- src/ViewModels/Repository.cs | 17 ++----- src/ViewModels/StashesPage.cs | 56 ++++++++++++--------- src/ViewModels/Welcome.cs | 14 +++--- src/ViewModels/WorkingCopy.cs | 56 +++++++++++++++++++-- src/Views/AssumeUnchangedManager.axaml | 4 +- src/Views/AssumeUnchangedManager.axaml.cs | 7 +++ src/Views/CaptionButtons.axaml | 4 +- src/Views/CommitBaseInfo.axaml | 16 +++--- src/Views/DiffView.axaml | 3 +- src/Views/Histories.axaml | 1 - src/Views/Histories.axaml.cs | 20 +------- src/Views/Launcher.axaml | 16 ++++-- src/Views/Launcher.axaml.cs | 61 ----------------------- src/Views/Repository.axaml | 16 +++++- src/Views/Repository.axaml.cs | 45 ----------------- src/Views/StashesPage.axaml | 10 +--- src/Views/StashesPage.axaml.cs | 10 ++++ src/Views/Welcome.axaml | 2 +- src/Views/WorkingCopy.axaml | 10 +--- 25 files changed, 174 insertions(+), 233 deletions(-) diff --git a/src/Converters/BoolConverters.cs b/src/Converters/BoolConverters.cs index c860a1a6..2eb8c60a 100644 --- a/src/Converters/BoolConverters.cs +++ b/src/Converters/BoolConverters.cs @@ -1,18 +1,17 @@ -using Avalonia.Controls; -using Avalonia.Data.Converters; +using Avalonia.Data.Converters; using Avalonia.Media; namespace SourceGit.Converters { public static class BoolConverters { + public static readonly FuncValueConverter ToPageTabWidth = + new FuncValueConverter(x => x ? 200 : double.NaN); + public static readonly FuncValueConverter HalfIfFalse = new FuncValueConverter(x => x ? 1 : 0.5); public static readonly FuncValueConverter BoldIfTrue = new FuncValueConverter(x => x ? FontWeight.Bold : FontWeight.Regular); - - public static readonly FuncValueConverter ToStarOrAutoGridLength = - new(value => value ? new GridLength(1, GridUnitType.Star) : new GridLength(1, GridUnitType.Auto)); } } diff --git a/src/Converters/StringConverters.cs b/src/Converters/StringConverters.cs index 35491a16..aa687f23 100644 --- a/src/Converters/StringConverters.cs +++ b/src/Converters/StringConverters.cs @@ -69,7 +69,7 @@ namespace SourceGit.Converters public static readonly FormatByResourceKeyConverter FormatByResourceKey = new FormatByResourceKeyConverter(); public static readonly FuncValueConverter ToShortSHA = - new FuncValueConverter(v => v.Length > 10 ? v.Substring(0, 10) : v); + new FuncValueConverter(v => v == null ? string.Empty : (v.Length > 10 ? v.Substring(0, 10) : v)); public static readonly FuncValueConverter UnderRecommendGitVersion = new(v => diff --git a/src/Converters/WindowStateConverters.cs b/src/Converters/WindowStateConverters.cs index 2c3b2ac6..7122dc1f 100644 --- a/src/Converters/WindowStateConverters.cs +++ b/src/Converters/WindowStateConverters.cs @@ -3,7 +3,6 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Data.Converters; -using Avalonia.Media; namespace SourceGit.Converters { @@ -39,19 +38,6 @@ namespace SourceGit.Converters } }); - public static readonly FuncValueConverter ToMaxOrRestoreIcon = - new FuncValueConverter(state => - { - if (state == WindowState.Maximized) - { - return Application.Current?.FindResource("Icons.Window.Restore") as StreamGeometry; - } - else - { - return Application.Current?.FindResource("Icons.Window.Maximize") as StreamGeometry; - } - }); - public static readonly FuncValueConverter IsNormal = new FuncValueConverter(state => state == WindowState.Normal); } diff --git a/src/Resources/Styles.axaml b/src/Resources/Styles.axaml index 6b76c2cf..85ccca13 100644 --- a/src/Resources/Styles.axaml +++ b/src/Resources/Styles.axaml @@ -66,6 +66,12 @@ + +