Skip to content

Commit

Permalink
Fix fileviewer ShowLineNumbers setting that was not honored
Browse files Browse the repository at this point in the history
and thus line numbers were displayed in blame even if explicitly set to be hidden

That was the case since 456ea65

See 456ea65#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
  • Loading branch information
pmiossec committed Mar 30, 2019
1 parent 9a7b05e commit 6c85524
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
1 change: 0 additions & 1 deletion GitUI/Editor/FileViewer.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions GitUI/Editor/FileViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 21 additions & 6 deletions GitUI/Editor/FileViewerInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion GitUI/Editor/IFileViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 6c85524

Please sign in to comment.