Start working on a Delete button

This commit is contained in:
zontreck 2024-07-22 04:12:39 -07:00
parent 495d750f6d
commit eee0c035b5
14 changed files with 35 additions and 21 deletions

View file

@ -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<Editor> {
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),

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, canBeNamed(this), false, this, context, didChangeState, true),
);
}
}

View file

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

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

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),
false, canBeNamed(this), true, this, context, didChangeState, true),
);
}
}

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),
false, canBeNamed(this), true, this, context, didChangeState, true),
);
}
}

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, canBeNamed(this), false, this, context, didChangeState, true),
);
}
}

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),
false, canBeNamed(this), true, this, context, didChangeState, true),
);
}
}

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, canBeNamed(this), false, this, context, didChangeState, true),
);
}
}

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, canBeNamed(this), false, this, context, didChangeState, true),
);
}
}

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),
false, canBeNamed(this), true, this, context, didChangeState, true),
);
}
}

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),
false, canBeNamed(this), true, this, context, didChangeState, true),
);
}
}

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),
false, canBeNamed(this), true, this, context, didChangeState, true),
);
}
}

View file

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