mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-15 23:54:58 +00:00
enhance: revision file viewer
- show current file path - add a toggle button to use global syntax highlighting setting (sometimes TextMateSharp will crash this app) Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
f003f67129
commit
ac55bed812
5 changed files with 71 additions and 17 deletions
|
@ -105,10 +105,16 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ViewRevisionFilePath
|
||||||
|
{
|
||||||
|
get => _viewRevisionFilePath;
|
||||||
|
private set => SetProperty(ref _viewRevisionFilePath, value);
|
||||||
|
}
|
||||||
|
|
||||||
public object ViewRevisionFileContent
|
public object ViewRevisionFileContent
|
||||||
{
|
{
|
||||||
get => _viewRevisionFileContent;
|
get => _viewRevisionFileContent;
|
||||||
set => SetProperty(ref _viewRevisionFileContent, value);
|
private set => SetProperty(ref _viewRevisionFileContent, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string RevisionFileSearchFilter
|
public string RevisionFileSearchFilter
|
||||||
|
@ -189,10 +195,13 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
if (file == null)
|
if (file == null)
|
||||||
{
|
{
|
||||||
|
ViewRevisionFilePath = string.Empty;
|
||||||
ViewRevisionFileContent = null;
|
ViewRevisionFileContent = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ViewRevisionFilePath = file.Path;
|
||||||
|
|
||||||
switch (file.Type)
|
switch (file.Type)
|
||||||
{
|
{
|
||||||
case Models.ObjectType.Blob:
|
case Models.ObjectType.Blob:
|
||||||
|
@ -893,6 +902,7 @@ namespace SourceGit.ViewModels
|
||||||
private List<Models.Change> _selectedChanges = null;
|
private List<Models.Change> _selectedChanges = null;
|
||||||
private string _searchChangeFilter = string.Empty;
|
private string _searchChangeFilter = string.Empty;
|
||||||
private DiffContext _diffContext = null;
|
private DiffContext _diffContext = null;
|
||||||
|
private string _viewRevisionFilePath = string.Empty;
|
||||||
private object _viewRevisionFileContent = null;
|
private object _viewRevisionFileContent = null;
|
||||||
private CancellationTokenSource _cancellationSource = null;
|
private CancellationTokenSource _cancellationSource = null;
|
||||||
private bool _requestingRevisionFiles = false;
|
private bool _requestingRevisionFiles = false;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
<v:RevisionTextFileView FontFamily="{DynamicResource Fonts.Monospace}"
|
<v:RevisionTextFileView FontFamily="{DynamicResource Fonts.Monospace}"
|
||||||
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
|
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
|
||||||
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
|
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
|
||||||
|
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSyntaxHighlighting}"
|
||||||
Background="{DynamicResource Brush.Contents}"/>
|
Background="{DynamicResource Brush.Contents}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,15 @@ namespace SourceGit.Views
|
||||||
set => SetValue(TabWidthProperty, value);
|
set => SetValue(TabWidthProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static readonly StyledProperty<bool> UseSyntaxHighlightingProperty =
|
||||||
|
AvaloniaProperty.Register<RevisionTextFileView, bool>(nameof(UseSyntaxHighlighting));
|
||||||
|
|
||||||
|
public bool UseSyntaxHighlighting
|
||||||
|
{
|
||||||
|
get => GetValue(UseSyntaxHighlightingProperty);
|
||||||
|
set => SetValue(UseSyntaxHighlightingProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
protected override Type StyleKeyOverride => typeof(TextEditor);
|
protected override Type StyleKeyOverride => typeof(TextEditor);
|
||||||
|
|
||||||
public RevisionTextFileView() : base(new TextArea(), new TextDocument())
|
public RevisionTextFileView() : base(new TextArea(), new TextDocument())
|
||||||
|
@ -72,8 +81,8 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
if (DataContext is Models.RevisionTextFile source)
|
if (DataContext is Models.RevisionTextFile source)
|
||||||
{
|
{
|
||||||
UpdateTextMate();
|
|
||||||
Text = source.Content;
|
Text = source.Content;
|
||||||
|
Models.TextMateHelper.SetGrammarByFileName(_textMate, source.FileName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -86,9 +95,9 @@ namespace SourceGit.Views
|
||||||
base.OnPropertyChanged(change);
|
base.OnPropertyChanged(change);
|
||||||
|
|
||||||
if (change.Property == TabWidthProperty)
|
if (change.Property == TabWidthProperty)
|
||||||
{
|
|
||||||
Options.IndentationSize = TabWidth;
|
Options.IndentationSize = TabWidth;
|
||||||
}
|
else if (change.Property == UseSyntaxHighlightingProperty)
|
||||||
|
UpdateTextMate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
||||||
|
@ -124,11 +133,22 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
private void UpdateTextMate()
|
private void UpdateTextMate()
|
||||||
{
|
{
|
||||||
if (_textMate == null)
|
if (UseSyntaxHighlighting)
|
||||||
_textMate = Models.TextMateHelper.CreateForEditor(this);
|
{
|
||||||
|
if (_textMate == null)
|
||||||
|
_textMate = Models.TextMateHelper.CreateForEditor(this);
|
||||||
|
|
||||||
if (DataContext is Models.RevisionTextFile file)
|
if (DataContext is Models.RevisionTextFile file)
|
||||||
Models.TextMateHelper.SetGrammarByFileName(_textMate, file.FileName);
|
Models.TextMateHelper.SetGrammarByFileName(_textMate, file.FileName);
|
||||||
|
}
|
||||||
|
else if (_textMate != null)
|
||||||
|
{
|
||||||
|
_textMate.Dispose();
|
||||||
|
_textMate = null;
|
||||||
|
GC.Collect();
|
||||||
|
|
||||||
|
TextArea.TextView.Redraw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TextMate.Installation _textMate = null;
|
private TextMate.Installation _textMate = null;
|
||||||
|
|
|
@ -313,16 +313,13 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
private void OnRowsSelectionChanged(object sender, SelectionChangedEventArgs _)
|
private void OnRowsSelectionChanged(object sender, SelectionChangedEventArgs _)
|
||||||
{
|
{
|
||||||
if (_disableSelectionChangingEvent)
|
if (_disableSelectionChangingEvent || DataContext is not ViewModels.CommitDetail vm)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (sender is ListBox { SelectedItem: ViewModels.RevisionFileTreeNode node } && DataContext is ViewModels.CommitDetail vm)
|
if (sender is ListBox { SelectedItem: ViewModels.RevisionFileTreeNode { IsFolder: false } node })
|
||||||
{
|
vm.ViewRevisionFile(node.Backend);
|
||||||
if (!node.IsFolder)
|
else
|
||||||
vm.ViewRevisionFile(node.Backend);
|
vm.ViewRevisionFile(null);
|
||||||
else
|
|
||||||
vm.ViewRevisionFile(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ViewModels.RevisionFileTreeNode> GetChildrenOfTreeNode(ViewModels.RevisionFileTreeNode node)
|
private List<ViewModels.RevisionFileTreeNode> GetChildrenOfTreeNode(ViewModels.RevisionFileTreeNode node)
|
||||||
|
|
|
@ -113,7 +113,33 @@
|
||||||
<!-- 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}"/>
|
<Grid RowDefinitions="Auto,*">
|
||||||
|
<Border Grid.Row="0"
|
||||||
|
Height="26"
|
||||||
|
BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="0,0,0,1"
|
||||||
|
IsVisible="{Binding ViewRevisionFilePath, Converter={x:Static StringConverters.IsNotNullOrEmpty}}">
|
||||||
|
<Grid ColumnDefinitions="Auto,*,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 ViewRevisionFilePath}"
|
||||||
|
FontSize="11"
|
||||||
|
TextTrimming="CharacterEllipsis"/>
|
||||||
|
|
||||||
|
<ToggleButton Grid.Column="2"
|
||||||
|
Classes="line_path"
|
||||||
|
Width="28"
|
||||||
|
Background="Transparent"
|
||||||
|
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSyntaxHighlighting, Mode=TwoWay}"
|
||||||
|
ToolTip.Tip="{DynamicResource Text.Diff.SyntaxHighlight}">
|
||||||
|
<Path Width="13" Height="13" Data="{StaticResource Icons.SyntaxHighlight}" Margin="0,3,0,0"/>
|
||||||
|
</ToggleButton>
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<v:RevisionFileContentViewer Grid.Row="1" Content="{Binding ViewRevisionFileContent}"/>
|
||||||
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue