@@ -54,6 +54,7 @@ pub enum Type {
54
54
Array ( Rc < Type > ) ,
55
55
Struct ( Rc < Struct > ) ,
56
56
Enumeration ( Rc < Enumeration > ) ,
57
+ KeyboardShortcut ,
57
58
58
59
/// A type made up of the product of several "unit" types.
59
60
/// The first parameter is the unit, and the second parameter is the power.
@@ -101,6 +102,7 @@ impl core::cmp::PartialEq for Type {
101
102
matches ! ( other, Type :: Struct ( rhs) if lhs. fields == rhs. fields && lhs. name == rhs. name)
102
103
}
103
104
Type :: Enumeration ( lhs) => matches ! ( other, Type :: Enumeration ( rhs) if lhs == rhs) ,
105
+ Type :: KeyboardShortcut => matches ! ( other, Type :: KeyboardShortcut ) ,
104
106
Type :: UnitProduct ( a) => matches ! ( other, Type :: UnitProduct ( b) if a == b) ,
105
107
Type :: ElementReference => matches ! ( other, Type :: ElementReference ) ,
106
108
Type :: LayoutCache => matches ! ( other, Type :: LayoutCache ) ,
@@ -160,6 +162,7 @@ impl Display for Type {
160
162
Type :: Easing => write ! ( f, "easing" ) ,
161
163
Type :: Brush => write ! ( f, "brush" ) ,
162
164
Type :: Enumeration ( enumeration) => write ! ( f, "enum {}" , enumeration. name) ,
165
+ Type :: KeyboardShortcut => write ! ( f, "keyboard-shortcut" ) ,
163
166
Type :: UnitProduct ( vec) => {
164
167
const POWERS : & [ char ] = & [ '⁰' , '¹' , '²' , '³' , '⁴' , '⁵' , '⁶' , '⁷' , '⁸' , '⁹' ] ;
165
168
let mut x = vec. iter ( ) . map ( |( unit, power) | {
@@ -208,6 +211,7 @@ impl Type {
208
211
| Self :: Bool
209
212
| Self :: Easing
210
213
| Self :: Enumeration ( _)
214
+ | Self :: KeyboardShortcut
211
215
| Self :: ElementReference
212
216
| Self :: Struct { .. }
213
217
| Self :: Array ( _)
@@ -265,6 +269,7 @@ impl Type {
265
269
| ( Type :: LogicalLength , Type :: Rem )
266
270
| ( Type :: PhysicalLength , Type :: Rem )
267
271
| ( Type :: Percent , Type :: Float32 )
272
+ | ( Type :: KeyboardShortcut , Type :: String )
268
273
| ( Type :: Brush , Type :: Color )
269
274
| ( Type :: Color , Type :: Brush ) => true ,
270
275
( Type :: Array ( a) , Type :: Model ) if a. is_property_type ( ) => true ,
@@ -311,6 +316,7 @@ impl Type {
311
316
Type :: Array ( _) => None ,
312
317
Type :: Struct { .. } => None ,
313
318
Type :: Enumeration ( _) => None ,
319
+ Type :: KeyboardShortcut => None ,
314
320
Type :: UnitProduct ( _) => None ,
315
321
Type :: ElementReference => None ,
316
322
Type :: LayoutCache => None ,
@@ -839,6 +845,40 @@ impl Enumeration {
839
845
}
840
846
}
841
847
848
+ #[ derive( Clone , Debug , Default ) ]
849
+ pub struct KeyboardModifiers {
850
+ pub alt : bool ,
851
+ pub control : bool ,
852
+ pub meta : bool ,
853
+ pub shift : bool ,
854
+ }
855
+
856
+ #[ derive( Clone , Debug , Default ) ]
857
+ pub struct KeyboardShortcut {
858
+ pub key : String ,
859
+ pub modifiers : KeyboardModifiers ,
860
+ }
861
+
862
+ impl PartialEq for KeyboardShortcut {
863
+ fn eq ( & self , _other : & Self ) -> bool {
864
+ true
865
+ }
866
+ }
867
+
868
+ impl std:: fmt:: Display for KeyboardShortcut {
869
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
870
+ let alt = if self . modifiers . alt { "alt+" } else { "" } ;
871
+ let ctrl = if self . modifiers . control { "ctrl+" } else { "" } ;
872
+ let meta = if self . modifiers . meta { "meta+" } else { "" } ;
873
+ let shift = if self . modifiers . shift { "shift+" } else { "" } ;
874
+ write ! ( f, "{alt}{ctrl}{meta}{shift}{}" , self . key)
875
+ }
876
+ }
877
+
878
+ pub fn keyboard_shortcuts_to_string ( shortcuts : & [ KeyboardShortcut ] ) -> String {
879
+ shortcuts. iter ( ) . map ( |ks| ks. to_string ( ) ) . join ( ", " )
880
+ }
881
+
842
882
#[ derive( Clone , Debug ) ]
843
883
pub struct EnumerationValue {
844
884
pub value : usize , // index in enumeration.values
0 commit comments