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.
3975 3976 3977 3978 |
# File 'lib/a-core.rb', line 3975 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.
3974 3975 3976 |
# File 'lib/a-core.rb', line 3974 def @last_focus_widget end |
Instance Method Details
#_replace_sel(_focused_widget, _method) ⇒ Object
4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 |
# File 'lib/a-core.rb', line 4099 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
4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 |
# File 'lib/a-core.rb', line 4030 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
4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 |
# File 'lib/a-core.rb', line 4017 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
4075 4076 4077 4078 4079 4080 4081 |
# File 'lib/a-core.rb', line 4075 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
4091 4092 4093 4094 4095 4096 4097 |
# File 'lib/a-core.rb', line 4091 def do_lower_case() if .respond_to?(:do_lower_case) .do_lower_case else _replace_sel(, :downcase) end end |
#do_paste(_focused_widget) ⇒ Object
4042 4043 4044 4045 4046 4047 4048 |
# File 'lib/a-core.rb', line 4042 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
4058 4059 4060 4061 4062 4063 4064 |
# File 'lib/a-core.rb', line 4058 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
4066 4067 4068 4069 4070 4071 4072 4073 |
# File 'lib/a-core.rb', line 4066 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
4050 4051 4052 4053 4054 4055 4056 |
# File 'lib/a-core.rb', line 4050 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
4083 4084 4085 4086 4087 4088 4089 |
# File 'lib/a-core.rb', line 4083 def do_upper_case() if .respond_to?(:do_upper_case) .do_upper_case else _replace_sel(, :upcase) end end |
#on_focus(_event) ⇒ Object
3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 |
# File 'lib/a-core.rb', line 3989 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
3980 3981 3982 3983 3984 3985 3986 3987 |
# File 'lib/a-core.rb', line 3980 def on_input(_event) case _event when InputEnterEvent @last_focus_widget = _event.receiver when InputExitEvent @last_focus_widget = nil end end |