diff --git a/FinModelUtility/Fin/Fin/src/io/bundles/AnnotatedFileBundleExtensions.cs b/FinModelUtility/Fin/Fin/src/io/bundles/AnnotatedFileBundleExtensions.cs new file mode 100644 index 000000000..f4e6a9b82 --- /dev/null +++ b/FinModelUtility/Fin/Fin/src/io/bundles/AnnotatedFileBundleExtensions.cs @@ -0,0 +1,16 @@ +namespace fin.io.bundles; + +public static class AnnotatedFileBundleExtensions { + public static bool IsOfType( + this IAnnotatedFileBundle file, + out IAnnotatedFileBundle outFile) + where TSpecificFile : IFileBundle { + if (file is IAnnotatedFileBundle) { + outFile = (IAnnotatedFileBundle) file; + return true; + } + + outFile = default; + return false; + } +} \ No newline at end of file diff --git a/FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui.Avalonia/common/treeViews/FileBundleTreeViewModels.cs b/FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui.Avalonia/common/treeViews/FileBundleTreeViewModels.cs index 8dfea3a3e..31e4a5c6f 100644 --- a/FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui.Avalonia/common/treeViews/FileBundleTreeViewModels.cs +++ b/FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui.Avalonia/common/treeViews/FileBundleTreeViewModels.cs @@ -10,6 +10,7 @@ using fin.model.io; using fin.scene; using fin.util.asserts; +using fin.util.linq; using grezzo.api; @@ -18,6 +19,7 @@ using ObservableCollections; using uni.ui.avalonia.ViewModels; +using uni.ui.winforms.common.fileTreeView; namespace uni.ui.avalonia.common.treeViews; @@ -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? subNodes_; - private readonly - ISynchronizedView? filteredSubNodes_; + private readonly ISynchronizedView? filteredSubNodes_; public FileBundleDirectoryNode( string label, @@ -98,7 +104,7 @@ public FileBundleDirectoryNode( public FileBundleDirectoryNode( string label, IReadOnlyList? subNodes, - IReadOnlySet filterTerms) { + IReadOnlySet filterTerms) : base(label) { this.subNodes_ = subNodes; this.Label = label; this.FilterTerms = filterTerms; @@ -141,10 +147,14 @@ public IFilter? Filter { } public bool InFilter { get; private set; } = true; + + public IEnumerable ChildNodes + => this.subNodes_.Cast(); } -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; @@ -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? Filter { set => this.InFilter = value?.MatchesNode(this) ?? true; @@ -168,7 +179,7 @@ public IFilter? Filter { public class FileBundleFilter(IReadOnlySet tokens) : IFilter { 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 diff --git a/FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui/src/winforms/common/fileTreeView/FileTreeView_LeafFileNode.cs b/FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui/src/winforms/common/fileTreeView/FileTreeView_LeafFileNode.cs index 5ffb2a9b6..97e5ded5d 100644 --- a/FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui/src/winforms/common/fileTreeView/FileTreeView_LeafFileNode.cs +++ b/FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui/src/winforms/common/fileTreeView/FileTreeView_LeafFileNode.cs @@ -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( - this IAnnotatedFileBundle file, - out IAnnotatedFileBundle outFile) - where TSpecificFile : IFileBundle { - if (file is IAnnotatedFileBundle) { - outFile = (IAnnotatedFileBundle) file; - return true; - } - - outFile = default; - return false; - } } \ No newline at end of file diff --git a/FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui/src/winforms/common/fileTreeView/FileTreeView_ParentFileNode.cs b/FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui/src/winforms/common/fileTreeView/FileTreeView_ParentFileNode.cs index 2bfc47805..63459a900 100644 --- a/FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui/src/winforms/common/fileTreeView/FileTreeView_ParentFileNode.cs +++ b/FinModelUtility/UniversalAssetTool/UniversalAssetTool.Ui/src/winforms/common/fileTreeView/FileTreeView_ParentFileNode.cs @@ -42,27 +42,6 @@ public LeafFileNode AddChild(IAnnotatedFileBundle file, public IEnumerable ChildNodes => this.filterNode.Children.Select(fuzzyNode => fuzzyNode.Data); - public IEnumerable GetFiles(bool recursive) { - var children = this.ChildNodes.OfType() - .Select(fileNode => fileNode.File); - return !recursive - ? children - : children.Concat( - this.ChildNodes - .OfType() - .SelectMany(parentNode - => parentNode - .GetFiles( - true))); - } - - public IEnumerable> GetFilesOfType< - TSpecificFile>(bool recursive) where TSpecificFile : IFileBundle - => this.GetFiles(recursive) - .SelectWhere>( - AnnotatedFileBundleExtensions.IsOfType); - public void Expand() => this.treeNode.Expand(); } } \ No newline at end of file diff --git a/FinModelUtility/UniversalAssetTool/UniversalAssetTool/src/common/FileTreeViewInterfaces.cs b/FinModelUtility/UniversalAssetTool/UniversalAssetTool/src/common/FileTreeViewInterfaces.cs index 1ef40fffc..ba1aeec72 100644 --- a/FinModelUtility/UniversalAssetTool/UniversalAssetTool/src/common/FileTreeViewInterfaces.cs +++ b/FinModelUtility/UniversalAssetTool/UniversalAssetTool/src/common/FileTreeViewInterfaces.cs @@ -1,6 +1,7 @@ using System.Drawing; using fin.io.bundles; +using fin.util.linq; namespace uni.ui.winforms.common.fileTreeView; @@ -26,11 +27,26 @@ public interface IFileTreeNode { public interface IFileTreeParentNode : IFileTreeNode { IEnumerable ChildNodes { get; } - IEnumerable GetFiles(bool recursive); - - IEnumerable> - GetFilesOfType(bool recursive) - where TSpecificFile : IFileBundle; + IEnumerable GetFiles(bool recursive) { + var children = this.ChildNodes.OfType() + .Select(fileNode => fileNode.File); + return !recursive + ? children + : children.Concat( + this.ChildNodes + .OfType() + .SelectMany(parentNode + => parentNode + .GetFiles( + true))); + } + + IEnumerable> GetFilesOfType< + TSpecificFile>(bool recursive) where TSpecificFile : IFileBundle + => this.GetFiles(recursive) + .SelectWhere>( + AnnotatedFileBundleExtensions.IsOfType); } public interface IFileTreeLeafNode : IFileTreeNode {