mirror of
https://github.com/zontreck/NBTEditor
synced 2024-11-21 13:48:56 -07:00
Adds delete functionality
This commit is contained in:
parent
eee0c035b5
commit
fbd2decd26
15 changed files with 29 additions and 30 deletions
|
@ -193,8 +193,7 @@ class EditorState extends State<Editor> {
|
||||||
body: TreeView(
|
body: TreeView(
|
||||||
nodeBuilder: (context, node) {
|
nodeBuilder: (context, node) {
|
||||||
if (node.data is Tag) {
|
if (node.data is Tag) {
|
||||||
return TagExt.render(
|
return TagExt.render(node.data as Tag, context, didChangeState);
|
||||||
node.data as Tag, context, didChangeState, true);
|
|
||||||
} else {
|
} else {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(node.label),
|
title: Text(node.label),
|
||||||
|
|
|
@ -25,7 +25,7 @@ extension ByteArrayTagExt on ByteArrayTag {
|
||||||
leading: TagExt.getTagIcon(getTagType()),
|
leading: TagExt.getTagIcon(getTagType()),
|
||||||
subtitle: TagExt.getElementDescriptor("${value.length} entries"),
|
subtitle: TagExt.getElementDescriptor("${value.length} entries"),
|
||||||
trailing: TagExt.getElementButtons(
|
trailing: TagExt.getElementButtons(
|
||||||
true, canBeNamed(this), false, this, context, didChangeState, true),
|
true, canBeNamed(this), false, this, context, didChangeState),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ extension ByteTagExt on ByteTag {
|
||||||
),
|
),
|
||||||
leading: TagExt.getTagIcon(getTagType()),
|
leading: TagExt.getTagIcon(getTagType()),
|
||||||
trailing: TagExt.getElementButtons(
|
trailing: TagExt.getElementButtons(
|
||||||
false, canBeNamed(this), true, this, context, didChangeState, true),
|
false, canBeNamed(this), true, this, context, didChangeState),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,15 @@ import 'package:libac_dart/nbt/impl/CompoundTag.dart';
|
||||||
import 'package:nbteditor/tags/Tag.dart';
|
import 'package:nbteditor/tags/Tag.dart';
|
||||||
|
|
||||||
extension CompoundTagExt on CompoundTag {
|
extension CompoundTagExt on CompoundTag {
|
||||||
Widget render(BuildContext context, Function didChangeState, bool isRootTag) {
|
Widget render(BuildContext context, Function didChangeState) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text("TAG_Compound (${getKey()})"),
|
title: Text("TAG_Compound (${getKey()})"),
|
||||||
subtitle: TagExt.getElementDescriptor(
|
subtitle: TagExt.getElementDescriptor(
|
||||||
"${value.length} tag${value.length > 1 ? "s" : ""}",
|
"${value.length} tag${value.length > 1 ? "s" : ""}",
|
||||||
),
|
),
|
||||||
leading: TagExt.getTagIcon(getTagType()),
|
leading: TagExt.getTagIcon(getTagType()),
|
||||||
trailing: TagExt.getElementButtons(true, canBeNamed(this), false, this,
|
trailing: TagExt.getElementButtons(
|
||||||
context, didChangeState, !isRootTag),
|
true, canBeNamed(this), false, this, context, didChangeState),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ extension DoubleTagExt on DoubleTag {
|
||||||
subtitle: TagExt.getElementDescriptor("$value"),
|
subtitle: TagExt.getElementDescriptor("$value"),
|
||||||
leading: TagExt.getTagIcon(getTagType()),
|
leading: TagExt.getTagIcon(getTagType()),
|
||||||
trailing: TagExt.getElementButtons(
|
trailing: TagExt.getElementButtons(
|
||||||
false, canBeNamed(this), true, this, context, didChangeState, true),
|
false, canBeNamed(this), true, this, context, didChangeState),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ extension FloatTagExt on FloatTag {
|
||||||
subtitle: TagExt.getElementDescriptor("$value"),
|
subtitle: TagExt.getElementDescriptor("$value"),
|
||||||
leading: TagExt.getTagIcon(getTagType()),
|
leading: TagExt.getTagIcon(getTagType()),
|
||||||
trailing: TagExt.getElementButtons(
|
trailing: TagExt.getElementButtons(
|
||||||
false, canBeNamed(this), true, this, context, didChangeState, true),
|
false, canBeNamed(this), true, this, context, didChangeState),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ extension IntArrayTagExt on IntArrayTag {
|
||||||
subtitle: TagExt.getElementDescriptor("${value.length} entries"),
|
subtitle: TagExt.getElementDescriptor("${value.length} entries"),
|
||||||
leading: TagExt.getTagIcon(getTagType()),
|
leading: TagExt.getTagIcon(getTagType()),
|
||||||
trailing: TagExt.getElementButtons(
|
trailing: TagExt.getElementButtons(
|
||||||
true, canBeNamed(this), false, this, context, didChangeState, true),
|
true, canBeNamed(this), false, this, context, didChangeState),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ extension IntTagExt on IntTag {
|
||||||
subtitle: TagExt.getElementDescriptor("$value"),
|
subtitle: TagExt.getElementDescriptor("$value"),
|
||||||
leading: TagExt.getTagIcon(getTagType()),
|
leading: TagExt.getTagIcon(getTagType()),
|
||||||
trailing: TagExt.getElementButtons(
|
trailing: TagExt.getElementButtons(
|
||||||
false, canBeNamed(this), true, this, context, didChangeState, true),
|
false, canBeNamed(this), true, this, context, didChangeState),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ extension ListTagExt on ListTag {
|
||||||
subtitle: TagExt.getElementDescriptor("${value.length} entries"),
|
subtitle: TagExt.getElementDescriptor("${value.length} entries"),
|
||||||
leading: TagExt.getTagIcon(getTagType()),
|
leading: TagExt.getTagIcon(getTagType()),
|
||||||
trailing: TagExt.getElementButtons(
|
trailing: TagExt.getElementButtons(
|
||||||
true, canBeNamed(this), false, this, context, didChangeState, true),
|
true, canBeNamed(this), false, this, context, didChangeState),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ extension LongArrayTagExt on LongArrayTag {
|
||||||
subtitle: TagExt.getElementDescriptor("${value.length} entries"),
|
subtitle: TagExt.getElementDescriptor("${value.length} entries"),
|
||||||
leading: TagExt.getTagIcon(getTagType()),
|
leading: TagExt.getTagIcon(getTagType()),
|
||||||
trailing: TagExt.getElementButtons(
|
trailing: TagExt.getElementButtons(
|
||||||
true, canBeNamed(this), false, this, context, didChangeState, true),
|
true, canBeNamed(this), false, this, context, didChangeState),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ extension LongTagExt on LongTag {
|
||||||
subtitle: TagExt.getElementDescriptor("$value"),
|
subtitle: TagExt.getElementDescriptor("$value"),
|
||||||
leading: TagExt.getTagIcon(getTagType()),
|
leading: TagExt.getTagIcon(getTagType()),
|
||||||
trailing: TagExt.getElementButtons(
|
trailing: TagExt.getElementButtons(
|
||||||
false, canBeNamed(this), true, this, context, didChangeState, true),
|
false, canBeNamed(this), true, this, context, didChangeState),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ extension ShortTagExt on ShortTag {
|
||||||
subtitle: TagExt.getElementDescriptor("$value"),
|
subtitle: TagExt.getElementDescriptor("$value"),
|
||||||
leading: TagExt.getTagIcon(getTagType()),
|
leading: TagExt.getTagIcon(getTagType()),
|
||||||
trailing: TagExt.getElementButtons(
|
trailing: TagExt.getElementButtons(
|
||||||
false, canBeNamed(this), true, this, context, didChangeState, true),
|
false, canBeNamed(this), true, this, context, didChangeState),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ extension StringTagExt on StringTag {
|
||||||
subtitle: TagExt.getElementDescriptor(value),
|
subtitle: TagExt.getElementDescriptor(value),
|
||||||
leading: TagExt.getTagIcon(getTagType()),
|
leading: TagExt.getTagIcon(getTagType()),
|
||||||
trailing: TagExt.getElementButtons(
|
trailing: TagExt.getElementButtons(
|
||||||
false, canBeNamed(this), true, this, context, didChangeState, true),
|
false, canBeNamed(this), true, this, context, didChangeState),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,7 @@ import 'package:nbteditor/tags/ShortTag.dart';
|
||||||
import 'package:nbteditor/tags/StringTag.dart';
|
import 'package:nbteditor/tags/StringTag.dart';
|
||||||
|
|
||||||
class TagExt {
|
class TagExt {
|
||||||
static Widget render(
|
static Widget render(Tag tag, BuildContext context, Function didChangeState) {
|
||||||
Tag tag, BuildContext context, Function didChangeState, bool isRootTag) {
|
|
||||||
switch (tag.getTagType()) {
|
switch (tag.getTagType()) {
|
||||||
case TagType.List:
|
case TagType.List:
|
||||||
{
|
{
|
||||||
|
@ -72,8 +71,7 @@ class TagExt {
|
||||||
}
|
}
|
||||||
case TagType.Compound:
|
case TagType.Compound:
|
||||||
{
|
{
|
||||||
return (tag as CompoundTag)
|
return (tag as CompoundTag).render(context, didChangeState);
|
||||||
.render(context, didChangeState, isRootTag);
|
|
||||||
}
|
}
|
||||||
case TagType.Short:
|
case TagType.Short:
|
||||||
{
|
{
|
||||||
|
@ -147,14 +145,8 @@ class TagExt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Widget getElementButtons(
|
static Widget getElementButtons(bool canAddElements, bool isNamed,
|
||||||
bool canAddElements,
|
bool editableValue, Tag tag, BuildContext ctx, Function didChangeState) {
|
||||||
bool isNamed,
|
|
||||||
bool editableValue,
|
|
||||||
Tag tag,
|
|
||||||
BuildContext ctx,
|
|
||||||
Function didChangeState,
|
|
||||||
bool canBeDeleted) {
|
|
||||||
return Row(
|
return Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
|
@ -238,10 +230,18 @@ class TagExt {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.edit_document)),
|
icon: const Icon(Icons.edit_document)),
|
||||||
if (canBeDeleted)
|
if (tag.hasParent)
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
// Remove the current tag from the containing tag
|
// 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))
|
icon: Icon(Icons.delete))
|
||||||
],
|
],
|
||||||
|
|
|
@ -16,7 +16,7 @@ dependencies:
|
||||||
flutter_treeview: ^1.0.7+1
|
flutter_treeview: ^1.0.7+1
|
||||||
libac_dart:
|
libac_dart:
|
||||||
hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/
|
hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/
|
||||||
version: 1.2.072124+0507
|
version: 1.2.072224+0449
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Reference in a new issue