From e5864d5c6974e8d1d2ced079d9d1801f05d51b54 Mon Sep 17 00:00:00 2001 From: TechnicJelle <22576047+TechnicJelle@users.noreply.github.com> Date: Tue, 3 Sep 2024 05:03:07 +0200 Subject: [PATCH] When deleting a map config, also delete the rendered map data --- lib/map_tile.dart | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/map_tile.dart b/lib/map_tile.dart index 7b955d7..3a67e19 100644 --- a/lib/map_tile.dart +++ b/lib/map_tile.dart @@ -6,6 +6,7 @@ import "package:path/path.dart" as p; import "delete_icon.dart"; import "dual_pane.dart"; +import "main.dart"; import "utils.dart"; class MapTile extends ConsumerStatefulWidget { @@ -91,16 +92,26 @@ class _MapTileState extends ConsumerState { ).then((bool? confirmed) { if (confirmed == null || confirmed == false) return; - //if the editor is open on that file, close it + // == If the editor is open on that file, close it == if (openConfig != null && p.equals(openConfig.path, configFile.path)) { ref.read(openConfigProvider.notifier).close(); } + + // == Delete the config file and the rendered map data == + final Directory? projectDirectory = + ref.watch(projectDirectoryProvider); //delete the file next frame, to ensure the editor is closed WidgetsBinding.instance.addPostFrameCallback((_) { configFile.delete(); - //TODO: Also delete the rendered map data (check if it exists first) - //($pwd/web/maps/map-id) + + if (projectDirectory == null) return; + final String mapID = p.basenameWithoutExtension(configFile.path); + final Directory mapDirectory = + Directory(p.join(projectDirectory.path, "web", "maps", mapID)); + if (mapDirectory.existsSync()) { + mapDirectory.delete(recursive: true); + } }); }); },