Skip to content

Commit

Permalink
Merge pull request #30 from J0nnyI/list-filter
Browse files Browse the repository at this point in the history
List filter
  • Loading branch information
J0nnyI authored Jan 28, 2022
2 parents 8580f89 + 82971fd commit 6329ba4
Show file tree
Hide file tree
Showing 42 changed files with 954 additions and 398 deletions.
12 changes: 11 additions & 1 deletion Core/TableTopCrucible.Core.Helper/IEnumerableHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;

using DynamicData;

namespace TableTopCrucible.Core.Helper
Expand Down Expand Up @@ -34,7 +35,16 @@ public static StringCollection ToStringCollection(this IEnumerable<string> list)

public static bool None<T>(this IEnumerable<T> list)
=> !list.Any();
public static bool None<T>(this IEnumerable<T> list, Func<T,bool> selector)
public static bool None<T>(this IEnumerable<T> list, Func<T, bool> selector)
=> !list.Any(selector);

//returns null if the collection is empty or has more than one element
public static T OnlyOrDefault<T>(this IEnumerable<T> list)
{
var arr = list.ToArray();
return arr.Count() == 1
? arr.First()
: default;
}
}
}
10 changes: 3 additions & 7 deletions Core/TableTopCrucible.Core.Helper/SettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace TableTopCrucible.Core.Helper
public static class SettingsHelper
{
public static bool AutoSaveEnabled = true;
public static TimeSpan AutoSaveThrottle = new(0,0,0,30);
public static TimeSpan AutoSaveThrottle = new(0, 0, 0, 30);
public static TimeSpan NotificationDelay => new(0, 0, 0, 5);
public static int FileMinLoadingScreenSize => 500000;
public static double NotificationResolution => NotificationDelay / AnimationResolution;
Expand All @@ -30,18 +30,14 @@ public static class SettingsHelper
public static int DoneJobLimit => 5;
public static Size ThumbnailSize = new(200, 200);
public static double ThumbnailHeight => ThumbnailSize.Height;
public static double ThumbnailWidth=> ThumbnailSize.Width;
public static double ThumbnailWidth => ThumbnailSize.Width;
public static bool GenerateThumbnailOnSync => false;
public static int MaxTagCountInDropDown = 30;
public static TimeSpan FilterThrottleSpan = TimeSpan.FromMilliseconds(500);

/// <summary>
/// the autoSave (subject) is buffered by this duration to prevent excessive writing
/// </summary>
public static TimeSpan AutoSaveBuffer => TimeSpan.FromMinutes(1);

public static string DefaultFilePath =>
//"library.ttcl";
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TableTopCrucible",
"Library.ttcl");
}
}
9 changes: 8 additions & 1 deletion Core/TableTopCrucible.Core.ValueTypes/FilePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public T ReadAllJson<T>()
using var sr = new StreamReader(s);
using JsonReader reader = new JsonTextReader(sr);
var serializer = JsonSerializer.CreateDefault();
return serializer.Deserialize<T>(reader);
var res = serializer.Deserialize<T>(reader);
reader.Close();
sr.Close();
s.Close();
return res;
}

public void WriteAllJson(object data)
Expand All @@ -67,6 +71,9 @@ public void WriteAllJson(object data)
using JsonWriter writer= new JsonTextWriter(sr);
var serializer = JsonSerializer.CreateDefault();
serializer.Serialize(writer,data);
writer.Close();
sr.Close();
s.Close();
}

public bool Exists() => FileSystemHelper.File.Exists(Value);
Expand Down
47 changes: 0 additions & 47 deletions Core/TableTopCrucible.Core.ValueTypes/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,4 @@ protected override void Validate(string value)
}
}

public class TagSourceListConverter : JsonConverter<SourceList<Tag>>
{
public override bool CanRead => true;
public override bool CanWrite => true;

public override void WriteJson(JsonWriter writer, SourceList<Tag>? value, JsonSerializer serializer)
{
if (value is null)
return;

var token = JToken.FromObject(value.Items.Select(tag=>tag.Value));

if (token.Type != JTokenType.Object)
token.WriteTo(writer);
else
{
var property = (JProperty)token;
property.AddRange(value.Items.Select(tag => new JValue(tag.Value)));
property.WriteTo(writer);
}
}

public override SourceList<Tag>? ReadJson(JsonReader reader, Type objectType, SourceList<Tag>? existingValue,
bool hasExistingValue,
JsonSerializer serializer)
{
if (objectType != typeof(SourceList<Tag>))
return new();


var obj = JArray.Load(reader);
var tags = obj
.Values<string>()
.Select(tag => (Tag)tag);

if (existingValue is null)
{
var res = new SourceList<Tag>();
res.AddRange(tags);
return res;
}

existingValue.Clear();
existingValue.AddRange(tags);
return existingValue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<SolidColorBrush x:Key="HeaderBackground" Color="#242320" />
<SolidColorBrush x:Key="SidebarBackground" Color="#302f2d" />
<SolidColorBrush x:Key="WorkspaceBackground" Color="#3d3b39" />
<SolidColorBrush x:Key="PlaceholderBackgroundBack" Color="red" />
<SolidColorBrush x:Key="PlaceholderBackgroundFront" Color="blue" />

<sys:Double x:Key="SidebarTitleFontSize">20</sys:Double>
<sys:Double x:Key="SidebarSubTitleFontSize">16</sys:Double>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800"
Height="58px">
d:DesignWidth="800">
<UserControl.Resources>
<Style TargetType="md:PackIcon">
<Setter Property="Width"
Expand All @@ -26,13 +25,15 @@
Value="16 0" />
<Setter Property="Background"
Value="Transparent" />
<Setter Property="BorderBrush"
Value="Transparent" />
</Style>
<Style TargetType="ToggleButton" BasedOn="{StaticResource MaterialDesignActionToggleButton}">
<Setter Property="Foreground"
Value="{DynamicResource MaterialDesignDarkForeground}" />
</Style>
</UserControl.Resources>
<md:ColorZone Padding="16 0"
<md:ColorZone Padding="16 8"
UseLayoutRounding="True"
VerticalAlignment="Stretch"
md:ShadowAssist.ShadowDepth="Depth2"
Expand All @@ -53,7 +54,7 @@
<Button x:Name="Save"
Content="{md:PackIcon ContentSave}"
BorderBrush="Transparent"
ToolTip="Save Data - Coming Soon" />
ToolTip="Save" />
</StackPanel>
<!-- Right -->
<StackPanel Orientation="Horizontal"
Expand Down Expand Up @@ -81,23 +82,23 @@
UseLayoutRounding="True"
VerticalAlignment="Center"
HorizontalAlignment="Center">
<md:PackIcon Kind="clock" />
<md:PackIcon Name="JobToggleIcon"/>
</Button>
</Grid>
</md:Badged>
<!--notifications-->
<md:Badged x:Name="NotificationBadge"
<md:Badged x:Name="NotificationToggleBadge"
ToolTip="Number of Notifications"
BadgePlacementMode="BottomRight"
VerticalAlignment="Center"
Padding="0 -10 -20 -10"
Margin="-20 0 0 0">
<Button Content="{md:PackIcon Bell}"
ToolTip="Notifications"
<Button ToolTip="Notifications"
md:RippleAssist.IsDisabled="False"
x:Name="ShowNotificationSidebar" />
x:Name="NotificationToggle">
<md:PackIcon Name="NotificationToggleIcon"/>
</Button>
</md:Badged>

</StackPanel>
<!-- Center -->
<TextBlock x:Name="CurrentPageTitle"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Media;
using MaterialDesignThemes.Wpf;
using ReactiveUI;
using TableTopCrucible.Core.Wpf.Engine.UserControls.ViewModels;

Expand Down Expand Up @@ -29,7 +30,7 @@ public AppHeaderV()
? string.Empty
: count.ToString())
.ObserveOn(RxApp.MainThreadScheduler)
.BindTo(this, v => v.NotificationBadge.Badge),
.BindTo(this, v => v.NotificationToggleBadge.Badge),

ViewModel!.JobCountChanges
.Select(c =>
Expand Down Expand Up @@ -58,14 +59,14 @@ public AppHeaderV()

ViewModel!.IsNotificationSidebarSelectedChanged
.Select(selected => selected
? buttonBorderSelected
: buttonBorder)
.BindTo(this, v => v.ShowNotificationSidebar.BorderBrush),
? PackIconKind.Bell
: PackIconKind.BellOutline)
.BindTo(this, v => v.NotificationToggleIcon.Kind),
ViewModel!.IsJobQueueSelectedChanged
.Select(selected => selected
? buttonBorderSelected
: buttonBorder)
.BindTo(this, v => v.ShowJobSidebar.BorderBrush),
? PackIconKind.Clock
: PackIconKind.ClockOutline)
.BindTo(this, v => v.JobToggleIcon.Kind),

this.Bind(ViewModel,
vm => vm.IsNavigationBarExpanded,
Expand All @@ -89,7 +90,7 @@ public AppHeaderV()

this.OneWayBind(ViewModel,
vm => vm.ShowNotificationSidebar,
v => v.ShowNotificationSidebar.Command)
v => v.NotificationToggle.Command)
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace TableTopCrucible.Core.Wpf.Helper.Converter
/// <summary>
/// valid parameters: h(false => hidden) + i(invert result)
/// </summary>
public class BoolVisibilityConverter:IValueConverter
public class VisibilityConverter:IValueConverter
{
public static IValueConverter Instance = new BoolVisibilityConverter();
public static IValueConverter Instance = new VisibilityConverter();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Expand All @@ -28,7 +28,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
notVisible = Visibility.Hidden;
}

return value is bool boolVal && (boolVal ^ invert)
return (value is true ^ invert) || ((value is not null && value is not false) ^ invert)
? Visibility.Visible
: notVisible;
}
Expand Down
Loading

0 comments on commit 6329ba4

Please sign in to comment.