mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-21 02:15:00 +00:00
Added feature to display LFS images in the file browser & file history
This commit is contained in:
parent
eebadd67a1
commit
6def15212c
7 changed files with 157 additions and 17 deletions
|
@ -230,9 +230,23 @@ namespace SourceGit.ViewModels
|
||||||
var matchLFS = REG_LFS_FORMAT().Match(content);
|
var matchLFS = REG_LFS_FORMAT().Match(content);
|
||||||
if (matchLFS.Success)
|
if (matchLFS.Success)
|
||||||
{
|
{
|
||||||
var obj = new Models.RevisionLFSObject() { Object = new Models.LFSObject() };
|
var lfsObj = new Models.RevisionLFSObject() { Object = new Models.LFSObject
|
||||||
obj.Object.Oid = matchLFS.Groups[1].Value;
|
{
|
||||||
obj.Object.Size = long.Parse(matchLFS.Groups[2].Value);
|
Oid = matchLFS.Groups[1].Value,
|
||||||
|
Size = long.Parse(matchLFS.Groups[2].Value)
|
||||||
|
}};
|
||||||
|
|
||||||
|
var ext = Path.GetExtension(file.Path);
|
||||||
|
var obj = null as object;
|
||||||
|
if (IMG_EXTS.Contains(ext))
|
||||||
|
{
|
||||||
|
var imageType = ext!.Substring(1).ToUpper(CultureInfo.CurrentCulture);
|
||||||
|
obj = new RevisionLFSImageObject(_repo.FullPath, lfsObj, imageType);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
obj = lfsObj;
|
||||||
|
}
|
||||||
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = obj);
|
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = obj);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -103,10 +103,23 @@ namespace SourceGit.ViewModels
|
||||||
var matchLFS = REG_LFS_FORMAT().Match(content);
|
var matchLFS = REG_LFS_FORMAT().Match(content);
|
||||||
if (matchLFS.Success)
|
if (matchLFS.Success)
|
||||||
{
|
{
|
||||||
var lfs = new Models.RevisionLFSObject() { Object = new() };
|
var lfs = new Models.RevisionLFSObject() { Object = new Models.LFSObject {
|
||||||
lfs.Object.Oid = matchLFS.Groups[1].Value;
|
Oid = matchLFS.Groups[1].Value,
|
||||||
lfs.Object.Size = long.Parse(matchLFS.Groups[2].Value);
|
Size = long.Parse(matchLFS.Groups[2].Value)
|
||||||
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, lfs));
|
} };
|
||||||
|
|
||||||
|
var ext = Path.GetExtension(_file);
|
||||||
|
var obj = null as object;
|
||||||
|
if (IMG_EXTS.Contains(ext))
|
||||||
|
{
|
||||||
|
var imageType = Path.GetExtension(_file)!.TrimStart('.').ToUpper(CultureInfo.CurrentCulture);
|
||||||
|
obj = new RevisionLFSImageObject(_repo.FullPath, lfs, ext);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
obj = lfs;
|
||||||
|
}
|
||||||
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, obj));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace SourceGit.ViewModels
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private (Bitmap, long) BitmapFromLFSObject(string repo, Models.LFSObject lfs)
|
public static (Bitmap, long) BitmapFromLFSObject(string repo, Models.LFSObject lfs)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(lfs.Oid) || lfs.Size == 0)
|
if (string.IsNullOrEmpty(lfs.Oid) || lfs.Size == 0)
|
||||||
return (null, 0);
|
return (null, 0);
|
||||||
|
|
38
src/ViewModels/RevisionLFSImageObject.cs
Normal file
38
src/ViewModels/RevisionLFSImageObject.cs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Avalonia.Threading;
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
namespace SourceGit.ViewModels
|
||||||
|
{
|
||||||
|
public class RevisionLFSImageObject : ObservableObject
|
||||||
|
{
|
||||||
|
public Models.RevisionLFSObject LFS
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Models.RevisionImageFile Image
|
||||||
|
{
|
||||||
|
get => _image;
|
||||||
|
private set => SetProperty(ref _image, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RevisionLFSImageObject(string repo, Models.RevisionLFSObject lfs, string ext)
|
||||||
|
{
|
||||||
|
LFS = lfs;
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
var img = new Models.RevisionImageFile
|
||||||
|
{
|
||||||
|
ImageType = ext
|
||||||
|
};
|
||||||
|
(img.Image, img.FileSize) = SourceGit.ViewModels.LFSImageDiff.BitmapFromLFSObject(repo, LFS.Object);
|
||||||
|
Dispatcher.UIThread.Invoke(() => Image = img);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private Models.RevisionImageFile _image;
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,15 +49,59 @@
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="m:RevisionLFSObject">
|
<DataTemplate DataType="m:RevisionLFSObject">
|
||||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
<v:RevisionFileLFSContentViewer/>
|
||||||
<TextBlock Text="{DynamicResource Text.CommitDetail.Files.LFS}" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
|
</DataTemplate>
|
||||||
<Path Width="64" Height="64" Margin="0,24,0,0" Data="{StaticResource Icons.LFS}" Fill="{DynamicResource Brush.FG2}"/>
|
|
||||||
<SelectableTextBlock Margin="0,16,0,0" Text="{Binding Object.Oid}" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
|
<DataTemplate DataType="vm:RevisionLFSImageObject">
|
||||||
<StackPanel Margin="0,8,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
|
<TabControl Margin="0,8,0,0" SelectedIndex="{Binding Source={x:Static vm:Preferences.Instance}, Path=LFSImageDiffActiveIdx, Mode=TwoWay}">
|
||||||
<TextBlock Classes="primary" Text="{Binding Object.Size}" Foreground="{DynamicResource Brush.FG2}"/>
|
<TabControl.Styles>
|
||||||
<TextBlock Text="{DynamicResource Text.Bytes}" Margin="8,0,0,0" Foreground="{DynamicResource Brush.FG2}"/>
|
<Style Selector="TabControl /template/ ItemsPresenter#PART_ItemsPresenter > WrapPanel">
|
||||||
</StackPanel>
|
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||||
|
</Style>
|
||||||
|
</TabControl.Styles>
|
||||||
|
|
||||||
|
<TabItem>
|
||||||
|
<TabItem.Header>
|
||||||
|
<TextBlock Text="LFS" FontWeight="Bold" />
|
||||||
|
</TabItem.Header>
|
||||||
|
|
||||||
|
<ContentControl Content="{Binding LFS}">
|
||||||
|
<ContentControl.DataTemplates>
|
||||||
|
<DataTemplate DataType="m:RevisionLFSObject">
|
||||||
|
<v:RevisionFileLFSContentViewer/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ContentControl.DataTemplates>
|
||||||
|
</ContentControl>
|
||||||
|
</TabItem>
|
||||||
|
|
||||||
|
<TabItem>
|
||||||
|
<TabItem.Header>
|
||||||
|
<TextBlock Text="IMAGE" FontWeight="Bold" />
|
||||||
|
</TabItem.Header>
|
||||||
|
|
||||||
|
<ContentControl Content="{Binding Image}">
|
||||||
|
<Grid RowDefinitions="*,Auto" Margin="0,8" VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||||
|
<Border Grid.Row="0" Effect="drop-shadow(0 0 8 #A0000000)">
|
||||||
|
<Border Background="{DynamicResource Brush.Window}">
|
||||||
|
<Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Margin="8">
|
||||||
|
<v:ImageView Image="{Binding Image.Image}"/>
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<StackPanel Grid.Row="1" Margin="0,8,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||||
|
<Border Height="16" Background="Green" CornerRadius="8" VerticalAlignment="Center">
|
||||||
|
<TextBlock Classes="primary" Text="{Binding Image.ImageType}" Margin="8,0" FontSize="10" Foreground="{DynamicResource Brush.BadgeFG}"/>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<TextBlock Classes="primary" Text="{Binding Image.ImageSize}" Margin="8,0,0,0"/>
|
||||||
|
<TextBlock Classes="primary" Text="{Binding Image.FileSize}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
|
||||||
|
<TextBlock Classes="primary" Text="{DynamicResource Text.Bytes}" Foreground="{DynamicResource Brush.FG2}" Margin="2,0,0,0"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
</ContentControl>
|
||||||
|
</TabItem>
|
||||||
|
</TabControl>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="m:RevisionSubmodule">
|
<DataTemplate DataType="m:RevisionSubmodule">
|
||||||
|
|
19
src/Views/RevisionFileLFSContentViewer.axaml
Normal file
19
src/Views/RevisionFileLFSContentViewer.axaml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:m="using:SourceGit.Models"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="SourceGit.Views.RevisionFileLFSContentViewer"
|
||||||
|
x:DataType="m:RevisionLFSObject">
|
||||||
|
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||||
|
<TextBlock Text="{DynamicResource Text.CommitDetail.Files.LFS}" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
|
||||||
|
<Path Width="64" Height="64" Margin="0,24,0,0" Data="{StaticResource Icons.LFS}" Fill="{DynamicResource Brush.FG2}"/>
|
||||||
|
<SelectableTextBlock Margin="0,16,0,0" Text="{Binding Object.Oid}" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
|
||||||
|
<StackPanel Margin="0,8,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||||
|
<TextBlock Classes="primary" Text="{Binding Object.Size}" Foreground="{DynamicResource Brush.FG2}"/>
|
||||||
|
<TextBlock Text="{DynamicResource Text.Bytes}" Margin="8,0,0,0" Foreground="{DynamicResource Brush.FG2}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</UserControl>
|
||||||
|
|
12
src/Views/RevisionFileLFSContentViewer.axaml.cs
Normal file
12
src/Views/RevisionFileLFSContentViewer.axaml.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace SourceGit.Views
|
||||||
|
{
|
||||||
|
public partial class RevisionFileLFSContentViewer : UserControl
|
||||||
|
{
|
||||||
|
public RevisionFileLFSContentViewer()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue