mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-15 07:35:04 +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
|
||||
{
|
||||
get => _viewRevisionFileContent;
|
||||
set => SetProperty(ref _viewRevisionFileContent, value);
|
||||
private set => SetProperty(ref _viewRevisionFileContent, value);
|
||||
}
|
||||
|
||||
public string RevisionFileSearchFilter
|
||||
|
@ -189,10 +195,13 @@ namespace SourceGit.ViewModels
|
|||
{
|
||||
if (file == null)
|
||||
{
|
||||
ViewRevisionFilePath = string.Empty;
|
||||
ViewRevisionFileContent = null;
|
||||
return;
|
||||
}
|
||||
|
||||
ViewRevisionFilePath = file.Path;
|
||||
|
||||
switch (file.Type)
|
||||
{
|
||||
case Models.ObjectType.Blob:
|
||||
|
@ -893,6 +902,7 @@ namespace SourceGit.ViewModels
|
|||
private List<Models.Change> _selectedChanges = null;
|
||||
private string _searchChangeFilter = string.Empty;
|
||||
private DiffContext _diffContext = null;
|
||||
private string _viewRevisionFilePath = string.Empty;
|
||||
private object _viewRevisionFileContent = null;
|
||||
private CancellationTokenSource _cancellationSource = null;
|
||||
private bool _requestingRevisionFiles = false;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
<v:RevisionTextFileView FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
|
||||
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
|
||||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseSyntaxHighlighting}"
|
||||
Background="{DynamicResource Brush.Contents}"/>
|
||||
</DataTemplate>
|
||||
|
||||
|
|
|
@ -24,6 +24,15 @@ namespace SourceGit.Views
|
|||
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);
|
||||
|
||||
public RevisionTextFileView() : base(new TextArea(), new TextDocument())
|
||||
|
@ -72,8 +81,8 @@ namespace SourceGit.Views
|
|||
|
||||
if (DataContext is Models.RevisionTextFile source)
|
||||
{
|
||||
UpdateTextMate();
|
||||
Text = source.Content;
|
||||
Models.TextMateHelper.SetGrammarByFileName(_textMate, source.FileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -86,9 +95,9 @@ namespace SourceGit.Views
|
|||
base.OnPropertyChanged(change);
|
||||
|
||||
if (change.Property == TabWidthProperty)
|
||||
{
|
||||
Options.IndentationSize = TabWidth;
|
||||
}
|
||||
else if (change.Property == UseSyntaxHighlightingProperty)
|
||||
UpdateTextMate();
|
||||
}
|
||||
|
||||
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
||||
|
@ -124,11 +133,22 @@ namespace SourceGit.Views
|
|||
|
||||
private void UpdateTextMate()
|
||||
{
|
||||
if (_textMate == null)
|
||||
_textMate = Models.TextMateHelper.CreateForEditor(this);
|
||||
if (UseSyntaxHighlighting)
|
||||
{
|
||||
if (_textMate == null)
|
||||
_textMate = Models.TextMateHelper.CreateForEditor(this);
|
||||
|
||||
if (DataContext is Models.RevisionTextFile file)
|
||||
Models.TextMateHelper.SetGrammarByFileName(_textMate, file.FileName);
|
||||
if (DataContext is Models.RevisionTextFile file)
|
||||
Models.TextMateHelper.SetGrammarByFileName(_textMate, file.FileName);
|
||||
}
|
||||
else if (_textMate != null)
|
||||
{
|
||||
_textMate.Dispose();
|
||||
_textMate = null;
|
||||
GC.Collect();
|
||||
|
||||
TextArea.TextView.Redraw();
|
||||
}
|
||||
}
|
||||
|
||||
private TextMate.Installation _textMate = null;
|
||||
|
|
|
@ -313,16 +313,13 @@ namespace SourceGit.Views
|
|||
|
||||
private void OnRowsSelectionChanged(object sender, SelectionChangedEventArgs _)
|
||||
{
|
||||
if (_disableSelectionChangingEvent)
|
||||
if (_disableSelectionChangingEvent || DataContext is not ViewModels.CommitDetail vm)
|
||||
return;
|
||||
|
||||
if (sender is ListBox { SelectedItem: ViewModels.RevisionFileTreeNode node } && DataContext is ViewModels.CommitDetail vm)
|
||||
{
|
||||
if (!node.IsFolder)
|
||||
vm.ViewRevisionFile(node.Backend);
|
||||
else
|
||||
vm.ViewRevisionFile(null);
|
||||
}
|
||||
if (sender is ListBox { SelectedItem: ViewModels.RevisionFileTreeNode { IsFolder: false } node })
|
||||
vm.ViewRevisionFile(node.Backend);
|
||||
else
|
||||
vm.ViewRevisionFile(null);
|
||||
}
|
||||
|
||||
private List<ViewModels.RevisionFileTreeNode> GetChildrenOfTreeNode(ViewModels.RevisionFileTreeNode node)
|
||||
|
|
|
@ -113,7 +113,33 @@
|
|||
<!-- Right: File Content Viewer -->
|
||||
<Grid Grid.Column="2">
|
||||
<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>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue