Class: TK::TextEdit
- Inherits:
-
TkEntry
- Object
- TkEntry
- TK::TextEdit
- Defined in:
- lib/wiki_lyrics/gui/gui-tk.rb
Instance Method Summary collapse
- #copy ⇒ Object
- #cut ⇒ Object
- #delete_selection ⇒ Object
- #get_value ⇒ Object (also: #value, #get_text, #text)
-
#initialize(parent, text, *args) ⇒ TextEdit
constructor
A new instance of TextEdit.
- #is_enabled ⇒ Object
- #paste ⇒ Object
- #redo2 ⇒ Object
- #select_all ⇒ Object
- #select_none ⇒ Object
- #set_enabled(enabled) ⇒ Object
- #set_value(value) ⇒ Object (also: #value=, #set_text, #text=)
- #undo ⇒ Object
Constructor Details
#initialize(parent, text, *args) ⇒ TextEdit
Returns a new instance of TextEdit.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 218 def initialize( parent, text, *args ) @variable = TkVariable.new( text ) super( parent, TK.proc_args( args, { "textvariable"=> @variable } ) ) = TkMenu.new( self, "tearoff"=>false ) # menu.add( "command", "label"=>I18n.get( "gui.common.undo" ), "accel"=>"Ctrl+Z", "command"=>proc { undo() } ) # menu.add( "command", "label"=>I18n.get( "gui.common.redo" ), "accel"=>"Ctrl+Shift+Z", "command"=>proc { redo2() } ) # menu.add( "separator" ) .add( "command", "label"=>I18n.get( "gui.common.cut" ), "accel"=>"Ctrl+X", "command"=>proc { cut() } ) .add( "command", "label"=>I18n.get( "gui.common.copy" ), "accel"=>"Ctrl+C", "command"=>proc { copy() } ) .add( "command", "label"=>I18n.get( "gui.common.paste" ), "accel"=>"Ctrl+V", "command"=>proc { paste() } ) .add( "command", "label"=>I18n.get( "gui.common.delete" ), "accel"=>"Delete", "command"=>proc{delete_selection()} ) .add( "separator" ) .add( "command", "label"=>I18n.get( "gui.common.selectall" ), "accel"=>"Ctrl+A", "command"=>proc { select_all() } ) .bind( "FocusOut", proc { .unpost() } ) bind( "Button-3", proc { |e| .post( e.x_root, e.y_root ); .set_focus() } ) bind( "FocusOut", proc { select_none() } ) bind( "Control-Key-X", proc { cut(); Tk.callback_break() } ) bind( "Control-Key-x", proc { cut(); Tk.callback_break() } ) bind( "Control-Key-C", proc { copy(); Tk.callback_break() } ) bind( "Control-Key-c", proc { copy(); Tk.callback_break() } ) bind( "Control-Key-V", proc { paste(); Tk.callback_break() } ) bind( "Control-Key-v", proc { paste(); Tk.callback_break() } ) bind( "Control-Key-A", proc { select_all(); Tk.callback_break() } ) bind( "Control-Key-a", proc { select_all(); Tk.callback_break() } ) bind( "Control-Key-Z", proc { undo(); Tk.callback_break() } ) bind( "Control-Key-z", proc { undo(); Tk.callback_break() } ) bind( "Control-Shift-Key-Z", proc { redo2(); Tk.callback_break() } ) bind( "Control-Shift-Key-z", proc { redo2(); Tk.callback_break() } ) end |
Instance Method Details
#copy ⇒ Object
269 270 271 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 269 def copy() TkClipboard.set( value().slice( index( "sel.first" ), index( "sel.last" ) ) ) if selection_present() end |
#cut ⇒ Object
262 263 264 265 266 267 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 262 def cut() if selection_present() TkClipboard.set( value().slice( index( "sel.first" ), index( "sel.last" ) ) ) delete( "sel.first", "sel.last" ) end end |
#delete_selection ⇒ Object
258 259 260 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 258 def delete_selection() delete( "sel.first", "sel.last" ) if selection_present() end |
#get_value ⇒ Object Also known as: value, get_text, text
296 297 298 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 296 def get_value() @variable.value() end |
#is_enabled ⇒ Object
292 293 294 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 292 def is_enabled() return state() != "disabled" end |
#paste ⇒ Object
273 274 275 276 277 278 279 280 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 273 def paste() data = TkClipboard.get() if ! TK.empty_string?( data ) insert( index( "insert" ), data ) xview( "insert" ) delete( "sel.first", "sel.last" ) if selection_present() end end |
#redo2 ⇒ Object
285 286 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 285 def redo2() end |
#select_all ⇒ Object
250 251 252 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 250 def select_all() selection_range( 0, "end" ) end |
#select_none ⇒ Object
254 255 256 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 254 def select_none() selection_clear() end |
#set_enabled(enabled) ⇒ Object
288 289 290 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 288 def set_enabled( enabled ) self.state = enabled ? "normal" : "disabled" end |
#set_value(value) ⇒ Object Also known as: value=, set_text, text=
300 301 302 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 300 def set_value( value ) @variable.set_value( value ) end |
#undo ⇒ Object
282 283 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 282 def undo() end |