feat: implement keyboard shortcuts
Added shortcuts for the following actions: - search chats - start chat - chat details - show widgets - cycle accounts - switch to account $i - toggle emoji picker - send file Related: #849 Signed-off-by: TheOneWithTheBraid <the-one@with-the-braid.cf>
This commit is contained in:
parent
7ce9d6384d
commit
824fcfc27c
7 changed files with 400 additions and 180 deletions
|
|
@ -2,10 +2,12 @@ import 'dart:async';
|
|||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:keyboard_shortcuts/keyboard_shortcuts.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
|
|
@ -16,6 +18,7 @@ import 'matrix.dart';
|
|||
class ChatSettingsPopupMenu extends StatefulWidget {
|
||||
final Room room;
|
||||
final bool displayChatDetails;
|
||||
|
||||
const ChatSettingsPopupMenu(this.room, this.displayChatDetails, {Key? key})
|
||||
: super(key: key);
|
||||
|
||||
|
|
@ -101,57 +104,88 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
),
|
||||
);
|
||||
}
|
||||
return PopupMenuButton(
|
||||
onSelected: (String choice) async {
|
||||
switch (choice) {
|
||||
case 'widgets':
|
||||
[TargetPlatform.iOS, TargetPlatform.macOS]
|
||||
.contains(Theme.of(context).platform)
|
||||
? showCupertinoModalPopup(
|
||||
return Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
KeyBoardShortcuts(
|
||||
child: Container(),
|
||||
keysToPress: {
|
||||
LogicalKeyboardKey.controlLeft,
|
||||
LogicalKeyboardKey.keyI
|
||||
},
|
||||
helpLabel: L10n.of(context)!.chatDetails,
|
||||
onKeysPressed: _showChatDetails,
|
||||
),
|
||||
KeyBoardShortcuts(
|
||||
child: Container(),
|
||||
keysToPress: {
|
||||
LogicalKeyboardKey.controlLeft,
|
||||
LogicalKeyboardKey.keyW
|
||||
},
|
||||
helpLabel: L10n.of(context)!.matrixWidgets,
|
||||
onKeysPressed: _showWidgets,
|
||||
),
|
||||
PopupMenuButton(
|
||||
onSelected: (String choice) async {
|
||||
switch (choice) {
|
||||
case 'widgets':
|
||||
_showWidgets();
|
||||
break;
|
||||
case 'leave':
|
||||
final confirmed = await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
cancelLabel: L10n.of(context)!.cancel,
|
||||
);
|
||||
if (confirmed == OkCancelResult.ok) {
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context, future: () => widget.room.leave());
|
||||
if (success.error == null) {
|
||||
VRouter.of(context).to('/rooms');
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'mute':
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
CupertinoWidgetsBottomSheet(room: widget.room),
|
||||
)
|
||||
: showModalBottomSheet(
|
||||
future: () => widget.room
|
||||
.setPushRuleState(PushRuleState.mentionsOnly));
|
||||
break;
|
||||
case 'unmute':
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
builder: (context) => WidgetsBottomSheet(room: widget.room),
|
||||
);
|
||||
break;
|
||||
case 'leave':
|
||||
final confirmed = await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
cancelLabel: L10n.of(context)!.cancel,
|
||||
);
|
||||
if (confirmed == OkCancelResult.ok) {
|
||||
final success = await showFutureLoadingDialog(
|
||||
context: context, future: () => widget.room.leave());
|
||||
if (success.error == null) {
|
||||
VRouter.of(context).to('/rooms');
|
||||
}
|
||||
future: () =>
|
||||
widget.room.setPushRuleState(PushRuleState.notify));
|
||||
break;
|
||||
case 'details':
|
||||
_showChatDetails();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'mute':
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
widget.room.setPushRuleState(PushRuleState.mentionsOnly));
|
||||
break;
|
||||
case 'unmute':
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
widget.room.setPushRuleState(PushRuleState.notify));
|
||||
break;
|
||||
case 'details':
|
||||
VRouter.of(context)
|
||||
.toSegments(['rooms', widget.room.id, 'details']);
|
||||
break;
|
||||
}
|
||||
},
|
||||
itemBuilder: (BuildContext context) => items,
|
||||
},
|
||||
itemBuilder: (BuildContext context) => items,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _showWidgets() => [TargetPlatform.iOS, TargetPlatform.macOS]
|
||||
.contains(Theme.of(context).platform)
|
||||
? showCupertinoModalPopup(
|
||||
context: context,
|
||||
builder: (context) => CupertinoWidgetsBottomSheet(room: widget.room),
|
||||
)
|
||||
: showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => WidgetsBottomSheet(room: widget.room),
|
||||
);
|
||||
|
||||
void _showChatDetails() {
|
||||
if (VRouter.of(context).path.endsWith('/details')) {
|
||||
VRouter.of(context).toSegments(['rooms', widget.room.id]);
|
||||
} else {
|
||||
VRouter.of(context).toSegments(['rooms', widget.room.id, 'details']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue