From 6c855242d9ba489004643e717f48b0ea344f401a Mon Sep 17 00:00:00 2001 From: Philippe Miossec Date: Sat, 23 Mar 2019 22:11:36 +0100 Subject: [PATCH] Fix fileviewer ShowLineNumbers setting that was not honored and thus line numbers were displayed in blame even if explicitly set to be hidden That was the case since 456ea65d7143e1555455c44d8bd385169f2feaf4 See https://github.com/gitextensions/gitextensions/commit/456ea65d7143e1555455c44d8bd385169f2feaf4#diff-555178f3fd75ec9d4f3aebcef1f48882R128 The strategy adopted is to not set the value by default so the setting is determined by the content (actual behavior) but if explicitly set, the value is used. Add padding and color it on white to add a margin when line numbers are hidden --- GitUI/Editor/FileViewer.Designer.cs | 1 - GitUI/Editor/FileViewer.cs | 4 ++-- GitUI/Editor/FileViewerInternal.cs | 27 +++++++++++++++++++++------ GitUI/Editor/IFileViewer.cs | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/GitUI/Editor/FileViewer.Designer.cs b/GitUI/Editor/FileViewer.Designer.cs index b1c7aabf8a1..cadf009b8bf 100644 --- a/GitUI/Editor/FileViewer.Designer.cs +++ b/GitUI/Editor/FileViewer.Designer.cs @@ -394,7 +394,6 @@ private void InitializeComponent() this.internalFileViewer.Name = "internalFileViewer"; this.internalFileViewer.VScrollPosition = 0; this.internalFileViewer.ShowEOLMarkers = false; - this.internalFileViewer.ShowLineNumbers = true; this.internalFileViewer.ShowSpaces = false; this.internalFileViewer.ShowTabs = false; this.internalFileViewer.Size = new System.Drawing.Size(757, 518); diff --git a/GitUI/Editor/FileViewer.cs b/GitUI/Editor/FileViewer.cs index 9a36c8a6233..db8bd8c7ca6 100644 --- a/GitUI/Editor/FileViewer.cs +++ b/GitUI/Editor/FileViewer.cs @@ -191,10 +191,10 @@ public bool IsReadOnly set => internalFileViewer.IsReadOnly = value; } - [DefaultValue(true)] + [DefaultValue(null)] [Description("If true line numbers are shown in the textarea")] [Category("Appearance")] - public bool ShowLineNumbers + public bool? ShowLineNumbers { get => internalFileViewer.ShowLineNumbers; set => internalFileViewer.ShowLineNumbers = value; diff --git a/GitUI/Editor/FileViewerInternal.cs b/GitUI/Editor/FileViewerInternal.cs index cdd31d15ec2..aa9628d164a 100644 --- a/GitUI/Editor/FileViewerInternal.cs +++ b/GitUI/Editor/FileViewerInternal.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using GitCommands; +using GitExtUtils.GitUI; using GitUI.Editor.Diff; using ICSharpCode.TextEditor; using ICSharpCode.TextEditor.Document; @@ -104,11 +105,7 @@ public string GetText() return TextEditor.Text; } - public bool ShowLineNumbers - { - get => TextEditor.ShowLineNumbers; - set => TextEditor.ShowLineNumbers = value; - } + public bool? ShowLineNumbers { get; set; } public void SetText(string text, Action openWithDifftool, bool isDiff = false) { @@ -137,12 +134,30 @@ public void SetText(string text, Action openWithDifftool, bool isDiff = false) // important to set after the text was changed // otherwise the may be rendering artifacts as noted in #5568 - TextEditor.ShowLineNumbers = !isDiff; + TextEditor.ShowLineNumbers = ShowLineNumbers ?? !isDiff; + if (ShowLineNumbers.HasValue && !ShowLineNumbers.Value) + { + Padding = new Padding(DpiUtil.Scale(5), Padding.Top, Padding.Right, Padding.Bottom); + } + TextEditor.Refresh(); _currentViewPositionCache.Restore(isDiff); } + private static readonly SolidBrush PaddingBrush = new SolidBrush(Color.White); + protected override void OnPaintBackground(PaintEventArgs e) + { + if (ShowLineNumbers.HasValue && !ShowLineNumbers.Value) + { + e.Graphics.FillRectangle(PaddingBrush, e.ClipRectangle); + } + else + { + base.OnPaintBackground(e); + } + } + public void SetHighlighting(string syntax) { TextEditor.SetHighlighting(syntax); diff --git a/GitUI/Editor/IFileViewer.cs b/GitUI/Editor/IFileViewer.cs index dc80039b78f..13ef8452451 100644 --- a/GitUI/Editor/IFileViewer.cs +++ b/GitUI/Editor/IFileViewer.cs @@ -47,7 +47,7 @@ public interface IFileViewer Action OpenWithDifftool { get; } int VScrollPosition { get; set; } - bool ShowLineNumbers { get; set; } + bool? ShowLineNumbers { get; set; } bool ShowEOLMarkers { get; set; } bool ShowSpaces { get; set; } bool ShowTabs { get; set; }