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.
3730 3731 3732 3733 |
# File 'lib/a-core.rb', line 3730 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.
3729 3730 3731 |
# File 'lib/a-core.rb', line 3729 def @last_focus_widget end |
Instance Method Details
#_replace_sel(_focused_widget, _method) ⇒ Object
3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 |
# File 'lib/a-core.rb', line 3854 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
3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 |
# File 'lib/a-core.rb', line 3785 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
3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 |
# File 'lib/a-core.rb', line 3772 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
3830 3831 3832 3833 3834 3835 3836 |
# File 'lib/a-core.rb', line 3830 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
3846 3847 3848 3849 3850 3851 3852 |
# File 'lib/a-core.rb', line 3846 def do_lower_case() if .respond_to?(:do_lower_case) .do_lower_case else _replace_sel(, :downcase) end end |
#do_paste(_focused_widget) ⇒ Object
3797 3798 3799 3800 3801 3802 3803 |
# File 'lib/a-core.rb', line 3797 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
3813 3814 3815 3816 3817 3818 3819 |
# File 'lib/a-core.rb', line 3813 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
3821 3822 3823 3824 3825 3826 3827 3828 |
# File 'lib/a-core.rb', line 3821 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
3805 3806 3807 3808 3809 3810 3811 |
# File 'lib/a-core.rb', line 3805 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
3838 3839 3840 3841 3842 3843 3844 |
# File 'lib/a-core.rb', line 3838 def do_upper_case() if .respond_to?(:do_upper_case) .do_upper_case else _replace_sel(, :upcase) end end |
#on_focus(_event) ⇒ Object
3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 |
# File 'lib/a-core.rb', line 3744 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
3735 3736 3737 3738 3739 3740 3741 3742 |
# File 'lib/a-core.rb', line 3735 def on_input(_event) case _event when InputEnterEvent @last_focus_widget = _event.receiver when InputExitEvent @last_focus_widget = nil end end |