Class: TkTextListBox
Instance Method Summary
collapse
#add_xscrollcommand, #add_yscrollcommand, #do_xscrollcommand, #do_yscrollcommand, #hide_h_scroll, #hide_v_scroll, #show, #show_h_scroll, #show_v_scroll
Constructor Details
#initialize(parent = nil, keys = {}) ⇒ TkTextListBox
Returns a new instance of TkTextListBox.
542
543
544
545
546
547
548
549
550
551
552
|
# File 'ext/ae-editor/ae-editor.rb', line 542
def initialize(parent=nil, keys={})
super(parent, keys)
wrap 'none'
tag_configure('selected','background' =>'#bbd9b1','borderwidth'=>1, 'relief'=>'raised')
tag_configure('class', 'foreground' => '#3398cb')
@count = 0
@selected = -1
self.bind_append('KeyPress'){|e| key_press(e)}
self.bind_append('KeyRelease'){|e| key_release(e)}
self.bind_append("ButtonPress-1", proc{|x,y| button_press(x,y)}, "%x %y")
end
|
Instance Method Details
#add(chars) ⇒ Object
559
560
561
562
563
564
565
566
567
568
569
570
|
# File 'ext/ae-editor/ae-editor.rb', line 559
def add(chars)
meth_str, class_str = chars.split('-')
if meth_str && meth_str.strip.length>0 && class_str
insert('end', "#{meth_str}")
insert('end', "-#{class_str}\n", 'class')
elsif meth_str && meth_str.strip.length==0 && class_str
insert('end', "-#{class_str}\n")
else
insert('end', "#{chars}\n")
end
@count = @count+1
end
|
577
578
579
580
581
|
# File 'ext/ae-editor/ae-editor.rb', line 577
def button_press(x,y)
_index = self.index("@#{x},#{y}")
_line = _index.split('.')[0].to_i
self.select(_line)
end
|
#clear ⇒ Object
572
573
574
575
|
# File 'ext/ae-editor/ae-editor.rb', line 572
def clear
delete('1.0','end')
@count = 0
end
|
#insert(index, chars, *tags) ⇒ Object
555
556
557
|
# File 'ext/ae-editor/ae-editor.rb', line 555
def insert(index, chars, *tags)
super(index, chars, *tags)
end
|
#key_press(_e) ⇒ Object
583
584
585
586
587
588
589
590
591
592
593
594
|
# File 'ext/ae-editor/ae-editor.rb', line 583
def key_press(_e)
case _e.keysym
when 'Up'
if @selected > 0
select(@selected-1)
end
when 'Down'
if @selected < @count
select(@selected+1)
end
end
end
|
#key_release(_e) ⇒ Object
596
597
598
599
600
601
602
603
|
# File 'ext/ae-editor/ae-editor.rb', line 596
def key_release(_e)
case _e.keysym
when 'Next','Prior'
index = self.index('@0,0')
line = index.split('.')[0].to_i
select(line)
end
end
|
#select(_row) ⇒ Object
611
612
613
614
615
616
617
618
619
|
# File 'ext/ae-editor/ae-editor.rb', line 611
def select(_row)
self.tag_remove('selected', '1.0', 'end')
_start_index = "#{_row.to_s}.0"
_end_index = "#{_start_index} +1 lines linestart"
self.tag_add('selected', _start_index, _end_index)
self.set_insert(_start_index)
self.see(_start_index)
@selected = _row
end
|
#selected_line ⇒ Object
605
606
607
608
609
|
# File 'ext/ae-editor/ae-editor.rb', line 605
def selected_line
if @selected > 0
self.get("#{@selected}.0", "#{@selected}.0 lineend")
end
end
|