Class: SublimeDSL::SublimeText::MouseMap::MouseBinding
- Inherits:
-
Object
- Object
- SublimeDSL::SublimeText::MouseMap::MouseBinding
- Defined in:
- lib/sublime_dsl/sublime_text/mousemap.rb
Overview
A mouse binding: a click with its command(s).
Instance Attribute Summary collapse
-
#click ⇒ Object
readonly
Returns the value of attribute click.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#press_command ⇒ Object
readonly
Returns the value of attribute press_command.
-
#source_file ⇒ Object
Returns the value of attribute source_file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(click, count, press_command, command) ⇒ MouseBinding
constructor
A new instance of MouseBinding.
- #to_dsl ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(click, count, press_command, command) ⇒ MouseBinding
Returns a new instance of MouseBinding.
92 93 94 95 96 97 |
# File 'lib/sublime_dsl/sublime_text/mousemap.rb', line 92 def initialize(click, count, press_command, command) @click = click @count = count @press_command = press_command @command = command end |
Instance Attribute Details
#click ⇒ Object (readonly)
Returns the value of attribute click.
89 90 91 |
# File 'lib/sublime_dsl/sublime_text/mousemap.rb', line 89 def click @click end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
89 90 91 |
# File 'lib/sublime_dsl/sublime_text/mousemap.rb', line 89 def command @command end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
89 90 91 |
# File 'lib/sublime_dsl/sublime_text/mousemap.rb', line 89 def count @count end |
#press_command ⇒ Object (readonly)
Returns the value of attribute press_command.
89 90 91 |
# File 'lib/sublime_dsl/sublime_text/mousemap.rb', line 89 def press_command @press_command end |
#source_file ⇒ Object
Returns the value of attribute source_file.
90 91 92 |
# File 'lib/sublime_dsl/sublime_text/mousemap.rb', line 90 def source_file @source_file end |
Class Method Details
.from_json(json_hash) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/sublime_dsl/sublime_text/mousemap.rb', line 63 def self.from_json(json_hash) h = json_hash.dup = h.delete('button') or raise Error, 'no button: ' << json_hash.inspect modifiers = h.delete('modifiers') spec = [*modifiers, ].join('+') click = Mouse.sublime.ensure_click(spec) count = h.delete('count') count = count.to_i if count press = h.delete('press_command') press_command = press ? Command.new(press, h.delete('press_args')) : nil cmd = h.delete('command') command = cmd ? Command.new(cmd, h.delete('args')) : nil h.empty? or raise Error, 'unexpected JSON keys: ' << h.inspect new(click, count, press_command, command) rescue => ex warn "error with binding #{json_hash.inspect}" warn ex. raise end |
Instance Method Details
#to_dsl ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/sublime_dsl/sublime_text/mousemap.rb', line 99 def to_dsl spec = click.to_spec dsl = "click#{count} #{spec.to_source}" dsl << ", down: #{press_command.to_dsl}" if press_command dsl << ", up: #{command.to_dsl}" if command dsl end |
#to_h ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/sublime_dsl/sublime_text/mousemap.rb', line 108 def to_h h = click.to_h h['count'] = count if count h.merge! press_command.to_h('press_command', 'press_args') if press_command h.merge! command.to_h if command h end |