|
1 | 1 | import 'package:butterfly/cubits/current_index.dart'; |
2 | 2 | import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter/services.dart'; |
3 | 4 | import 'package:flutter_bloc/flutter_bloc.dart'; |
| 5 | +import 'package:keybinder/keybinder.dart'; |
4 | 6 |
|
5 | 7 | import '../bloc/document_bloc.dart'; |
6 | 8 |
|
7 | 9 | class ChangeToolIntent extends Intent { |
8 | | - final BuildContext context; |
9 | 10 | final int index; |
10 | 11 |
|
11 | | - const ChangeToolIntent(this.context, this.index); |
| 12 | + const ChangeToolIntent(this.index); |
12 | 13 | } |
13 | 14 |
|
| 15 | +final changeToolShortcuts = List.generate(10, (index) { |
| 16 | + final key = [ |
| 17 | + LogicalKeyboardKey.digit1, |
| 18 | + LogicalKeyboardKey.digit2, |
| 19 | + LogicalKeyboardKey.digit3, |
| 20 | + LogicalKeyboardKey.digit4, |
| 21 | + LogicalKeyboardKey.digit5, |
| 22 | + LogicalKeyboardKey.digit6, |
| 23 | + LogicalKeyboardKey.digit7, |
| 24 | + LogicalKeyboardKey.digit8, |
| 25 | + LogicalKeyboardKey.digit9, |
| 26 | + LogicalKeyboardKey.digit0, |
| 27 | + ][index]; |
| 28 | + return ShortcutDefinition( |
| 29 | + id: 'tool_$index', |
| 30 | + intent: ChangeToolIntent(index), |
| 31 | + defaultActivator: SingleActivator(key, control: true), |
| 32 | + ); |
| 33 | +}); |
| 34 | + |
14 | 35 | class ChangeToolAction extends Action<ChangeToolIntent> { |
15 | | - ChangeToolAction(); |
| 36 | + final BuildContext context; |
| 37 | + |
| 38 | + ChangeToolAction(this.context); |
16 | 39 |
|
17 | 40 | @override |
18 | 41 | Future<void> invoke(ChangeToolIntent intent) async { |
19 | | - final bloc = intent.context.read<DocumentBloc>(); |
20 | | - intent.context.read<CurrentIndexCubit>().changeTool( |
| 42 | + final bloc = context.read<DocumentBloc>(); |
| 43 | + context.read<CurrentIndexCubit>().changeTool( |
21 | 44 | bloc, |
22 | | - context: intent.context, |
| 45 | + context: context, |
23 | 46 | index: intent.index, |
24 | 47 | ); |
25 | 48 | } |
|
0 commit comments