diff --git a/assets/langs/en.yaml b/assets/langs/en.yaml index 6b6689aa..327e905e 100644 --- a/assets/langs/en.yaml +++ b/assets/langs/en.yaml @@ -46,7 +46,8 @@ screens: discard: Discard errorDialog: title: Error - content: Cannot delete a Folder which contains notes + deleteContent: Cannot delete a Folder which contains notes + renameContent: Cannot rename Root Folder ok: Ok actions: rename: Rename Folder diff --git a/lib/screens/folder_listing.dart b/lib/screens/folder_listing.dart index faebf77a..7d5036f8 100644 --- a/lib/screens/folder_listing.dart +++ b/lib/screens/folder_listing.dart @@ -68,6 +68,14 @@ class _FolderListingScreenState extends State { }, onSelected: (String value) async { if (value == "Rename") { + if (selectedFolder.pathSpec().isEmpty) { + await showDialog( + context: context, + builder: (_) => RenameFolderErrorDialog(), + ); + _folderTreeViewKey.currentState.resetSelection(); + return; + } var folderName = await showDialog( context: context, builder: (_) => RenameDialog( @@ -95,7 +103,7 @@ class _FolderListingScreenState extends State { if (selectedFolder.hasNotesRecursive) { await showDialog( context: context, - builder: (_) => FolderErrorDialog(), + builder: (_) => DeleteFolderErrorDialog(), ); } else { var container = @@ -217,11 +225,15 @@ class _CreateFolderAlertDialogState extends State { } class FolderErrorDialog extends StatelessWidget { + final String content; + + FolderErrorDialog(this.content); + @override Widget build(BuildContext context) { return AlertDialog( title: Text(tr("screens.folders.errorDialog.title")), - content: Text(tr("screens.folders.errorDialog.content")), + content: Text(content), actions: [ FlatButton( child: Text(tr("screens.folders.errorDialog.ok")), @@ -231,3 +243,17 @@ class FolderErrorDialog extends StatelessWidget { ); } } + +class DeleteFolderErrorDialog extends StatelessWidget { + @override + Widget build(BuildContext context) { + return FolderErrorDialog(tr("screens.folders.errorDialog.deleteContent")); + } +} + +class RenameFolderErrorDialog extends StatelessWidget { + @override + Widget build(BuildContext context) { + return FolderErrorDialog(tr("screens.folders.errorDialog.renameContent")); + } +}