Class: FocusEventManager
- Inherits:
-
Object
- Object
- FocusEventManager
- Defined in:
- lib/a-core.rb
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
Constructor Details
#initialize ⇒ FocusEventManager
Returns a new instance of FocusEventManager.
3117 3118 3119 |
# File 'lib/a-core.rb', line 3117 def initialize Arcadia.attach_listener(self, FocusEvent) end |
Instance Method Details
#_replace_sel(_focused_widget, _method) ⇒ Object
3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 |
# File 'lib/a-core.rb', line 3201 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 end end |
#do_copy(_focused_widget) ⇒ Object
3149 3150 3151 |
# File 'lib/a-core.rb', line 3149 def do_copy() .text_copy if .respond_to?(:text_copy) end |
#do_cut(_focused_widget) ⇒ Object
3145 3146 3147 |
# File 'lib/a-core.rb', line 3145 def do_cut() .text_cut if .respond_to?(:text_cut) end |
#do_invert_selection(_focused_widget) ⇒ Object
3177 3178 3179 3180 3181 3182 3183 |
# File 'lib/a-core.rb', line 3177 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
3193 3194 3195 3196 3197 3198 3199 |
# File 'lib/a-core.rb', line 3193 def do_lower_case() if .respond_to?(:do_lower_case) .do_lower_case else _replace_sel(, :downcase) end end |
#do_paste(_focused_widget) ⇒ Object
3153 3154 3155 |
# File 'lib/a-core.rb', line 3153 def do_paste() .text_paste if .respond_to?(:text_paste) end |
#do_redo(_focused_widget) ⇒ Object
3165 3166 3167 3168 3169 3170 3171 |
# File 'lib/a-core.rb', line 3165 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
3173 3174 3175 |
# File 'lib/a-core.rb', line 3173 def do_select_all() .tag_add('sel','1.0','end') if .respond_to?(:tag_add) end |
#do_undo(_focused_widget) ⇒ Object
3157 3158 3159 3160 3161 3162 3163 |
# File 'lib/a-core.rb', line 3157 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
3185 3186 3187 3188 3189 3190 3191 |
# File 'lib/a-core.rb', line 3185 def do_upper_case() if .respond_to?(:do_upper_case) .do_upper_case else _replace_sel(, :upcase) end end |
#on_focus(_event) ⇒ Object
3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 |
# File 'lib/a-core.rb', line 3121 def on_focus(_event) _event.=Tk.focus 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 |