Class: TkTextListBox
- Inherits:
-
TkText
- Object
- TkText
- TkTextListBox
- Defined in:
- ext/ae-editor/ae-editor.rb
Constant Summary collapse
- SEP =
'@@@'
Instance Method Summary collapse
- #add(chars, *tags) ⇒ 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(_keysym) ⇒ Object
- #key_release(_keysym) ⇒ Object
- #length ⇒ Object
- #select(_row) ⇒ Object
- #selected_line ⇒ Object
Constructor Details
#initialize(parent = nil, keys = {}) ⇒ TkTextListBox
Returns a new instance of TkTextListBox.
912 913 914 915 916 917 918 919 920 921 922 |
# File 'ext/ae-editor/ae-editor.rb', line 912 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.class_variable.foreground')) @count = 0 @selected = -1 self.bind_append('KeyPress', "%K"){|_keysym| key_press(_keysym)} self.bind_append('KeyRelease', "%K"){|_keysym| key_release(_keysym)} self.bind_append("ButtonPress-1", proc{|x,y| (x,y)}, "%x %y") end |
Instance Method Details
#add(chars, *tags) ⇒ Object
932 933 934 935 936 937 938 939 940 941 942 943 |
# File 'ext/ae-editor/ae-editor.rb', line 932 def add(chars, *) meth_str, class_str = chars.split(TkTextListBox::SEP) 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
950 951 952 953 954 |
# File 'ext/ae-editor/ae-editor.rb', line 950 def (x,y) _index = self.index("@#{x},#{y}") _line = _index.split('.')[0].to_i self.select(_line) end |
#clear ⇒ Object
945 946 947 948 |
# File 'ext/ae-editor/ae-editor.rb', line 945 def clear delete('1.0','end') @count = 0 end |
#insert(index, chars, *tags) ⇒ Object
928 929 930 |
# File 'ext/ae-editor/ae-editor.rb', line 928 def insert(index, chars, *) super(index, chars, *) end |
#key_press(_keysym) ⇒ Object
956 957 958 959 960 961 962 963 964 965 966 967 |
# File 'ext/ae-editor/ae-editor.rb', line 956 def key_press(_keysym) case _keysym when 'Up' if @selected > 0 select(@selected-1) end when 'Down' if @selected < @count select(@selected+1) end end end |
#key_release(_keysym) ⇒ Object
969 970 971 972 973 974 975 976 |
# File 'ext/ae-editor/ae-editor.rb', line 969 def key_release(_keysym) case _keysym when 'Next','Prior' index = self.index('@0,0') line = index.split('.')[0].to_i select(line) end end |
#length ⇒ Object
924 925 926 |
# File 'ext/ae-editor/ae-editor.rb', line 924 def length @count end |
#select(_row) ⇒ Object
984 985 986 987 988 989 990 991 992 |
# File 'ext/ae-editor/ae-editor.rb', line 984 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
978 979 980 981 982 |
# File 'ext/ae-editor/ae-editor.rb', line 978 def selected_line if @selected > 0 self.get("#{@selected}.0", "#{@selected}.0 lineend") end end |