mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-21 02:15:00 +00:00
Tried to unify looks of file viewer and history file content
This commit is contained in:
parent
eebadd67a1
commit
714aad2e10
7 changed files with 68 additions and 42 deletions
|
@ -213,13 +213,13 @@ namespace SourceGit.ViewModels
|
||||||
var bitmap = fileSize > 0 ? new Bitmap(stream) : null;
|
var bitmap = fileSize > 0 ? new Bitmap(stream) : null;
|
||||||
var imageType = ext!.Substring(1).ToUpper(CultureInfo.CurrentCulture);
|
var imageType = ext!.Substring(1).ToUpper(CultureInfo.CurrentCulture);
|
||||||
var image = new Models.RevisionImageFile() { Image = bitmap, FileSize = fileSize, ImageType = imageType };
|
var image = new Models.RevisionImageFile() { Image = bitmap, FileSize = fileSize, ImageType = imageType };
|
||||||
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = image);
|
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = new FileContent(file.Path, image));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var size = new Commands.QueryFileSize(_repo.FullPath, file.Path, _commit.SHA).Result();
|
var size = new Commands.QueryFileSize(_repo.FullPath, file.Path, _commit.SHA).Result();
|
||||||
var binary = new Models.RevisionBinaryFile() { Size = size };
|
var binary = new Models.RevisionBinaryFile() { Size = size };
|
||||||
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = binary);
|
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = new FileContent(file.Path, binary));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -233,12 +233,12 @@ namespace SourceGit.ViewModels
|
||||||
var obj = new Models.RevisionLFSObject() { Object = new Models.LFSObject() };
|
var obj = new Models.RevisionLFSObject() { Object = new Models.LFSObject() };
|
||||||
obj.Object.Oid = matchLFS.Groups[1].Value;
|
obj.Object.Oid = matchLFS.Groups[1].Value;
|
||||||
obj.Object.Size = long.Parse(matchLFS.Groups[2].Value);
|
obj.Object.Size = long.Parse(matchLFS.Groups[2].Value);
|
||||||
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = obj);
|
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = new FileContent(file.Path, obj));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var txt = new Models.RevisionTextFile() { FileName = file.Path, Content = content };
|
var txt = new Models.RevisionTextFile() { FileName = file.Path, Content = content };
|
||||||
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = txt);
|
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = new FileContent(file.Path, txt));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -256,17 +256,17 @@ namespace SourceGit.ViewModels
|
||||||
FullMessage = new Models.CommitFullMessage { Message = body }
|
FullMessage = new Models.CommitFullMessage { Message = body }
|
||||||
};
|
};
|
||||||
|
|
||||||
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = submodule);
|
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = new FileContent(file.Path, submodule));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
ViewRevisionFileContent = new Models.RevisionSubmodule()
|
ViewRevisionFileContent = new FileContent(file.Path, new Models.RevisionSubmodule()
|
||||||
{
|
{
|
||||||
Commit = new Models.Commit() { SHA = file.SHA },
|
Commit = new Models.Commit() { SHA = file.SHA },
|
||||||
FullMessage = null,
|
FullMessage = null,
|
||||||
};
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
8
src/ViewModels/FileContent.cs
Normal file
8
src/ViewModels/FileContent.cs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
namespace SourceGit.ViewModels
|
||||||
|
{
|
||||||
|
public class FileContent(string path, object content)
|
||||||
|
{
|
||||||
|
public string Path { get; set; } = path;
|
||||||
|
public object Content { get; set; } = content;
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,12 +12,6 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
public class FileHistoriesRevisionFile(string path, object content)
|
|
||||||
{
|
|
||||||
public string Path { get; set; } = path;
|
|
||||||
public object Content { get; set; } = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public partial class FileHistoriesSingleRevision : ObservableObject
|
public partial class FileHistoriesSingleRevision : ObservableObject
|
||||||
{
|
{
|
||||||
public bool IsDiffMode
|
public bool IsDiffMode
|
||||||
|
@ -65,7 +59,7 @@ namespace SourceGit.ViewModels
|
||||||
var objs = new Commands.QueryRevisionObjects(_repo.FullPath, _revision.SHA, _file).Result();
|
var objs = new Commands.QueryRevisionObjects(_repo.FullPath, _revision.SHA, _file).Result();
|
||||||
if (objs.Count == 0)
|
if (objs.Count == 0)
|
||||||
{
|
{
|
||||||
ViewContent = new FileHistoriesRevisionFile(_file, null);
|
ViewContent = new FileContent(_file, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,13 +80,13 @@ namespace SourceGit.ViewModels
|
||||||
var bitmap = fileSize > 0 ? new Bitmap(stream) : null;
|
var bitmap = fileSize > 0 ? new Bitmap(stream) : null;
|
||||||
var imageType = Path.GetExtension(_file)!.TrimStart('.').ToUpper(CultureInfo.CurrentCulture);
|
var imageType = Path.GetExtension(_file)!.TrimStart('.').ToUpper(CultureInfo.CurrentCulture);
|
||||||
var image = new Models.RevisionImageFile() { Image = bitmap, FileSize = fileSize, ImageType = imageType };
|
var image = new Models.RevisionImageFile() { Image = bitmap, FileSize = fileSize, ImageType = imageType };
|
||||||
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, image));
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileContent(_file, image));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var size = new Commands.QueryFileSize(_repo.FullPath, _file, _revision.SHA).Result();
|
var size = new Commands.QueryFileSize(_repo.FullPath, _file, _revision.SHA).Result();
|
||||||
var binaryFile = new Models.RevisionBinaryFile() { Size = size };
|
var binaryFile = new Models.RevisionBinaryFile() { Size = size };
|
||||||
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, binaryFile));
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileContent(_file, binaryFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -106,12 +100,12 @@ namespace SourceGit.ViewModels
|
||||||
var lfs = new Models.RevisionLFSObject() { Object = new() };
|
var lfs = new Models.RevisionLFSObject() { Object = new() };
|
||||||
lfs.Object.Oid = matchLFS.Groups[1].Value;
|
lfs.Object.Oid = matchLFS.Groups[1].Value;
|
||||||
lfs.Object.Size = long.Parse(matchLFS.Groups[2].Value);
|
lfs.Object.Size = long.Parse(matchLFS.Groups[2].Value);
|
||||||
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, lfs));
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileContent(_file, lfs));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var txt = new Models.RevisionTextFile() { FileName = obj.Path, Content = content };
|
var txt = new Models.RevisionTextFile() { FileName = obj.Path, Content = content };
|
||||||
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, txt));
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileContent(_file, txt));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -128,7 +122,7 @@ namespace SourceGit.ViewModels
|
||||||
Commit = commit,
|
Commit = commit,
|
||||||
FullMessage = new Models.CommitFullMessage { Message = message }
|
FullMessage = new Models.CommitFullMessage { Message = message }
|
||||||
};
|
};
|
||||||
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, module));
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileContent(_file, module));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -137,12 +131,12 @@ namespace SourceGit.ViewModels
|
||||||
Commit = new Models.Commit() { SHA = obj.SHA },
|
Commit = new Models.Commit() { SHA = obj.SHA },
|
||||||
FullMessage = null
|
FullMessage = null
|
||||||
};
|
};
|
||||||
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, module));
|
Dispatcher.UIThread.Invoke(() => ViewContent = new FileContent(_file, module));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ViewContent = new FileHistoriesRevisionFile(_file, null);
|
ViewContent = new FileContent(_file, null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
30
src/Views/FileContentViewer.axaml
Normal file
30
src/Views/FileContentViewer.axaml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<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"
|
||||||
|
xmlns:vm="using:SourceGit.ViewModels"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="SourceGit.Views.FileContentViewer"
|
||||||
|
x:DataType="vm:FileContent">
|
||||||
|
<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>
|
||||||
|
</UserControl>
|
12
src/Views/FileContentViewer.axaml.cs
Normal file
12
src/Views/FileContentViewer.axaml.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace SourceGit.Views
|
||||||
|
{
|
||||||
|
public partial class FileContentViewer : UserControl
|
||||||
|
{
|
||||||
|
public FileContentViewer()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -133,26 +133,8 @@
|
||||||
<v:DiffView/>
|
<v:DiffView/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="vm:FileHistoriesRevisionFile">
|
<DataTemplate DataType="vm:FileContent">
|
||||||
<Border BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}">
|
<v:FileContentViewer />
|
||||||
<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>
|
</DataTemplate>
|
||||||
</ContentControl.DataTemplates>
|
</ContentControl.DataTemplates>
|
||||||
</ContentControl>
|
</ContentControl>
|
||||||
|
|
|
@ -113,7 +113,7 @@
|
||||||
<!-- Right: File Content Viewer -->
|
<!-- Right: 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}">
|
||||||
<v:RevisionFileContentViewer Content="{Binding ViewRevisionFileContent}"/>
|
<v:FileContentViewer DataContext="{Binding ViewRevisionFileContent}"/>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue