feat: Implement paste shortcut and remove popup menu option
taken from https://github.com/krille-chan/fluffychat/pull/2775
This commit is contained in:
parent
bd9ca7c9b3
commit
bf21b7f42c
4 changed files with 15 additions and 31 deletions
|
|
@ -1618,11 +1618,6 @@
|
||||||
"type": "String",
|
"type": "String",
|
||||||
"placeholders": {}
|
"placeholders": {}
|
||||||
},
|
},
|
||||||
"pasteImage": "Image from clipboard",
|
|
||||||
"@pasteImage": {
|
|
||||||
"type": "String",
|
|
||||||
"placeholders": {}
|
|
||||||
},
|
|
||||||
"sendImages": "Send {count} image",
|
"sendImages": "Send {count} image",
|
||||||
"@sendImages": {
|
"@sendImages": {
|
||||||
"type": "String",
|
"type": "String",
|
||||||
|
|
|
||||||
|
|
@ -1452,11 +1452,6 @@
|
||||||
"type": "String",
|
"type": "String",
|
||||||
"placeholders": {}
|
"placeholders": {}
|
||||||
},
|
},
|
||||||
"pasteImage": "Изображение из буфера обмена",
|
|
||||||
"@pasteImage": {
|
|
||||||
"type": "String",
|
|
||||||
"placeholders": {}
|
|
||||||
},
|
|
||||||
"sendMessages": "Отправить сообщения",
|
"sendMessages": "Отправить сообщения",
|
||||||
"@sendMessages": {
|
"@sendMessages": {
|
||||||
"type": "String",
|
"type": "String",
|
||||||
|
|
|
||||||
|
|
@ -344,6 +344,12 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return KeyEventResult.ignored;
|
||||||
|
} else if (evt is KeyDownEvent &&
|
||||||
|
evt.logicalKey == LogicalKeyboardKey.keyV &&
|
||||||
|
(HardwareKeyboard.instance.isControlPressed ||
|
||||||
|
HardwareKeyboard.instance.isMetaPressed)) {
|
||||||
|
sendImageFromClipBoardAction();
|
||||||
return KeyEventResult.ignored;
|
return KeyEventResult.ignored;
|
||||||
} else {
|
} else {
|
||||||
return KeyEventResult.ignored;
|
return KeyEventResult.ignored;
|
||||||
|
|
@ -659,10 +665,17 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
|
|
||||||
Future<void> sendImageFromClipBoard(Uint8List? image) async {
|
Future<void> sendImageFromClipBoard(Uint8List? image) async {
|
||||||
if (image == null) return;
|
if (image == null) return;
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
final mimeType = lookupMimeType('', headerBytes: image);
|
||||||
|
final fileType = mimeType == null ? null : extensionFromMime(mimeType);
|
||||||
|
final extension = fileType == null ? '' : '.$fileType';
|
||||||
|
final fileName = 'clipboard-image$extension';
|
||||||
|
|
||||||
await showAdaptiveDialog(
|
await showAdaptiveDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (c) => SendFileDialog(
|
builder: (c) => SendFileDialog(
|
||||||
files: [XFile.fromData(image)],
|
files: [XFile.fromData(image, name: fileName, mimeType: mimeType)],
|
||||||
room: room,
|
room: room,
|
||||||
outerContext: context,
|
outerContext: context,
|
||||||
threadRootEventId: activeThreadId,
|
threadRootEventId: activeThreadId,
|
||||||
|
|
@ -1248,9 +1261,6 @@ class ChatController extends State<ChatPageWithRoom>
|
||||||
case AddPopupMenuActions.location:
|
case AddPopupMenuActions.location:
|
||||||
sendLocationAction();
|
sendLocationAction();
|
||||||
return;
|
return;
|
||||||
case AddPopupMenuActions.pasteImage:
|
|
||||||
sendImageFromClipBoardAction();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1458,5 +1468,4 @@ enum AddPopupMenuActions {
|
||||||
photoCamera,
|
photoCamera,
|
||||||
videoCamera,
|
videoCamera,
|
||||||
location,
|
location,
|
||||||
pasteImage,
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -171,21 +171,6 @@ class ChatInputRow extends StatelessWidget {
|
||||||
contentPadding: const EdgeInsets.all(0),
|
contentPadding: const EdgeInsets.all(0),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (!PlatformInfos.isMobile)
|
|
||||||
PopupMenuItem(
|
|
||||||
value: AddPopupMenuActions.pasteImage,
|
|
||||||
child: ListTile(
|
|
||||||
leading: CircleAvatar(
|
|
||||||
backgroundColor:
|
|
||||||
theme.colorScheme.onPrimaryContainer,
|
|
||||||
foregroundColor:
|
|
||||||
theme.colorScheme.primaryContainer,
|
|
||||||
child: const Icon(Icons.content_paste),
|
|
||||||
),
|
|
||||||
title: Text(L10n.of(context).pasteImage),
|
|
||||||
contentPadding: const EdgeInsets.all(0),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: AddPopupMenuActions.image,
|
value: AddPopupMenuActions.image,
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue