-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- v7.9
- v7.8.3
- v7.8.2
- v7.8.1
- v7.8
- v7.7.3
- v7.7.2
- v7.7.1
- v7.7
- v7.6
- v7.5
- v7.4
- v7.3
- v7.2
- v7.1
- v7.0
- v6.6
- v6.5.3
- v6.5.2
- v6.5.1
- v6.5
- v6.4
- v6.3.1
- v6.3
- v6.2
- v6.1
- v6.0
- v5.13
- v5.13-beta
- v5.12.2
- v5.12
- v5.11
- v5.10
- v5.9.1
- v5.9
- v5.8
- v5.7
- v5.6.1
- v5.6
- v5.5
- v5.4
- v5.3
- v5.2
- v5.1.1
- v5.1
- v5.0
- v4.6.2
- v4.6
- v4.5
- v4.4
- v4.3
- v4.2
- v4.1
- v4.0
- v3.9
- v3.8
- 5.12.1
Showing
10 changed files
with
548 additions
and
782 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,137 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Media; | ||
using AppHelpers; | ||
using Codist.Classifiers; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Classification; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using Microsoft.VisualStudio.Text.Tagging; | ||
|
||
namespace Codist.Margins | ||
{ | ||
/// <summary> | ||
/// Margin's canvas and visual definition including both size and content | ||
/// </summary> | ||
sealed class LineNumberMargin : Canvas, IWpfTextViewMargin | ||
sealed class LineNumberMargin : FrameworkElement, IDisposable, IWpfTextViewMargin | ||
{ | ||
/// <summary> | ||
/// Margin name. | ||
/// </summary> | ||
public const string MarginName = nameof(LineNumberMargin); | ||
const double LineNumberRenderPadding = -3; | ||
readonly IWpfTextView _TextView; | ||
readonly IEditorFormatMap _EditorFormatMap; | ||
readonly IVerticalScrollBar _ScrollBar; | ||
readonly TaggerResult _Tags; | ||
|
||
readonly LineNumberMarginElement _LineNumberMarginElement; | ||
readonly IWpfTextViewHost _TextView; | ||
bool isDisposed; | ||
static readonly SolidColorBrush LineNumberBrush = Brushes.DarkGray; | ||
static readonly Pen LineNumberPen = new Pen(LineNumberBrush, 1) { DashStyle = DashStyles.Dash }; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LineNumberMargin"/> class for a given <paramref name="textView"/>. | ||
/// </summary> | ||
/// <param name="textView">The <see cref="IWpfTextView"/> to attach the margin to.</param> | ||
public LineNumberMargin(IWpfTextViewHost textView, IVerticalScrollBar scrollBar, LineNumberMarginFactory container) { | ||
_LineNumberMarginElement = new LineNumberMarginElement(textView.TextView, scrollBar); | ||
textView.Closed += TextView_Closed; | ||
double _ScrollbarWidth; | ||
|
||
public LineNumberMargin(IWpfTextView textView, IVerticalScrollBar scrollBar) { | ||
_TextView = textView; | ||
|
||
IsHitTestVisible = false; | ||
|
||
_ScrollBar = scrollBar; | ||
_Tags = textView.Properties.GetOrCreateSingletonProperty(() => new TaggerResult()); | ||
_EditorFormatMap = ServicesHelper.Instance.EditorFormatMap.GetEditorFormatMap(textView); | ||
|
||
Width = 0; | ||
|
||
Visibility = Config.Instance.MarkerOptions.MatchFlags(MarkerOptions.LineNumber) ? Visibility.Visible : Visibility.Collapsed; | ||
Config.Updated += Config_Updated; | ||
_TextView.TextBuffer.Changed += TextView_TextBufferChanged; | ||
_ScrollBar.TrackSpanChanged += OnMappingChanged; | ||
_TextView.Closed += (s, args) => Dispose(); | ||
} | ||
|
||
public FrameworkElement VisualElement => this; | ||
public double MarginSize => ActualWidth; | ||
public bool Enabled => true; | ||
|
||
public double MarginSize => _LineNumberMarginElement.ActualWidth; | ||
public ITextViewMargin GetTextViewMargin(string marginName) { | ||
return string.Equals(marginName, MarginName, StringComparison.OrdinalIgnoreCase) ? this : null; | ||
} | ||
|
||
public FrameworkElement VisualElement => _LineNumberMarginElement; | ||
void Config_Updated(object sender, ConfigUpdatedEventArgs e) { | ||
if (e.UpdatedFeature.MatchFlags(Features.ScrollbarMarkers) == false) { | ||
return; | ||
} | ||
var setVisible = Config.Instance.MarkerOptions.MatchFlags(MarkerOptions.LineNumber); | ||
var visible = Visibility == Visibility.Visible; | ||
if (setVisible == false && visible) { | ||
Visibility = Visibility.Collapsed; | ||
_TextView.TextBuffer.Changed -= TextView_TextBufferChanged; | ||
_ScrollBar.TrackSpanChanged -= OnMappingChanged; | ||
InvalidateVisual(); | ||
} | ||
else if (setVisible && visible == false) { | ||
Visibility = Visibility.Visible; | ||
_TextView.TextBuffer.Changed += TextView_TextBufferChanged; | ||
_ScrollBar.TrackSpanChanged += OnMappingChanged; | ||
InvalidateVisual(); | ||
} | ||
} | ||
|
||
public void Dispose() { | ||
if (!isDisposed) { | ||
_TextView.Closed -= TextView_Closed; | ||
GC.SuppressFinalize(this); | ||
isDisposed = true; | ||
void TextView_TextBufferChanged(object sender, TextContentChangedEventArgs args) { | ||
if (args.Changes.Count == 0) { | ||
return; | ||
} | ||
InvalidateVisual(); | ||
} | ||
|
||
public ITextViewMargin GetTextViewMargin(string marginName) { | ||
return string.Equals(marginName, MarginName, StringComparison.OrdinalIgnoreCase) ? this : null; | ||
/// <summary> | ||
/// Handler for the scrollbar changing its coordinate mapping. | ||
/// </summary> | ||
void OnMappingChanged(object sender, EventArgs e) { | ||
InvalidateVisual(); | ||
} | ||
/// <summary> | ||
/// Override for the FrameworkElement's OnRender. When called, redraw all markers. | ||
/// </summary> | ||
/// <param name="drawingContext">The <see cref="DrawingContext"/> used to render the margin.</param> | ||
protected override void OnRender(DrawingContext drawingContext) { | ||
base.OnRender(drawingContext); | ||
if (_TextView.IsClosed) { | ||
return; | ||
} | ||
if (Config.Instance.MarkerOptions.MatchFlags(MarkerOptions.LineNumber)) { | ||
DrawLineNumbers(drawingContext); | ||
} | ||
} | ||
|
||
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) { | ||
base.OnRenderSizeChanged(sizeInfo); | ||
_ScrollbarWidth = (_ScrollBar as FrameworkElement).ActualWidth + LineNumberRenderPadding; | ||
} | ||
|
||
void TextView_Closed(object sender, EventArgs e) { | ||
_LineNumberMarginElement.Dispose(); | ||
void DrawLineNumbers(DrawingContext drawingContext) { | ||
var snapshot = _TextView.TextSnapshot; | ||
var lc = snapshot.LineCount; | ||
var step = lc < 500 ? 50 : lc < 2000 ? 100 : lc < 3000 ? 200 : lc < 5000 ? 500 : lc < 20000 ? 1000 : lc < 100000 ? 5000 : 10000; | ||
for (int i = step; i < lc; i += step) { | ||
var y = _ScrollBar.GetYCoordinateOfBufferPosition(new SnapshotPoint(snapshot, snapshot.GetLineFromLineNumber(i - 1).Start)); | ||
drawingContext.DrawLine(LineNumberPen, new Point(-100, y), new Point(100, y)); | ||
var t = WpfHelper.ToFormattedText(i.ToString(), 9, LineNumberBrush); | ||
drawingContext.DrawText(t, new Point(_ScrollbarWidth - t.Width, y)); | ||
} | ||
} | ||
|
||
#region IDisposable Support | ||
bool disposedValue = false; | ||
|
||
void Dispose(bool disposing) { | ||
if (!disposedValue) { | ||
if (disposing) { | ||
//_TextView.VisualElement.IsVisibleChanged -= OnViewOrMarginVisiblityChanged; | ||
Config.Updated -= Config_Updated; | ||
_TextView.TextBuffer.Changed -= TextView_TextBufferChanged; | ||
_ScrollBar.TrackSpanChanged += OnMappingChanged; | ||
} | ||
|
||
disposedValue = true; | ||
} | ||
} | ||
|
||
public void Dispose() { | ||
Dispose(true); | ||
} | ||
#endregion | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters