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



696
697
698
699
700
701
702
703
704
705
706
# File 'ext/ae-editor/ae-editor.rb', line 696

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



713
714
715
716
717
718
719
720
721
722
723
724
# File 'ext/ae-editor/ae-editor.rb', line 713

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



731
732
733
734
735
# File 'ext/ae-editor/ae-editor.rb', line 731

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

#clearObject



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

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

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



709
710
711
# File 'ext/ae-editor/ae-editor.rb', line 709

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

#key_press(_e) ⇒ Object



737
738
739
740
741
742
743
744
745
746
747
748
# File 'ext/ae-editor/ae-editor.rb', line 737

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



750
751
752
753
754
755
756
757
# File 'ext/ae-editor/ae-editor.rb', line 750

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



765
766
767
768
769
770
771
772
773
# File 'ext/ae-editor/ae-editor.rb', line 765

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



759
760
761
762
763
# File 'ext/ae-editor/ae-editor.rb', line 759

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