Skip to content

Commit

Permalink
Merge pull request RolandPheasant#192 from bachmeierm/LineNumbers
Browse files Browse the repository at this point in the history
Add line numbers
  • Loading branch information
RolandPheasant authored Jun 8, 2018
2 parents 1a61c8e + 4b2e551 commit 0c0073e
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 14 deletions.
4 changes: 3 additions & 1 deletion Source/TailBlazer.Domain/Formatting/GeneralOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ 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;
HighlightDuration = highlightTailDuration;
Scale = scale;
Rating = rating;
OpenRecentOnStartup = openRecentOnStartup;
ShowLineNumbers = showLineNumbers;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -44,14 +46,15 @@ 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);
}

public GeneralOptions GetDefaultValue()
{
return new GeneralOptions(Theme.Light, true, 5, 100, 5, true);
return new GeneralOptions(Theme.Light, true, 5, 100, 5, true, false);
}
}
}
2 changes: 1 addition & 1 deletion Source/TailBlazer.Fixtures/SettingsConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions Source/TailBlazer/Themes/Lines.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<DataTemplate DataType="{x:Type tail:LineProxy}">
<Grid Margin="2,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="16" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

Expand Down Expand Up @@ -103,7 +103,15 @@

</materialDesign:PopupBox>

<Grid Grid.Column="1" Margin="4,0,0,0">
<TextBlock Grid.Column="0"
Opacity="0.5"
TextAlignment="Right"
VerticalAlignment="Center"
Margin="8,0,0,0"
Text="{Binding LineNumber.Value}"
Visibility="{Binding Path=DataContext.GeneralOptionBindings.ShowLineNumbers.Value, ElementName=Control, Converter={StaticResource BooleanToVisibilityConverter}}"/>

<Grid Grid.Column="1" Margin="16,0,0,0">
<controls:HighlightTextControl
VerticalAlignment="Center"
FormattedText="{Binding FormattedText.Value}"
Expand Down
10 changes: 9 additions & 1 deletion Source/TailBlazer/Views/Options/GeneralOptionsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -83,6 +84,13 @@
VerticalAlignment="Center"
Margin="4"
IsChecked="{Binding OpenRecentOnStartup}" />

<TextBlock Grid.Row="4" Grid.Column="0" VerticalAlignment="Center">Show Line Numbers?</TextBlock>
<CheckBox Grid.Row="4" Grid.Column="1"
VerticalAlignment="Center"
Margin="4"
IsChecked="{Binding ShowLineNumbers}" />

</Grid>

<TextBlock
Expand Down
11 changes: 9 additions & 2 deletions Source/TailBlazer/Views/Options/GeneralOptionsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using DynamicData.Binding;
using TailBlazer.Domain.Formatting;
using TailBlazer.Domain.Infrastructure;
using TailBlazer.Domain.Ratings;
using TailBlazer.Domain.Settings;
using TailBlazer.Infrastucture;

Expand All @@ -24,6 +23,7 @@ public sealed class GeneralOptionsViewModel : AbstractNotifyPropertyChanged, IDi
private bool _useDarkTheme;
private int _rating;
private bool _openRecentOnStartup;
private bool _showLineNumbers;

public GeneralOptionsViewModel(ISetting<GeneralOptions> setting)
{
Expand All @@ -35,6 +35,7 @@ public GeneralOptionsViewModel(ISetting<GeneralOptions> setting)
Scale = options.Scale;
Rating = options.Rating;
OpenRecentOnStartup = options.OpenRecentOnStartup;
ShowLineNumbers = options.ShowLineNumbers;
});

RequiresRestart = setting.Value.Select(options => options.Rating)
Expand All @@ -50,7 +51,7 @@ public GeneralOptionsViewModel(ISetting<GeneralOptions> 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)
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion Source/TailBlazer/Views/Tail/GeneralOptionBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class GeneralOptionBindings: IDisposable
{
public IProperty<bool> HighlightTail { get; }
public IProperty<bool> UsingDarkTheme { get; }
public IProperty<bool> ShowLineNumbers { get; }

private readonly IDisposable _cleanUp;

Expand All @@ -27,7 +28,12 @@ public GeneralOptionBindings([NotNull] ISetting<GeneralOptions> 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()
Expand Down
13 changes: 9 additions & 4 deletions Source/TailBlazer/Views/Tail/LineProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public class LineProxy: AbstractNotifyPropertyChanged,IComparable<LineProxy>, IC
public IProperty<PackIconKind> IndicatorIcon { get; }
public IProperty<IEnumerable<LineMatchProxy>> IndicatorMatches { get; }
public IProperty<Visibility> ShowIndicator { get; }
public IProperty<string> LineNumber { get; }

public LineProxy([NotNull] Line line,
[NotNull] IObservable<IEnumerable<DisplayText>> formattedText,
[NotNull] IObservable<LineMatchCollection> lineMatches,
[NotNull] IObservable<TextScrollInfo> textScroll,
[NotNull] IObservable<LineMatchCollection> lineMatches,
[NotNull] IObservable<TextScrollInfo> textScroll,
[NotNull] IThemeProvider themeProvider)
{

Expand All @@ -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))
Expand Down Expand Up @@ -99,14 +104,14 @@ public LineProxy([NotNull] Line line,
.Subscribe(_ => IsRecent = false);
}


_cleanUp = new CompositeDisposable(FormattedText,
IndicatorColour,
IndicatorMatches,
IndicatorIcon,
ShowIndicator,
FormattedText,
PlainText,
LineNumber,
lineMatchesShared.Connect(),
textScrollShared.Connect());
}
Expand Down

0 comments on commit 0c0073e

Please sign in to comment.