mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
refactor: rewrite file histories page to only focus on selected file (#403)
This commit is contained in:
parent
1caf02ff06
commit
db8de81120
9 changed files with 327 additions and 103 deletions
|
@ -243,6 +243,8 @@
|
||||||
<x:String x:Key="Text.FileCM.UseTheirs" xml:space="preserve">Use Theirs (checkout --theirs)</x:String>
|
<x:String x:Key="Text.FileCM.UseTheirs" xml:space="preserve">Use Theirs (checkout --theirs)</x:String>
|
||||||
<x:String x:Key="Text.FileCM.UseMine" xml:space="preserve">Use Mine (checkout --ours)</x:String>
|
<x:String x:Key="Text.FileCM.UseMine" xml:space="preserve">Use Mine (checkout --ours)</x:String>
|
||||||
<x:String x:Key="Text.FileHistory" xml:space="preserve">File History</x:String>
|
<x:String x:Key="Text.FileHistory" xml:space="preserve">File History</x:String>
|
||||||
|
<x:String x:Key="Text.FileHistory.FileContent" xml:space="preserve">CONTENT</x:String>
|
||||||
|
<x:String x:Key="Text.FileHistory.FileChange" xml:space="preserve">CHANGE</x:String>
|
||||||
<x:String x:Key="Text.Filter" xml:space="preserve">FILTER</x:String>
|
<x:String x:Key="Text.Filter" xml:space="preserve">FILTER</x:String>
|
||||||
<x:String x:Key="Text.GitFlow" xml:space="preserve">Git-Flow</x:String>
|
<x:String x:Key="Text.GitFlow" xml:space="preserve">Git-Flow</x:String>
|
||||||
<x:String x:Key="Text.GitFlow.DevelopBranch" xml:space="preserve">Development Branch:</x:String>
|
<x:String x:Key="Text.GitFlow.DevelopBranch" xml:space="preserve">Development Branch:</x:String>
|
||||||
|
|
|
@ -246,6 +246,8 @@
|
||||||
<x:String x:Key="Text.FileCM.UseTheirs" xml:space="preserve">使用 THEIRS (checkout --theirs)</x:String>
|
<x:String x:Key="Text.FileCM.UseTheirs" xml:space="preserve">使用 THEIRS (checkout --theirs)</x:String>
|
||||||
<x:String x:Key="Text.FileCM.UseMine" xml:space="preserve">使用 MINE (checkout --ours)</x:String>
|
<x:String x:Key="Text.FileCM.UseMine" xml:space="preserve">使用 MINE (checkout --ours)</x:String>
|
||||||
<x:String x:Key="Text.FileHistory" xml:space="preserve">文件历史</x:String>
|
<x:String x:Key="Text.FileHistory" xml:space="preserve">文件历史</x:String>
|
||||||
|
<x:String x:Key="Text.FileHistory.FileContent" xml:space="preserve">文件内容</x:String>
|
||||||
|
<x:String x:Key="Text.FileHistory.FileChange" xml:space="preserve">文件变更</x:String>
|
||||||
<x:String x:Key="Text.Filter" xml:space="preserve">过滤</x:String>
|
<x:String x:Key="Text.Filter" xml:space="preserve">过滤</x:String>
|
||||||
<x:String x:Key="Text.GitFlow" xml:space="preserve">GIT工作流</x:String>
|
<x:String x:Key="Text.GitFlow" xml:space="preserve">GIT工作流</x:String>
|
||||||
<x:String x:Key="Text.GitFlow.DevelopBranch" xml:space="preserve">开发分支 :</x:String>
|
<x:String x:Key="Text.GitFlow.DevelopBranch" xml:space="preserve">开发分支 :</x:String>
|
||||||
|
|
|
@ -246,6 +246,8 @@
|
||||||
<x:String x:Key="Text.FileCM.UseTheirs" xml:space="preserve">使用 THEIRS (checkout --theirs)</x:String>
|
<x:String x:Key="Text.FileCM.UseTheirs" xml:space="preserve">使用 THEIRS (checkout --theirs)</x:String>
|
||||||
<x:String x:Key="Text.FileCM.UseMine" xml:space="preserve">使用 MINE (checkout --ours)</x:String>
|
<x:String x:Key="Text.FileCM.UseMine" xml:space="preserve">使用 MINE (checkout --ours)</x:String>
|
||||||
<x:String x:Key="Text.FileHistory" xml:space="preserve">檔案歷史</x:String>
|
<x:String x:Key="Text.FileHistory" xml:space="preserve">檔案歷史</x:String>
|
||||||
|
<x:String x:Key="Text.FileHistory.FileContent" xml:space="preserve">檔案内容</x:String>
|
||||||
|
<x:String x:Key="Text.FileHistory.FileChange" xml:space="preserve">檔案更改</x:String>
|
||||||
<x:String x:Key="Text.Filter" xml:space="preserve">過濾</x:String>
|
<x:String x:Key="Text.Filter" xml:space="preserve">過濾</x:String>
|
||||||
<x:String x:Key="Text.GitFlow" xml:space="preserve">GIT工作流</x:String>
|
<x:String x:Key="Text.GitFlow" xml:space="preserve">GIT工作流</x:String>
|
||||||
<x:String x:Key="Text.GitFlow.DevelopBranch" xml:space="preserve">開發分支 :</x:String>
|
<x:String x:Key="Text.GitFlow.DevelopBranch" xml:space="preserve">開發分支 :</x:String>
|
||||||
|
|
|
@ -1,11 +1,22 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Avalonia.Media.Imaging;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class FileHistories : ObservableObject
|
public class FileHistoriesRevisionFile(string path, object content)
|
||||||
|
{
|
||||||
|
public string Path { get; set; } = path;
|
||||||
|
public object Content { get; set; } = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class FileHistories : ObservableObject
|
||||||
{
|
{
|
||||||
public bool IsLoading
|
public bool IsLoading
|
||||||
{
|
{
|
||||||
|
@ -25,38 +36,30 @@ namespace SourceGit.ViewModels
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _selectedCommit, value))
|
if (SetProperty(ref _selectedCommit, value))
|
||||||
{
|
RefreshViewContent();
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
DiffContext = null;
|
|
||||||
DetailContext.Commit = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DiffContext = new DiffContext(_repo.FullPath, new Models.DiffOption(value, _file), _diffContext);
|
|
||||||
DetailContext.Commit = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiffContext DiffContext
|
public int ViewMode
|
||||||
{
|
{
|
||||||
get => _diffContext;
|
get => _viewMode;
|
||||||
set => SetProperty(ref _diffContext, value);
|
set
|
||||||
|
{
|
||||||
|
if (SetProperty(ref _viewMode, value))
|
||||||
|
RefreshViewContent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommitDetail DetailContext
|
public object ViewContent
|
||||||
{
|
{
|
||||||
get => _detailContext;
|
get => _viewContent;
|
||||||
set => SetProperty(ref _detailContext, value);
|
private set => SetProperty(ref _viewContent, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileHistories(Repository repo, string file)
|
public FileHistories(Repository repo, string file)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
_file = file;
|
_file = file;
|
||||||
_detailContext = new CommitDetail(repo);
|
|
||||||
|
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
|
@ -71,12 +74,122 @@ namespace SourceGit.ViewModels
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void NavigateToCommit(Models.Commit commit)
|
||||||
|
{
|
||||||
|
_repo.NavigateToCommit(commit.SHA);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshViewContent()
|
||||||
|
{
|
||||||
|
if (_selectedCommit == null)
|
||||||
|
{
|
||||||
|
ViewContent = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_viewMode == 0)
|
||||||
|
SetViewContentAsRevisionFile();
|
||||||
|
else
|
||||||
|
SetViewContentAsDiff();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetViewContentAsRevisionFile()
|
||||||
|
{
|
||||||
|
var objs = new Commands.QueryRevisionObjects(_repo.FullPath, _selectedCommit.SHA, _file).Result();
|
||||||
|
if (objs.Count == 0)
|
||||||
|
{
|
||||||
|
ViewContent = new FileHistoriesRevisionFile(_file, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var obj = objs[0];
|
||||||
|
switch (obj.Type)
|
||||||
|
{
|
||||||
|
case Models.ObjectType.Blob:
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
var isBinary = new Commands.IsBinary(_repo.FullPath, _selectedCommit.SHA, _file).Result();
|
||||||
|
if (isBinary)
|
||||||
|
{
|
||||||
|
var ext = Path.GetExtension(_file);
|
||||||
|
if (IMG_EXTS.Contains(ext))
|
||||||
|
{
|
||||||
|
var stream = Commands.QueryFileContent.Run(_repo.FullPath, _selectedCommit.SHA, _file);
|
||||||
|
var bitmap = stream.Length > 0 ? new Bitmap(stream) : null;
|
||||||
|
var image = new Models.RevisionImageFile() { Image = bitmap };
|
||||||
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, image));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var size = new Commands.QueryFileSize(_repo.FullPath, _file, _selectedCommit.SHA).Result();
|
||||||
|
var binaryFile = new Models.RevisionBinaryFile() { Size = size };
|
||||||
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, binaryFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var contentStream = Commands.QueryFileContent.Run(_repo.FullPath, _selectedCommit.SHA, _file);
|
||||||
|
var content = new StreamReader(contentStream).ReadToEnd();
|
||||||
|
var matchLFS = REG_LFS_FORMAT().Match(content);
|
||||||
|
if (matchLFS.Success)
|
||||||
|
{
|
||||||
|
var lfs = new Models.RevisionLFSObject() { Object = new Models.LFSObject() };
|
||||||
|
lfs.Object.Oid = matchLFS.Groups[1].Value;
|
||||||
|
lfs.Object.Size = long.Parse(matchLFS.Groups[2].Value);
|
||||||
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, lfs));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var txt = new Models.RevisionTextFile() { FileName = obj.Path, Content = content };
|
||||||
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, txt));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case Models.ObjectType.Commit:
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
var submoduleRoot = Path.Combine(_repo.FullPath, _file);
|
||||||
|
var commit = new Commands.QuerySingleCommit(submoduleRoot, obj.SHA).Result();
|
||||||
|
if (commit != null)
|
||||||
|
{
|
||||||
|
var message = new Commands.QueryCommitFullMessage(submoduleRoot, obj.SHA).Result();
|
||||||
|
var module = new Models.RevisionSubmodule() { Commit = commit, FullMessage = message };
|
||||||
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, module));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var module = new Models.RevisionSubmodule() { Commit = new Models.Commit() { SHA = obj.SHA }, FullMessage = "" };
|
||||||
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, module));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ViewContent = new FileHistoriesRevisionFile(_file, null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetViewContentAsDiff()
|
||||||
|
{
|
||||||
|
var option = new Models.DiffOption(_selectedCommit, _file);
|
||||||
|
ViewContent = new DiffContext(_repo.FullPath, option, _viewContent as DiffContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex(@"^version https://git-lfs.github.com/spec/v\d+\r?\noid sha256:([0-9a-f]+)\r?\nsize (\d+)[\r\n]*$")]
|
||||||
|
private static partial Regex REG_LFS_FORMAT();
|
||||||
|
|
||||||
|
private static readonly HashSet<string> IMG_EXTS = new HashSet<string>()
|
||||||
|
{
|
||||||
|
".ico", ".bmp", ".jpg", ".png", ".jpeg"
|
||||||
|
};
|
||||||
|
|
||||||
private readonly Repository _repo = null;
|
private readonly Repository _repo = null;
|
||||||
private readonly string _file = null;
|
private readonly string _file = null;
|
||||||
private bool _isLoading = true;
|
private bool _isLoading = true;
|
||||||
private List<Models.Commit> _commits = null;
|
private List<Models.Commit> _commits = null;
|
||||||
private Models.Commit _selectedCommit = null;
|
private Models.Commit _selectedCommit = null;
|
||||||
private DiffContext _diffContext = null;
|
private int _viewMode = 0;
|
||||||
private CommitDetail _detailContext = null;
|
private object _viewContent = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
<!-- TitleBar -->
|
<!-- TitleBar -->
|
||||||
<Grid Grid.Row="0" ColumnDefinitions="Auto,Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
|
<Grid Grid.Row="0" ColumnDefinitions="Auto,Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
|
||||||
<!-- Bottom border -->
|
<!-- Bottom border -->
|
||||||
<Border Grid.Column="0" Grid.ColumnSpan="5"
|
<Border Grid.Column="0" Grid.ColumnSpan="4"
|
||||||
Background="{DynamicResource Brush.TitleBar}"
|
Background="{DynamicResource Brush.TitleBar}"
|
||||||
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
|
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
|
||||||
DoubleTapped="MaximizeOrRestoreWindow"
|
DoubleTapped="MaximizeOrRestoreWindow"
|
||||||
|
@ -79,7 +79,14 @@
|
||||||
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,Auto">
|
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,Auto">
|
||||||
<v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
|
<v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
|
||||||
<TextBlock Grid.Column="1" Classes="primary" Text="{Binding Author.Name}" Margin="8,0,0,0"/>
|
<TextBlock Grid.Column="1" Classes="primary" Text="{Binding Author.Name}" Margin="8,0,0,0"/>
|
||||||
<TextBlock Grid.Column="2" Classes="primary" Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange" Margin="8,0,0,0"/>
|
<TextBlock Grid.Column="2"
|
||||||
|
Classes="primary"
|
||||||
|
Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}"
|
||||||
|
Background="Transparent"
|
||||||
|
Foreground="DarkOrange"
|
||||||
|
TextDecorations="Underline"
|
||||||
|
Margin="8,0,0,0"
|
||||||
|
PointerPressed="OnPressCommitSHA"/>
|
||||||
<TextBlock Grid.Column="3" Classes="primary" Text="{Binding AuthorTimeShortStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
|
<TextBlock Grid.Column="3" Classes="primary" Text="{Binding AuthorTimeShortStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
@ -104,40 +111,106 @@
|
||||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||||
IsVisible="{Binding IsLoading}"/>
|
IsVisible="{Binding IsLoading}"/>
|
||||||
|
|
||||||
<Grid Grid.Column="2" RowDefinitions="*,3,*" IsVisible="{Binding !IsLoading}">
|
<Grid Grid.Column="2" RowDefinitions="Auto,*" IsVisible="{Binding !IsLoading}">
|
||||||
<ContentControl Grid.Row="0" Margin="4,4,8,0" Content="{Binding DiffContext}">
|
<ListBox Grid.Row="0"
|
||||||
|
Margin="0,8"
|
||||||
|
SelectedIndex="{Binding ViewMode, Mode=TwoWay}"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Background="Transparent"
|
||||||
|
BorderThickness="1"
|
||||||
|
BorderBrush="{DynamicResource Brush.Border2}"
|
||||||
|
CornerRadius="14"
|
||||||
|
Padding="3,0">
|
||||||
|
<ListBox.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal"/>
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ListBox.ItemsPanel>
|
||||||
|
|
||||||
|
<ListBox.Styles>
|
||||||
|
<Style Selector="ListBoxItem">
|
||||||
|
<Setter Property="Height" Value="28"/>
|
||||||
|
<Setter Property="Padding" Value="0"/>
|
||||||
|
<Setter Property="Background" Value="Transparent"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="ListBoxItem:pointerover /template/ ContentPresenter#PART_ContentPresenter">
|
||||||
|
<Setter Property="Background" Value="Transparent"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="ListBoxItem:selected /template/ ContentPresenter#PART_ContentPresenter">
|
||||||
|
<Setter Property="Background" Value="Transparent"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="ListBoxItem Border.switcher_bg">
|
||||||
|
<Setter Property="Height" Value="22"/>
|
||||||
|
<Setter Property="CornerRadius" Value="11"/>
|
||||||
|
<Setter Property="Background" Value="Transparent"/>
|
||||||
|
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||||
|
<Setter Property="Padding" Value="16,0"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="ListBoxItem:selected Border.switcher_bg">
|
||||||
|
<Setter Property="Background" Value="{DynamicResource Brush.Accent}"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="TextBlock.view_mode_switcher">
|
||||||
|
<Setter Property="FontWeight" Value="Bold"/>
|
||||||
|
<Setter Property="Foreground" Value="{DynamicResource Brush.FG2}"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="ListBoxItem:pointerover TextBlock.view_mode_switcher">
|
||||||
|
<Setter Property="Foreground" Value="{DynamicResource Brush.FG1}"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="ListBoxItem:selected TextBlock.view_mode_switcher">
|
||||||
|
<Setter Property="Foreground" Value="White"/>
|
||||||
|
</Style>
|
||||||
|
</ListBox.Styles>
|
||||||
|
|
||||||
|
<ListBoxItem>
|
||||||
|
<Border Classes="switcher_bg">
|
||||||
|
<TextBlock Classes="view_mode_switcher" Text="{DynamicResource Text.FileHistory.FileContent}"/>
|
||||||
|
</Border>
|
||||||
|
</ListBoxItem>
|
||||||
|
|
||||||
|
<ListBoxItem>
|
||||||
|
<Border Classes="switcher_bg">
|
||||||
|
<TextBlock Classes="view_mode_switcher" Text="{DynamicResource Text.FileHistory.FileChange}"/>
|
||||||
|
</Border>
|
||||||
|
</ListBoxItem>
|
||||||
|
</ListBox>
|
||||||
|
|
||||||
|
<ContentControl Grid.Row="1" Margin="4,4,8,8" Content="{Binding ViewContent}">
|
||||||
<ContentControl.DataTemplates>
|
<ContentControl.DataTemplates>
|
||||||
<DataTemplate DataType="vm:DiffContext">
|
<DataTemplate DataType="vm:DiffContext">
|
||||||
<v:DiffView/>
|
<v:DiffView/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
|
<DataTemplate DataType="vm:FileHistoriesRevisionFile">
|
||||||
|
<Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}">
|
||||||
|
<Grid RowDefinitions="26,*">
|
||||||
|
<Border Grid.Row="0"
|
||||||
|
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}"
|
||||||
|
Background="{DynamicResource Brush.Window}">
|
||||||
|
<Grid ColumnDefinitions="Auto,*">
|
||||||
|
<Path Grid.Column="0" Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
|
||||||
|
<TextBlock Grid.Column="1"
|
||||||
|
Classes="primary"
|
||||||
|
Margin="4,0,0,0"
|
||||||
|
Text="{Binding Path}"
|
||||||
|
FontSize="11"
|
||||||
|
TextTrimming="CharacterEllipsis"/>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<v:RevisionFileContentViewer Grid.Row="1" Content="{Binding Content}"/>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</DataTemplate>
|
||||||
</ContentControl.DataTemplates>
|
</ContentControl.DataTemplates>
|
||||||
</ContentControl>
|
</ContentControl>
|
||||||
|
|
||||||
<GridSplitter Grid.Row="1"
|
|
||||||
MinHeight="1"
|
|
||||||
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
|
|
||||||
Background="Transparent"/>
|
|
||||||
|
|
||||||
<Border Grid.Row="2" Margin="0,0,4,4">
|
|
||||||
<ContentControl>
|
|
||||||
<ContentControl.Content>
|
|
||||||
<Binding Path="DetailContext">
|
|
||||||
<Binding.TargetNullValue>
|
|
||||||
<Path Width="128" Height="128"
|
|
||||||
Data="{StaticResource Icons.Detail}"
|
|
||||||
HorizontalAlignment="Center"
|
|
||||||
Fill="{DynamicResource Brush.FG2}"/>
|
|
||||||
</Binding.TargetNullValue>
|
|
||||||
</Binding>
|
|
||||||
</ContentControl.Content>
|
|
||||||
|
|
||||||
<ContentControl.DataTemplates>
|
|
||||||
<DataTemplate DataType="vm:CommitDetail">
|
|
||||||
<v:CommitDetail/>
|
|
||||||
</DataTemplate>
|
|
||||||
</ContentControl.DataTemplates>
|
|
||||||
</ContentControl>
|
|
||||||
</Border>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -27,5 +27,16 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnPressCommitSHA(object sender, PointerPressedEventArgs e)
|
||||||
|
{
|
||||||
|
if (sender is TextBlock { DataContext: Models.Commit commit } &&
|
||||||
|
DataContext is ViewModels.FileHistories vm)
|
||||||
|
{
|
||||||
|
vm.NavigateToCommit(commit);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
58
src/Views/RevisionFileContentViewer.axaml
Normal file
58
src/Views/RevisionFileContentViewer.axaml
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<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"
|
||||||
|
xmlns:v="using:SourceGit.Views"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="SourceGit.Views.RevisionFileContentViewer">
|
||||||
|
<UserControl.DataTemplates>
|
||||||
|
<DataTemplate DataType="m:RevisionBinaryFile">
|
||||||
|
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||||
|
<Path Width="64" Height="64" Data="{StaticResource Icons.Error}" Fill="{DynamicResource Brush.FG2}"/>
|
||||||
|
<TextBlock Margin="0,16,0,0" Text="{DynamicResource Text.BinaryNotSupported}" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
|
||||||
|
<StackPanel Margin="0,8,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||||
|
<TextBlock Classes="primary" Text="{Binding Size}" Foreground="{DynamicResource Brush.FG2}"/>
|
||||||
|
<TextBlock Text="{DynamicResource Text.Bytes}" Margin="8,0,0,0" Foreground="{DynamicResource Brush.FG2}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
|
||||||
|
<DataTemplate DataType="m:RevisionTextFile">
|
||||||
|
<v:RevisionTextFileView FontFamily="{DynamicResource Fonts.Monospace}" Background="{DynamicResource Brush.Contents}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
|
||||||
|
<DataTemplate DataType="m:RevisionImageFile">
|
||||||
|
<Border Margin="0,8" VerticalAlignment="Center" HorizontalAlignment="Center" Effect="drop-shadow(0 0 8 #A0000000)">
|
||||||
|
<Border Background="{DynamicResource Brush.Window}">
|
||||||
|
<Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Margin="8">
|
||||||
|
<Grid>
|
||||||
|
<v:ImageContainer/>
|
||||||
|
<Image Source="{Binding Image}" Stretch="Uniform" VerticalAlignment="Center" RenderOptions.BitmapInterpolationMode="HighQuality"/>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
</Border>
|
||||||
|
</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>
|
||||||
|
</DataTemplate>
|
||||||
|
|
||||||
|
<DataTemplate DataType="m:RevisionSubmodule">
|
||||||
|
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" Margin="8,8,8,0">
|
||||||
|
<TextBlock Text="{DynamicResource Text.CommitDetail.Files.Submodule}" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
|
||||||
|
<v:CommitBaseInfo Margin="0,16,0,0" Content="{Binding Commit}" Message="{Binding FullMessage}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</UserControl.DataTemplates>
|
||||||
|
</UserControl>
|
||||||
|
|
13
src/Views/RevisionFileContentViewer.axaml.cs
Normal file
13
src/Views/RevisionFileContentViewer.axaml.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace SourceGit.Views
|
||||||
|
{
|
||||||
|
public partial class RevisionFileContentViewer : UserControl
|
||||||
|
{
|
||||||
|
public RevisionFileContentViewer()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:m="using:SourceGit.Models"
|
|
||||||
xmlns:vm="using:SourceGit.ViewModels"
|
xmlns:vm="using:SourceGit.ViewModels"
|
||||||
xmlns:v="using:SourceGit.Views"
|
xmlns:v="using:SourceGit.Views"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
@ -28,56 +27,7 @@
|
||||||
<!-- File Content Viewer -->
|
<!-- File Content Viewer -->
|
||||||
<Grid Grid.Column="2">
|
<Grid Grid.Column="2">
|
||||||
<Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}">
|
<Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}">
|
||||||
<ContentControl Content="{Binding ViewRevisionFileContent}">
|
<v:RevisionFileContentViewer Content="{Binding ViewRevisionFileContent}"/>
|
||||||
<ContentControl.DataTemplates>
|
|
||||||
<DataTemplate DataType="m:RevisionBinaryFile">
|
|
||||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
|
||||||
<Path Width="64" Height="64" Data="{StaticResource Icons.Error}" Fill="{DynamicResource Brush.FG2}"/>
|
|
||||||
<TextBlock Margin="0,16,0,0" Text="{DynamicResource Text.BinaryNotSupported}" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
|
|
||||||
<StackPanel Margin="0,8,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
|
|
||||||
<TextBlock Classes="primary" Text="{Binding Size}" Foreground="{DynamicResource Brush.FG2}"/>
|
|
||||||
<TextBlock Text="{DynamicResource Text.Bytes}" Margin="8,0,0,0" Foreground="{DynamicResource Brush.FG2}"/>
|
|
||||||
</StackPanel>
|
|
||||||
</StackPanel>
|
|
||||||
</DataTemplate>
|
|
||||||
|
|
||||||
<DataTemplate DataType="m:RevisionTextFile">
|
|
||||||
<v:RevisionTextFileView FontFamily="{DynamicResource Fonts.Monospace}" Background="{DynamicResource Brush.Contents}"/>
|
|
||||||
</DataTemplate>
|
|
||||||
|
|
||||||
<DataTemplate DataType="m:RevisionImageFile">
|
|
||||||
<Border Margin="0,8" VerticalAlignment="Center" HorizontalAlignment="Center" Effect="drop-shadow(0 0 8 #A0000000)">
|
|
||||||
<Border Background="{DynamicResource Brush.Window}">
|
|
||||||
<Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Margin="8">
|
|
||||||
<Grid>
|
|
||||||
<v:ImageContainer/>
|
|
||||||
<Image Source="{Binding Image}" Stretch="Uniform" VerticalAlignment="Center" RenderOptions.BitmapInterpolationMode="HighQuality"/>
|
|
||||||
</Grid>
|
|
||||||
</Border>
|
|
||||||
</Border>
|
|
||||||
</Border>
|
|
||||||
</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>
|
|
||||||
</DataTemplate>
|
|
||||||
|
|
||||||
<DataTemplate DataType="m:RevisionSubmodule">
|
|
||||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" Margin="8,8,8,0">
|
|
||||||
<TextBlock Text="{DynamicResource Text.CommitDetail.Files.Submodule}" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
|
|
||||||
<v:CommitBaseInfo Margin="0,16,0,0" Content="{Binding Commit}" Message="{Binding FullMessage}"/>
|
|
||||||
</StackPanel>
|
|
||||||
</DataTemplate>
|
|
||||||
</ContentControl.DataTemplates>
|
|
||||||
</ContentControl>
|
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
Loading…
Reference in a new issue