diff --git a/lib/Editor.dart b/lib/Editor.dart index f139f36..bdd9a92 100644 --- a/lib/Editor.dart +++ b/lib/Editor.dart @@ -193,8 +193,7 @@ class EditorState extends State { body: TreeView( nodeBuilder: (context, node) { if (node.data is Tag) { - return TagExt.render( - node.data as Tag, context, didChangeState, true); + return TagExt.render(node.data as Tag, context, didChangeState); } else { return ListTile( title: Text(node.label), diff --git a/lib/tags/ByteArrayTag.dart b/lib/tags/ByteArrayTag.dart index edda1d4..42fd739 100644 --- a/lib/tags/ByteArrayTag.dart +++ b/lib/tags/ByteArrayTag.dart @@ -25,7 +25,7 @@ extension ByteArrayTagExt on ByteArrayTag { leading: TagExt.getTagIcon(getTagType()), subtitle: TagExt.getElementDescriptor("${value.length} entries"), trailing: TagExt.getElementButtons( - true, canBeNamed(this), false, this, context, didChangeState, true), + true, canBeNamed(this), false, this, context, didChangeState), ); } } diff --git a/lib/tags/ByteTag.dart b/lib/tags/ByteTag.dart index 3879e32..a45985b 100644 --- a/lib/tags/ByteTag.dart +++ b/lib/tags/ByteTag.dart @@ -16,7 +16,7 @@ extension ByteTagExt on ByteTag { ), leading: TagExt.getTagIcon(getTagType()), trailing: TagExt.getElementButtons( - false, canBeNamed(this), true, this, context, didChangeState, true), + false, canBeNamed(this), true, this, context, didChangeState), ); } } diff --git a/lib/tags/CompoundTag.dart b/lib/tags/CompoundTag.dart index 82b0028..211d1bb 100644 --- a/lib/tags/CompoundTag.dart +++ b/lib/tags/CompoundTag.dart @@ -4,15 +4,15 @@ import 'package:libac_dart/nbt/impl/CompoundTag.dart'; import 'package:nbteditor/tags/Tag.dart'; extension CompoundTagExt on CompoundTag { - Widget render(BuildContext context, Function didChangeState, bool isRootTag) { + Widget render(BuildContext context, Function didChangeState) { return ListTile( title: Text("TAG_Compound (${getKey()})"), subtitle: TagExt.getElementDescriptor( "${value.length} tag${value.length > 1 ? "s" : ""}", ), leading: TagExt.getTagIcon(getTagType()), - trailing: TagExt.getElementButtons(true, canBeNamed(this), false, this, - context, didChangeState, !isRootTag), + trailing: TagExt.getElementButtons( + true, canBeNamed(this), false, this, context, didChangeState), ); } diff --git a/lib/tags/DoubleTag.dart b/lib/tags/DoubleTag.dart index 90b95ef..bd9b359 100644 --- a/lib/tags/DoubleTag.dart +++ b/lib/tags/DoubleTag.dart @@ -14,7 +14,7 @@ extension DoubleTagExt on DoubleTag { subtitle: TagExt.getElementDescriptor("$value"), leading: TagExt.getTagIcon(getTagType()), trailing: TagExt.getElementButtons( - false, canBeNamed(this), true, this, context, didChangeState, true), + false, canBeNamed(this), true, this, context, didChangeState), ); } } diff --git a/lib/tags/FloatTag.dart b/lib/tags/FloatTag.dart index b21b79c..e8659fa 100644 --- a/lib/tags/FloatTag.dart +++ b/lib/tags/FloatTag.dart @@ -15,7 +15,7 @@ extension FloatTagExt on FloatTag { subtitle: TagExt.getElementDescriptor("$value"), leading: TagExt.getTagIcon(getTagType()), trailing: TagExt.getElementButtons( - false, canBeNamed(this), true, this, context, didChangeState, true), + false, canBeNamed(this), true, this, context, didChangeState), ); } } diff --git a/lib/tags/IntArrayTag.dart b/lib/tags/IntArrayTag.dart index a2defe2..dbff13a 100644 --- a/lib/tags/IntArrayTag.dart +++ b/lib/tags/IntArrayTag.dart @@ -26,7 +26,7 @@ extension IntArrayTagExt on IntArrayTag { subtitle: TagExt.getElementDescriptor("${value.length} entries"), leading: TagExt.getTagIcon(getTagType()), trailing: TagExt.getElementButtons( - true, canBeNamed(this), false, this, context, didChangeState, true), + true, canBeNamed(this), false, this, context, didChangeState), ); } } diff --git a/lib/tags/IntTag.dart b/lib/tags/IntTag.dart index e2d1a22..5fe830c 100644 --- a/lib/tags/IntTag.dart +++ b/lib/tags/IntTag.dart @@ -15,7 +15,7 @@ extension IntTagExt on IntTag { subtitle: TagExt.getElementDescriptor("$value"), leading: TagExt.getTagIcon(getTagType()), trailing: TagExt.getElementButtons( - false, canBeNamed(this), true, this, context, didChangeState, true), + false, canBeNamed(this), true, this, context, didChangeState), ); } } diff --git a/lib/tags/ListTag.dart b/lib/tags/ListTag.dart index a2215e9..1adb520 100644 --- a/lib/tags/ListTag.dart +++ b/lib/tags/ListTag.dart @@ -26,7 +26,7 @@ extension ListTagExt on ListTag { subtitle: TagExt.getElementDescriptor("${value.length} entries"), leading: TagExt.getTagIcon(getTagType()), trailing: TagExt.getElementButtons( - true, canBeNamed(this), false, this, context, didChangeState, true), + true, canBeNamed(this), false, this, context, didChangeState), ); } } diff --git a/lib/tags/LongArrayTag.dart b/lib/tags/LongArrayTag.dart index bb06b4e..18cdb53 100644 --- a/lib/tags/LongArrayTag.dart +++ b/lib/tags/LongArrayTag.dart @@ -26,7 +26,7 @@ extension LongArrayTagExt on LongArrayTag { subtitle: TagExt.getElementDescriptor("${value.length} entries"), leading: TagExt.getTagIcon(getTagType()), trailing: TagExt.getElementButtons( - true, canBeNamed(this), false, this, context, didChangeState, true), + true, canBeNamed(this), false, this, context, didChangeState), ); } } diff --git a/lib/tags/LongTag.dart b/lib/tags/LongTag.dart index c38bb33..9525090 100644 --- a/lib/tags/LongTag.dart +++ b/lib/tags/LongTag.dart @@ -15,7 +15,7 @@ extension LongTagExt on LongTag { subtitle: TagExt.getElementDescriptor("$value"), leading: TagExt.getTagIcon(getTagType()), trailing: TagExt.getElementButtons( - false, canBeNamed(this), true, this, context, didChangeState, true), + false, canBeNamed(this), true, this, context, didChangeState), ); } } diff --git a/lib/tags/ShortTag.dart b/lib/tags/ShortTag.dart index fecad5c..0bc2012 100644 --- a/lib/tags/ShortTag.dart +++ b/lib/tags/ShortTag.dart @@ -15,7 +15,7 @@ extension ShortTagExt on ShortTag { subtitle: TagExt.getElementDescriptor("$value"), leading: TagExt.getTagIcon(getTagType()), trailing: TagExt.getElementButtons( - false, canBeNamed(this), true, this, context, didChangeState, true), + false, canBeNamed(this), true, this, context, didChangeState), ); } } diff --git a/lib/tags/StringTag.dart b/lib/tags/StringTag.dart index 56857af..7d1acf6 100644 --- a/lib/tags/StringTag.dart +++ b/lib/tags/StringTag.dart @@ -15,7 +15,7 @@ extension StringTagExt on StringTag { subtitle: TagExt.getElementDescriptor(value), leading: TagExt.getTagIcon(getTagType()), trailing: TagExt.getElementButtons( - false, canBeNamed(this), true, this, context, didChangeState, true), + false, canBeNamed(this), true, this, context, didChangeState), ); } } diff --git a/lib/tags/Tag.dart b/lib/tags/Tag.dart index 9af8e98..c94e977 100644 --- a/lib/tags/Tag.dart +++ b/lib/tags/Tag.dart @@ -31,8 +31,7 @@ import 'package:nbteditor/tags/ShortTag.dart'; import 'package:nbteditor/tags/StringTag.dart'; class TagExt { - static Widget render( - Tag tag, BuildContext context, Function didChangeState, bool isRootTag) { + static Widget render(Tag tag, BuildContext context, Function didChangeState) { switch (tag.getTagType()) { case TagType.List: { @@ -72,8 +71,7 @@ class TagExt { } case TagType.Compound: { - return (tag as CompoundTag) - .render(context, didChangeState, isRootTag); + return (tag as CompoundTag).render(context, didChangeState); } case TagType.Short: { @@ -147,14 +145,8 @@ class TagExt { } } - static Widget getElementButtons( - bool canAddElements, - bool isNamed, - bool editableValue, - Tag tag, - BuildContext ctx, - Function didChangeState, - bool canBeDeleted) { + static Widget getElementButtons(bool canAddElements, bool isNamed, + bool editableValue, Tag tag, BuildContext ctx, Function didChangeState) { return Row( mainAxisSize: MainAxisSize.min, children: [ @@ -238,10 +230,18 @@ class TagExt { } }, icon: const Icon(Icons.edit_document)), - if (canBeDeleted) + if (tag.hasParent) IconButton( onPressed: () async { // Remove the current tag from the containing tag + Tag parent = tag.getParent!; + if (tag.parentTagType == TagType.Compound) { + parent.asCompoundTag().remove(tag.getKey()); + } else if (tag.parentTagType == TagType.List) { + (parent as ListTag).remove(tag); + } + + didChangeState.call(); }, icon: Icon(Icons.delete)) ], diff --git a/pubspec.yaml b/pubspec.yaml index 62be269..33bd627 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: flutter_treeview: ^1.0.7+1 libac_dart: hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/ - version: 1.2.072124+0507 + version: 1.2.072224+0449 dev_dependencies: flutter_test: