Class: TK::TextArea
- Inherits:
-
TkText
- Object
- TkText
- TK::TextArea
- Defined in:
- lib/wiki_lyrics/gui/gui-tk.rb
Instance Method Summary collapse
- #append_text(text) ⇒ Object
- #copy ⇒ Object
- #cut ⇒ Object
- #delete_selection ⇒ Object
- #get_value ⇒ Object (also: #get_text, #text)
-
#initialize(parent, *args) ⇒ TextArea
constructor
A new instance of TextArea.
- #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, *args) ⇒ TextArea
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 63 def initialize( parent, *args ) super( parent, TK.proc_args( args ) ) = 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( "FocusOut", proc { select_none() } ) bind( "Button-3", proc { |e| .post( e.x_root, e.y_root ); .set_focus() } ) 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
#append_text(text) ⇒ Object
138 139 140 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 138 def append_text( text ) insert( "end", text ) end |
#copy ⇒ Object
101 102 103 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 101 def copy() text_copy() end |
#cut ⇒ Object
105 106 107 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 105 def cut() text_cut() end |
#delete_selection ⇒ Object
120 121 122 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 120 def delete_selection() delete( "sel.first", "sel.last" ) if tag_ranges( "sel" ).size > 0 end |
#get_value ⇒ Object Also known as: get_text, text
142 143 144 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 142 def get_value() value() end |
#is_enabled ⇒ Object
134 135 136 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 134 def is_enabled() return state() != "disabled" end |
#paste ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 109 def paste() selected = tag_ranges( "sel" ).size > 0 if selected length = value.size tag_add( "prev_sel", "sel.first", "sel.last" ) end text_paste() delete( "prev_sel.first", "prev_sel.last" ) if selected && value.size != length see( "insert" ) end |
#redo2 ⇒ Object
127 128 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 127 def redo2() end |
#select_all ⇒ Object
93 94 95 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 93 def select_all() tag_add( "sel", "0.0", "end" ) end |
#select_none ⇒ Object
97 98 99 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 97 def select_none() tag_remove( "sel", "0.0", "end" ) end |
#set_enabled(enabled) ⇒ Object
130 131 132 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 130 def set_enabled( enabled ) self.state = enabled ? "normal" : "disabled" end |
#set_value(value) ⇒ Object Also known as: value=, set_text, text=
146 147 148 149 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 146 def set_value( value ) delete( "0.0", "end" ) insert( "end", value ) end |
#undo ⇒ Object
124 125 |
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 124 def undo() end |