Class: TkTextListBox
- Inherits:
-
TkText
- Object
- TkText
- TkTextListBox
- Defined in:
- ext/ae-editor/ae-editor.rb
Instance Method Summary collapse
- #add(chars) ⇒ Object
- #button_press(x, y) ⇒ Object
- #clear ⇒ Object
-
#initialize(parent = nil, keys = {}) ⇒ TkTextListBox
constructor
A new instance of TkTextListBox.
- #insert(index, chars, *tags) ⇒ Object
- #key_press(_e) ⇒ Object
- #key_release(_e) ⇒ Object
- #select(_row) ⇒ Object
- #selected_line ⇒ Object
Constructor Details
#initialize(parent = nil, keys = {}) ⇒ TkTextListBox
Returns a new instance of TkTextListBox.
617 618 619 620 621 622 623 624 625 626 627 |
# File 'ext/ae-editor/ae-editor.rb', line 617 def initialize(parent=nil, keys={}) super(parent, keys) wrap 'none' tag_configure('selected','background' =>Arcadia.conf('hightlight.sel.background'),'borderwidth'=>1, 'relief'=>'raised') tag_configure('class', 'foreground' => Arcadia.conf('hightlight.sel.foreground')) @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| (x,y)}, "%x %y") end |
Instance Method Details
#add(chars) ⇒ Object
634 635 636 637 638 639 640 641 642 643 644 645 |
# File 'ext/ae-editor/ae-editor.rb', line 634 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 |
#button_press(x, y) ⇒ Object
652 653 654 655 656 |
# File 'ext/ae-editor/ae-editor.rb', line 652 def (x,y) _index = self.index("@#{x},#{y}") _line = _index.split('.')[0].to_i self.select(_line) end |
#clear ⇒ Object
647 648 649 650 |
# File 'ext/ae-editor/ae-editor.rb', line 647 def clear delete('1.0','end') @count = 0 end |
#insert(index, chars, *tags) ⇒ Object
630 631 632 |
# File 'ext/ae-editor/ae-editor.rb', line 630 def insert(index, chars, *) super(index, chars, *) end |
#key_press(_e) ⇒ Object
658 659 660 661 662 663 664 665 666 667 668 669 |
# File 'ext/ae-editor/ae-editor.rb', line 658 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
671 672 673 674 675 676 677 678 |
# File 'ext/ae-editor/ae-editor.rb', line 671 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
686 687 688 689 690 691 692 693 694 |
# File 'ext/ae-editor/ae-editor.rb', line 686 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
680 681 682 683 684 |
# File 'ext/ae-editor/ae-editor.rb', line 680 def selected_line if @selected > 0 self.get("#{@selected}.0", "#{@selected}.0 lineend") end end |