Skip to content

Commit

Permalink
When deleting a map config, also delete the rendered map data
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed Sep 3, 2024
1 parent fab33f3 commit e5864d5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/map_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -91,16 +92,26 @@ class _MapTileState extends ConsumerState<MapTile> {
).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);
}
});
});
},
Expand Down

0 comments on commit e5864d5

Please sign in to comment.