feature: add a button in file histories view to reset selected file to selected commit

This commit is contained in:
leo 2024-08-24 12:06:38 +08:00
parent db8de81120
commit 9a68d70b29
No known key found for this signature in database
3 changed files with 39 additions and 1 deletions

View file

@ -79,6 +79,11 @@ namespace SourceGit.ViewModels
_repo.NavigateToCommit(commit.SHA);
}
public void ResetToSelectedRevision()
{
new Commands.Checkout(_repo.FullPath).FileWithRevision(_file, $"{_selectedCommit.SHA}");
}
private void RefreshViewContent()
{
if (_selectedCommit == null)

View file

@ -111,7 +111,7 @@
HorizontalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding IsLoading}"/>
<Grid Grid.Column="2" RowDefinitions="Auto,*" IsVisible="{Binding !IsLoading}">
<Grid Grid.Column="2" RowDefinitions="Auto,*,Auto" IsVisible="{Binding !IsLoading}">
<ListBox Grid.Row="0"
Margin="0,8"
SelectedIndex="{Binding ViewMode, Mode=TwoWay}"
@ -211,7 +211,22 @@
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
<Button Grid.Row="2"
Classes="flat primary"
Margin="0,0,0,8"
HorizontalAlignment="Center"
Content="{DynamicResource Text.ChangeCM.CheckoutThisRevision}"
Click="OnResetToSelectedRevision"/>
</Grid>
</Grid>
<Border Grid.Row="1" x:Name="NotifyDonePanel" Background="Transparent" IsVisible="False" PointerPressed="OnCloseNotifyPanel">
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Effect="drop-shadow(0 0 12 #80000000)">
<Border CornerRadius="8" Background="{DynamicResource Brush.Popup}" Padding="32">
<Path Width="52" Height="52" Data="{StaticResource Icons.Check}" Fill="Green"/>
</Border>
</Border>
</Border>
</Grid>
</v:ChromelessWindow>

View file

@ -1,5 +1,6 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
namespace SourceGit.Views
{
@ -38,5 +39,22 @@ namespace SourceGit.Views
e.Handled = true;
}
private void OnResetToSelectedRevision(object _, RoutedEventArgs e)
{
if (DataContext is ViewModels.FileHistories vm)
{
vm.ResetToSelectedRevision();
NotifyDonePanel.IsVisible = true;
}
e.Handled = true;
}
private void OnCloseNotifyPanel(object _, PointerPressedEventArgs e)
{
NotifyDonePanel.IsVisible = false;
e.Handled = true;
}
}
}