Class: TK::TextEdit

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

Instance Method Summary collapse

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 } ) )

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

#copyObject



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

#cutObject



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_selectionObject



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



292
293
294
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 292

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

#pasteObject



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

#redo2Object



285
286
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 285

def redo2()
end

#select_allObject



250
251
252
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 250

def select_all()
	selection_range( 0, "end" )
end

#select_noneObject



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

#undoObject



282
283
# File 'lib/wiki_lyrics/gui/gui-tk.rb', line 282

def undo()
end