Skip to content

Commit a06796d

Browse files
committed
Editor: Delete directory
1 parent 151c4e0 commit a06796d

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

lib/filebrowser/widgets/directory_widget.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ class DirectoryWidget extends StatelessWidget {
1717
final String directoryName;
1818
final DateTime lastModified;
1919
final VoidCallback? onPressedNext;
20+
final void Function(String filepath) onLongTap;
2021

2122
DirectoryWidget({
2223
required this.path,
2324
required this.directoryName,
2425
required this.lastModified,
2526
this.onPressedNext,
27+
required this.onLongTap
2628
});
2729

2830
@override
@@ -47,6 +49,7 @@ class DirectoryWidget extends StatelessWidget {
4749

4850
return TextButton(
4951
onPressed: (() => onPressedNext!()),
52+
onLongPress: (() => onLongTap(path)),
5053
child: Row(children: [
5154
folderIcon,
5255
titleWidget,

lib/screens/editor/editor.dart

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,26 @@ class _EditorPageState extends State<EditorPage> {
110110
}
111111

112112
//TODO: Add file under directory
113+
//TODO: Add dir under dir
113114
//TODO: Rename file
114115
//TODO: Move file
115116

116-
void deleteFileOrFolder(String filepath) async {
117-
var file = File(filepath);
118-
file.delete();
117+
void deleteFile(String filepath) async {
118+
final file = File(filepath);
119+
await file.delete();
119120
refreshFileBrowser();
120121
}
121122

123+
void deleteDir(String dirpath) async {
124+
final dir = Directory(dirpath);
125+
await dir.delete(recursive: true);
126+
refreshFileBrowser();
127+
}
128+
129+
void createFile(String filepath) {
130+
final file = File(filepath);
131+
}
132+
122133
void refreshFileBrowser() async {
123134
List<Document> docs = List.empty(growable: true);
124135

@@ -417,16 +428,30 @@ class _EditorPageState extends State<EditorPage> {
417428
var selection = await showMenu(context: context, position: const RelativeRect.fromLTRB(1, 1, 1, 1), items: <PopupMenuEntry<String>>[
418429
const PopupMenuItem<String>(
419430
value: "delete",
420-
child: Text('Delete item'),
431+
child: Text('Delete file'),
421432
),
422433
]);
423434
//TODO: Menu should show up at tap location
424435
//TODO: Refactor menu into separate file
425436
switch(selection) {
426437
case 'delete':
427-
deleteFileOrFolder(filepath);
438+
deleteFile(filepath);
428439
}
429-
}),
440+
}, (String dirpath) async {
441+
var selection = await showMenu(context: context, position: const RelativeRect.fromLTRB(1, 1, 1, 1), items: <PopupMenuEntry<String>>[
442+
const PopupMenuItem<String>(
443+
value: "delete",
444+
child: Text('Delete folder'),
445+
),
446+
]);
447+
//TODO: Menu should show up at tap location
448+
//TODO: Refactor menu into separate file
449+
switch(selection) {
450+
case 'delete':
451+
deleteDir(dirpath);
452+
}
453+
}
454+
),
430455
appBar: AppBar(
431456
title: null,
432457
centerTitle: false,

lib/screens/editor/editor_drawer.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ class MyDrawer extends StatelessWidget {
2828
final List<Document> documentList;
2929
final void Function(String filepath) onFileTap;
3030
final void Function(String filepath) onFileLongTap;
31+
final void Function(String filepath) onDirLongTap;
3132

32-
const MyDrawer(this.documentList, this.project, this.onFileTap, this.onFileLongTap);
33+
const MyDrawer(this.documentList, this.project, this.onFileTap, this.onFileLongTap, this.onDirLongTap);
3334

3435
@override
3536
Widget build(BuildContext context) {
@@ -106,6 +107,7 @@ class MyDrawer extends StatelessWidget {
106107
directoryName: document.name,
107108
lastModified: document.dateModified,
108109
onPressedNext: onPressedNext,
110+
onLongTap: onDirLongTap
109111
);
110112

111113
FileWidget _getFileWidget({required Document document}) => FileWidget(

0 commit comments

Comments
 (0)