Class: Shoes::Swt::KeyListener
- Inherits:
-
Object
- Object
- Shoes::Swt::KeyListener
- Includes:
- Common::SafelyEvaluate, Swt::KeyListener
- Defined in:
- shoes-swt/lib/shoes/swt/key_listener.rb
Direct Known Subclasses
Constant Summary collapse
- SPECIAL_KEY_NAMES =
Hash[ %w[TAB PAGE_UP PAGE_DOWN HOME END F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15].map do |key| [get_swt_constant(key), key.downcase]
- MODIFIER_KEYS =
%w[CTRL SHIFT ALT CAPS_LOCK COMMAND].map do |key| get_swt_constant key end
- BUTTON_EXCLUDES =
["\n", " "].freeze
- COMBO_EXCLUDES =
%w[up down] + BUTTON_EXCLUDES
Class Method Summary collapse
Instance Method Summary collapse
- #handle_key_event(event) ⇒ Object
-
#ignore_event?(event) ⇒ Boolean
For a variety of SWT controls, certain characters should not be passed to Shoes key listeners, since they’re already handled by the controls.
-
#initialize(_dsl, app, &blk) ⇒ KeyListener
constructor
A new instance of KeyListener.
- #remove ⇒ Object
Methods included from Common::SafelyEvaluate
Constructor Details
#initialize(_dsl, app, &blk) ⇒ KeyListener
Returns a new instance of KeyListener.
35 36 37 38 39 |
# File 'shoes-swt/lib/shoes/swt/key_listener.rb', line 35 def initialize(_dsl, app, &blk) @block = blk @app = app @app.add_key_listener(self) end |
Class Method Details
.get_swt_constant(name) ⇒ Object
9 10 11 |
# File 'shoes-swt/lib/shoes/swt/key_listener.rb', line 9 def self.get_swt_constant(name) ::Swt::SWT.const_get name end |
Instance Method Details
#handle_key_event(event) ⇒ Object
41 42 43 44 45 46 47 |
# File 'shoes-swt/lib/shoes/swt/key_listener.rb', line 41 def handle_key_event(event) modifiers = modifier_keys(event) character = character_key(event) key_string = modifiers + character key_string = key_string.to_sym if should_be_symbol?(event, modifiers) eval_block key_string unless character.empty? end |
#ignore_event?(event) ⇒ Boolean
For a variety of SWT controls, certain characters should not be passed to Shoes key listeners, since they’re already handled by the controls.
* Buttons ignore activating key press (enter, space depending on OS)
* Text boxes ignore all key presses
* Combo boxes ignore up/down and activating key presses
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'shoes-swt/lib/shoes/swt/key_listener.rb', line 62 def ignore_event?(event) char = character_key(event) case event. when Java::OrgEclipseSwtWidgets::Button BUTTON_EXCLUDES.include?(char) when Java::OrgEclipseSwtWidgets::Text true when Java::OrgEclipseSwtWidgets::Combo COMBO_EXCLUDES.include?(char) else # Default? Don't ignore it! false end end |
#remove ⇒ Object
49 50 51 |
# File 'shoes-swt/lib/shoes/swt/key_listener.rb', line 49 def remove @app.remove_key_listener(self) end |