JJ_MKVMaker/lib/ui/explorer/name_dialog.dart

31 lines
1.3 KiB
Dart

import 'package:flutter/material.dart';
import '../../l10n/tr.dart';
/// 약속 (E5d-5): 이름 하나를 묻는 창 (새 폴더 · 이름 변경 · PDF 이름 등). 처음 값은 [initial] (확장자 앞까지 고른 채 -
/// [selectAll] 이면 모두). 빈 칸 · [취소] 는 null, 아니면 앞뒤 빈칸을 뺀 이름
Future<String?> askName(BuildContext context, String title, String initial, {String? hint, bool selectAll = false}) {
final ctl = TextEditingController(text: initial);
final dot = initial.lastIndexOf('.');
ctl.selection = TextSelection(baseOffset: 0, extentOffset: dot > 0 && !selectAll ? dot : initial.length);
return showDialog<String>(
context: context,
builder: (ctx) => AlertDialog(
scrollable: true,
title: Text(title),
content: TextField(
controller: ctl,
autofocus: true,
decoration: InputDecoration(hintText: hint ?? tr('이름')),
onSubmitted: (v) => Navigator.pop(ctx, v.trim().isEmpty ? null : v.trim()),
),
actions: [
TextButton(onPressed: () => Navigator.pop(ctx), child: Text(tr('취소'))),
FilledButton(
onPressed: () => Navigator.pop(ctx, ctl.text.trim().isEmpty ? null : ctl.text.trim()),
child: Text(tr('확인'))),
],
),
);
}