Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Feature] Added missed LFS Image cases to file browser and file history #1395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
20 changes: 17 additions & 3 deletions src/ViewModels/CommitDetail.cs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,23 @@ public void ViewRevisionFile(Models.Object file)
var matchLFS = REG_LFS_FORMAT().Match(content);
if (matchLFS.Success)
{
var obj = new Models.RevisionLFSObject() { Object = new Models.LFSObject() };
obj.Object.Oid = matchLFS.Groups[1].Value;
obj.Object.Size = long.Parse(matchLFS.Groups[2].Value);
var lfsObj = new Models.RevisionLFSObject() { Object = new Models.LFSObject
{
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);
}
else
Expand Down
21 changes: 17 additions & 4 deletions src/ViewModels/FileHistories.cs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,23 @@ private void SetViewContentAsRevisionFile()
var matchLFS = REG_LFS_FORMAT().Match(content);
if (matchLFS.Success)
{
var lfs = new Models.RevisionLFSObject() { Object = new() };
lfs.Object.Oid = matchLFS.Groups[1].Value;
lfs.Object.Size = long.Parse(matchLFS.Groups[2].Value);
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, lfs));
var lfs = new Models.RevisionLFSObject() { Object = new Models.LFSObject {
Oid = matchLFS.Groups[1].Value,
Size = long.Parse(matchLFS.Groups[2].Value)
} };

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
{
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/LFSImageDiff.cs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public LFSImageDiff(string repo, Models.LFSDiff lfs)
});
}

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)
return (null, 0);
Expand Down
38 changes: 38 additions & 0 deletions src/ViewModels/RevisionLFSImageObject.cs
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -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;
}
}
62 changes: 53 additions & 9 deletions src/Views/RevisionFileContentViewer.axaml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,59 @@
</DataTemplate>

<DataTemplate 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>
<v:RevisionFileLFSContentViewer/>
</DataTemplate>

<DataTemplate DataType="vm:RevisionLFSImageObject">
<TabControl Margin="0,8,0,0" SelectedIndex="{Binding Source={x:Static vm:Preferences.Instance}, Path=LFSImageDiffActiveIdx, Mode=TwoWay}">
<TabControl.Styles>
<Style Selector="TabControl /template/ ItemsPresenter#PART_ItemsPresenter > WrapPanel">
<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>
</Grid>
</ContentControl>
</TabItem>
</TabControl>
</DataTemplate>

<DataTemplate DataType="m:RevisionSubmodule">
Expand Down
19 changes: 19 additions & 0 deletions src/Views/RevisionFileLFSContentViewer.axaml
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions src/Views/RevisionFileLFSContentViewer.axaml.cs
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Avalonia.Controls;

namespace SourceGit.Views
{
public partial class RevisionFileLFSContentViewer : UserControl
{
public RevisionFileLFSContentViewer()
{
InitializeComponent();
}
}
}

AltStyle によって変換されたページ (->オリジナル) /