Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@
<x:String x:Key="Text.CommitCM.SaveAsPatch" xml:space="preserve">Save as Patch...</x:String>
<x:String x:Key="Text.CommitDetail.Changes" xml:space="preserve">CHANGES</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Count" xml:space="preserve">changed file(s)</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Message.Collapse" xml:space="preserve">Collapse commit message</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Message.Expand" xml:space="preserve">Expand commit message</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Search" xml:space="preserve">Search Changes...</x:String>
<x:String x:Key="Text.CommitDetail.CollapseToBottom" xml:space="preserve">Collapse details</x:String>
<x:String x:Key="Text.CommitDetail.Files" xml:space="preserve">FILES</x:String>
Expand Down
21 changes: 17 additions & 4 deletions src/ViewModels/CommitDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public Models.CommitFullMessage FullMessage
private set => SetProperty(ref _fullMessage, value);
}

public Vector ChangesMessageScrollOffset
{
get => _changesMessageScrollOffset;
set => SetProperty(ref _changesMessageScrollOffset, value);
}

public Models.CommitSignInfo SignInfo
{
get => _signInfo;
Expand Down Expand Up @@ -453,6 +459,11 @@ await Commands.SaveRevisionFile

private void Refresh()
{
if (_cancellationSource is { IsCancellationRequested: false })
_cancellationSource.Cancel();

FullMessage = null;
ChangesMessageScrollOffset = Vector.Zero;
_requestingRevisionFiles = false;
_revisionFiles = null;

Expand All @@ -472,22 +483,23 @@ private void Refresh()
return;
}

if (_cancellationSource is { IsCancellationRequested: false })
_cancellationSource.Cancel();

_cancellationSource = new CancellationTokenSource();
var token = _cancellationSource.Token;

var messageCommitSHA = _commit.SHA;
Task.Run(async () =>
{
var message = await new Commands.QueryCommitFullMessage(_repo.FullPath, _commit.SHA)
var message = await new Commands.QueryCommitFullMessage(_repo.FullPath, messageCommitSHA)
.GetResultAsync()
.ConfigureAwait(false);
var inlines = await ParseInlinesInMessageAsync(message).ConfigureAwait(false);

if (!token.IsCancellationRequested)
Dispatcher.UIThread.Post(() =>
{
if (token.IsCancellationRequested)
return;

FullMessage = new Models.CommitFullMessage
{
Message = message,
Expand Down Expand Up @@ -732,6 +744,7 @@ private async Task SetViewingCommitAsync(Models.Object file)
private CommitDetailSharedData _sharedData = null;
private Models.Commit _commit = null;
private Models.CommitFullMessage _fullMessage = null;
private Vector _changesMessageScrollOffset = Vector.Zero;
private Models.CommitSignInfo _signInfo = null;
private List<Models.Change> _changes = [];
private List<Models.Change> _visibleChanges = [];
Expand Down
36 changes: 35 additions & 1 deletion src/ViewModels/LayoutInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Controls;
using System.Text.Json.Serialization;
using Avalonia.Controls;
using CommunityToolkit.Mvvm.ComponentModel;

namespace SourceGit.ViewModels
Expand Down Expand Up @@ -71,6 +72,37 @@ public GridLength CommitDetailChangesLeftWidth
set => SetProperty(ref _commitDetailChangesLeftWidth, value);
}

public GridLength CommitDetailChangesMessageHeight
{
get => _commitDetailChangesMessageHeight;
set
{
if (SetProperty(ref _commitDetailChangesMessageHeight, value))
OnPropertyChanged(nameof(CommitDetailChangesMessageRowHeight));
}
}

public bool IsCommitDetailChangesMessageExpanded
{
get => _isCommitDetailChangesMessageExpanded;
set
{
if (SetProperty(ref _isCommitDetailChangesMessageExpanded, value))
OnPropertyChanged(nameof(CommitDetailChangesMessageRowHeight));
}
}

[JsonIgnore]
public GridLength CommitDetailChangesMessageRowHeight
{
get => _isCommitDetailChangesMessageExpanded ? _commitDetailChangesMessageHeight : GridLength.Auto;
set
{
if (_isCommitDetailChangesMessageExpanded)
CommitDetailChangesMessageHeight = value;
}
}

public GridLength CommitDetailFilesLeftWidth
{
get => _commitDetailFilesLeftWidth;
Expand All @@ -81,6 +113,8 @@ public GridLength CommitDetailFilesLeftWidth
private GridLength _stashesLeftWidth = new GridLength(300, GridUnitType.Pixel);
private GridLength _commitDetailChangesLeftWidth = new GridLength(256, GridUnitType.Pixel);
private GridLength _commitDetailFilesLeftWidth = new GridLength(256, GridUnitType.Pixel);
private GridLength _commitDetailChangesMessageHeight = new GridLength(96, GridUnitType.Pixel);
private bool _isCommitDetailChangesMessageExpanded = true;
private bool _isSidebarCollapsedInLocalChanges = false;
}
}
83 changes: 80 additions & 3 deletions src/Views/CommitChanges.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:m="using:SourceGit.Models"
xmlns:v="using:SourceGit.Views"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.CommitChanges"
Expand Down Expand Up @@ -81,8 +82,84 @@
Background="Transparent"
Focusable="False"/>

<Grid Grid.Column="2">
<Border CornerRadius="4" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}">
<Grid Grid.Column="2" x:Name="ChangesDiffArea" SizeChanged="OnDiffAreaSizeChanged">
<Grid.RowDefinitions>
<RowDefinition Height="{Binding Source={x:Static vm:Preferences.Instance}, Path=Layout.CommitDetailChangesMessageRowHeight, Mode=TwoWay}" MinHeight="28"/>
<RowDefinition Height="4"/>
<RowDefinition Height="*" MinHeight="80"/>
</Grid.RowDefinitions>

<Border Grid.Row="0" x:Name="CommitMessageArea" CornerRadius="4"
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}"
Background="{DynamicResource Brush.Contents}" ClipToBounds="True">
<Grid ColumnDefinitions="*,24" Margin="6,3,3,3">
<ScrollViewer Grid.Column="0" x:Name="CommitMessageScrollViewer"
HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"
Offset="{Binding ChangesMessageScrollOffset, Mode=TwoWay}"
IsVisible="{Binding Source={x:Static vm:Preferences.Instance}, Path=Layout.IsCommitDetailChangesMessageExpanded}">
<v:CommitMessagePresenter x:Name="ChangesCommitMessage"
FullMessage="{Binding FullMessage}"
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize}"
Foreground="{DynamicResource Brush.FG1}"
HorizontalAlignment="Stretch" VerticalAlignment="Top" TextWrapping="Wrap">
<ToolTip.IsOpen>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="$self.IsPointerOver"/>
<Binding Path="$self.(ToolTip.Tip)" Converter="{x:Static ObjectConverters.IsNotNull}"/>
</MultiBinding>
</ToolTip.IsOpen>
<v:CommitMessagePresenter.ContextFlyout>
<MenuFlyout>
<MenuItem Header="{DynamicResource Text.Copy}"
Command="{Binding $parent[SelectableTextBlock].Copy}"
IsEnabled="{Binding $parent[SelectableTextBlock].CanCopy}"
InputGesture="{x:Static TextBox.CopyGesture}"/>
<MenuItem Header="{DynamicResource Text.CopyAllText}" Click="OnCopyCommitMessage"/>
</MenuFlyout>
</v:CommitMessagePresenter.ContextFlyout>
<v:CommitMessagePresenter.DataTemplates>
<DataTemplate DataType="m:Commit">
<StackPanel MinWidth="300" MaxWidth="500">
<TextBlock Text="{Binding Author.Name}" Foreground="{DynamicResource Brush.FG2}"/>
<TextBlock Text="{Binding Subject}" TextWrapping="Wrap" Margin="0,4,0,0"/>
</StackPanel>
</DataTemplate>
</v:CommitMessagePresenter.DataTemplates>
</v:CommitMessagePresenter>
</ScrollViewer>

<SelectableTextBlock Grid.Column="0" x:Name="CollapsedCommitMessage"
Text="{Binding Commit.Subject}" MaxLines="1" TextWrapping="NoWrap"
TextTrimming="CharacterEllipsis" VerticalAlignment="Center"
IsVisible="{Binding Source={x:Static vm:Preferences.Instance}, Path=!Layout.IsCommitDetailChangesMessageExpanded}"/>

<ToggleButton Grid.Column="1" x:Name="CommitMessageToggle" Classes="line_path"
Width="20" Height="20" VerticalAlignment="Top" Focusable="False"
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=Layout.IsCommitDetailChangesMessageExpanded, Mode=TwoWay}">
<ToggleButton.Styles>
<Style Selector="ToggleButton">
<Setter Property="ToolTip.Tip" Value="{DynamicResource Text.CommitDetail.Changes.Message.Expand}"/>
</Style>
<Style Selector="ToggleButton:checked">
<Setter Property="ToolTip.Tip" Value="{DynamicResource Text.CommitDetail.Changes.Message.Collapse}"/>
</Style>
</ToggleButton.Styles>
<Grid>
<Path Width="12" Height="12" Data="{StaticResource Icons.Up}"
IsVisible="{Binding Source={x:Static vm:Preferences.Instance}, Path=Layout.IsCommitDetailChangesMessageExpanded}"/>
<Path Width="12" Height="12" Data="{StaticResource Icons.Down}"
IsVisible="{Binding Source={x:Static vm:Preferences.Instance}, Path=!Layout.IsCommitDetailChangesMessageExpanded}"/>
</Grid>
</ToggleButton>
</Grid>
</Border>

<GridSplitter Grid.Row="1" x:Name="CommitMessageSplitter" ResizeDirection="Rows" ResizeBehavior="PreviousAndNext"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent"
BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="0,1,0,0" Focusable="False"
IsEnabled="{Binding Source={x:Static vm:Preferences.Instance}, Path=Layout.IsCommitDetailChangesMessageExpanded}"/>

<Border Grid.Row="2" CornerRadius="4" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}">
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<Path Width="64" Height="64" Data="{StaticResource Icons.Diff}" Fill="{DynamicResource Brush.FG2}"/>
<TextBlock Margin="0,16,0,0"
Expand All @@ -93,7 +170,7 @@
</StackPanel>
</Border>

<ContentControl Content="{Binding DiffContext}">
<ContentControl Grid.Row="2" x:Name="ChangesDiffContent" Content="{Binding DiffContext}">
<ContentControl.DataTemplates>
<DataTemplate DataType="vm:DiffContext">
<v:DiffView/>
Expand Down
14 changes: 14 additions & 0 deletions src/Views/CommitChanges.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using Avalonia.VisualTree;

Expand All @@ -16,6 +17,19 @@ public CommitChanges()
InitializeComponent();
}

private void OnDiffAreaSizeChanged(object sender, SizeChangedEventArgs e)
{
// Keep room for the diff even when restoring a taller message pane.
ChangesDiffArea.RowDefinitions[0].MaxHeight = Math.Max(28, e.NewSize.Height - 84);
}

private async void OnCopyCommitMessage(object sender, RoutedEventArgs e)
{
if (DataContext is ViewModels.CommitDetail { FullMessage: { } message })
await this.CopyTextAsync(message.Message);
e.Handled = true;
}

private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e)
{
e.Handled = true;
Expand Down
17 changes: 10 additions & 7 deletions src/Views/CommitMessagePresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)

if (type == Models.InlineElementType.CommitSHA)
{
var parentView = this.FindAncestorOfType<CommitBaseInfo>();
if (parentView is { DataContext: ViewModels.CommitDetail detail })
if (GetCommitDetail() is { } detail)
{
if (point.Properties.IsLeftButtonPressed)
{
Expand Down Expand Up @@ -249,6 +248,12 @@ protected override void OnPointerExited(PointerEventArgs e)
ClearHoveredIssueLink();
}

private ViewModels.CommitDetail GetCommitDetail()
{
return DataContext as ViewModels.CommitDetail ??
this.FindAncestorOfType<CommitBaseInfo>()?.DataContext as ViewModels.CommitDetail;
}

private void ProcessHoverCommitLink(Models.InlineElement link)
{
var sha = link.Link;
Expand All @@ -259,8 +264,7 @@ private void ProcessHoverCommitLink(Models.InlineElement link)
return;
}

var parentView = this.FindAncestorOfType<CommitBaseInfo>();
if (parentView is { DataContext: ViewModels.CommitDetail detail })
if (GetCommitDetail() is { Commit: { } } detail)
{
var lastDetailCommit = detail.Commit.SHA;
Task.Run(async () =>
Expand All @@ -269,9 +273,8 @@ private void ProcessHoverCommitLink(Models.InlineElement link)

Dispatcher.UIThread.Post(() =>
{
var currentParent = this.FindAncestorOfType<CommitBaseInfo>();
if (currentParent is { DataContext: ViewModels.CommitDetail currentDetail } &&
currentDetail.Commit.SHA.Equals(lastDetailCommit, StringComparison.Ordinal))
if (GetCommitDetail() is { Commit: { } currentCommit } &&
currentCommit.SHA.Equals(lastDetailCommit, StringComparison.Ordinal))
{
_inlineCommits.TryAdd(sha, c);
if (_lastHover == link && c != null)
Expand Down
11 changes: 11 additions & 0 deletions tests/ChangesMessageChecks/ChangesMessageChecks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/SourceGit.csproj" />
<PackageReference Include="Avalonia.Headless" Version="11.3.22" />
</ItemGroup>
</Project>
Loading