code_style: general cleanup (#1428)

This commit is contained in:
Nathan Baulch 2025-06-18 11:29:18 +10:00 committed by GitHub
parent ae46728bbc
commit d404f6dbe2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
48 changed files with 123 additions and 240 deletions

View file

@ -12,13 +12,7 @@
Icon="/App.ico"
Title="{DynamicResource Text.Blame}"
MinWidth="1280" MinHeight="720">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="24"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid RowDefinitions="Auto,24,*">
<!-- TitleBar -->
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
<!-- Bottom border -->

View file

@ -306,7 +306,7 @@ namespace SourceGit.Views
return;
var view = TextArea.TextView;
if (view == null || !view.VisualLinesValid)
if (view is not { VisualLinesValid: true })
return;
var color = (Color)this.FindResource("SystemAccentColor")!;

View file

@ -13,13 +13,7 @@
Title="{DynamicResource Text.BranchCompare}"
MinWidth="1280" MinHeight="720"
WindowStartupLocation="CenterOwner">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="64"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid RowDefinitions="Auto,64,*">
<!-- TitleBar -->
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
<!-- Bottom border -->

View file

@ -82,7 +82,7 @@ namespace SourceGit.Views
{
base.OnPropertyChanged(change);
if (change.Property == IsUnstagedChangeProperty ||
if (change.Property == IsUnstagedChangeProperty ||
change.Property == ChangeProperty ||
(change.Property.Name == "ActualThemeVariant" && change.NewValue != null))
InvalidateVisual();

View file

@ -10,7 +10,7 @@ namespace SourceGit.Views
public class ColorPicker : Control
{
public static readonly StyledProperty<uint> ValueProperty =
AvaloniaProperty.Register<ColorPicker, uint>(nameof(Value), 0);
AvaloniaProperty.Register<ColorPicker, uint>(nameof(Value));
public uint Value
{

View file

@ -11,7 +11,7 @@ namespace SourceGit.Views
public class CommandLogTime : TextBlock
{
public static readonly StyledProperty<ViewModels.CommandLog> LogProperty =
AvaloniaProperty.Register<CommandLogTime, ViewModels.CommandLog>(nameof(Log), null);
AvaloniaProperty.Register<CommandLogTime, ViewModels.CommandLog>(nameof(Log));
public ViewModels.CommandLog Log
{

View file

@ -58,7 +58,7 @@
<Run Text="{Binding IndexDesc, Mode=OneWay}" Foreground="Gray"/>
</TextBlock>
</ToolTip.Tip>
<v:ChangeStatusIcon Grid.Column="0"
Width="14" Height="14"
HorizontalAlignment="Left"

View file

@ -57,7 +57,7 @@ namespace SourceGit.Views
}
public static readonly StyledProperty<bool> ShowAdvancedOptionsProperty =
AvaloniaProperty.Register<CommitMessageTextBox, bool>(nameof(ShowAdvancedOptions), false);
AvaloniaProperty.Register<CommitMessageTextBox, bool>(nameof(ShowAdvancedOptions));
public static readonly StyledProperty<string> TextProperty =
AvaloniaProperty.Register<CommitMessageTextBox, string>(nameof(Text), string.Empty);
@ -182,7 +182,7 @@ namespace SourceGit.Views
{
var menu = vm.CreateContextMenuForCommitMessages();
menu.Placement = PlacementMode.TopEdgeAlignedLeft;
menu?.Open(button);
menu.Open(button);
}
e.Handled = true;

View file

@ -19,7 +19,7 @@ namespace SourceGit.Views
}
public static readonly StyledProperty<int> DateTimeFormatProperty =
AvaloniaProperty.Register<CommitTimeTextBlock, int>(nameof(DateTimeFormat), 0);
AvaloniaProperty.Register<CommitTimeTextBlock, int>(nameof(DateTimeFormat));
public int DateTimeFormat
{

View file

@ -112,7 +112,7 @@
</Grid>
</Border>
<StackPanel Margin="0,8,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
<StackPanel Margin="0,8,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Classes="flat" Margin="0,0,0,0" Command="{Binding UseTheirs}">
<StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Data="{StaticResource Icons.Incoming}"/>

View file

@ -264,7 +264,7 @@
<Border Height="16" HorizontalAlignment="Center" Background="Red" CornerRadius="8" IsVisible="{Binding New, Converter={x:Static ObjectConverters.IsNull}}">
<TextBlock Classes="primary" Text="{DynamicResource Text.Diff.Submodule.Deleted}" Margin="8,0" FontSize="10" Foreground="White"/>
</Border>
<Border Margin="0,8,0,0" IsVisible="{Binding Old, Converter={x:Static ObjectConverters.IsNotNull}}">
<ContentControl Content="{Binding Old}">
<ContentControl.DataTemplates>

View file

@ -13,12 +13,7 @@
Icon="/App.ico"
Title="{DynamicResource Text.FileHistory}"
MinWidth="1280" MinHeight="720">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid RowDefinitions="Auto,*">
<!-- TitleBar -->
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
<!-- Bottom border -->

View file

@ -12,7 +12,7 @@ namespace SourceGit.Views
public class HistoriesLayout : Grid
{
public static readonly StyledProperty<bool> UseHorizontalProperty =
AvaloniaProperty.Register<HistoriesLayout, bool>(nameof(UseHorizontal), false);
AvaloniaProperty.Register<HistoriesLayout, bool>(nameof(UseHorizontal));
public bool UseHorizontal
{

View file

@ -55,7 +55,7 @@ namespace SourceGit.Views
{
if (sender is ContentPresenter presenter)
{
if (presenter.DataContext == null || presenter.DataContext is not ViewModels.Popup)
if (presenter.DataContext is not ViewModels.Popup)
{
presenter.Content = null;
return;

View file

@ -84,7 +84,7 @@ namespace SourceGit.Views
return;
var geo = new StreamGeometry();
var angle = Math.PI / 2;
const double angle = Math.PI / 2;
var y = height + 0.5;
using (var ctx = geo.Open())
{

View file

@ -1,12 +1,11 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data;
namespace SourceGit.Views
{
public class MenuItemExtension : AvaloniaObject
{
public static readonly AttachedProperty<string> CommandProperty =
AvaloniaProperty.RegisterAttached<MenuItemExtension, MenuItem, string>("Command", string.Empty, false, BindingMode.OneWay);
AvaloniaProperty.RegisterAttached<MenuItemExtension, MenuItem, string>("Command", string.Empty);
}
}

View file

@ -12,7 +12,7 @@ namespace SourceGit.Views
public class CounterPresenter : Control
{
public static readonly StyledProperty<int> CountProperty =
AvaloniaProperty.Register<CounterPresenter, int>(nameof(Count), 0);
AvaloniaProperty.Register<CounterPresenter, int>(nameof(Count));
public int Count
{

View file

@ -155,7 +155,7 @@ namespace SourceGit.Views
private void NavigateToHead(object sender, RoutedEventArgs e)
{
if (DataContext is ViewModels.Repository { CurrentBranch: { } } repo)
if (DataContext is ViewModels.Repository { CurrentBranch: not null } repo)
{
repo.NavigateToCommit(repo.CurrentBranch.Head);
e.Handled = true;

View file

@ -136,8 +136,7 @@ namespace SourceGit.Views
{
if (UseSyntaxHighlighting)
{
if (_textMate == null)
_textMate = Models.TextMateHelper.CreateForEditor(this);
_textMate ??= Models.TextMateHelper.CreateForEditor(this);
if (DataContext is Models.RevisionTextFile file)
Models.TextMateHelper.SetGrammarByFileName(_textMate, file.FileName);

View file

@ -134,10 +134,7 @@ namespace SourceGit.Views
set => SetValue(RevisionProperty, value);
}
public AvaloniaList<ViewModels.RevisionFileTreeNode> Rows
{
get => _rows;
}
public AvaloniaList<ViewModels.RevisionFileTreeNode> Rows { get; } = [];
public RevisionFileTreeView()
{
@ -146,7 +143,7 @@ namespace SourceGit.Views
public void SetSearchResult(string file)
{
_rows.Clear();
Rows.Clear();
_searchResult.Clear();
var rows = new List<ViewModels.RevisionFileTreeNode>();
@ -161,10 +158,10 @@ namespace SourceGit.Views
return;
var objects = vm.GetRevisionFilesUnderFolder(file);
if (objects == null || objects.Count != 1)
if (objects is not { Count: 1 })
return;
var routes = file.Split('/', StringSplitOptions.None);
var routes = file.Split('/');
if (routes.Length == 1)
{
_searchResult.Add(new ViewModels.RevisionFileTreeNode
@ -202,7 +199,7 @@ namespace SourceGit.Views
MakeRows(rows, _searchResult, 0);
}
_rows.AddRange(rows);
Rows.AddRange(rows);
GC.Collect();
}
@ -212,7 +209,7 @@ namespace SourceGit.Views
node.IsExpanded = !node.IsExpanded;
var depth = node.Depth;
var idx = _rows.IndexOf(node);
var idx = Rows.IndexOf(node);
if (idx == -1)
return;
@ -223,21 +220,21 @@ namespace SourceGit.Views
{
var subrows = new List<ViewModels.RevisionFileTreeNode>();
MakeRows(subrows, subtree, depth + 1);
_rows.InsertRange(idx + 1, subrows);
Rows.InsertRange(idx + 1, subrows);
}
}
else
{
var removeCount = 0;
for (int i = idx + 1; i < _rows.Count; i++)
for (int i = idx + 1; i < Rows.Count; i++)
{
var row = _rows[i];
var row = Rows[i];
if (row.Depth <= depth)
break;
removeCount++;
}
_rows.RemoveRange(idx + 1, removeCount);
Rows.RemoveRange(idx + 1, removeCount);
}
_disableSelectionChangingEvent = false;
@ -250,7 +247,7 @@ namespace SourceGit.Views
if (change.Property == RevisionProperty)
{
_tree.Clear();
_rows.Clear();
Rows.Clear();
_searchResult.Clear();
var vm = DataContext as ViewModels.CommitDetail;
@ -274,7 +271,7 @@ namespace SourceGit.Views
var topTree = new List<ViewModels.RevisionFileTreeNode>();
MakeRows(topTree, _tree, 0);
_rows.AddRange(topTree);
Rows.AddRange(topTree);
GC.Collect();
}
}
@ -365,7 +362,6 @@ namespace SourceGit.Views
}
private List<ViewModels.RevisionFileTreeNode> _tree = [];
private AvaloniaList<ViewModels.RevisionFileTreeNode> _rows = [];
private bool _disableSelectionChangingEvent = false;
private List<ViewModels.RevisionFileTreeNode> _searchResult = [];
}

View file

@ -348,16 +348,11 @@ namespace SourceGit.Views
private ThemedTextDiffPresenter _presenter = null;
}
public class LineStyleTransformer : DocumentColorizingTransformer
public class LineStyleTransformer(ThemedTextDiffPresenter presenter) : DocumentColorizingTransformer
{
public LineStyleTransformer(ThemedTextDiffPresenter presenter)
{
_presenter = presenter;
}
protected override void ColorizeLine(DocumentLine line)
{
var lines = _presenter.GetLines();
var lines = presenter.GetLines();
var idx = line.LineNumber;
if (idx > lines.Count)
return;
@ -367,13 +362,11 @@ namespace SourceGit.Views
{
ChangeLinePart(line.Offset, line.EndOffset, v =>
{
v.TextRunProperties.SetForegroundBrush(_presenter.IndicatorForeground);
v.TextRunProperties.SetTypeface(new Typeface(_presenter.FontFamily, FontStyle.Italic));
v.TextRunProperties.SetForegroundBrush(presenter.IndicatorForeground);
v.TextRunProperties.SetTypeface(new Typeface(presenter.FontFamily, FontStyle.Italic));
});
}
}
private readonly ThemedTextDiffPresenter _presenter;
}
public static readonly StyledProperty<string> FileNameProperty =