-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #428
- Loading branch information
Showing
7 changed files
with
194 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:saber/components/theming/adaptive_alert_dialog.dart'; | ||
import 'package:saber/components/theming/adaptive_text_field.dart'; | ||
import 'package:saber/i18n/strings.g.dart'; | ||
|
||
class RenameFolderButton extends StatelessWidget { | ||
const RenameFolderButton({ | ||
super.key, | ||
required this.folderName, | ||
required this.doesFolderExist, | ||
required this.renameFolder, | ||
}); | ||
|
||
final String folderName; | ||
final bool Function(String) doesFolderExist; | ||
final Future<void> Function(String newName) renameFolder; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return IconButton( | ||
padding: EdgeInsets.zero, | ||
tooltip: t.home.renameFolder.renameFolder, | ||
onPressed: () { | ||
showDialog( | ||
context: context, | ||
builder: (BuildContext context) { | ||
return _RenameFolderDialog( | ||
folderName: folderName, | ||
doesFolderExist: doesFolderExist, | ||
renameFolder: renameFolder, | ||
); | ||
}, | ||
); | ||
}, | ||
icon: const Icon(Icons.edit_square), | ||
); | ||
} | ||
} | ||
|
||
class _RenameFolderDialog extends StatefulWidget { | ||
const _RenameFolderDialog({ | ||
// ignore: unused_element | ||
super.key, | ||
required this.folderName, | ||
required this.doesFolderExist, | ||
required this.renameFolder, | ||
}); | ||
|
||
final String folderName; | ||
final bool Function(String) doesFolderExist; | ||
final Future<void> Function(String newName) renameFolder; | ||
|
||
@override | ||
State<_RenameFolderDialog> createState() => _RenameFolderDialogState(); | ||
} | ||
class _RenameFolderDialogState extends State<_RenameFolderDialog> { | ||
final _formKey = GlobalKey<FormState>(); | ||
final TextEditingController _controller = TextEditingController(); | ||
|
||
String? validateFolderName(String? folderName) { | ||
if (folderName == null || folderName.isEmpty) { | ||
return t.home.renameFolder.folderNameEmpty; | ||
} | ||
if (folderName.contains('/') || folderName.contains('\\')) { | ||
return t.home.renameFolder.folderNameContainsSlash; | ||
} | ||
if (folderName != widget.folderName && widget.doesFolderExist(folderName)) { | ||
return t.home.renameFolder.folderNameExists; | ||
} | ||
return null; | ||
} | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_controller.text = widget.folderName; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AdaptiveAlertDialog( | ||
title: Text(t.home.renameFolder.renameFolder), | ||
content: Form( | ||
key: _formKey, | ||
autovalidateMode: AutovalidateMode.onUserInteraction, | ||
child: AdaptiveTextField( | ||
controller: _controller, | ||
keyboardType: TextInputType.text, | ||
textInputAction: TextInputAction.done, | ||
focusOrder: const NumericFocusOrder(1), | ||
placeholder: t.home.renameFolder.folderName, | ||
prefixIcon: const Icon(Icons.edit_square), | ||
validator: validateFolderName, | ||
), | ||
), | ||
actions: [ | ||
CupertinoDialogAction( | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
child: Text(t.editor.newerFileFormat.cancel), | ||
), | ||
CupertinoDialogAction( | ||
onPressed: () async { | ||
if (!_formKey.currentState!.validate()) return; | ||
if (_controller.text != widget.folderName) { | ||
await widget.renameFolder(_controller.text); | ||
if (!mounted) return; | ||
} | ||
Navigator.of(context).pop(); | ||
}, | ||
child: Text(t.home.renameFolder.rename), | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b1b8c45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New translation alert!
@Sdarfeesh @mamasch19 @fischerjosue @albanobattistella @jhihyulin @comcloudway @ShevT @ceskyDJ @fybx @mehdeej @Parameter15 @Polux49 @muhammadbahaa2001 @myanesp @theIuser @nagiyu @Jesse205 🚀
https://github.com/adil192/saber/edit/main/lib/i18n/_missing_translations.yaml
Instructions: https://github.com/adil192/saber#translating