mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
Change the way to preview binary in CommitViewer
This commit is contained in:
parent
261b4d635c
commit
689b02cd61
3 changed files with 34 additions and 17 deletions
|
@ -190,19 +190,19 @@ namespace SourceGit.Git {
|
||||||
/// <param name="repo"></param>
|
/// <param name="repo"></param>
|
||||||
/// <param name="file"></param>
|
/// <param name="file"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public string GetTextFileContent(Repository repo, string file) {
|
public string GetTextFileContent(Repository repo, string file, out bool isBinary) {
|
||||||
var data = new List<string>();
|
var data = new List<string>();
|
||||||
var isBinary = false;
|
|
||||||
var count = 0;
|
var count = 0;
|
||||||
|
var binary = false;
|
||||||
|
|
||||||
var errs = repo.RunCommand($"show {SHA}:\"{file}\"", line => {
|
var errs = repo.RunCommand($"show {SHA}:\"{file}\"", line => {
|
||||||
if (isBinary) return;
|
if (binary) return;
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
if (data.Count >= 1000) return;
|
if (data.Count >= 1000) return;
|
||||||
|
|
||||||
if (line.IndexOf('\0') >= 0) {
|
if (line.IndexOf('\0') >= 0) {
|
||||||
isBinary = true;
|
binary = true;
|
||||||
data.Clear();
|
data.Clear();
|
||||||
data.Add("BINARY FILE PREVIEW NOT SUPPORTED!");
|
data.Add("BINARY FILE PREVIEW NOT SUPPORTED!");
|
||||||
return;
|
return;
|
||||||
|
@ -211,11 +211,13 @@ namespace SourceGit.Git {
|
||||||
data.Add(line);
|
data.Add(line);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isBinary && count > 1000) {
|
if (!binary && count > 1000) {
|
||||||
data.Add("...");
|
data.Add("...");
|
||||||
data.Add($"Total {count} lines. Hide {count-1000} lines.");
|
data.Add($"Total {count} lines. Hide {count-1000} lines.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isBinary = binary;
|
||||||
|
|
||||||
if (errs != null) App.RaiseError(errs);
|
if (errs != null) App.RaiseError(errs);
|
||||||
return string.Join("\n", data);
|
return string.Join("\n", data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,8 +392,10 @@
|
||||||
<GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent"/>
|
<GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent"/>
|
||||||
|
|
||||||
<Border Grid.Column="2" BorderThickness="1" Margin="2,0" BorderBrush="{StaticResource Brush.Border2}">
|
<Border Grid.Column="2" BorderThickness="1" Margin="2,0" BorderBrush="{StaticResource Brush.Border2}">
|
||||||
|
<Grid>
|
||||||
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
|
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
|
||||||
<TextBlock FontSize="10pt"
|
<TextBlock
|
||||||
|
FontSize="10pt"
|
||||||
FontFamily="Consolas"
|
FontFamily="Consolas"
|
||||||
Padding="8"
|
Padding="8"
|
||||||
Opacity="0.8"
|
Opacity="0.8"
|
||||||
|
@ -401,6 +403,12 @@
|
||||||
Foreground="{StaticResource Brush.FG}"
|
Foreground="{StaticResource Brush.FG}"
|
||||||
x:Name="filePreview"/>
|
x:Name="filePreview"/>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
|
|
||||||
|
<StackPanel x:Name="maskPreviewNotSupported" Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="Collapsed">
|
||||||
|
<Path Width="64" Height="64" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Info}" Fill="{StaticResource Brush.FG2}"/>
|
||||||
|
<Label Margin="0,16,0,0" Content="BINARY FILE DETECTED" FontFamily="Consolas" FontSize="18" FontWeight="UltraBold" HorizontalAlignment="Center" Foreground="{StaticResource Brush.FG2}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
|
@ -345,13 +345,20 @@ namespace SourceGit.UI {
|
||||||
|
|
||||||
private async void FileTreeItemSelected(object sender, RoutedPropertyChangedEventArgs<object> e) {
|
private async void FileTreeItemSelected(object sender, RoutedPropertyChangedEventArgs<object> e) {
|
||||||
filePreview.Text = "";
|
filePreview.Text = "";
|
||||||
|
maskPreviewNotSupported.Visibility = Visibility.Collapsed;
|
||||||
|
|
||||||
var node = e.NewValue as Node;
|
var node = e.NewValue as Node;
|
||||||
if (node == null || !node.IsFile) return;
|
if (node == null || !node.IsFile) return;
|
||||||
|
|
||||||
await Task.Run(() => {
|
await Task.Run(() => {
|
||||||
var data = commit.GetTextFileContent(repo, node.FilePath);
|
var isBinary = false;
|
||||||
|
var data = commit.GetTextFileContent(repo, node.FilePath, out isBinary);
|
||||||
|
|
||||||
|
if (isBinary) {
|
||||||
|
Dispatcher.Invoke(() => maskPreviewNotSupported.Visibility = Visibility.Visible);
|
||||||
|
} else {
|
||||||
Dispatcher.Invoke(() => filePreview.Text = data);
|
Dispatcher.Invoke(() => filePreview.Text = data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in a new issue