Adds delete functionality

This commit is contained in:
zontreck 2024-07-22 05:00:36 -07:00
parent eee0c035b5
commit fbd2decd26
15 changed files with 29 additions and 30 deletions

View file

@ -193,8 +193,7 @@ class EditorState extends State<Editor> {
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),

View file

@ -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),
);
}
}

View file

@ -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),
);
}
}

View file

@ -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),
);
}

View file

@ -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),
);
}
}

View file

@ -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),
);
}
}

View file

@ -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),
);
}
}

View file

@ -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),
);
}
}

View file

@ -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),
);
}
}

View file

@ -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),
);
}
}

View file

@ -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),
);
}
}

View file

@ -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),
);
}
}

View file

@ -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),
);
}
}

View file

@ -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))
],

View file

@ -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: