#1248 fixed new album name resolution to allow same name as existing empty directory
This commit is contained in:
parent
c6ec5afba1
commit
ae22a25a13
2 changed files with 29 additions and 8 deletions
|
@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
- crash when loading large collection
|
||||
- Viewer: copying content URI item
|
||||
- Albums: creating album with same name as existing empty directory
|
||||
|
||||
## <a id="v1.11.16"></a>[v1.11.16] - 2024-10-10
|
||||
|
||||
|
|
|
@ -147,23 +147,43 @@ class _CreateAlbumDialogState extends State<CreateAlbumDialog> {
|
|||
);
|
||||
}
|
||||
|
||||
String _buildAlbumPath(String name) {
|
||||
String _sanitize(String input) => input.trim();
|
||||
|
||||
String? _buildAlbumPath(String name) {
|
||||
final selectedVolume = _selectedVolume;
|
||||
if (selectedVolume == null || name.isEmpty) return '';
|
||||
if (selectedVolume == null || name.isEmpty) return null;
|
||||
return pContext.join(selectedVolume.path, 'Pictures', name);
|
||||
}
|
||||
|
||||
Future<void> _validate() async {
|
||||
final newName = _nameController.text;
|
||||
final newName = _sanitize(_nameController.text);
|
||||
final path = _buildAlbumPath(newName);
|
||||
final exists = newName.isNotEmpty && await Directory(path).exists();
|
||||
// this check ignores case
|
||||
final exists = path != null && await Directory(path).exists();
|
||||
_existsNotifier.value = exists;
|
||||
_isValidNotifier.value = newName.isNotEmpty && !exists;
|
||||
_isValidNotifier.value = path != null && newName.isNotEmpty;
|
||||
}
|
||||
|
||||
void _submit(BuildContext context) {
|
||||
if (_isValidNotifier.value) {
|
||||
Navigator.maybeOf(context)?.pop(_buildAlbumPath(_nameController.text));
|
||||
Future<void> _submit(BuildContext context) async {
|
||||
if (!_isValidNotifier.value) return;
|
||||
|
||||
final newName = _sanitize(_nameController.text);
|
||||
final albumPath = _buildAlbumPath(newName);
|
||||
final volumePath = _selectedVolume?.path;
|
||||
if (albumPath == null || volumePath == null) return;
|
||||
|
||||
// uses resolved directory name case if it exists
|
||||
var resolvedPath = volumePath;
|
||||
final relativePathSegments = pContext.split(pContext.relative(albumPath, from: volumePath));
|
||||
for (final targetSegment in relativePathSegments) {
|
||||
String? resolvedSegment;
|
||||
final directory = Directory(resolvedPath);
|
||||
if (await directory.exists()) {
|
||||
final lowerTargetSegment = targetSegment.toLowerCase();
|
||||
resolvedSegment = directory.listSync().map((v) => pContext.basename(v.path)).firstWhereOrNull((v) => v.toLowerCase() == lowerTargetSegment);
|
||||
}
|
||||
resolvedPath = pContext.join(resolvedPath, resolvedSegment ?? targetSegment);
|
||||
}
|
||||
Navigator.maybeOf(context)?.pop(resolvedPath);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue