From 264f873fb079aa28c719b1d69399805f1fd1a377 Mon Sep 17 00:00:00 2001 From: romibi Date: Sat, 25 Nov 2023 13:05:36 +0100 Subject: [PATCH 1/3] Fix GUI tree childs created as ScrapTreeEntry instead of TreeViewTreeEntry --- ScrapPackedExplorer/MainWindow.xaml.cs | 6 ++++++ ScrapPackedLibrary/ScrapPackedTree.cs | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ScrapPackedExplorer/MainWindow.xaml.cs b/ScrapPackedExplorer/MainWindow.xaml.cs index 435d133..e2111ab 100644 --- a/ScrapPackedExplorer/MainWindow.xaml.cs +++ b/ScrapPackedExplorer/MainWindow.xaml.cs @@ -416,6 +416,12 @@ public TreeViewTreeEntryAlias(ScrapTreeEntry p_Reference) : base(p_Reference.Par } public class TreeViewTreeEntry : ScrapTreeEntry { + public override ScrapTreeEntry CreateAndAdd(ScrapTreeEntry p_Parent, string p_Name = "", PackedFileIndexData p_IndexData = null) { + TreeViewTreeEntry Result = new TreeViewTreeEntry(p_Parent) { Name = p_Name, IndexData = p_IndexData }; + Items.Add(Result); + return Result; + } + public TreeViewTreeEntry(ScrapTreeEntry p_Parent) : base(p_Parent) { } diff --git a/ScrapPackedLibrary/ScrapPackedTree.cs b/ScrapPackedLibrary/ScrapPackedTree.cs index 45800f4..51b19bd 100644 --- a/ScrapPackedLibrary/ScrapPackedTree.cs +++ b/ScrapPackedLibrary/ScrapPackedTree.cs @@ -8,6 +8,12 @@ namespace ch.romibi.Scrap.Packed.PackerLib { public class ScrapTreeEntry : IComparable { + public virtual ScrapTreeEntry CreateAndAdd(ScrapTreeEntry p_Parent, string p_Name = "", PackedFileIndexData p_IndexData = null) { + ScrapTreeEntry Result = new ScrapTreeEntry(p_Parent) { Name = p_Name, IndexData = p_IndexData }; + Items.Add(Result); + return Result; + } + public ScrapTreeEntry(ScrapTreeEntry p_Parent) { Items = new ObservableCollection(); IndexData = null; @@ -49,12 +55,11 @@ public void AddFileData(PackedFileIndexData p_File, string p_SubdirFilename = "" } } if (subDir == null) { - subDir = new ScrapTreeEntry(this) { Name = nextDir }; - Items.Add(subDir); + subDir = CreateAndAdd(this, nextDir); } subDir.AddFileData(p_File, fileName.Substring(nextDir.Length + 1)); } else { - Items.Add(new ScrapTreeEntry(this) { Name = fileName, IndexData = p_File }); + CreateAndAdd(this, fileName, p_File); } } From 0b35d0d0d8c46fc8e7c60e53006d73520b54a257 Mon Sep 17 00:00:00 2001 From: romibi Date: Sun, 10 Dec 2023 15:55:41 +0100 Subject: [PATCH 2/3] Better name for method to create child node in tree --- ScrapPackedExplorer/MainWindow.xaml.cs | 2 +- ScrapPackedLibrary/ScrapPackedTree.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ScrapPackedExplorer/MainWindow.xaml.cs b/ScrapPackedExplorer/MainWindow.xaml.cs index e2111ab..32cb5c5 100644 --- a/ScrapPackedExplorer/MainWindow.xaml.cs +++ b/ScrapPackedExplorer/MainWindow.xaml.cs @@ -416,7 +416,7 @@ public TreeViewTreeEntryAlias(ScrapTreeEntry p_Reference) : base(p_Reference.Par } public class TreeViewTreeEntry : ScrapTreeEntry { - public override ScrapTreeEntry CreateAndAdd(ScrapTreeEntry p_Parent, string p_Name = "", PackedFileIndexData p_IndexData = null) { + public override ScrapTreeEntry CreateChild(ScrapTreeEntry p_Parent, string p_Name = "", PackedFileIndexData p_IndexData = null) { TreeViewTreeEntry Result = new TreeViewTreeEntry(p_Parent) { Name = p_Name, IndexData = p_IndexData }; Items.Add(Result); return Result; diff --git a/ScrapPackedLibrary/ScrapPackedTree.cs b/ScrapPackedLibrary/ScrapPackedTree.cs index 51b19bd..c476287 100644 --- a/ScrapPackedLibrary/ScrapPackedTree.cs +++ b/ScrapPackedLibrary/ScrapPackedTree.cs @@ -8,7 +8,7 @@ namespace ch.romibi.Scrap.Packed.PackerLib { public class ScrapTreeEntry : IComparable { - public virtual ScrapTreeEntry CreateAndAdd(ScrapTreeEntry p_Parent, string p_Name = "", PackedFileIndexData p_IndexData = null) { + public virtual ScrapTreeEntry CreateChild(ScrapTreeEntry p_Parent, string p_Name = "", PackedFileIndexData p_IndexData = null) { ScrapTreeEntry Result = new ScrapTreeEntry(p_Parent) { Name = p_Name, IndexData = p_IndexData }; Items.Add(Result); return Result; @@ -55,11 +55,11 @@ public void AddFileData(PackedFileIndexData p_File, string p_SubdirFilename = "" } } if (subDir == null) { - subDir = CreateAndAdd(this, nextDir); + subDir = CreateChild(this, nextDir); } subDir.AddFileData(p_File, fileName.Substring(nextDir.Length + 1)); } else { - CreateAndAdd(this, fileName, p_File); + CreateChild(this, fileName, p_File); } } From 5498c061f0b46a523ee035b5991b50bb4f5fe640 Mon Sep 17 00:00:00 2001 From: romibi Date: Sun, 10 Dec 2023 16:00:45 +0100 Subject: [PATCH 3/3] Make all methods virtual extendability outside the library --- ScrapPackedLibrary/ScrapPackedTree.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ScrapPackedLibrary/ScrapPackedTree.cs b/ScrapPackedLibrary/ScrapPackedTree.cs index c476287..d1a94d5 100644 --- a/ScrapPackedLibrary/ScrapPackedTree.cs +++ b/ScrapPackedLibrary/ScrapPackedTree.cs @@ -20,24 +20,24 @@ public ScrapTreeEntry(ScrapTreeEntry p_Parent) { Parent = p_Parent; } - public string Name { get; set; } + public virtual string Name { get; set; } - public ScrapTreeEntry Parent { get; set; } + public virtual ScrapTreeEntry Parent { get; set; } - public PackedFileIndexData IndexData { get; set; } + public virtual PackedFileIndexData IndexData { get; set; } public bool IsFile { get { return !IsDirectory; } } - public bool IsDirectory { + public virtual bool IsDirectory { get { return IndexData is null; } } - public void AddFileData(PackedFileIndexData p_File, string p_SubdirFilename = "") { + public virtual void AddFileData(PackedFileIndexData p_File, string p_SubdirFilename = "") { string fileName; if (p_SubdirFilename.Length == 0) { fileName = p_File.FilePath; @@ -63,7 +63,7 @@ public void AddFileData(PackedFileIndexData p_File, string p_SubdirFilename = "" } } - public List GetItemPath() { + public virtual List GetItemPath() { // get a list of TreeItems from parent to selection // Todo: move logic inside TreeEntry and cache List itemPath = new List(); @@ -78,7 +78,7 @@ public List GetItemPath() { return itemPath; } - public string GetItemPathString(bool p_IgnoreRoot = true) { + public virtual string GetItemPathString(bool p_IgnoreRoot = true) { List itemPath = GetItemPath(); string pathString = ""; @@ -96,7 +96,7 @@ public string GetItemPathString(bool p_IgnoreRoot = true) { return pathString; } - public int CompareTo(object p_Other) { + public virtual int CompareTo(object p_Other) { ScrapTreeEntry a = this; ScrapTreeEntry b = (ScrapTreeEntry)p_Other; if (a.IsDirectory == b.IsDirectory) @@ -108,7 +108,7 @@ public int CompareTo(object p_Other) { return 1; } - public void Sort() { + public virtual void Sort() { var sorted = Items.OrderBy(p_X => p_X).ToList(); for (int i = 0; i < sorted.Count; i++) @@ -121,6 +121,6 @@ public void Sort() { } } - public ObservableCollection Items { get; set; } + public virtual ObservableCollection Items { get; set; } } }