diff --git a/lib/Editor.dart b/lib/Editor.dart index c0da51b..f139f36 100644 --- a/lib/Editor.dart +++ b/lib/Editor.dart @@ -1,4 +1,3 @@ - import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter_treeview/flutter_treeview.dart'; @@ -194,7 +193,8 @@ class EditorState extends State { body: TreeView( nodeBuilder: (context, node) { if (node.data is Tag) { - return TagExt.render(node.data as Tag, context, didChangeState); + return TagExt.render( + node.data as Tag, context, didChangeState, true); } else { return ListTile( title: Text(node.label), diff --git a/lib/tags/ByteArrayTag.dart b/lib/tags/ByteArrayTag.dart index 42fd739..edda1d4 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, canBeNamed(this), false, this, context, didChangeState, true), ); } } diff --git a/lib/tags/ByteTag.dart b/lib/tags/ByteTag.dart index a45985b..3879e32 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), + false, canBeNamed(this), true, this, context, didChangeState, true), ); } } diff --git a/lib/tags/CompoundTag.dart b/lib/tags/CompoundTag.dart index 211d1bb..82b0028 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) { + Widget render(BuildContext context, Function didChangeState, bool isRootTag) { 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), + trailing: TagExt.getElementButtons(true, canBeNamed(this), false, this, + context, didChangeState, !isRootTag), ); } diff --git a/lib/tags/DoubleTag.dart b/lib/tags/DoubleTag.dart index bd9b359..90b95ef 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), + false, canBeNamed(this), true, this, context, didChangeState, true), ); } } diff --git a/lib/tags/FloatTag.dart b/lib/tags/FloatTag.dart index e8659fa..b21b79c 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), + false, canBeNamed(this), true, this, context, didChangeState, true), ); } } diff --git a/lib/tags/IntArrayTag.dart b/lib/tags/IntArrayTag.dart index dbff13a..a2defe2 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, canBeNamed(this), false, this, context, didChangeState, true), ); } } diff --git a/lib/tags/IntTag.dart b/lib/tags/IntTag.dart index 5fe830c..e2d1a22 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), + false, canBeNamed(this), true, this, context, didChangeState, true), ); } } diff --git a/lib/tags/ListTag.dart b/lib/tags/ListTag.dart index 1adb520..a2215e9 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, canBeNamed(this), false, this, context, didChangeState, true), ); } } diff --git a/lib/tags/LongArrayTag.dart b/lib/tags/LongArrayTag.dart index 18cdb53..bb06b4e 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, canBeNamed(this), false, this, context, didChangeState, true), ); } } diff --git a/lib/tags/LongTag.dart b/lib/tags/LongTag.dart index 9525090..c38bb33 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), + false, canBeNamed(this), true, this, context, didChangeState, true), ); } } diff --git a/lib/tags/ShortTag.dart b/lib/tags/ShortTag.dart index 0bc2012..fecad5c 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), + false, canBeNamed(this), true, this, context, didChangeState, true), ); } } diff --git a/lib/tags/StringTag.dart b/lib/tags/StringTag.dart index 7d1acf6..56857af 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), + false, canBeNamed(this), true, this, context, didChangeState, true), ); } } diff --git a/lib/tags/Tag.dart b/lib/tags/Tag.dart index ca2e7df..9af8e98 100644 --- a/lib/tags/Tag.dart +++ b/lib/tags/Tag.dart @@ -31,7 +31,8 @@ import 'package:nbteditor/tags/ShortTag.dart'; import 'package:nbteditor/tags/StringTag.dart'; class TagExt { - static Widget render(Tag tag, BuildContext context, Function didChangeState) { + static Widget render( + Tag tag, BuildContext context, Function didChangeState, bool isRootTag) { switch (tag.getTagType()) { case TagType.List: { @@ -71,7 +72,8 @@ class TagExt { } case TagType.Compound: { - return (tag as CompoundTag).render(context, didChangeState); + return (tag as CompoundTag) + .render(context, didChangeState, isRootTag); } case TagType.Short: { @@ -145,8 +147,14 @@ class TagExt { } } - static Widget getElementButtons(bool canAddElements, bool isNamed, - bool editableValue, Tag tag, BuildContext ctx, Function didChangeState) { + static Widget getElementButtons( + bool canAddElements, + bool isNamed, + bool editableValue, + Tag tag, + BuildContext ctx, + Function didChangeState, + bool canBeDeleted) { return Row( mainAxisSize: MainAxisSize.min, children: [ @@ -229,7 +237,13 @@ class TagExt { didChangeState.call(); } }, - icon: const Icon(Icons.edit_document)) + icon: const Icon(Icons.edit_document)), + if (canBeDeleted) + IconButton( + onPressed: () async { + // Remove the current tag from the containing tag + }, + icon: Icon(Icons.delete)) ], ); }