Skip to content

Commit

Permalink
Set up the file tree view to use the old tree view interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Dec 19, 2024
1 parent 795fb5a commit 634a702
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace fin.io.bundles;

public static class AnnotatedFileBundleExtensions {
public static bool IsOfType<TSpecificFile>(
this IAnnotatedFileBundle file,
out IAnnotatedFileBundle<TSpecificFile> outFile)
where TSpecificFile : IFileBundle {
if (file is IAnnotatedFileBundle<TSpecificFile>) {
outFile = (IAnnotatedFileBundle<TSpecificFile>) file;
return true;
}

outFile = default;
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using fin.model.io;
using fin.scene;
using fin.util.asserts;
using fin.util.linq;

using grezzo.api;

Expand All @@ -18,6 +19,7 @@
using ObservableCollections;

using uni.ui.avalonia.ViewModels;
using uni.ui.winforms.common.fileTreeView;

namespace uni.ui.avalonia.common.treeViews;

Expand Down Expand Up @@ -81,13 +83,17 @@ public class FileBundleTreeViewModelForDesigner()
]);

// Node types
public abstract class BFileBundleNode(string text) : ViewModelBase, IFileTreeNode {
public string Text => text;
public IFileTreeParentNode? Parent => null;
}

public class FileBundleDirectoryNode
: ViewModelBase, IFileBundleNode {
: BFileBundleNode, IFileBundleNode, IFileTreeParentNode {
private readonly IReadOnlyList<IFileBundleNode>? subNodes_;

private readonly
ISynchronizedView<IFileBundleNode,
IFileBundleNode>? filteredSubNodes_;
private readonly ISynchronizedView<IFileBundleNode,
IFileBundleNode>? filteredSubNodes_;

public FileBundleDirectoryNode(
string label,
Expand All @@ -98,7 +104,7 @@ public FileBundleDirectoryNode(
public FileBundleDirectoryNode(
string label,
IReadOnlyList<IFileBundleNode>? subNodes,
IReadOnlySet<string> filterTerms) {
IReadOnlySet<string> filterTerms) : base(label) {
this.subNodes_ = subNodes;
this.Label = label;
this.FilterTerms = filterTerms;
Expand Down Expand Up @@ -141,10 +147,14 @@ public IFilter<IAnnotatedFileBundle>? Filter {
}

public bool InFilter { get; private set; } = true;

public IEnumerable<IFileTreeNode> ChildNodes
=> this.subNodes_.Cast<IFileTreeNode>();

Check failure on line 152 in FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui.Avalonia/common/treeViews/FileBundleTreeViewModels.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'IEnumerable<IFileTreeNode> Enumerable.Cast<IFileTreeNode>(IEnumerable source)'.
}

public class FileBundleLeafNode(string label, IAnnotatedFileBundle data)
: ViewModelBase, IFileBundleNode {
public class FileBundleLeafNode(string label,
IAnnotatedFileBundle data)
: BFileBundleNode(label), IFileBundleNode, IFileTreeLeafNode {
public INotifyCollectionChangedSynchronizedViewList<
IFileBundleNode>? FilteredSubNodes => null;

Expand All @@ -156,7 +166,8 @@ public INotifyCollectionChangedSynchronizedViewList<
};

public IAnnotatedFileBundle Value => data;
public string Label { get; } = label;
public IAnnotatedFileBundle File => data;
public string Label => label;

public IFilter<IAnnotatedFileBundle>? Filter {
set => this.InFilter = value?.MatchesNode(this) ?? true;
Expand All @@ -168,7 +179,7 @@ public IFilter<IAnnotatedFileBundle>? Filter {
public class FileBundleFilter(IReadOnlySet<string> tokens)
: IFilter<IAnnotatedFileBundle> {
public static FileBundleFilter? FromText(string? text) {
var tokens = text?.Split(new[] { ' ', '\t', '\n' },
var tokens = text?.Split([' ', '\t', '\n'],
StringSplitOptions.RemoveEmptyEntries |
StringSplitOptions.TrimEntries);
return tokens?.Length > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,4 @@ public LeafFileNode(ParentFileNode parent,
public IAnnotatedFileBundle File { get; }
public override string FullName => this.File.FileBundle.TrueFullPath;
}
}

public static class AnnotatedFileBundleExtensions {
public static bool IsOfType<TSpecificFile>(
this IAnnotatedFileBundle file,
out IAnnotatedFileBundle<TSpecificFile> outFile)
where TSpecificFile : IFileBundle {
if (file is IAnnotatedFileBundle<TSpecificFile>) {
outFile = (IAnnotatedFileBundle<TSpecificFile>) file;
return true;
}

outFile = default;
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,6 @@ public LeafFileNode AddChild(IAnnotatedFileBundle file,
public IEnumerable<IFileTreeNode> ChildNodes
=> this.filterNode.Children.Select(fuzzyNode => fuzzyNode.Data);

public IEnumerable<IAnnotatedFileBundle> GetFiles(bool recursive) {
var children = this.ChildNodes.OfType<IFileTreeLeafNode>()
.Select(fileNode => fileNode.File);
return !recursive
? children
: children.Concat(
this.ChildNodes
.OfType<IFileTreeParentNode>()
.SelectMany(parentNode
=> parentNode
.GetFiles(
true)));
}

public IEnumerable<IAnnotatedFileBundle<TSpecificFile>> GetFilesOfType<
TSpecificFile>(bool recursive) where TSpecificFile : IFileBundle
=> this.GetFiles(recursive)
.SelectWhere<IAnnotatedFileBundle,
IAnnotatedFileBundle<TSpecificFile>>(
AnnotatedFileBundleExtensions.IsOfType);

public void Expand() => this.treeNode.Expand();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Drawing;

using fin.io.bundles;
using fin.util.linq;

namespace uni.ui.winforms.common.fileTreeView;

Expand All @@ -26,11 +27,26 @@ public interface IFileTreeNode {
public interface IFileTreeParentNode : IFileTreeNode {
IEnumerable<IFileTreeNode> ChildNodes { get; }

IEnumerable<IAnnotatedFileBundle> GetFiles(bool recursive);

IEnumerable<IAnnotatedFileBundle<TSpecificFile>>
GetFilesOfType<TSpecificFile>(bool recursive)
where TSpecificFile : IFileBundle;
IEnumerable<IAnnotatedFileBundle> GetFiles(bool recursive) {
var children = this.ChildNodes.OfType<IFileTreeLeafNode>()
.Select(fileNode => fileNode.File);
return !recursive
? children
: children.Concat(
this.ChildNodes
.OfType<IFileTreeParentNode>()
.SelectMany(parentNode
=> parentNode
.GetFiles(
true)));
}

IEnumerable<IAnnotatedFileBundle<TSpecificFile>> GetFilesOfType<
TSpecificFile>(bool recursive) where TSpecificFile : IFileBundle
=> this.GetFiles(recursive)
.SelectWhere<IAnnotatedFileBundle,
IAnnotatedFileBundle<TSpecificFile>>(
AnnotatedFileBundleExtensions.IsOfType);
}

public interface IFileTreeLeafNode : IFileTreeNode {
Expand Down

0 comments on commit 634a702

Please sign in to comment.