- display whole file path for the root element (if applicable)

This commit is contained in:
BuildTools 2023-07-23 18:09:29 +02:00
parent 15b1b2891f
commit d74e34e2da
5 changed files with 57 additions and 59 deletions

View file

@ -0,0 +1,45 @@
using System;
using System.IO;
namespace NBTExplorer.Model
{
/// <summary>
/// Common functionality for a few nodes that represent files.
/// </summary>
public class AbstractFileDataNode : DataNode
{
protected string _path;
protected AbstractFileDataNode(string path)
{
_path = path;
}
/// <summary>
/// Not only the name of the node but also (in some cases, but not all) the value (or part of the value) that is displayed to the user.
/// Return the full path if this node is the root, otherwise return only the file/folder name
/// </summary>
public override string NodeName
{
get => Parent == null ? _path : Path.GetFileName(_path);
}
/// <summary>
/// Just return NodeName, since that is where the display name is build.
/// Side note: I believe NodeName and NodeDisplay should be separated, this would then allow to replace NodePathName with NodeName, but that
/// would require changing a lot of unfamiliar (to me) code.
/// </summary>
public override string NodeDisplay
{
get => NodeName;
}
/// <summary>
/// The actual name of the node in a path. Return only the name of the file or folder, not the whole path.
/// </summary>
public override string NodePathName
{
get => Path.GetFileName(_path);
}
}
}

View file

@ -5,17 +5,14 @@ using NBTModel.Interop;
namespace NBTExplorer.Model namespace NBTExplorer.Model
{ {
public class CubicRegionDataNode : DataNode public class CubicRegionDataNode : AbstractFileDataNode
{ {
private string _path;
private CubicRegionFile _region; private CubicRegionFile _region;
private static Regex _namePattern = new Regex(@"^r2(\.-?\d+){3}\.(mcr|mca)$"); private static Regex _namePattern = new Regex(@"^r2(\.-?\d+){3}\.(mcr|mca)$");
private CubicRegionDataNode (string path) private CubicRegionDataNode (string path) : base(path)
{ {}
_path = path;
}
public static CubicRegionDataNode TryCreateFrom (string path) public static CubicRegionDataNode TryCreateFrom (string path)
{ {
@ -47,16 +44,6 @@ namespace NBTExplorer.Model
get { return true; } get { return true; }
} }
public override string NodePathName
{
get { return Path.GetFileName(_path); }
}
public override string NodeDisplay
{
get { return Path.GetFileName(_path); }
}
protected override void ExpandCore () protected override void ExpandCore ()
{ {
try { try {

View file

@ -4,14 +4,10 @@ using System;
namespace NBTExplorer.Model namespace NBTExplorer.Model
{ {
public class DirectoryDataNode : DataNode public class DirectoryDataNode : AbstractFileDataNode
{ {
private string _path; public DirectoryDataNode (string path) : base(path)
{}
public DirectoryDataNode (string path)
{
_path = path;
}
protected override NodeCapabilities Capabilities protected override NodeCapabilities Capabilities
{ {
@ -40,11 +36,6 @@ namespace NBTExplorer.Model
} }
} }
public override string NodeDisplay
{
get { return Path.GetFileName(_path); }
}
public override bool HasUnexpandedChildren public override bool HasUnexpandedChildren
{ {
get { return !IsExpanded; } get { return !IsExpanded; }

View file

@ -8,19 +8,17 @@ using NBTModel.Interop;
namespace NBTExplorer.Model namespace NBTExplorer.Model
{ {
public class NbtFileDataNode : DataNode, IMetaTagContainer public class NbtFileDataNode : AbstractFileDataNode, IMetaTagContainer
{ {
private NbtTree _tree; private NbtTree _tree;
private string _path;
private CompressionType _compressionType; private CompressionType _compressionType;
private CompoundTagContainer _container; private CompoundTagContainer _container;
private static Regex _namePattern = new Regex(@"\.(dat|nbt|schematic|dat_mcr|dat_old|bpt|rc)$"); private static Regex _namePattern = new Regex(@"\.(dat|nbt|schematic|dat_mcr|dat_old|bpt|rc)$");
private NbtFileDataNode (string path, CompressionType compressionType) private NbtFileDataNode (string path, CompressionType compressionType) : base(path)
{ {
_path = path;
_compressionType = compressionType; _compressionType = compressionType;
_container = new CompoundTagContainer(new TagNodeCompound()); _container = new CompoundTagContainer(new TagNodeCompound());
} }
@ -66,16 +64,6 @@ namespace NBTExplorer.Model
} }
} }
public override string NodeName
{
get { return Path.GetFileName(_path); }
}
public override string NodePathName
{
get { return Path.GetFileName(_path); }
}
public override string NodeDisplay public override string NodeDisplay
{ {
get get

View file

@ -7,18 +7,15 @@ using System;
namespace NBTExplorer.Model namespace NBTExplorer.Model
{ {
public class RegionFileDataNode : DataNode public class RegionFileDataNode : AbstractFileDataNode
{ {
private string _path;
private RegionFile _region; private RegionFile _region;
private List<RegionKey> _deleteQueue = new List<RegionKey>(); private List<RegionKey> _deleteQueue = new List<RegionKey>();
private static Regex _namePattern = new Regex(@"^r\.(-?\d+)\.(-?\d+)\.(mcr|mca)$"); private static Regex _namePattern = new Regex(@"^r\.(-?\d+)\.(-?\d+)\.(mcr|mca)$");
private RegionFileDataNode (string path) private RegionFileDataNode (string path) : base(path)
{ {}
_path = path;
}
public static RegionFileDataNode TryCreateFrom (string path) public static RegionFileDataNode TryCreateFrom (string path)
{ {
@ -64,16 +61,6 @@ namespace NBTExplorer.Model
get { return true; } get { return true; }
} }
public override string NodePathName
{
get { return Path.GetFileName(_path); }
}
public override string NodeDisplay
{
get { return Path.GetFileName(_path); }
}
protected override void ExpandCore () protected override void ExpandCore ()
{ {
try { try {