Hooks up rename prompt
This commit is contained in:
parent
2bc99f6bd9
commit
dc6dffc3ba
4 changed files with 121 additions and 3 deletions
|
@ -19,7 +19,21 @@ class EditorState extends State<Editor> {
|
||||||
List<Node> nodes = [CompoundTag().getNode("/")];
|
List<Node> nodes = [CompoundTag().getNode("/")];
|
||||||
bool compressed = false;
|
bool compressed = false;
|
||||||
|
|
||||||
|
static EditorState? _inst;
|
||||||
|
EditorState._() {
|
||||||
|
_inst = this;
|
||||||
|
}
|
||||||
late TreeViewController controller;
|
late TreeViewController controller;
|
||||||
|
factory EditorState() {
|
||||||
|
if (_inst == null)
|
||||||
|
return EditorState._();
|
||||||
|
else
|
||||||
|
return _inst!;
|
||||||
|
}
|
||||||
|
|
||||||
|
void update() {
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
String appendCompressed() {
|
String appendCompressed() {
|
||||||
if (compressed) {
|
if (compressed) {
|
||||||
|
|
|
@ -34,5 +34,14 @@ class AddState extends State<AddPage> {
|
||||||
|
|
||||||
class AddElementArgs {
|
class AddElementArgs {
|
||||||
Tag tag;
|
Tag tag;
|
||||||
AddElementArgs({required this.tag});
|
bool allowAllTagTypes;
|
||||||
|
bool isArray;
|
||||||
|
|
||||||
|
List<TagType> allowedTagTypes;
|
||||||
|
|
||||||
|
AddElementArgs(
|
||||||
|
{required this.tag,
|
||||||
|
required this.allowAllTagTypes,
|
||||||
|
required this.isArray,
|
||||||
|
this.allowedTagTypes = const []});
|
||||||
}
|
}
|
||||||
|
|
42
lib/pages/RenamePrompt.dart
Normal file
42
lib/pages/RenamePrompt.dart
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class RenamePrompt extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
State<StatefulWidget> createState() {
|
||||||
|
return RenameState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RenameState extends State<RenamePrompt> {
|
||||||
|
TextEditingController name = TextEditingController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
var args = ModalRoute.of(context)!.settings.arguments as String;
|
||||||
|
|
||||||
|
name.text = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
icon: Icon(Icons.edit_attributes),
|
||||||
|
title: Text("Edit Tag Name"),
|
||||||
|
actions: [
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context, name.text);
|
||||||
|
},
|
||||||
|
child: Text("SUBMIT")),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
child: const Text("CANCEL"),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
content: TextField(
|
||||||
|
controller: name,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,9 @@ import 'package:libac_dart/nbt/impl/LongArrayTag.dart';
|
||||||
import 'package:libac_dart/nbt/impl/LongTag.dart';
|
import 'package:libac_dart/nbt/impl/LongTag.dart';
|
||||||
import 'package:libac_dart/nbt/impl/ShortTag.dart';
|
import 'package:libac_dart/nbt/impl/ShortTag.dart';
|
||||||
import 'package:libac_dart/nbt/impl/StringTag.dart';
|
import 'package:libac_dart/nbt/impl/StringTag.dart';
|
||||||
|
import 'package:nbteditor/Editor.dart';
|
||||||
import 'package:nbteditor/pages/AddPage.dart';
|
import 'package:nbteditor/pages/AddPage.dart';
|
||||||
|
import 'package:nbteditor/pages/RenamePrompt.dart';
|
||||||
import 'package:nbteditor/tags/ByteArrayTag.dart';
|
import 'package:nbteditor/tags/ByteArrayTag.dart';
|
||||||
import 'package:nbteditor/tags/ByteTag.dart';
|
import 'package:nbteditor/tags/ByteTag.dart';
|
||||||
import 'package:nbteditor/tags/CompoundTag.dart';
|
import 'package:nbteditor/tags/CompoundTag.dart';
|
||||||
|
@ -153,12 +155,63 @@ class TagExt {
|
||||||
if (canAddElements)
|
if (canAddElements)
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
bool allowAllTagTypes = true;
|
||||||
|
bool isArray = false;
|
||||||
|
List<TagType> allowedTypes = [];
|
||||||
|
if (tag is CompoundTag) allowAllTagTypes = true;
|
||||||
|
if (tag is ListTag) {
|
||||||
|
ListTag lst = tag as ListTag;
|
||||||
|
if (lst.size() == 0)
|
||||||
|
allowAllTagTypes = true;
|
||||||
|
else {
|
||||||
|
allowAllTagTypes = false;
|
||||||
|
allowedTypes = [lst.get(0).getTagType()];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tag is ByteArrayTag) {
|
||||||
|
allowAllTagTypes = false;
|
||||||
|
isArray = true;
|
||||||
|
allowedTypes = [TagType.Byte];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag is IntArrayTag) {
|
||||||
|
allowAllTagTypes = false;
|
||||||
|
isArray = true;
|
||||||
|
allowedTypes = [TagType.Int];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag is LongArrayTag) {
|
||||||
|
allowAllTagTypes = false;
|
||||||
|
isArray = true;
|
||||||
|
allowedTypes = [TagType.Long];
|
||||||
|
}
|
||||||
|
|
||||||
var response = await Navigator.pushNamed(ctx, "/add",
|
var response = await Navigator.pushNamed(ctx, "/add",
|
||||||
arguments: AddElementArgs(tag: tag));
|
arguments: AddElementArgs(
|
||||||
|
tag: tag,
|
||||||
|
allowAllTagTypes: allowAllTagTypes,
|
||||||
|
isArray: isArray,
|
||||||
|
allowedTagTypes: allowedTypes));
|
||||||
},
|
},
|
||||||
child: Icon(Icons.add)),
|
child: Icon(Icons.add)),
|
||||||
if (isNamed)
|
if (isNamed)
|
||||||
ElevatedButton(onPressed: () {}, child: Text("R E N A M E")),
|
ElevatedButton(
|
||||||
|
onPressed: () async {
|
||||||
|
var response = await showDialog(
|
||||||
|
context: ctx,
|
||||||
|
routeSettings: RouteSettings(arguments: tag.getKey()),
|
||||||
|
builder: (B) {
|
||||||
|
return RenamePrompt();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response is String) {
|
||||||
|
tag.setKey(response as String);
|
||||||
|
|
||||||
|
EditorState state = EditorState();
|
||||||
|
state.update();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Text("R E N A M E")),
|
||||||
if (editableValue)
|
if (editableValue)
|
||||||
ElevatedButton(onPressed: () {}, child: Text("E D I T"))
|
ElevatedButton(onPressed: () {}, child: Text("E D I T"))
|
||||||
],
|
],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue