Skip to content

Commit

Permalink
Show how many items are in lists inside Properties window (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco authored Apr 13, 2024
1 parent b88c84e commit 4f31901
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/KKManager.Core/Data/Cards/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ public abstract class Card : IFileInfoBase
[DisplayName("Extended Data Size")]
public FileSize ExtendedSize { get; }

[ReadOnly(true)] public string[] MissingZipmods { get; set; }
[ReadOnly(true)] public string[] MissingPlugins { get; set; }
[ReadOnly(true)] public string[] MissingPluginsMaybe { get; set; }
[ReadOnly(true), TypeConverter(typeof(ReadOnlyStringCollectionConverterWithPreview))]
public string[] MissingZipmods { get; set; }
[ReadOnly(true), TypeConverter(typeof(ReadOnlyStringCollectionConverterWithPreview))]
public string[] MissingPlugins { get; set; }
[ReadOnly(true), TypeConverter(typeof(ReadOnlyStringCollectionConverterWithPreview))]
public string[] MissingPluginsMaybe { get; set; }

public virtual Image GetCardImage()
{
Expand Down
13 changes: 13 additions & 0 deletions src/KKManager.Core/Util/TypeConverters/DictionaryTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;

namespace KKManager.Util
{
public class DictionaryTypeConverter<T, T2> : CollectionConverter
{
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == null)
throw new ArgumentNullException(nameof(destinationType));

if (value is ICollection arr)
return $"{arr.Count} item{(arr.Count == 1 ? "" : "s")}";

return base.ConvertTo(context, culture, value, destinationType);
}

public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
{
var d = value as Dictionary<T, T2>;
Expand Down
12 changes: 12 additions & 0 deletions src/KKManager.Core/Util/TypeConverters/ListTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
Expand All @@ -9,6 +10,17 @@ namespace KKManager.Util
{
public class ListTypeConverter : CollectionConverter
{
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == null)
throw new ArgumentNullException(nameof(destinationType));

if (value is ICollection arr)
return $"{arr.Count} item{(arr.Count == 1 ? "" : "s")}";

return base.ConvertTo(context, culture, value, destinationType);
}

public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
if (arr != null || arr2 != null)
{
var count = arr?.Count ?? arr2.Count;
var result = $"{count} items";
var result = $"{count} item{(count == 1 ? "" : "s")}";
if (count > 0)
{
result += $" - {string.Join(", ", ((IEnumerable<string>)arr ?? arr2).Take(3))}";
Expand Down

0 comments on commit 4f31901

Please sign in to comment.