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.
3568 3569 3570 3571 |
# File 'lib/a-core.rb', line 3568 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.
3567 3568 3569 |
# File 'lib/a-core.rb', line 3567 def end |
Instance Method Details
#_replace_sel(_focused_widget, _method) ⇒ Object
3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 |
# File 'lib/a-core.rb', line 3692 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
3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 |
# File 'lib/a-core.rb', line 3623 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
3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 |
# File 'lib/a-core.rb', line 3610 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
3668 3669 3670 3671 3672 3673 3674 |
# File 'lib/a-core.rb', line 3668 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
3684 3685 3686 3687 3688 3689 3690 |
# File 'lib/a-core.rb', line 3684 def do_lower_case() if .respond_to?(:do_lower_case) .do_lower_case else _replace_sel(, :downcase) end end |
#do_paste(_focused_widget) ⇒ Object
3635 3636 3637 3638 3639 3640 3641 |
# File 'lib/a-core.rb', line 3635 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
3651 3652 3653 3654 3655 3656 3657 |
# File 'lib/a-core.rb', line 3651 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
3659 3660 3661 3662 3663 3664 3665 3666 |
# File 'lib/a-core.rb', line 3659 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
3643 3644 3645 3646 3647 3648 3649 |
# File 'lib/a-core.rb', line 3643 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
3676 3677 3678 3679 3680 3681 3682 |
# File 'lib/a-core.rb', line 3676 def do_upper_case() if .respond_to?(:do_upper_case) .do_upper_case else _replace_sel(, :upcase) end end |
#on_focus(_event) ⇒ Object
3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 |
# File 'lib/a-core.rb', line 3582 def on_focus(_event) if _event. = 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
3573 3574 3575 3576 3577 3578 3579 3580 |
# File 'lib/a-core.rb', line 3573 def on_input(_event) case _event when InputEnterEvent = _event.receiver when InputExitEvent = nil end end |