Class: TkTextListBox

Inherits:
TkText
  • Object
show all
Defined in:
ext/ae-editor/ae-editor.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, keys = {}) ⇒ TkTextListBox

Returns a new instance of TkTextListBox.



692
693
694
695
696
697
698
699
700
701
702
# File 'ext/ae-editor/ae-editor.rb', line 692

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| button_press(x,y)}, "%x %y")
end

Instance Method Details

#add(chars) ⇒ Object



709
710
711
712
713
714
715
716
717
718
719
720
# File 'ext/ae-editor/ae-editor.rb', line 709

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



727
728
729
730
731
# File 'ext/ae-editor/ae-editor.rb', line 727

def button_press(x,y)
  _index = self.index("@#{x},#{y}")
  _line = _index.split('.')[0].to_i
  self.select(_line)
end

#clearObject



722
723
724
725
# File 'ext/ae-editor/ae-editor.rb', line 722

def clear
  delete('1.0','end')
  @count = 0
end

#insert(index, chars, *tags) ⇒ Object



705
706
707
# File 'ext/ae-editor/ae-editor.rb', line 705

def insert(index, chars, *tags)
  super(index, chars, *tags)
end

#key_press(_e) ⇒ Object



733
734
735
736
737
738
739
740
741
742
743
744
# File 'ext/ae-editor/ae-editor.rb', line 733

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



746
747
748
749
750
751
752
753
# File 'ext/ae-editor/ae-editor.rb', line 746

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



761
762
763
764
765
766
767
768
769
# File 'ext/ae-editor/ae-editor.rb', line 761

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_lineObject



755
756
757
758
759
# File 'ext/ae-editor/ae-editor.rb', line 755

def selected_line
  if @selected > 0
    self.get("#{@selected}.0", "#{@selected}.0 lineend")
  end
end