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.
3105 3106 3107 |
# File 'lib/a-core.rb', line 3105 def initialize Arcadia.attach_listener(self, FocusEvent) end |
Instance Method Details
#_replace_sel(_focused_widget, _method) ⇒ Object
3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 |
# File 'lib/a-core.rb', line 3189 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
3137 3138 3139 |
# File 'lib/a-core.rb', line 3137 def do_copy() .text_copy if .respond_to?(:text_copy) end |
#do_cut(_focused_widget) ⇒ Object
3133 3134 3135 |
# File 'lib/a-core.rb', line 3133 def do_cut() .text_cut if .respond_to?(:text_cut) end |
#do_invert_selection(_focused_widget) ⇒ Object
3165 3166 3167 3168 3169 3170 3171 |
# File 'lib/a-core.rb', line 3165 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
3181 3182 3183 3184 3185 3186 3187 |
# File 'lib/a-core.rb', line 3181 def do_lower_case() if .respond_to?(:do_lower_case) .do_lower_case else _replace_sel(, :downcase) end end |
#do_paste(_focused_widget) ⇒ Object
3141 3142 3143 |
# File 'lib/a-core.rb', line 3141 def do_paste() .text_paste if .respond_to?(:text_paste) end |
#do_redo(_focused_widget) ⇒ Object
3153 3154 3155 3156 3157 3158 3159 |
# File 'lib/a-core.rb', line 3153 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
3161 3162 3163 |
# File 'lib/a-core.rb', line 3161 def do_select_all() .tag_add('sel','1.0','end') if .respond_to?(:tag_add) end |
#do_undo(_focused_widget) ⇒ Object
3145 3146 3147 3148 3149 3150 3151 |
# File 'lib/a-core.rb', line 3145 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
3173 3174 3175 3176 3177 3178 3179 |
# File 'lib/a-core.rb', line 3173 def do_upper_case() if .respond_to?(:do_upper_case) .do_upper_case else _replace_sel(, :upcase) end end |
#on_focus(_event) ⇒ Object
3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 |
# File 'lib/a-core.rb', line 3109 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 |