mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
optimize<Blame>: using ItemsControl instead of TextBox to show line numbers
This commit is contained in:
parent
b97d5e608d
commit
cad64f6352
2 changed files with 48 additions and 25 deletions
|
@ -110,30 +110,49 @@
|
|||
<Border Grid.Row="2" BorderThickness="1" BorderBrush="{StaticResource Brush.Border2}" ClipToBounds="True">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="4"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="4"/>
|
||||
<ColumnDefinition Width="1"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBox
|
||||
x:Name="lineNumber"
|
||||
Grid.Column="0"
|
||||
AcceptsReturn="True"
|
||||
AcceptsTab="True"
|
||||
BorderThickness="0"
|
||||
Background="Transparent"
|
||||
IsReadOnly="True"
|
||||
Margin="4,0,4,0"
|
||||
FontSize="13"
|
||||
HorizontalContentAlignment="Right"
|
||||
VerticalAlignment="Stretch"
|
||||
FontFamily="Consolas"/>
|
||||
<ItemsControl
|
||||
Grid.Column="1"
|
||||
x:Name="lineNumber"
|
||||
Padding="0"
|
||||
Margin="0"
|
||||
BorderThickness="0"
|
||||
Background="Transparent"
|
||||
VirtualizingPanel.ScrollUnit="Item"
|
||||
VirtualizingPanel.IsVirtualizing="True"
|
||||
VirtualizingPanel.VirtualizationMode="Recycling">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel Orientation="Vertical"/>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
|
||||
<Rectangle Grid.Column="1" Width="1" Fill="{StaticResource Brush.Border2}"/>
|
||||
<ItemsControl.Template>
|
||||
<ControlTemplate TargetType="{x:Type ItemsControl}">
|
||||
<ScrollViewer CanContentScroll="True" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled">
|
||||
<ItemsPresenter/>
|
||||
</ScrollViewer>
|
||||
</ControlTemplate>
|
||||
</ItemsControl.Template>
|
||||
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding .}" Padding="0" Margin="0" FontFamily="Consolas" FontSize="13" HorizontalAlignment="Right" VerticalAlignment="Center" Foreground="{StaticResource Brush.FG}"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<Rectangle Grid.Column="3" Width="1" Fill="{StaticResource Brush.Border2}"/>
|
||||
|
||||
<RichTextBox
|
||||
x:Name="content"
|
||||
Grid.Column="2"
|
||||
Grid.Column="4"
|
||||
AcceptsReturn="True"
|
||||
AcceptsTab="True"
|
||||
IsReadOnly="True"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
@ -56,7 +55,7 @@ namespace SourceGit.UI {
|
|||
content.Document.Blocks.Clear();
|
||||
|
||||
if (blame.IsBinary) {
|
||||
lineNumber.Text = "";
|
||||
lineNumber.ItemsSource = null;
|
||||
|
||||
Paragraph p = new Paragraph(new Run("BINARY FILE BLAME NOT SUPPORTED!!!"));
|
||||
p.Margin = new Thickness(0);
|
||||
|
@ -68,9 +67,14 @@ namespace SourceGit.UI {
|
|||
|
||||
content.Document.Blocks.Add(p);
|
||||
} else {
|
||||
var numbers = new StringBuilder();
|
||||
for (int i = 0; i < blame.LineCount; i++) numbers.AppendLine(i.ToString());
|
||||
lineNumber.Text = numbers.ToString();
|
||||
List<string> numbers = new List<string>();
|
||||
for (int i = 0; i < blame.LineCount; i++) numbers.Add(i.ToString());
|
||||
lineNumber.ItemsSource = numbers;
|
||||
|
||||
var fg = FindResource("Brush.FG") as SolidColorBrush;
|
||||
var tf = new Typeface(content.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
|
||||
var ns = new NumberSubstitution();
|
||||
var mp = new Thickness(0);
|
||||
|
||||
for (int i = 0; i < blame.Blocks.Count; i++) {
|
||||
var frag = blame.Blocks[i];
|
||||
|
@ -78,11 +82,11 @@ namespace SourceGit.UI {
|
|||
|
||||
Paragraph p = new Paragraph(new Run(frag.Content));
|
||||
p.DataContext = frag;
|
||||
p.Margin = new Thickness(0);
|
||||
p.Padding = new Thickness(0);
|
||||
p.Margin = mp;
|
||||
p.Padding = mp;
|
||||
p.LineHeight = 1;
|
||||
p.Background = BG[i % 2];
|
||||
p.Foreground = FindResource("Brush.FG") as SolidColorBrush;
|
||||
p.Foreground = fg;
|
||||
p.FontStyle = FontStyles.Normal;
|
||||
p.ContextMenuOpening += (sender, ev) => {
|
||||
if (!content.Selection.IsEmpty) return;
|
||||
|
@ -114,10 +118,10 @@ namespace SourceGit.UI {
|
|||
frag.Content,
|
||||
CultureInfo.CurrentUICulture,
|
||||
FlowDirection.LeftToRight,
|
||||
new Typeface(content.FontFamily, p.FontStyle, p.FontWeight, p.FontStretch),
|
||||
tf,
|
||||
content.FontSize,
|
||||
Brushes.Black,
|
||||
new NumberSubstitution(),
|
||||
ns,
|
||||
TextFormattingMode.Ideal);
|
||||
if (minWidth < formatter.Width) {
|
||||
content.Document.PageWidth = formatter.Width + 16;
|
||||
|
|
Loading…
Reference in a new issue