From 4b2e551cd2671fd565f4481e94f590b1c61a4194 Mon Sep 17 00:00:00 2001 From: Maximilian Bachmeier Date: Fri, 8 Jun 2018 12:24:35 +0200 Subject: [PATCH] Add line numbers This feature can be turned on and off in the settings. --- .../TailBlazer.Domain/Formatting/GeneralOptions.cs | 4 +++- .../Formatting/GeneralOptionsConverter.cs | 7 +++++-- Source/TailBlazer.Fixtures/SettingsConversion.cs | 2 +- Source/TailBlazer/Themes/Lines.xaml | 12 ++++++++++-- .../Views/Options/GeneralOptionsView.xaml | 10 +++++++++- .../Views/Options/GeneralOptionsViewModel.cs | 11 +++++++++-- .../TailBlazer/Views/Tail/GeneralOptionBindings.cs | 8 +++++++- Source/TailBlazer/Views/Tail/LineProxy.cs | 13 +++++++++---- 8 files changed, 53 insertions(+), 14 deletions(-) diff --git a/Source/TailBlazer.Domain/Formatting/GeneralOptions.cs b/Source/TailBlazer.Domain/Formatting/GeneralOptions.cs index df83ea19..a05087be 100644 --- a/Source/TailBlazer.Domain/Formatting/GeneralOptions.cs +++ b/Source/TailBlazer.Domain/Formatting/GeneralOptions.cs @@ -8,8 +8,9 @@ public class GeneralOptions public double Scale { get; } public int Rating { get; } public bool OpenRecentOnStartup { get; } + public bool ShowLineNumbers { get; } - public GeneralOptions(Theme theme, bool highlightTail, double highlightTailDuration, double scale, int rating, bool openRecentOnStartup) + public GeneralOptions(Theme theme, bool highlightTail, double highlightTailDuration, double scale, int rating, bool openRecentOnStartup, bool showLineNumbers) { Theme = theme; HighlightTail = highlightTail; @@ -17,6 +18,7 @@ public GeneralOptions(Theme theme, bool highlightTail, double highlightTailDurat Scale = scale; Rating = rating; OpenRecentOnStartup = openRecentOnStartup; + ShowLineNumbers = showLineNumbers; } } diff --git a/Source/TailBlazer.Domain/Formatting/GeneralOptionsConverter.cs b/Source/TailBlazer.Domain/Formatting/GeneralOptionsConverter.cs index 8bcc1f94..c4102667 100644 --- a/Source/TailBlazer.Domain/Formatting/GeneralOptionsConverter.cs +++ b/Source/TailBlazer.Domain/Formatting/GeneralOptionsConverter.cs @@ -16,6 +16,7 @@ private static class Structure public const string Scale = "Scale"; public const string Rating = "FrameRate"; public const string OpenRecentOnStartup = "OpenRecentOnStartup"; + public const string ShowLineNumbers = "ShowLineNumbers"; } public GeneralOptions Convert(State state) @@ -31,8 +32,9 @@ public GeneralOptions Convert(State state) var scale = root.ElementOrThrow(Structure.Scale).ParseDouble().ValueOr(()=>defaults.Scale); var frameRate = root.OptionalElement(Structure.Rating).ConvertOr(rate=>rate.ParseInt().Value, () => defaults.Rating); var openRecent = root.ElementOrThrow(Structure.OpenRecentOnStartup).ParseBool().ValueOr(() => defaults.OpenRecentOnStartup); + var showLineNumbers = root.OptionalElement(Structure.ShowLineNumbers).ConvertOr(x => x.ParseBool().Value, () => defaults.ShowLineNumbers); - return new GeneralOptions(theme,highlight, duration,scale, frameRate, openRecent); + return new GeneralOptions(theme,highlight, duration,scale, frameRate, openRecent, showLineNumbers); } public State Convert(GeneralOptions options) @@ -44,6 +46,7 @@ public State Convert(GeneralOptions options) root.Add(new XElement(Structure.Scale, options.Scale)); root.Add(new XElement(Structure.Rating, options.Rating)); root.Add(new XElement(Structure.OpenRecentOnStartup, options.OpenRecentOnStartup)); + root.Add(new XElement(Structure.ShowLineNumbers, options.ShowLineNumbers)); var doc = new XDocument(root); var value= doc.ToString(); return new State(1, value); @@ -51,7 +54,7 @@ public State Convert(GeneralOptions options) public GeneralOptions GetDefaultValue() { - return new GeneralOptions(Theme.Light, true, 5, 100, 5, true); + return new GeneralOptions(Theme.Light, true, 5, 100, 5, true, false); } } } \ No newline at end of file diff --git a/Source/TailBlazer.Fixtures/SettingsConversion.cs b/Source/TailBlazer.Fixtures/SettingsConversion.cs index b91f4766..e15905dd 100644 --- a/Source/TailBlazer.Fixtures/SettingsConversion.cs +++ b/Source/TailBlazer.Fixtures/SettingsConversion.cs @@ -61,7 +61,7 @@ private void SerializeAndDeserializeWithCulture(string cultureName) { Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureName); - var original = new GeneralOptions(Theme.Dark, false,0.5, 125,5, true); + var original = new GeneralOptions(Theme.Dark, false,0.5, 125,5, true, false); var converter = new GeneralOptionsConverter(); var state = converter.Convert(original); var restored = converter.Convert(state); diff --git a/Source/TailBlazer/Themes/Lines.xaml b/Source/TailBlazer/Themes/Lines.xaml index 0e464444..bf3f2406 100644 --- a/Source/TailBlazer/Themes/Lines.xaml +++ b/Source/TailBlazer/Themes/Lines.xaml @@ -19,7 +19,7 @@ - + @@ -103,7 +103,15 @@ - + + + - + + @@ -83,6 +84,13 @@ VerticalAlignment="Center" Margin="4" IsChecked="{Binding OpenRecentOnStartup}" /> + + Show Line Numbers? + + setting) { @@ -35,6 +35,7 @@ public GeneralOptionsViewModel(ISetting setting) Scale = options.Scale; Rating = options.Rating; OpenRecentOnStartup = options.OpenRecentOnStartup; + ShowLineNumbers = options.ShowLineNumbers; }); RequiresRestart = setting.Value.Select(options => options.Rating) @@ -50,7 +51,7 @@ public GeneralOptionsViewModel(ISetting setting) var writter = this.WhenAnyPropertyChanged() .Subscribe(vm => { - setting.Write(new GeneralOptions(UseDarkTheme ? Theme.Dark : Theme.Light, HighlightTail, HighlightDuration, Scale, Rating, OpenRecentOnStartup)); + setting.Write(new GeneralOptions(UseDarkTheme ? Theme.Dark : Theme.Light, HighlightTail, HighlightDuration, Scale, Rating, OpenRecentOnStartup, ShowLineNumbers)); }); HighlightDurationText = this.WhenValueChanged(vm=>vm.HighlightDuration) @@ -117,6 +118,12 @@ public bool OpenRecentOnStartup set { SetAndRaise(ref _openRecentOnStartup, value); } } + public bool ShowLineNumbers + { + get { return _showLineNumbers; } + set { SetAndRaise(ref _showLineNumbers, value); } + } + void IDisposable.Dispose() { _cleanUp.Dispose(); diff --git a/Source/TailBlazer/Views/Tail/GeneralOptionBindings.cs b/Source/TailBlazer/Views/Tail/GeneralOptionBindings.cs index a1c772e5..94d6a6cb 100644 --- a/Source/TailBlazer/Views/Tail/GeneralOptionBindings.cs +++ b/Source/TailBlazer/Views/Tail/GeneralOptionBindings.cs @@ -12,6 +12,7 @@ public class GeneralOptionBindings: IDisposable { public IProperty HighlightTail { get; } public IProperty UsingDarkTheme { get; } + public IProperty ShowLineNumbers { get; } private readonly IDisposable _cleanUp; @@ -27,7 +28,12 @@ public GeneralOptionBindings([NotNull] ISetting generalOptions, .Select(options => options.HighlightTail) .ForBinding(); - _cleanUp = new CompositeDisposable(UsingDarkTheme, HighlightTail); + ShowLineNumbers = generalOptions.Value + .ObserveOn(schedulerProvider.MainThread) + .Select(options => options.ShowLineNumbers) + .ForBinding(); + + _cleanUp = new CompositeDisposable(UsingDarkTheme, HighlightTail, ShowLineNumbers); } public void Dispose() diff --git a/Source/TailBlazer/Views/Tail/LineProxy.cs b/Source/TailBlazer/Views/Tail/LineProxy.cs index 67e523c6..aa52e7b5 100644 --- a/Source/TailBlazer/Views/Tail/LineProxy.cs +++ b/Source/TailBlazer/Views/Tail/LineProxy.cs @@ -36,11 +36,12 @@ public class LineProxy: AbstractNotifyPropertyChanged,IComparable, IC public IProperty IndicatorIcon { get; } public IProperty> IndicatorMatches { get; } public IProperty ShowIndicator { get; } + public IProperty LineNumber { get; } public LineProxy([NotNull] Line line, [NotNull] IObservable> formattedText, - [NotNull] IObservable lineMatches, - [NotNull] IObservable textScroll, + [NotNull] IObservable lineMatches, + [NotNull] IObservable textScroll, [NotNull] IThemeProvider themeProvider) { @@ -60,7 +61,11 @@ public LineProxy([NotNull] Line line, PlainText = textScrollShared .Select(ts => line.Text.Virtualise(ts)) - .ForBinding(); + .ForBinding(); + + LineNumber = textScrollShared + .Select(ts => line.Number.ToString()) + .ForBinding(); FormattedText = formattedText .CombineLatest(textScrollShared, (fmt, scroll) => fmt.Virtualise(scroll)) @@ -99,7 +104,6 @@ public LineProxy([NotNull] Line line, .Subscribe(_ => IsRecent = false); } - _cleanUp = new CompositeDisposable(FormattedText, IndicatorColour, IndicatorMatches, @@ -107,6 +111,7 @@ public LineProxy([NotNull] Line line, ShowIndicator, FormattedText, PlainText, + LineNumber, lineMatchesShared.Connect(), textScrollShared.Connect()); }