Class: TK::TextArea

Inherits:
TkText
  • Object
show all
Defined in:
lib/wiki_lyrics/gui/gui-tk.rb

Instance Method Summary collapse

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 ) )
  menu = 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" )
  menu.add( "command", "label"=>I18n.get( "gui.common.cut" ), "accel"=>"Ctrl+X", "command"=>proc { cut() } )
  menu.add( "command", "label"=>I18n.get( "gui.common.copy" ), "accel"=>"Ctrl+C", "command"=>proc { copy() } )
  menu.add( "command", "label"=>I18n.get( "gui.common.paste" ), "accel"=>"Ctrl+V", "command"=>proc { paste() } )
  menu.add( "command", "label"=>I18n.get( "gui.common.delete" ), "accel"=>"Delete", "command"=>proc{delete_selection()} )
  menu.add( "separator" )
  menu.add( "command", "label"=>I18n.get( "gui.common.selectall" ), "accel"=>"Ctrl+A", "command"=>proc { select_all() } )
  menu.bind( "FocusOut", proc { menu.unpost() } )

  bind( "FocusOut", proc { select_none() } )
  bind( "Button-3", proc { |e| menu.post( e.x_root, e.y_root ); menu.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

#copyObject



101
102
103
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 101

def copy()
  text_copy()
end

#cutObject



105
106
107
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 105

def cut()
  text_cut()
end

#delete_selectionObject



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_valueObject 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_enabledObject



134
135
136
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 134

def is_enabled()
  return state() != "disabled"
end

#pasteObject



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

#redo2Object



127
128
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 127

def redo2()
end

#select_allObject



93
94
95
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 93

def select_all()
  tag_add( "sel", "0.0", "end" )
end

#select_noneObject



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

#undoObject



124
125
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 124

def undo()
end