@@ -11,15 +11,11 @@ abstract class KeybinderStore {
1111/// Defines a shortcut with an ID, display name, intent, and default activator.
1212class ShortcutDefinition {
1313 final String id;
14- final String displayName;
1514 final Intent intent;
1615 final ShortcutActivator defaultActivator;
1716
18- Type get intentType => intent.runtimeType;
19-
2017 const ShortcutDefinition ({
2118 required this .id,
22- required this .displayName,
2319 required this .intent,
2420 required this .defaultActivator,
2521 });
@@ -28,7 +24,6 @@ class ShortcutDefinition {
2824/// Manages keyboard shortcuts, including persistence and state management.
2925class Keybinder with ChangeNotifier {
3026 final Map <String , ShortcutDefinition > _definitionsById = {};
31- final Map <Type , ShortcutDefinition > _definitionsByType = {};
3227 final Map <String , ShortcutActivator > _activators = {};
3328 final KeybinderStore ? _store;
3429
@@ -42,61 +37,57 @@ class Keybinder with ChangeNotifier {
4237 }) : _store = store {
4338 for (final def in definitions) {
4439 _definitionsById[def.id] = def;
45- _definitionsByType[def.intentType] = def;
4640 _activators[def.id] = def.defaultActivator;
4741 }
4842 _load ();
4943 }
5044
51- /// Returns the current activator for the given Intent type .
52- ShortcutActivator getActivator (Type intentType ) {
53- final def = _definitionsByType[intentType ];
45+ /// Returns the current activator for the given ID .
46+ ShortcutActivator getActivator (String id ) {
47+ final def = _definitionsById[id ];
5448 if (def == null ) return const SingleActivator (LogicalKeyboardKey .keyA);
55- return _activators[def. id] ?? def.defaultActivator;
49+ return _activators[id] ?? def.defaultActivator;
5650 }
5751
58- /// Returns the definition for the given Intent type .
59- ShortcutDefinition ? getDefinition (Type intentType ) {
60- return _definitionsByType[intentType ];
52+ /// Returns the definition for the given ID .
53+ ShortcutDefinition ? getDefinition (String id ) {
54+ return _definitionsById[id ];
6155 }
6256
6357 /// Returns all registered definitions.
6458 Iterable <ShortcutDefinition > get definitions => _definitionsById.values;
6559
6660 /// Generates the map of activators to intents for use in the [Shortcuts] widget.
6761 ///
68- /// [intentTypes ] is a list of Intent types that should be active.
69- Map <ShortcutActivator , Intent > getShortcuts ([List <Type >? intentTypes ]) {
62+ /// [ids ] is a list of IDs that should be active.
63+ Map <ShortcutActivator , Intent > getShortcuts ([List <String >? ids ]) {
7064 final result = < ShortcutActivator , Intent > {};
71- for (final type in intentTypes ?? _definitionsByType .keys) {
72- final def = _definitionsByType[type ];
65+ for (final id in ids ?? _definitionsById .keys) {
66+ final def = _definitionsById[id ];
7367 if (def != null ) {
74- final activator = _activators[def. id] ?? def.defaultActivator;
68+ final activator = _activators[id] ?? def.defaultActivator;
7569 result[activator] = def.intent;
7670 }
7771 }
7872 return result;
7973 }
8074
81- /// Updates the binding for a specific Intent type.
82- Future <void > updateBinding (
83- Type intentType,
84- SingleActivator newActivator,
85- ) async {
86- final def = _definitionsByType[intentType];
75+ /// Updates the binding for a specific ID.
76+ Future <void > updateBinding (String id, SingleActivator newActivator) async {
77+ final def = _definitionsById[id];
8778 if (def == null ) return ;
8879
89- _activators[def. id] = newActivator;
80+ _activators[id] = newActivator;
9081 notifyListeners ();
9182 await _save ();
9283 }
9384
94- /// Resets the binding for a specific Intent type to its default.
95- Future <void > resetBinding (Type intentType ) async {
96- final def = _definitionsByType[intentType ];
85+ /// Resets the binding for a specific ID to its default.
86+ Future <void > resetBinding (String id ) async {
87+ final def = _definitionsById[id ];
9788 if (def == null ) return ;
9889
99- _activators[def. id] = def.defaultActivator;
90+ _activators[id] = def.defaultActivator;
10091 notifyListeners ();
10192 await _save ();
10293 }
0 commit comments