Skip to content

Commit

Permalink
Merge pull request #10 from arungovindm2001/alertBoxOnNewFolderClick
Browse files Browse the repository at this point in the history
Adds an alert box with text field to new folder click
  • Loading branch information
HrX03 authored Apr 17, 2022
2 parents f6e26c2 + edd554f commit 711d8c6
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions lib/widgets/workspace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ class _FilesWorkspaceState extends State<FilesWorkspace> {
/* TO KEEP */
late final CachingScrollController horizontalController;
late final CachingScrollController verticalController;
late TextEditingController textController;

WorkspaceController get controller => widget.controller;

String folderName = ' ';

@override
void initState() {
super.initState();
horizontalController = CachingScrollController(
initialScrollOffset: controller.lastHorizontalScrollOffset);
verticalController = CachingScrollController(
initialScrollOffset: controller.lastVerticalScrollOffset);
textController = TextEditingController();
controller.addListener(onControllerUpdate);
}

Expand All @@ -47,6 +51,7 @@ class _FilesWorkspaceState extends State<FilesWorkspace> {
horizontalController.lastPosition.pixels;
controller.lastVerticalScrollOffset =
verticalController.lastPosition.pixels;
textController.dispose();
controller.removeListener(onControllerUpdate);
super.dispose();
}
Expand Down Expand Up @@ -102,10 +107,15 @@ class _FilesWorkspaceState extends State<FilesWorkspace> {
),
tooltip: "New folder",
onPressed: () async {
final folderNameDialog = await openDialog();
final PathParts currentDir =
PathParts.parse(controller.currentDir);
currentDir.parts.add("sussy");
await Directory(currentDir.toPath()).create();
currentDir.parts.add('$folderNameDialog');
if (folderNameDialog != null) {
await Directory(currentDir.toPath())
.create(recursive: true);
controller.currentDir = currentDir.toPath();
}
},
splashRadius: 16,
),
Expand Down Expand Up @@ -139,6 +149,49 @@ class _FilesWorkspaceState extends State<FilesWorkspace> {
);
}

Future<String?> openDialog() => showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text("New Folder"),
content: TextField(
autofocus: true,
decoration: const InputDecoration(
hintText: "Folder name",
),
controller: textController,
onSubmitted: (value) {
Navigator.pop(context, value);
},
),
actions: [
TextButton(
child: const Text("Cancel"),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
child: const Text("Create"),
onPressed: textController.text != ""
? () => showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text("Folder name cannot be empty"),
actions: [
TextButton(
child: Text("OK"),
onPressed: () {
Navigator.pop(context);
},
),
]),
)
: () => Navigator.of(context).pop(textController.text),
),
],
),
);

String get selectedItemsLabel {
if (controller.selectedItems.isEmpty) return "";

Expand Down

0 comments on commit 711d8c6

Please sign in to comment.