@@ -45,78 +45,100 @@ class ShortcutSerialization {
45
45
/// Creates a [ShortcutSerialization] representing a single character.
46
46
///
47
47
/// This is used by a [CharacterActivator] to serialize itself.
48
- ShortcutSerialization .character (String character)
49
- : _internal = < String , Object ? > {_kShortcutCharacter: character},
48
+ ShortcutSerialization .character (String character, {
49
+ bool alt = false ,
50
+ bool control = false ,
51
+ bool meta = false ,
52
+ }) : assert (character.length == 1 ),
50
53
_character = character,
51
- assert (character.length == 1 );
54
+ _trigger = null ,
55
+ _alt = alt,
56
+ _control = control,
57
+ _meta = meta,
58
+ _shift = null ,
59
+ _internal = < String , Object ? > {
60
+ _kShortcutCharacter: character,
61
+ _kShortcutModifiers: (control ? _shortcutModifierControl : 0 ) |
62
+ (alt ? _shortcutModifierAlt : 0 ) |
63
+ (meta ? _shortcutModifierMeta : 0 ),
64
+ };
52
65
53
66
/// Creates a [ShortcutSerialization] representing a specific
54
67
/// [LogicalKeyboardKey] and modifiers.
55
68
///
56
69
/// This is used by a [SingleActivator] to serialize itself.
57
70
ShortcutSerialization .modifier (
58
71
LogicalKeyboardKey trigger, {
59
- bool control = false ,
60
- bool shift = false ,
61
72
bool alt = false ,
73
+ bool control = false ,
62
74
bool meta = false ,
63
- }) : assert (trigger != LogicalKeyboardKey .shift &&
64
- trigger != LogicalKeyboardKey .shiftLeft &&
65
- trigger != LogicalKeyboardKey .shiftRight &&
66
- trigger != LogicalKeyboardKey .alt &&
75
+ bool shift = false ,
76
+ }) : assert (trigger != LogicalKeyboardKey .alt &&
67
77
trigger != LogicalKeyboardKey .altLeft &&
68
78
trigger != LogicalKeyboardKey .altRight &&
69
79
trigger != LogicalKeyboardKey .control &&
70
80
trigger != LogicalKeyboardKey .controlLeft &&
71
81
trigger != LogicalKeyboardKey .controlRight &&
72
82
trigger != LogicalKeyboardKey .meta &&
73
83
trigger != LogicalKeyboardKey .metaLeft &&
74
- trigger != LogicalKeyboardKey .metaRight,
84
+ trigger != LogicalKeyboardKey .metaRight &&
85
+ trigger != LogicalKeyboardKey .shift &&
86
+ trigger != LogicalKeyboardKey .shiftLeft &&
87
+ trigger != LogicalKeyboardKey .shiftRight,
75
88
'Specifying a modifier key as a trigger is not allowed. '
76
89
'Use provided boolean parameters instead.' ),
77
90
_trigger = trigger,
78
- _control = control,
79
- _shift = shift,
91
+ _character = null ,
80
92
_alt = alt,
93
+ _control = control,
81
94
_meta = meta,
95
+ _shift = shift,
82
96
_internal = < String , Object ? > {
83
97
_kShortcutTrigger: trigger.keyId,
84
- _kShortcutModifiers: (control ? _shortcutModifierControl : 0 ) |
85
- (alt ? _shortcutModifierAlt : 0 ) |
86
- (shift ? _shortcutModifierShift : 0 ) |
87
- (meta ? _shortcutModifierMeta : 0 ),
98
+ _kShortcutModifiers: (alt ? _shortcutModifierAlt : 0 ) |
99
+ (control ? _shortcutModifierControl : 0 ) |
100
+ (meta ? _shortcutModifierMeta : 0 ) |
101
+ (shift ? _shortcutModifierShift : 0 ),
88
102
};
89
103
90
104
final Map <String , Object ?> _internal;
91
105
92
106
/// The keyboard key that triggers this shortcut, if any.
93
107
LogicalKeyboardKey ? get trigger => _trigger;
94
- LogicalKeyboardKey ? _trigger;
108
+ final LogicalKeyboardKey ? _trigger;
95
109
96
110
/// The character that triggers this shortcut, if any.
97
111
String ? get character => _character;
98
- String ? _character;
112
+ final String ? _character;
113
+
114
+ /// If this shortcut has a [trigger] , this indicates whether or not the
115
+ /// alt modifier needs to be down or not.
116
+ bool ? get alt => _alt;
117
+ final bool ? _alt;
99
118
100
119
/// If this shortcut has a [trigger] , this indicates whether or not the
101
120
/// control modifier needs to be down or not.
102
121
bool ? get control => _control;
103
- bool ? _control;
122
+ final bool ? _control;
123
+
124
+ /// If this shortcut has a [trigger] , this indicates whether or not the meta
125
+ /// (also known as the Windows or Command key) modifier needs to be down or
126
+ /// not.
127
+ bool ? get meta => _meta;
128
+ final bool ? _meta;
104
129
105
130
/// If this shortcut has a [trigger] , this indicates whether or not the
106
131
/// shift modifier needs to be down or not.
107
132
bool ? get shift => _shift;
108
- bool ? _shift;
133
+ final bool ? _shift;
109
134
110
- /// If this shortcut has a [trigger] , this indicates whether or not the
111
- /// alt modifier needs to be down or not.
112
- bool ? get alt => _alt;
113
- bool ? _alt;
135
+ /// The bit mask for the [LogicalKeyboardKey.alt] key (or it's left/right
136
+ /// equivalents) being down.
137
+ static const int _shortcutModifierAlt = 1 << 2 ;
114
138
115
- /// If this shortcut has a [trigger] , this indicates whether or not the meta
116
- /// (also known as the Windows or Command key) modifier needs to be down or
117
- /// not.
118
- bool ? get meta => _meta;
119
- bool ? _meta;
139
+ /// The bit mask for the [LogicalKeyboardKey.control] key (or it's left/right
140
+ /// equivalents) being down.
141
+ static const int _shortcutModifierControl = 1 << 3 ;
120
142
121
143
/// The bit mask for the [LogicalKeyboardKey.meta] key (or it's left/right
122
144
/// equivalents) being down.
@@ -126,14 +148,6 @@ class ShortcutSerialization {
126
148
/// equivalents) being down.
127
149
static const int _shortcutModifierShift = 1 << 1 ;
128
150
129
- /// The bit mask for the [LogicalKeyboardKey.alt] key (or it's left/right
130
- /// equivalents) being down.
131
- static const int _shortcutModifierAlt = 1 << 2 ;
132
-
133
- /// The bit mask for the [LogicalKeyboardKey.alt] key (or it's left/right
134
- /// equivalents) being down.
135
- static const int _shortcutModifierControl = 1 << 3 ;
136
-
137
151
/// Converts the internal representation to the format needed for a
138
152
/// [PlatformMenuItem] to include it in its serialized form for sending to the
139
153
/// platform.
0 commit comments