@@ -54,6 +54,7 @@ pub enum Type {
5454 Array ( Rc < Type > ) ,
5555 Struct ( Rc < Struct > ) ,
5656 Enumeration ( Rc < Enumeration > ) ,
57+ KeyboardShortcut ,
5758
5859 /// A type made up of the product of several "unit" types.
5960 /// The first parameter is the unit, and the second parameter is the power.
@@ -101,6 +102,7 @@ impl core::cmp::PartialEq for Type {
101102 matches ! ( other, Type :: Struct ( rhs) if lhs. fields == rhs. fields && lhs. name == rhs. name)
102103 }
103104 Type :: Enumeration ( lhs) => matches ! ( other, Type :: Enumeration ( rhs) if lhs == rhs) ,
105+ Type :: KeyboardShortcut => matches ! ( other, Type :: KeyboardShortcut ) ,
104106 Type :: UnitProduct ( a) => matches ! ( other, Type :: UnitProduct ( b) if a == b) ,
105107 Type :: ElementReference => matches ! ( other, Type :: ElementReference ) ,
106108 Type :: LayoutCache => matches ! ( other, Type :: LayoutCache ) ,
@@ -160,6 +162,7 @@ impl Display for Type {
160162 Type :: Easing => write ! ( f, "easing" ) ,
161163 Type :: Brush => write ! ( f, "brush" ) ,
162164 Type :: Enumeration ( enumeration) => write ! ( f, "enum {}" , enumeration. name) ,
165+ Type :: KeyboardShortcut => write ! ( f, "keyboard-shortcut" ) ,
163166 Type :: UnitProduct ( vec) => {
164167 const POWERS : & [ char ] = & [ '⁰' , '¹' , '²' , '³' , '⁴' , '⁵' , '⁶' , '⁷' , '⁸' , '⁹' ] ;
165168 let mut x = vec. iter ( ) . map ( |( unit, power) | {
@@ -208,6 +211,7 @@ impl Type {
208211 | Self :: Bool
209212 | Self :: Easing
210213 | Self :: Enumeration ( _)
214+ | Self :: KeyboardShortcut
211215 | Self :: ElementReference
212216 | Self :: Struct { .. }
213217 | Self :: Array ( _)
@@ -265,6 +269,7 @@ impl Type {
265269 | ( Type :: LogicalLength , Type :: Rem )
266270 | ( Type :: PhysicalLength , Type :: Rem )
267271 | ( Type :: Percent , Type :: Float32 )
272+ | ( Type :: KeyboardShortcut , Type :: String )
268273 | ( Type :: Brush , Type :: Color )
269274 | ( Type :: Color , Type :: Brush ) => true ,
270275 ( Type :: Array ( a) , Type :: Model ) if a. is_property_type ( ) => true ,
@@ -311,6 +316,7 @@ impl Type {
311316 Type :: Array ( _) => None ,
312317 Type :: Struct { .. } => None ,
313318 Type :: Enumeration ( _) => None ,
319+ Type :: KeyboardShortcut => None ,
314320 Type :: UnitProduct ( _) => None ,
315321 Type :: ElementReference => None ,
316322 Type :: LayoutCache => None ,
@@ -839,6 +845,40 @@ impl Enumeration {
839845 }
840846}
841847
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+
842882#[ derive( Clone , Debug ) ]
843883pub struct EnumerationValue {
844884 pub value : usize , // index in enumeration.values
0 commit comments