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.
530
531
532
533
534
535
536
537
538
539
540
|
# File 'ext/ae-editor/ae-editor.rb', line 530
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
547
548
549
550
551
552
553
554
555
556
557
558
|
# File 'ext/ae-editor/ae-editor.rb', line 547
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
|
565
566
567
568
569
|
# File 'ext/ae-editor/ae-editor.rb', line 565
def button_press(x,y)
_index = self.index("@#{x},#{y}")
_line = _index.split('.')[0].to_i
self.select(_line)
end
|
#clear ⇒ Object
560
561
562
563
|
# File 'ext/ae-editor/ae-editor.rb', line 560
def clear
delete('1.0','end')
@count = 0
end
|
#insert(index, chars, *tags) ⇒ Object
543
544
545
|
# File 'ext/ae-editor/ae-editor.rb', line 543
def insert(index, chars, *tags)
super(index, chars, *tags)
end
|
#key_press(_e) ⇒ Object
571
572
573
574
575
576
577
578
579
580
581
582
|
# File 'ext/ae-editor/ae-editor.rb', line 571
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
584
585
586
587
588
589
590
591
|
# File 'ext/ae-editor/ae-editor.rb', line 584
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
599
600
601
602
603
604
605
606
607
|
# File 'ext/ae-editor/ae-editor.rb', line 599
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
593
594
595
596
597
|
# File 'ext/ae-editor/ae-editor.rb', line 593
def selected_line
if @selected > 0
self.get("#{@selected}.0", "#{@selected}.0 lineend")
end
end
|