Skip to content

Commit 61bcf81

Browse files
committed
Fixes #26
1 parent da71f81 commit 61bcf81

File tree

10 files changed

+111
-59
lines changed

10 files changed

+111
-59
lines changed

Debuggee/Debuggee.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
3434
<PackageReference Include="NodaTime" Version="3.0.0" />
35-
<PackageReference Include="ZSpitz.Util" Version="0.0.32" />
35+
<PackageReference Include="ZSpitz.Util" Version="0.0.34" />
3636
</ItemGroup>
3737

3838
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">

Package/Package.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434

3535
<ItemGroup>
3636
<PackageReference Include="NodaTime" Version="3.0.0" />
37-
<PackageReference Include="ZSpitz.Util" Version="0.0.32" />
38-
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.0.32" />
37+
<PackageReference Include="OneOf" Version="2.1.155" />
38+
<PackageReference Include="ZSpitz.Util" Version="0.0.39" />
39+
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.0.39" />
3940
</ItemGroup>
4041

4142
</Project>

UI/Converters.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
using System.Collections.Generic;
99
using ZSpitz.Util;
1010
using NodaTime.TimeZones;
11+
using System.Windows.Media;
12+
using static ZSpitz.Util.Wpf.FilterStates;
13+
using System.Windows;
1114

1215
namespace DateTimeVisualizer {
1316
public class InstantToStringConverter : ReadOnlyConverterBase {
@@ -70,4 +73,19 @@ public override object Convert(object value, Type targetType, object parameter,
7073
return value.ToString().ToUpper();
7174
}
7275
}
76+
77+
public class FilterStateConverter : ReadOnlyConverterBase {
78+
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
79+
var filterState = (FilterStates?)value;
80+
if (targetType == typeof(Brush)) {
81+
return filterState == DescendantMatched ? Brushes.Gray : UnsetValue;
82+
} else if (targetType == typeof(Visibility)) {
83+
if (filterState == null) { return UnsetValue; }
84+
return filterState.In(Matched, DescendantMatched) ? Visibility.Visible : Visibility.Collapsed;
85+
} else if (targetType == typeof(FontWeight)) {
86+
return filterState == Matched ? FontWeights.Bold : UnsetValue;
87+
}
88+
throw new NotImplementedException();
89+
}
90+
}
7391
}

UI/UI.projitems

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
</Page>
1818
</ItemGroup>
1919
<ItemGroup>
20-
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ZoneProviderVM.cs" />
21-
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ZoneVM.cs" />
20+
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ZoneNodeVM.cs" />
2221
<Compile Include="$(MSBuildThisFileDirectory)Views\ConfigView.xaml.cs">
2322
<SubType>Code</SubType>
2423
<DependentUpon>ConfigView.xaml</DependentUpon>

UI/ViewModels/ConfigVM.cs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
11
using DateTimeVisualizer.Serialization;
2-
using DateTimeVisualizer.ViewModels;
32
using ZSpitz.Util.Wpf;
4-
using NodaTime;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using ZSpitz.Util;
6+
using static NodaTime.DateTimeZoneProviders;
57

68
namespace DateTimeVisualizer.UI {
79
public class ConfigVM : ViewModelBase<Config> {
810
public ConfigVM(Config model) : base(model) {
9-
Tzdb = new ZoneProviderVM(DateTimeZoneProviders.Tzdb, model.TzdbIds);
10-
Bcl = new ZoneProviderVM(DateTimeZoneProviders.Bcl, model.BclIds);
11+
AvailableBclZones = Bcl.Ids.Select(id => new ZoneNodeVM(id, Bcl, model.BclIds)).ToArray();
12+
13+
var parents = new Dictionary<string, ZoneNodeVM>();
14+
15+
(string parentPath, string last) parsePath(string s) {
16+
var lastIndex = s.LastIndexOf("/");
17+
if (lastIndex <0 ) { return ("", s); }
18+
return (
19+
s.Substring(0, lastIndex),
20+
s.Substring(lastIndex + 1)
21+
);
22+
}
23+
24+
ZoneNodeVM? getParent(string s) {
25+
var (parentPath, last) = parsePath(s);
26+
if (parentPath =="") { return null; }
27+
if (!parents!.TryGetValue(parentPath, out var parent)) {
28+
parent = new ZoneNodeVM(parentPath) {
29+
Parent = getParent(parentPath)
30+
};
31+
parents.Add(parentPath, parent);
32+
}
33+
return parent;
34+
}
35+
36+
foreach (var id in Tzdb.Ids) {
37+
var node = new ZoneNodeVM(id, Tzdb, model.TzdbIds) {
38+
Parent = getParent(id)
39+
};
40+
}
41+
42+
AvailableTzdbZones = parents.Where(kvp => kvp.Value.Parent is null).Values().ToArray();
1143
}
1244

13-
public ZoneProviderVM Tzdb { get; }
14-
public ZoneProviderVM Bcl { get; }
45+
public ZoneNodeVM[] AvailableBclZones { get; }
46+
public ZoneNodeVM[] AvailableTzdbZones { get; }
1547
}
1648
}

UI/ViewModels/ZoneNodeVM.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using NodaTime;
2+
using OneOf;
3+
using System.Collections.Generic;
4+
using ZSpitz.Util;
5+
using ZSpitz.Util.Wpf;
6+
7+
namespace DateTimeVisualizer {
8+
public class ZoneNodeVM : TreeNodeVM<OneOf<string, DateTimeZone>> {
9+
public ZoneNodeVM(string id) {
10+
Data = id;
11+
}
12+
public ZoneNodeVM(string id, IDateTimeZoneProvider provider, HashSet<string> selectionStore) : this(id) {
13+
Data = provider.GetZoneOrNull(id)!;
14+
IsSelected = id.In(selectionStore);
15+
PropertyChanged += (s, e) => {
16+
if (e.PropertyName != nameof(IsSelected)) { return; }
17+
selectionStore.AddRemove(IsSelected.Value, id);
18+
};
19+
}
20+
21+
public string Text => Data.Match(s => s, zone => zone.ToString());
22+
public override string ToString() => Text;
23+
}
24+
}

UI/ViewModels/ZoneProviderVM.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

UI/ViewModels/ZoneVM.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

UI/Views/ConfigView.xaml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,44 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:util="clr-namespace:ZSpitz.Util.Wpf;assembly=ZSpitz.Util.Wpf"
5+
xmlns:nt="clr-namespace:NodaTime;assembly=NodaTime"
6+
xmlns:my="clr-namespace:DateTimeVisualizer"
57
Orientation="Vertical" RowCount="3">
8+
<util:AutoGrid.Resources>
9+
<my:FilterStateConverter x:Key="FilterStateConverter" />
10+
</util:AutoGrid.Resources>
611

712
<TextBlock Text="TZDB zones:" Margin="0,0,12,3" />
8-
<ListBox SelectionMode="Multiple" MaxHeight="300" SelectedValuePath="Model" ItemsSource="{Binding Tzdb.AvailableZones}" Margin="0,0,12,3">
9-
<ListBox.ItemContainerStyle>
10-
<Style TargetType="ListBoxItem">
11-
<Setter Property="IsSelected" Value="{Binding IsSelected}" />
13+
<TreeView MaxHeight="300" ItemsSource="{Binding AvailableTzdbZones}">
14+
<TreeView.ItemContainerStyle>
15+
<Style TargetType="TreeViewItem">
16+
<Setter Property="Visibility" Value="{Binding FilterState, Converter={StaticResource FilterStateConverter}}" />
1217
</Style>
13-
</ListBox.ItemContainerStyle>
14-
<ListBox.ItemTemplate>
15-
<DataTemplate>
16-
<TextBlock Text="{Binding Model}" />
17-
</DataTemplate>
18-
</ListBox.ItemTemplate>
19-
</ListBox>
20-
<TextBlock Text="{Binding Tzdb.Model.VersionId}" />
18+
</TreeView.ItemContainerStyle>
19+
<TreeView.ItemTemplate>
20+
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
21+
<StackPanel Orientation="Horizontal" Visibility="{Binding FilterState, Converter={StaticResource FilterStateConverter}}">
22+
<CheckBox Margin="2" IsChecked="{Binding IsSelected}" />
23+
<TextBlock Text="{Binding Text}" Foreground="{Binding FilterState, Converter={StaticResource FilterStateConverter}}" FontWeight="{Binding FilterState, Converter={StaticResource FilterStateConverter}}" />
24+
</StackPanel>
25+
</HierarchicalDataTemplate>
26+
</TreeView.ItemTemplate>
27+
</TreeView>
28+
<TextBlock Text="{Binding VersionId, Source={x:Static nt:DateTimeZoneProviders.Tzdb}}" />
2129

2230
<TextBlock Text="BCL zones:" Margin="0,0,0,3" />
23-
<ListBox SelectionMode="Multiple" MaxHeight="300" SelectedValuePath="Model" ItemsSource="{Binding Bcl.AvailableZones}" Margin="0,0,0,3">
31+
<ListBox SelectionMode="Multiple" MaxHeight="300" SelectedValuePath="Text" ItemsSource="{Binding AvailableBclZones}" Margin="0,0,0,3">
2432
<ListBox.ItemContainerStyle>
2533
<Style TargetType="ListBoxItem">
2634
<Setter Property="IsSelected" Value="{Binding IsSelected}" />
2735
</Style>
2836
</ListBox.ItemContainerStyle>
2937
<ListBox.ItemTemplate>
3038
<DataTemplate>
31-
<TextBlock Text="{Binding Model}" />
39+
<TextBlock Text="{Binding Text}" />
3240
</DataTemplate>
3341
</ListBox.ItemTemplate>
3442
</ListBox>
35-
<TextBlock Text="{Binding Bcl.Model.VersionId}" />
43+
<TextBlock Text="{Binding VersionId, Source={x:Static nt:DateTimeZoneProviders.Bcl}}" />
3644

3745
</util:AutoGrid>

Visualizer/Visualizer.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
<Private>false</Private>
1919
</Reference>
2020
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
21-
<PackageReference Include="ZSpitz.Util" Version="0.0.32" />
22-
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.0.32" />
21+
<PackageReference Include="OneOf" Version="2.1.155" />
22+
<PackageReference Include="ZSpitz.Util" Version="0.0.39" />
23+
<PackageReference Include="ZSpitz.Util.Wpf" Version="0.0.39" />
2324
<PackageReference Include="Octokit" Version="0.48.0" />
2425
<PackageReference Include="NodaTime" Version="3.0.0" />
2526
<ProjectReference Include="..\Debuggee\Debuggee.csproj" />

0 commit comments

Comments
 (0)