Skip to content

Commit

Permalink
Show/hide LineNumbers and Space/Tabs by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirkster99 committed Sep 4, 2020
1 parent 38a5481 commit e576f3c
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,55 @@

<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=VerticalSLideThumbForegroundBrushKey}"
ResourceId=VerticalSLideThumbForegroundBrushKey}"
Opacity="0.25"
Color="{DynamicResource {x:Static MLib_reskeys:ResourceKeys.ControlAccentColorKey}}" />

<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=EditorSelectionBrush}"
ResourceId=EditorSelectionBrush}"
options:Freeze="true"
Opacity="0.45"
Color="{DynamicResource {x:Static MLib_reskeys:ResourceKeys.ControlAccentColorKey}}" />

<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=EditorSelectionBorder}"
ResourceId=EditorSelectionBorder}"
options:Freeze="true"
Opacity="0.45"
Color="{DynamicResource {x:Static MLib_reskeys:ResourceKeys.ControlAccentColorKey}}" />

<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=SelectedFocusedCellBackgroundBrushKey}"
ResourceId=SelectedFocusedCellBackgroundBrushKey}"
options:Freeze="true"
Opacity="0.55"
Color="{DynamicResource {x:Static MLib_reskeys:ResourceKeys.ControlAccentColorKey}}" />

<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=SelectedCellBackgroundBrushKey}"
ResourceId=SelectedCellBackgroundBrushKey}"
options:Freeze="true"
Opacity="0.30"
Color="{DynamicResource {x:Static MLib_reskeys:ResourceKeys.ControlAccentColorKey}}" />

<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=SelectedFocusedCellBorderBrushKey}"
ResourceId=SelectedFocusedCellBorderBrushKey}"
options:Freeze="true"
Opacity="0.55"
Color="{DynamicResource {x:Static MLib_reskeys:ResourceKeys.ControlAccentColorKey}}" />

<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=SelectedCellBorderBrushKey}"
ResourceId=SelectedCellBorderBrushKey}"
options:Freeze="true"
Opacity="0.30"
Color="{DynamicResource {x:Static MLib_reskeys:ResourceKeys.ControlAccentColorKey}}" />

<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=EditorCurrentLineBorderBrushKey}"
ResourceId=EditorCurrentLineBorderBrushKey}"
options:Freeze="true"
Opacity=".6"
Color="{DynamicResource {x:Static MLib_reskeys:ResourceKeys.ControlAccentColorKey}}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@

<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=ControlAccentBrushKey}"
ResourceId=ControlAccentBrushKey}"
options:Freeze="true"
Color="{DynamicResource {x:Static MLib_reskeys:ResourceKeys.ControlAccentColorKey}}" />

<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=ControlPopupBackgroundBrushKey}"
ResourceId=ControlPopupBackgroundBrushKey}"
options:Freeze="true"
Color="{DynamicResource {x:Static MLib_reskeys:ResourceKeys.ControlPopupBackgroundKey}}" />

<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=ControlItemBackgroundSelectedKey}"
ResourceId=ControlItemBackgroundSelectedKey}"
options:Freeze="true"
Color="{DynamicResource {x:Static MLib_reskeys:ResourceKeys.ControlAccentColorKey}}" />

<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=ControlItemBorderSelectedKey}"
ResourceId=ControlItemBorderSelectedKey}"
options:Freeze="true"
Color="{DynamicResource {x:Static MLib_reskeys:ResourceKeys.ControlAccentColorKey}}" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
using System.Windows.Media;
using Utils;

/// <summary>
/// Margin showing line numbers.
/// </summary>
/// <summary>Margin showing line numbers.</summary>
internal class CustomLineNumberMargin : LineNumberMargin, IWeakEventListener
{
#region fields
Expand Down
4 changes: 2 additions & 2 deletions source/AehnlichViewLib/Controls/DiffTextView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
Line="{Binding LeftDiffView.Line, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
LineDiffDataProvider="{Binding LeftDiffView, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
Options="{TemplateBinding DiffViewOptions}"
ShowLineNumbers="{Binding LeftDiffView.ShowLineNumbers, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
ShowCustomLineNumbers="{Binding LeftDiffView.ShowLineNumbers, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
SyntaxHighlighting="{Binding LeftDiffView.HighlightingDefinition, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
TextBoxController="{Binding LeftDiffView.TxtControl, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
ViewMode="{Binding LeftDiffView.CurrentViewMode, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
Expand All @@ -84,7 +84,7 @@
Line="{Binding RightDiffView.Line, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
LineDiffDataProvider="{Binding RightDiffView, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
Options="{TemplateBinding DiffViewOptions}"
ShowLineNumbers="{Binding RightDiffView.ShowLineNumbers, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
ShowCustomLineNumbers="{Binding RightDiffView.ShowLineNumbers, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
SyntaxHighlighting="{Binding RightDiffView.HighlightingDefinition, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
TextBoxController="{Binding RightDiffView.TxtControl, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
ViewMode="{Binding RightDiffView.CurrentViewMode, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:DiffTextView}}}"
Expand Down
29 changes: 4 additions & 25 deletions source/AehnlichViewLib/Controls/DiffView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,9 @@
Grid.Column="0"
Background="Transparent">
<Grid.ColumnDefinitions>
<!-- ColumnDefinition Width="Auto" / -->
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<!--unit:UnitCombobox DataContext="{Binding SizeUnitLabel}"
FontSize="10"
Height="{Binding ElementName=PART_HorizontalScrollBar, Path=ActualHeight}"
ItemsSource="{Binding SelectedItem.DefaultValues}"
ToolTip="{Binding ValueTip}"
HorizontalAlignment="Stretch" VerticalAlignment="Center"
Grid.Column="0"
Margin="3,0"
Padding="0"
BorderThickness="1"
BorderBrush="Transparent"
IsEditable="True">
<unit:UnitCombobox.Text>
<Binding Path="StringValue" Mode="TwoWay" ValidatesOnDataErrors="True"/>
</unit:UnitCombobox.Text>
</unit:UnitCombobox-->

<ScrollBar
Name="PART_HorizontalScrollBar"
Grid.Column="1"
Expand All @@ -162,13 +144,6 @@
Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
Value="{TemplateBinding HorizontalOffset}" />
</Grid>
<!-- Using DialogBackgroundBrush since Editor can use a WPF Theme independent background color -->
<!--DockPanel Grid.Column="1" Grid.Row="1"
LastChildFill="false"
Background="White">
<Rectangle Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Width="1" Fill="White" DockPanel.Dock="Left" />
<Rectangle Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Height="1" Fill="White" DockPanel.Dock="Top" />
</DockPanel-->
</Grid>
</Border>
</ControlTemplate>
Expand All @@ -187,6 +162,10 @@
<Setter.Value>
<ContextMenu>

<MenuItem Header="View">
<MenuItem Command="{Binding PlacementTarget.DataContext.DiffCtrl.ToggleShowLineNumbersCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}" Header="Show Line Numbers" />
</MenuItem>

<MenuItem Command="Cut" Header="Cut">
<MenuItem.Icon>
<Image
Expand Down
107 changes: 76 additions & 31 deletions source/AehnlichViewLib/Controls/DiffView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@
public partial class DiffView : TextEditor
{
#region fields
/// <summary>
/// Implements the backing store of the <see cref="ItemsSource"/> dependency property.
/// </summary>
/// <summary>Implements the backing store of the <see cref="ItemsSource"/> dependency property.</summary>
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(IEnumerable),
typeof(DiffView), new PropertyMetadata(new PropertyChangedCallback(ItemsSourceChanged)));

/// <summary>
/// Implements the backing store of the <see cref="LineDiffDataProvider"/> dependency property.
/// </summary>
/// <summary>Implements the backing store of the <see cref="LineDiffDataProvider"/> dependency property.</summary>
public static readonly DependencyProperty LineDiffDataProviderProperty =
DependencyProperty.Register("LineDiffDataProvider", typeof(ILineDiffProvider),
typeof(DiffView), new PropertyMetadata(null, OnLineDiffDataProviderChanged));
Expand Down Expand Up @@ -116,9 +112,7 @@ public partial class DiffView : TextEditor
typeof(DiffView), new UIPropertyMetadata(1));
#endregion CaretPosition

/// <summary>
/// Implements the backing store of the <see cref="ActivationTimeStamp"/> dependency property.
/// </summary>
/// <summary>Implements the backing store of the <see cref="ActivationTimeStamp"/> dependency property.</summary>
public static readonly DependencyProperty ActivationTimeStampProperty =
DependencyProperty.Register("ActivationTimeStamp", typeof(DateTime),
typeof(DiffView), new PropertyMetadata(default(DateTime)));
Expand All @@ -142,20 +136,43 @@ public partial class DiffView : TextEditor
typeof(DiffView), new PropertyMetadata(2.0d));
#endregion EditorCurrentLine Highlighting Colors

public DisplayMode ViewMode
{
get { return (DisplayMode)GetValue(ViewModeProperty); }
set { SetValue(ViewModeProperty, value); }
}

// Using a DependencyProperty as the backing store for ViewMode. This enables animation, styling, binding, etc...
/// <summary>Implements the backing store of the <see cref="ViewMode"/> dependency property.</summary>
public static readonly DependencyProperty ViewModeProperty =
DependencyProperty.Register("ViewMode", typeof(DisplayMode)
, typeof(DiffView), new PropertyMetadata(DisplayMode.Comparing));

/// <summary>Gets/sets whether the control should show custom line numbers (including gaps) via binding with <see cref="ItemsSource"/> and <see cref="IDiffLineInfo"/> or not.</summary>
public bool ShowCustomLineNumbers
{
get { return (bool)GetValue(ShowCustomLineNumbersProperty); }
set { SetValue(ShowCustomLineNumbersProperty, value); }
}

/// <summary>Implements the backing store of the <see cref="ShowCustomLineNumbers"/> dependency property.</summary>
public static readonly DependencyProperty ShowCustomLineNumbersProperty =
DependencyProperty.Register("ShowCustomLineNumbers",
typeof(bool),
typeof(DiffView), new PropertyMetadata(true, OnShowCustomLineNumbers));

private static void OnShowCustomLineNumbers(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ctrl = d as DiffView;

ctrl.OnShowCustomLineNumbers(e);
}

private void OnShowCustomLineNumbers(DependencyPropertyChangedEventArgs e)
{
if ((bool)e.OldValue != (bool)e.NewValue)
{
DisplayCustomLineNumbers((bool)e.NewValue);
}
}

private INotifyCollectionChanged _observeableDiffContext;
private DiffLineBackgroundRenderer _DiffBackgroundRenderer;
private IVisualLineTransformer _Colorizer;
private bool? _currentShowCustomLineNumbers = null;
#endregion fields

#region ctors
Expand Down Expand Up @@ -366,6 +383,14 @@ public double EditorCurrentLineBorderThickness
set { SetValue(EditorCurrentLineBorderThicknessProperty, value); }
}
#endregion EditorCurrentLine Highlighting Colors

/// <summary>Gets/sets whether the current view supports editing or comparing.</summary>
public DisplayMode ViewMode
{
get { return (DisplayMode)GetValue(ViewModeProperty); }
set { SetValue(ViewModeProperty, value); }
}

#endregion properties

#region methods
Expand Down Expand Up @@ -492,21 +517,7 @@ private void OnLoaded(object obj, RoutedEventArgs args)
_DiffBackgroundRenderer = new DiffLineBackgroundRenderer(this);
this.TextArea.TextView.BackgroundRenderers.Add(_DiffBackgroundRenderer);

// Customize display of line numbers using real lines (shown with a number)
// and imaginary lines (shown without a number)
// Switch off default line handler in AvalonEdit
ShowLineNumbers = false;
this.TextArea.LeftMargins.Clear();
var leftMargins = this.TextArea.LeftMargins;

// Configure and insert custom line number margin indicator
LineNumberMargin lineNumbers = new CustomLineNumberMargin(this);
Line line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = this };
line.SetBinding(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.SetBinding(Control.ForegroundProperty, lineNumbersForeground);
DisplayCustomLineNumbers(ShowCustomLineNumbers);

// Attach more event handlers
this.GotFocus += DiffView_GotFocus;
Expand All @@ -528,6 +539,40 @@ private void OnLoaded(object obj, RoutedEventArgs args)
}
}

/// <summary>Updates the Custom Display of LineNumbers (inlcuding gaps) via binding through <see cref="ItemsSource"/></summary>
/// <param name="showCustomLineNumbers"></param>
private void DisplayCustomLineNumbers(bool showCustomLineNumbers)
{
// Check if current setup is different from request and return if this is already set
if (_currentShowCustomLineNumbers != null)
{
if (_currentShowCustomLineNumbers == showCustomLineNumbers)
return;
}

// Customize display of line numbers using real lines (shown with a number)
// and imaginary lines (shown without a number)
// Switch off default line handler in AvalonEdit
ShowLineNumbers = false;
this.TextArea.LeftMargins.Clear();

if (showCustomLineNumbers)
{
var leftMargins = this.TextArea.LeftMargins;

// Configure and insert custom line number margin indicator
LineNumberMargin lineNumbers = new CustomLineNumberMargin(this);
Line line = (Line)DottedLineMargin.Create();
leftMargins.Insert(0, lineNumbers);
leftMargins.Insert(1, line);
var lineNumbersForeground = new Binding("LineNumbersForeground") { Source = this };
line.SetBinding(Shape.StrokeProperty, lineNumbersForeground);
lineNumbers.SetBinding(Control.ForegroundProperty, lineNumbersForeground);
}

_currentShowCustomLineNumbers = showCustomLineNumbers;
}

/// <summary>
/// Unhock event handlers and save editor states (to be recovered later)
/// when the control is unloaded.
Expand Down
6 changes: 3 additions & 3 deletions source/AehnlichViewLib/Controls/GridStyle.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- DATAGRID -->
<Style
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=DefaultDataGridStyleKey}"
ResourceId=DefaultDataGridStyleKey}"
BasedOn="{StaticResource {x:Type DataGrid}}"
TargetType="{x:Type DataGrid}">

Expand Down Expand Up @@ -39,7 +39,7 @@

<Style
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=DefaultColumnHeaderGripperStyleKey}"
ResourceId=DefaultColumnHeaderGripperStyleKey}"
BasedOn="{StaticResource {x:Type Thumb}}"
TargetType="{x:Type Thumb}">
<Setter Property="Background" Value="Transparent" />
Expand All @@ -62,7 +62,7 @@

<Style
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type reskeys:ResourceKeys},
ResourceId=DefaultDataGridHeaderStyleKey}"
ResourceId=DefaultDataGridHeaderStyleKey}"
BasedOn="{StaticResource {x:Type DataGridColumnHeader}}"
TargetType="DataGridColumnHeader">
<Setter Property="VerticalContentAlignment" Value="Center" />
Expand Down
8 changes: 4 additions & 4 deletions source/AehnlichViewLib/Controls/Overview/RangeScrollbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@
Mode="OneWay"
Path="ViewportSize"
RelativeSource="{RelativeSource Mode=FindAncestor,
AncestorType={x:Type local:RangeScrollbar}}"
AncestorType={x:Type local:RangeScrollbar}}"
UpdateSourceTrigger="PropertyChanged" />
<Binding
Mode="OneWay"
Path="DocumentSize"
RelativeSource="{RelativeSource Mode=FindAncestor,
AncestorType={x:Type local:RangeScrollbar}}"
AncestorType={x:Type local:RangeScrollbar}}"
UpdateSourceTrigger="PropertyChanged" />
</MultiBinding>
</Thumb.Visibility>
Expand Down Expand Up @@ -531,13 +531,13 @@
Mode="OneWay"
Path="ViewportSize"
RelativeSource="{RelativeSource Mode=FindAncestor,
AncestorType={x:Type local:RangeScrollbar}}"
AncestorType={x:Type local:RangeScrollbar}}"
UpdateSourceTrigger="PropertyChanged" />
<Binding
Mode="OneWay"
Path="DocumentSize"
RelativeSource="{RelativeSource Mode=FindAncestor,
AncestorType={x:Type local:RangeScrollbar}}"
AncestorType={x:Type local:RangeScrollbar}}"
UpdateSourceTrigger="PropertyChanged" />
</MultiBinding>
</Thumb.Visibility>
Expand Down
Loading

0 comments on commit e576f3c

Please sign in to comment.