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.



784
785
786
787
788
789
790
791
792
793
794
# File 'ext/ae-editor/ae-editor.rb', line 784

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



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

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



819
820
821
822
823
# File 'ext/ae-editor/ae-editor.rb', line 819

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

#clearObject



814
815
816
817
# File 'ext/ae-editor/ae-editor.rb', line 814

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

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



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

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

#key_press(_e) ⇒ Object



825
826
827
828
829
830
831
832
833
834
835
836
# File 'ext/ae-editor/ae-editor.rb', line 825

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



838
839
840
841
842
843
844
845
# File 'ext/ae-editor/ae-editor.rb', line 838

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



853
854
855
856
857
858
859
860
861
# File 'ext/ae-editor/ae-editor.rb', line 853

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



847
848
849
850
851
# File 'ext/ae-editor/ae-editor.rb', line 847

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