1 // Copyright 2015-present 650 Industries. All rights reserved.
2 
3 @objc
4 open class DevMenuAction: DevMenuItem {
5   @objc
6   public let actionId: String
7 
8   @objc
9   public var action: () -> () = {}
10 
11   @objc
12   public var keyCommand: UIKeyCommand?
13 
14   @objc
15   public init(withId id: String) {
16     self.actionId = id
17     super.init(type: .Action)
18   }
19 
20   @objc
21   public convenience init(withId id: String, action: @escaping () -> ()) {
22     self.init(withId: id)
23     self.action = action
24   }
25 
26   @objc
27   open override func serialize() -> [String : Any] {
28     var dict = super.serialize()
29     dict["actionId"] = actionId
30     dict["keyCommand"] = keyCommand == nil ? nil : [
31       "input": keyCommand!.input,
32       "modifiers": keyCommand!.modifierFlags.rawValue
33     ]
34     return dict
35   }
36 
37   @objc
38   open func registerKeyCommand(input: String, modifiers: UIKeyModifierFlags) {
39     keyCommand = UIKeyCommand(input: input, modifierFlags: modifiers, action: #selector(DevMenuUIResponderExtensionProtocol.EXDevMenu_handleKeyCommand(_:)))
40   }
41 }
42