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.



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

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



751
752
753
754
755
756
757
758
759
760
761
762
# File 'ext/ae-editor/ae-editor.rb', line 751

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



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

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

#clearObject



764
765
766
767
# File 'ext/ae-editor/ae-editor.rb', line 764

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

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



747
748
749
# File 'ext/ae-editor/ae-editor.rb', line 747

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

#key_press(_e) ⇒ Object



775
776
777
778
779
780
781
782
783
784
785
786
# File 'ext/ae-editor/ae-editor.rb', line 775

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



788
789
790
791
792
793
794
795
# File 'ext/ae-editor/ae-editor.rb', line 788

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



803
804
805
806
807
808
809
810
811
# File 'ext/ae-editor/ae-editor.rb', line 803

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



797
798
799
800
801
# File 'ext/ae-editor/ae-editor.rb', line 797

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