From 0c54b02c2cf4015a2c7da0e9e7af053980b3271e Mon Sep 17 00:00:00 2001 From: "philipp.monz" Date: Tue, 21 Nov 2023 19:03:21 +0100 Subject: [PATCH] #141 deleted KeyBoardShortcuts for changing Accounts --- .../chat_list/client_chooser_button.dart | 114 ------------------ 1 file changed, 114 deletions(-) diff --git a/lib/pages/chat_list/client_chooser_button.dart b/lib/pages/chat_list/client_chooser_button.dart index 8c8a8c2a13..c61c671dfe 100644 --- a/lib/pages/chat_list/client_chooser_button.dart +++ b/lib/pages/chat_list/client_chooser_button.dart @@ -1,9 +1,7 @@ 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:keyboard_shortcuts/keyboard_shortcuts.dart'; import 'package:matrix/matrix.dart'; import 'package:vrouter/vrouter.dart'; @@ -83,38 +81,6 @@ class ClientChooserButton extends StatelessWidget { builder: (context, snapshot) => Stack( alignment: Alignment.center, children: [ - ...List.generate( - clientCount, - (index) => KeyBoardShortcuts( - keysToPress: _buildKeyboardShortcut(index + 1), - helpLabel: L10n.of(context)!.switchToAccount(index + 1), - onKeysPressed: () => _handleKeyboardShortcut( - matrix, - index, - context, - ), - child: Container(), - ), - ), - KeyBoardShortcuts( - keysToPress: { - LogicalKeyboardKey.controlLeft, - LogicalKeyboardKey.tab - }, - helpLabel: L10n.of(context)!.nextAccount, - onKeysPressed: () => _nextAccount(matrix, context), - child: Container(), - ), - KeyBoardShortcuts( - keysToPress: { - LogicalKeyboardKey.controlLeft, - LogicalKeyboardKey.shiftLeft, - LogicalKeyboardKey.tab - }, - helpLabel: L10n.of(context)!.previousAccount, - onKeysPressed: () => _previousAccount(matrix, context), - child: Container(), - ), PopupMenuButton( onSelected: (o) => _clientSelected(o, context), itemBuilder: _bundleMenuItems, @@ -152,17 +118,6 @@ class ClientChooserButton extends StatelessWidget { ); } - Set? _buildKeyboardShortcut(int index) { - if (index > 0 && index < 10) { - return { - LogicalKeyboardKey.altLeft, - LogicalKeyboardKey(0x00000000030 + index) - }; - } else { - return null; - } - } - void _clientSelected( Object object, BuildContext context, @@ -202,75 +157,6 @@ class ClientChooserButton extends StatelessWidget { } } } - - void _handleKeyboardShortcut( - MatrixState matrix, - int index, - BuildContext context, - ) { - final bundles = matrix.accountBundles.keys.toList() - ..sort( - (a, b) => a!.isValidMatrixId == b!.isValidMatrixId - ? 0 - : a.isValidMatrixId && !b.isValidMatrixId - ? -1 - : 1, - ); - // beginning from end if negative - if (index < 0) { - int clientCount = 0; - matrix.accountBundles - .forEach((key, value) => clientCount += value.length); - _handleKeyboardShortcut(matrix, clientCount, context); - } - for (final bundleName in bundles) { - final bundle = matrix.accountBundles[bundleName]; - if (bundle != null) { - if (index < bundle.length) { - return _clientSelected(bundle[index]!, context); - } else { - index -= bundle.length; - } - } - } - // if index too high, restarting from 0 - _handleKeyboardShortcut(matrix, 0, context); - } - - int? _shortcutIndexOfClient(MatrixState matrix, Client client) { - int index = 0; - - final bundles = matrix.accountBundles.keys.toList() - ..sort( - (a, b) => a!.isValidMatrixId == b!.isValidMatrixId - ? 0 - : a.isValidMatrixId && !b.isValidMatrixId - ? -1 - : 1, - ); - for (final bundleName in bundles) { - final bundle = matrix.accountBundles[bundleName]; - if (bundle == null) return null; - if (bundle.contains(client)) { - return index + bundle.indexOf(client); - } else { - index += bundle.length; - } - } - return null; - } - - void _nextAccount(MatrixState matrix, BuildContext context) { - final client = matrix.client; - final lastIndex = _shortcutIndexOfClient(matrix, client); - _handleKeyboardShortcut(matrix, lastIndex! + 1, context); - } - - void _previousAccount(MatrixState matrix, BuildContext context) { - final client = matrix.client; - final lastIndex = _shortcutIndexOfClient(matrix, client); - _handleKeyboardShortcut(matrix, lastIndex! - 1, context); - } } enum SettingsAction {