Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
frankhaugen committed Aug 18, 2024
1 parent 1d8a5a1 commit 3b8732c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<ItemGroup>
<ProjectReference Include="..\Frank.Wpf.Controls.SimpleInputs\Frank.Wpf.Controls.SimpleInputs.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.VarDump\Frank.Wpf.Controls.VarDump.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Frank.Wpf.Controls.JsonRenderer/JsonRendererControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void HandleKeyDownEvent(object sender, KeyEventArgs e)
{
if (!item.IsSelected) return true;

var text = item.Header.As<Label>()?.Content.As<string>();
var text = item.Tag.As<string>();
if (text is not null)
Clipboard.SetText(text);
return false;
Expand Down
18 changes: 0 additions & 18 deletions Frank.Wpf.Controls.VarDump/DumpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@ namespace Frank.Wpf.Controls.VarDump;
public class DumpHelper
{
private static DumpOptions? _options = null;
// private static DumpOptions _options = new()
// {
// DateKind = DateKind.ConvertToUtc,
// DateTimeInstantiation = DateTimeInstantiation.New,
// // Descriptors = null,
// // ExcludeTypes = null,
// // GenerateVariableInitializer = false,
// GetPropertiesBindingFlags = BindingFlags.Default,
// // GetFieldsBindingFlags = null,
// // IgnoreDefaultValues = false,
// IgnoreNullValues = true,
// // MaxCollectionSize = 0,
// MaxDepth = 32,
// // SortDirection = null,
// // UseNamedArgumentsForReferenceRecordTypes = false,
// UseTypeFullName = false,
// // WritablePropertiesOnly = false
// };

public static string DumpEnumerable<T>(IEnumerable<T> enumerable, Func<T, string> idSelector) => enumerable.DumpEnumerable(idSelector, _options);
public static string DumpVar<T>(T obj) => obj.DumpVar(_options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<ItemGroup>
<ProjectReference Include="..\Frank.Wpf.Controls.SimpleInputs\Frank.Wpf.Controls.SimpleInputs.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.VarDump\Frank.Wpf.Controls.VarDump.csproj" />
<ProjectReference Include="..\Frank.Wpf.Core\Frank.Wpf.Core.csproj" />
</ItemGroup>

Expand Down
33 changes: 17 additions & 16 deletions Frank.Wpf.Controls.XmlRenderer/Internals/XmlTreeViewFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using System.Windows.Controls;
using System.Windows.Controls;
using System.Xml.Linq;

namespace Frank.Wpf.Controls.XmlRenderer.Internals;
Expand Down Expand Up @@ -51,33 +50,36 @@ private static void AddAttributesToTreeViewItem(XElement element, TreeViewItem t

private static void AddChildElementsToTreeViewItem(XElement element, TreeViewItem treeViewItem)
{
var childGroups = element.Elements().GroupBy(e => e.Name.LocalName).ToList();
var childElements = element.Elements().ToList();

// Group child elements by their name to identify collections
var groupedElements = childElements.GroupBy(e => e.Name.LocalName);

foreach (var group in childGroups)
foreach (var group in groupedElements)
{
var isCollection = group.Count() > 1;

// Add count suffix for collections, even if they have only one element
if (isCollection || group.Count() == 1)
{
treeViewItem.Header = $"{treeViewItem.Header} [{group.Count()}]";
}

int index = 0;

foreach (var childElement in group)
{
var childItem = CreateTreeViewItem(childElement);

// Prepend index if this is part of a collection
if (isCollection || group.Count() == 1)
// Only apply index prefix if it is part of a collection (i.e., multiple elements with the same name)
if (isCollection)
{
childItem.Header = $"[{index}] {childItem.Header}";
index++;
}

treeViewItem.Items.Add(childItem);
}

// Add count suffix for collection parent
if (isCollection)
{
treeViewItem.Header = $"{treeViewItem.Header} [{group.Count()}]";
treeViewItem.Tag = group.Count();
}
}
}

Expand All @@ -92,16 +94,15 @@ private static TreeViewItem CreateBasicTreeViewItem(XElement element)
return new TreeViewItem
{
Header = element.Name.LocalName,
IsExpanded = true
Tag = element.Value
};
}

private static TreeViewItem CreateTreeViewItemFromAttribute(XAttribute attribute)
{
return new TreeViewItem
{
Header = $"@{attribute.Name.LocalName}: {attribute.Value}",
IsExpanded = true
Header = $"@{attribute.Name.LocalName}: {attribute.Value}"
};
}
}
2 changes: 1 addition & 1 deletion Frank.Wpf.Controls.XmlRenderer/XmlRendererControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void HandleKeyDownEvent(object sender, KeyEventArgs e)
{
if (!item.IsSelected) return true;

var text = item.Header.As<Label>()?.Content.As<string>();
var text = item.Tag.As<string>();
if (text is not null)
Clipboard.SetText(text);
return false;
Expand Down
2 changes: 2 additions & 0 deletions Frank.Wpf.Tests.App/Frank.Wpf.Tests.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ProjectReference Include="..\Frank.Wpf.Controls.CompletionPopup\Frank.Wpf.Controls.CompletionPopup.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.Code\Frank.Wpf.Controls.Code.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.Console\Frank.Wpf.Controls.Console.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.CSharpRenderer\Frank.Wpf.Controls.CSharpRenderer.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.DataTableGrid\Frank.Wpf.Controls.DataTableGrid.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.ExpandoControl\Frank.Wpf.Controls.ExpandoControl.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.Git\Frank.Wpf.Controls.Git.csproj" />
Expand All @@ -20,6 +21,7 @@
<ProjectReference Include="..\Frank.Wpf.Controls.RoslynScript\Frank.Wpf.Controls.RoslynScript.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.SearchableList\Frank.Wpf.Controls.SearchableList.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.SimpleInputs\Frank.Wpf.Controls.SimpleInputs.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.VarDump\Frank.Wpf.Controls.VarDump.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.XmlRenderer\Frank.Wpf.Controls.XmlRenderer.csproj" />
<ProjectReference Include="..\Frank.Wpf.Core\Frank.Wpf.Core.csproj" />
<ProjectReference Include="..\Frank.Wpf.Dialogs\Frank.Wpf.Dialogs.csproj" />
Expand Down
1 change: 1 addition & 0 deletions Frank.Wpf.Tests/Frank.Wpf.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<ProjectReference Include="..\Frank.Wpf.Controls.CompletionPopup\Frank.Wpf.Controls.CompletionPopup.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.CSharpRenderer\Frank.Wpf.Controls.CSharpRenderer.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.JsonRenderer\Frank.Wpf.Controls.JsonRenderer.csproj" />
<ProjectReference Include="..\Frank.Wpf.Controls.VarDump\Frank.Wpf.Controls.VarDump.csproj" />
<ProjectReference Include="..\Frank.Wpf.Tests.App\Frank.Wpf.Tests.App.csproj" />
</ItemGroup>

Expand Down

0 comments on commit 3b8732c

Please sign in to comment.