Class: FocusEventManager
- Inherits:
-
Object
- Object
- FocusEventManager
- Defined in:
- lib/a-core.rb
Instance Attribute Summary collapse
-
#last_focus_widget ⇒ Object
readonly
Returns the value of attribute last_focus_widget.
Instance Method Summary collapse
- #_replace_sel(_focused_widget, _method) ⇒ Object
- #do_copy(_focused_widget) ⇒ Object
- #do_cut(_focused_widget) ⇒ Object
- #do_invert_selection(_focused_widget) ⇒ Object
- #do_lower_case(_focused_widget) ⇒ Object
- #do_paste(_focused_widget) ⇒ Object
- #do_redo(_focused_widget) ⇒ Object
- #do_select_all(_focused_widget) ⇒ Object
- #do_undo(_focused_widget) ⇒ Object
- #do_upper_case(_focused_widget) ⇒ Object
-
#initialize ⇒ FocusEventManager
constructor
A new instance of FocusEventManager.
- #on_focus(_event) ⇒ Object
- #on_input(_event) ⇒ Object
Constructor Details
#initialize ⇒ FocusEventManager
Returns a new instance of FocusEventManager.
4445 4446 4447 4448 |
# File 'lib/a-core.rb', line 4445 def initialize Arcadia.attach_listener(self, FocusEvent) Arcadia.attach_listener(self, InputEvent) end |
Instance Attribute Details
#last_focus_widget ⇒ Object (readonly)
Returns the value of attribute last_focus_widget.
4444 4445 4446 |
# File 'lib/a-core.rb', line 4444 def @last_focus_widget end |
Instance Method Details
#_replace_sel(_focused_widget, _method) ⇒ Object
4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 |
# File 'lib/a-core.rb', line 4569 def _replace_sel(, _method) if .respond_to?(:tag_ranges) r = .tag_ranges('sel') if .respond_to?(:get) && r && r[0] target_text = .get(r[0][0],r[0][1]) if target_text .delete(r[0][0],r[0][1]) .insert(r[0][0],target_text.send(_method)) end end elsif .kind_of?(Tk::Entry) if .selection_present i1= .index("sel.first") i2= .index("sel.last") target_text = .value[i1.to_i..i2.to_i-1] .delete(i1,i2) .insert(i1,target_text.send(_method)) end end end |
#do_copy(_focused_widget) ⇒ Object
4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 |
# File 'lib/a-core.rb', line 4500 def do_copy() if .respond_to?(:text_copy) .text_copy elsif .kind_of?(Tk::Entry) if .selection_present i1= .index("sel.first") i2= .index("sel.last") TkClipboard::set(.value[i1.to_i..i2.to_i-1]) end end end |
#do_cut(_focused_widget) ⇒ Object
4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 |
# File 'lib/a-core.rb', line 4487 def do_cut() if .respond_to?(:text_cut) .text_cut elsif .kind_of?(Tk::Entry) if .selection_present i1= .index("sel.first") i2= .index("sel.last") TkClipboard::set(.value[i1.to_i..i2.to_i-1]) .delete(i1,i2) end end end |
#do_invert_selection(_focused_widget) ⇒ Object
4545 4546 4547 4548 4549 4550 4551 |
# File 'lib/a-core.rb', line 4545 def do_invert_selection() if .respond_to?(:tag_ranges) r = .tag_ranges('sel') .tag_add('sel','1.0','end') if .respond_to?(:tag_add) .tag_remove('sel',r[0][0],r[0][1]) if .respond_to?(:tag_remove) && r && r[0] end end |
#do_lower_case(_focused_widget) ⇒ Object
4561 4562 4563 4564 4565 4566 4567 |
# File 'lib/a-core.rb', line 4561 def do_lower_case() if .respond_to?(:do_lower_case) .do_lower_case else _replace_sel(, :downcase) end end |
#do_paste(_focused_widget) ⇒ Object
4512 4513 4514 4515 4516 4517 4518 |
# File 'lib/a-core.rb', line 4512 def do_paste() if .respond_to?(:text_paste) .text_paste elsif .kind_of?(Tk::Entry) .insert(.index("insert"), TkClipboard::get) end end |
#do_redo(_focused_widget) ⇒ Object
4528 4529 4530 4531 4532 4533 4534 |
# File 'lib/a-core.rb', line 4528 def do_redo() begin .edit_redo if .respond_to?(:edit_redo) rescue RuntimeError => e throw e unless e.to_s.include? "nothing to redo" # this is ok--we've done redo back to the beginning end end |
#do_select_all(_focused_widget) ⇒ Object
4536 4537 4538 4539 4540 4541 4542 4543 |
# File 'lib/a-core.rb', line 4536 def do_select_all() if .respond_to?(:tag_add) .tag_add('sel','1.0','end') elsif .kind_of?(Tk::Entry) .selection_from('0') .selection_to('end') end end |
#do_undo(_focused_widget) ⇒ Object
4520 4521 4522 4523 4524 4525 4526 |
# File 'lib/a-core.rb', line 4520 def do_undo() begin .edit_undo if .respond_to?(:edit_undo) rescue RuntimeError => e throw e unless e.to_s.include? "nothing to undo" # this is ok--we've done undo back to the beginning end end |
#do_upper_case(_focused_widget) ⇒ Object
4553 4554 4555 4556 4557 4558 4559 |
# File 'lib/a-core.rb', line 4553 def do_upper_case() if .respond_to?(:do_upper_case) .do_upper_case else _replace_sel(, :upcase) end end |
#on_focus(_event) ⇒ Object
4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 |
# File 'lib/a-core.rb', line 4459 def on_focus(_event) if @last_focus_widget _event. = @last_focus_widget else _event.=Tk.focus end case _event when CutTextEvent do_cut(_event.) when CopyTextEvent do_copy(_event.) when PasteTextEvent do_paste(_event.) when UndoTextEvent do_undo(_event.) when RedoTextEvent do_redo(_event.) when SelectAllTextEvent do_select_all(_event.) when InvertSelectionTextEvent do_invert_selection(_event.) when UpperCaseTextEvent do_upper_case(_event.) when LowerCaseTextEvent do_lower_case(_event.) end end |
#on_input(_event) ⇒ Object
4450 4451 4452 4453 4454 4455 4456 4457 |
# File 'lib/a-core.rb', line 4450 def on_input(_event) case _event when InputEnterEvent @last_focus_widget = _event.receiver when InputExitEvent @last_focus_widget = nil end end |