rename tag
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
46b3cf1871
commit
db45552a05
@ -9,6 +9,7 @@ import '../../desktop/widgets/material_mod_popup_menu.dart' as mod_menu;
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../common.dart';
|
||||
import 'dialog.dart';
|
||||
import 'login.dart';
|
||||
|
||||
final hideAbTagsPanel = false.obs;
|
||||
@ -473,6 +474,29 @@ class AddressBookTag extends StatelessWidget {
|
||||
|
||||
void _showMenu(BuildContext context, RelativeRect pos) {
|
||||
final items = [
|
||||
getEntry(translate("Rename"), () {
|
||||
renameDialog(
|
||||
oldName: name,
|
||||
validator: (String? newName) {
|
||||
if (newName == null || newName.isEmpty) {
|
||||
return translate('Can not be empty');
|
||||
}
|
||||
if (newName != name && gFFI.abModel.tags.contains(newName)) {
|
||||
return translate('Already exists');
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSubmit: (String newName) {
|
||||
if (name != newName) {
|
||||
gFFI.abModel.renameTag(name, newName);
|
||||
gFFI.abModel.pushAb();
|
||||
}
|
||||
Future.delayed(Duration.zero, () => Get.back());
|
||||
},
|
||||
onCancel: () {
|
||||
Future.delayed(Duration.zero, () => Get.back());
|
||||
});
|
||||
}),
|
||||
getEntry(translate("Delete"), () {
|
||||
gFFI.abModel.deleteTag(name);
|
||||
gFFI.abModel.pushAb();
|
||||
|
@ -1448,3 +1448,74 @@ void editAbTagDialog(
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void renameDialog(
|
||||
{required String oldName,
|
||||
FormFieldValidator<String>? validator,
|
||||
required ValueChanged<String> onSubmit,
|
||||
Function? onCancel}) async {
|
||||
RxBool isInProgress = false.obs;
|
||||
var controller = TextEditingController(text: oldName);
|
||||
final formKey = GlobalKey<FormState>();
|
||||
gFFI.dialogManager.show((setState, close, context) {
|
||||
submit() async {
|
||||
String text = controller.text.trim();
|
||||
if (validator != null && formKey.currentState?.validate() == false) {
|
||||
return;
|
||||
}
|
||||
isInProgress.value = true;
|
||||
onSubmit(text);
|
||||
close();
|
||||
isInProgress.value = false;
|
||||
}
|
||||
|
||||
cancel() {
|
||||
onCancel?.call();
|
||||
close();
|
||||
}
|
||||
|
||||
return CustomAlertDialog(
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.edit_rounded, color: MyTheme.accent),
|
||||
Text(translate('Rename')).paddingOnly(left: 10),
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
child: Form(
|
||||
key: formKey,
|
||||
child: TextFormField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(labelText: translate('Name')),
|
||||
validator: validator,
|
||||
),
|
||||
),
|
||||
),
|
||||
Obx(() => Offstage(
|
||||
offstage: isInProgress.isFalse,
|
||||
child: const LinearProgressIndicator())),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
dialogButton(
|
||||
"Cancel",
|
||||
icon: Icon(Icons.close_rounded),
|
||||
onPressed: cancel,
|
||||
isOutline: true,
|
||||
),
|
||||
dialogButton(
|
||||
"OK",
|
||||
icon: Icon(Icons.done_rounded),
|
||||
onPressed: submit,
|
||||
),
|
||||
],
|
||||
onSubmit: submit,
|
||||
onCancel: cancel,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -139,9 +139,10 @@ class _PeerCardState extends State<_PeerCard>
|
||||
);
|
||||
},
|
||||
child: GestureDetector(
|
||||
onDoubleTap: peerTabModel.multiSelectionMode
|
||||
? null
|
||||
: () => widget.connect(context, peer.id),
|
||||
onDoubleTap:
|
||||
peerTabModel.multiSelectionMode || peerTabModel.isShiftDown
|
||||
? null
|
||||
: () => widget.connect(context, peer.id),
|
||||
onTap: () => peerTabModel.select(peer),
|
||||
onLongPress: () => peerTabModel.select(peer),
|
||||
child: Obx(() => peerCardUiType.value == PeerUiType.grid
|
||||
@ -600,8 +601,16 @@ abstract class BasePeerCard extends StatelessWidget {
|
||||
translate('Rename'),
|
||||
style: style,
|
||||
),
|
||||
proc: () {
|
||||
_rename(id);
|
||||
proc: () async {
|
||||
String oldName = await _getAlias(id);
|
||||
renameDialog(
|
||||
oldName: oldName,
|
||||
onSubmit: (String newName) async {
|
||||
if (newName != oldName) {
|
||||
await bind.mainSetPeerAlias(id: id, alias: newName);
|
||||
_update();
|
||||
}
|
||||
});
|
||||
},
|
||||
padding: menuPadding,
|
||||
dismissOnClicked: true,
|
||||
@ -771,64 +780,6 @@ abstract class BasePeerCard extends StatelessWidget {
|
||||
Future<String> _getAlias(String id) async =>
|
||||
await bind.mainGetPeerOption(id: id, key: 'alias');
|
||||
|
||||
void _rename(String id) async {
|
||||
RxBool isInProgress = false.obs;
|
||||
String name = await _getAlias(id);
|
||||
var controller = TextEditingController(text: name);
|
||||
gFFI.dialogManager.show((setState, close, context) {
|
||||
submit() async {
|
||||
isInProgress.value = true;
|
||||
String name = controller.text.trim();
|
||||
await bind.mainSetPeerAlias(id: id, alias: name);
|
||||
_update();
|
||||
close();
|
||||
isInProgress.value = false;
|
||||
}
|
||||
|
||||
return CustomAlertDialog(
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.edit_rounded, color: MyTheme.accent),
|
||||
Text(translate('Rename')).paddingOnly(left: 10),
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
child: Form(
|
||||
child: TextFormField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(labelText: translate('Name')),
|
||||
),
|
||||
),
|
||||
),
|
||||
Obx(() => Offstage(
|
||||
offstage: isInProgress.isFalse,
|
||||
child: const LinearProgressIndicator())),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
dialogButton(
|
||||
"Cancel",
|
||||
icon: Icon(Icons.close_rounded),
|
||||
onPressed: close,
|
||||
isOutline: true,
|
||||
),
|
||||
dialogButton(
|
||||
"OK",
|
||||
icon: Icon(Icons.done_rounded),
|
||||
onPressed: submit,
|
||||
),
|
||||
],
|
||||
onSubmit: submit,
|
||||
onCancel: close,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@protected
|
||||
void _update();
|
||||
}
|
||||
|
@ -223,6 +223,33 @@ class AbModel {
|
||||
}
|
||||
}
|
||||
|
||||
void renameTag(String oldTag, String newTag) {
|
||||
if (tags.contains(newTag)) return;
|
||||
tags.value = tags.map((e) {
|
||||
if (e == oldTag) {
|
||||
return newTag;
|
||||
} else {
|
||||
return oldTag;
|
||||
}
|
||||
}).toList();
|
||||
selectedTags.value = selectedTags.map((e) {
|
||||
if (e == oldTag) {
|
||||
return newTag;
|
||||
} else {
|
||||
return oldTag;
|
||||
}
|
||||
}).toList();
|
||||
for (var peer in peers) {
|
||||
peer.tags = peer.tags.map((e) {
|
||||
if (e == oldTag) {
|
||||
return newTag;
|
||||
} else {
|
||||
return oldTag;
|
||||
}
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
|
||||
void unsetSelectedTags() {
|
||||
selectedTags.clear();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", "对标签进行排序"),
|
||||
("Open connection in new tab", "在选项卡中打开新连接"),
|
||||
("Move tab to new window", "将标签页移至新窗口"),
|
||||
("Can not be empty", "不能为空"),
|
||||
("Already exists", "已经存在"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", "Tags sortieren"),
|
||||
("Open connection in new tab", "Verbindung in neuem Tab öffnen"),
|
||||
("Move tab to new window", "Tab in neues Fenster verschieben"),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", "Ordenar etiquetas"),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", "Ordina etichette"),
|
||||
("Open connection in new tab", "Apri connessione in una nuova scheda"),
|
||||
("Move tab to new window", "Sposta scheda nella finestra successiva"),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", "Labels sorteren"),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", "Znaczniki sortowania"),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", "Przenieś zakładkę do nowego okna"),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", "Сортировка меток"),
|
||||
("Open connection in new tab", "Открыть подключение в новой вкладке"),
|
||||
("Move tab to new window", "Переместить вкладку в отдельное окно"),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -529,5 +529,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", "排序標籤"),
|
||||
("Open connection in new tab", "在新分頁開啟連線"),
|
||||
("Move tab to new window", "移動標籤到新視窗"),
|
||||
("Can not be empty", "不能為空"),
|
||||
("Already exists", "已經存在"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -526,5 +526,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Sort tags", ""),
|
||||
("Open connection in new tab", ""),
|
||||
("Move tab to new window", ""),
|
||||
("Can not be empty", ""),
|
||||
("Already exists", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user