Class: AgEditor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_controller, _page_frame) ⇒ AgEditor

Returns a new instance of AgEditor.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'ext/ae-editor/ae-editor.rb', line 38

def initialize(_controller, _page_frame)
  @controller = _controller
  @page_frame = _page_frame
  @set_mod = false
  @font = @controller.conf('font')
  @font_bold = @controller.conf('font.bold')
  @font_metrics = TkFont.new(@font).metrics
  @font_metrics_bold = TkFont.new(@font_bold).metrics
  @highlighting = false
  @classbrowsing = false
  @find = @controller.get_find
  @read_only=false
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



34
35
36
# File 'ext/ae-editor/ae-editor.rb', line 34

def file
  @file
end

#page_frameObject (readonly)

Returns the value of attribute page_frame.



36
37
38
# File 'ext/ae-editor/ae-editor.rb', line 36

def page_frame
  @page_frame
end

#read_onlyObject (readonly)

Returns the value of attribute read_only.



35
36
37
# File 'ext/ae-editor/ae-editor.rb', line 35

def read_only
  @read_only
end

#rootObject (readonly)

Returns the value of attribute root.



37
38
39
# File 'ext/ae-editor/ae-editor.rb', line 37

def root
  @root
end

#textObject (readonly)

Returns the value of attribute text.



37
38
39
# File 'ext/ae-editor/ae-editor.rb', line 37

def text
  @text
end

Instance Method Details

#build_tree(_sel = nil) ⇒ Object



868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
# File 'ext/ae-editor/ae-editor.rb', line 868

def build_tree(_sel=nil)
  if _sel
    _label_sel = @tree_exp.itemcget(_sel,'text')
  end
  
  #clear tree
  begin
    @tree_exp.delete(@tree_exp.nodes('root'))
  rescue Exception
    # workaround on windows
    @tree_exp.delete(@tree_exp.nodes('root'))
  end
  
  
  #(re)build tree
  _txt = @text.get('1.0','end')
  @root = build_tree_from_source(_txt)
  @selected = nil
  build_tree_from_node(@root, _label_sel)
  if @selected
    @tree_exp.selection_add(@selected.rif)
    @tree_exp.open_tree(@selected.parent.rif)
    @tree_exp.see(@selected.rif)
  end
end

#build_tree_from_node(_node, _label_match = nil) ⇒ Object



835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
# File 'ext/ae-editor/ae-editor.rb', line 835

def build_tree_from_node(_node, _label_match=nil)
  
  @image_kclass = TkPhotoImage.new('dat' => TREE_NODE_CLASS_GIF)
  @image_kmodule =  TkPhotoImage.new('dat' => TREE_NODE_MODULE_GIF)
  @image_kdef =  TkPhotoImage.new('dat' => TREE_NODE_DEF_GIF)
  @image_kdefclass =  TkPhotoImage.new('dat' => TREE_NODE_DEFCLASS_GIF)
  
  _sorted_sons = _node.sons.sort
  for inode in 0.._sorted_sons.length - 1
    _son = _sorted_sons[inode]
    if _son.kind == 'KClass'
        _image = @image_kclass
    elsif _son.kind == 'KModule'
        _image = @image_kmodule
    elsif _son.kind == 'KDef'
        _image = @image_kdef
    elsif _son.kind == 'KDefClass'
        _image = @image_kdefclass
    end
    @tree_exp.insert('end', _son.parent.rif ,_son.rif, {
      'text' =>  _son.label ,
      'helptext' => _son.helptext,
      'font'=>$arcadia['conf']['editor.explorer_panel.tree.font'],
      'image'=> _image
    }
    )
    if (_label_match) && (_label_match.strip == _son.label.strip)
      @selected = _son
    end
    build_tree_from_node(_son, _label_match)
  end
end

#build_tree_from_source(_source) ⇒ Object



753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
# File 'ext/ae-editor/ae-editor.rb', line 753

def build_tree_from_source(_source)
  _row = 1
  _liv = 0
  _livs = Array.new
  root = TreeNode.new(nil, 'KRoot'){|_node|
    _node.rif= 'root'
    _node.label=''
  }
  _livs[_liv]=root
  _source.each_line{|line|
    line = "\s"+line.split("#")[0]+"\s"
    m = /[\s\n\t\;]+(module|class|def|if|unless|begin|case|for|while|do)[\s\n\t\;]+/.match(line)
    if m
      index = m.post_match.strip.length - 1
      if m.post_match.strip[index,index]=='{'
        _row = _row +1
        next
      end
      _liv>=0? _liv = _liv + 1:_liv=1
      _pliv = _liv
      _parent = nil
      while (_parent == nil && _pliv>=0)
        _pliv = _pliv -1
        _parent = _livs[_pliv]
      end
      if _parent
        _helptext = m.post_match.strip
        _label = _helptext.split('<')[0]
        if _label == nil || _label.strip.length==0
          _label = _helptext
        end
        if (m[0].strip[0..4] == "class" && m.pre_match.strip.length==0)
          _kind = 'KClass'
        elsif (m[0].strip[0..4] == "class" && m.pre_match.strip.length>0)
          _row = _row +1
          _liv = _liv - 1
          next
        elsif (m[0].strip[0..5] == "module" && m.pre_match.strip.length==0)
          _kind = 'KModule'
        elsif (m[0].strip[0..5] == "module" && m.pre_match.strip.length>0)
          _row = _row +1
          _liv = _liv - 1
          next
        elsif ((m[0].strip[0..4] == "begin")||(m[0].strip[0..3] == "case") ||(m[0].strip[0..4] == "while") || (m[0].strip[0..2] == "for") || (m[0].strip[0..1] == "do") || ((m[0].strip[0..1] == "if" || m[0].strip[0..5] == "unless") && m.pre_match.strip.length==0))
          _row = _row +1
          next
        elsif ((m[0].strip[0..1] == "if" || m[0].strip[0..5] == "unless") && m.pre_match.strip.length>0)
          _row = _row +1
          _liv = _liv - 1
          next
        elsif (m[0].strip[0..2] == "def" && m.pre_match.strip.length==0)
          _kind = 'KDef'
          if _label.include?(_parent.label + '.')
            _kind = 'KDefClass'
          end
#          elsif (m[0].strip[0..10] == "attr_reader" && m.pre_match.strip.length==0)
#            _kind = 'KAttr_reader'
#            _liv = _liv - 1
#            _row = _row +1
        end

        TreeNode.new(_parent, _kind){|_node|
          _node.label = _label
          _node.helptext = _helptext
          _node.rif = _row.to_s
          _livs[_pliv + 1]=_node
        }
      else
        _row = _row +1
        _liv = _liv - 1
        next
      end
    end
    m_end = /[\s\n\t\;]+end[\s\n\t\;]+/.match(line)
    if m_end
      _liv = _liv - 1
    end
    _row = _row +1
  }
  return root
end

#check_file_last_access_timeObject



1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
# File 'ext/ae-editor/ae-editor.rb', line 1357

def check_file_last_access_time
  if @file && @file_last_access_time
 
  ftime = File.mtime(@file)
    if @file_last_access_time != ftime
      msg = 'File "'+@file+'" is changed! Reload?'
        if Tk.messageBox('icon' => 'error', 'type' => 'yesno',
          'title' => '(Arcadia) Libs', 'parent' => @text,
          'message' => msg) == 'yes'
          @text.delete('1.0','end')
          load_file(@file)
        else
          @file_last_access_time = ftime
        end
    end
  end
end

#check_modifyObject



1349
1350
1351
1352
1353
1354
1355
# File 'ext/ae-editor/ae-editor.rb', line 1349

def check_modify
  if modified? 
    set_modify if !@set_mod
  else
    reset_modify
  end
end

#create_temp_fileObject



167
168
169
170
171
172
173
174
175
176
177
178
# File 'ext/ae-editor/ae-editor.rb', line 167

def create_temp_file
  _file = @file+'~~'
  f = File.new(@file+'~~', "w")
  begin
    if f
      f.syswrite(text_value)
    end
  ensure
    f.close unless f.nil?
  end
  _file
end

#do_line_updateObject



1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
# File 'ext/ae-editor/ae-editor.rb', line 1220

def do_line_update
  #re num in @text_line_num the portion of visibled screen  of @text
  if @text_line_num
    line_begin = @text.index('@0,0').split('.')[0].to_i
    line_end = @text.index('@0,'+TkWinfo.height(@text).to_s).split('.')[0].to_i + 1
    # breakpoint
    b = @controller.breakpoint_lines_on_file(@file)
    @text_line_num.delete('1.0','end')
    for j in line_begin...line_end
      #nline = j.to_s.rjust(6)
      nline = j.to_s.rjust(7)
      _index = @text_line_num.index('end')
      if @highlighting && @is_line_bold[j]
        @text_line_num.insert('end', "#{nline}\n",'bold_case')
      else
        @text_line_num.insert('end', "#{nline}\n")
      end
      if b.include?(j.to_s)
        @text_line_num.tag_add('breakpoint',_index+' -1 lines',_index+' -1 lines  lineend')
      end
    end
    
    if @highlighting
      _zone_begin = ((line_begin) / @highlight_zone_length).to_i + 1
      _zone_end = ((line_end) / @highlight_zone_length).to_i + 1
      (_zone_begin >=@last_zone_begin)?_zone_begin.upto(_zone_end+1){|_zone| 
        highlight_zone(_zone)	
      }:_zone_end.downto(_zone_begin-1){|_zone| 
        highlight_zone(_zone)		
      }
      @last_line_begin = line_begin
      @last_line_end = line_end
      @last_zone_begin = _zone_begin
      @last_zone_end = _zone_end
    end
  end
end

#do_tag_configure(_name) ⇒ Object



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'ext/ae-editor/ae-editor.rb', line 514

def do_tag_configure(_name)
  h = Hash.new
  if @lang_hash['hightlight.'+_name+'.color.foreground']
    h['foreground']=@lang_hash['hightlight.'+_name+'.color.foreground']
  end
  if @lang_hash['hightlight.'+_name+'.color.background']
    h['background']=@lang_hash['hightlight.'+_name+'.color.background']
  end
  if @lang_hash['hightlight.'+_name+'.style']== 'bold'
    h['font']=@font_bold
    @is_tag_bold[_name]= true
  end
  if @lang_hash['hightlight.'+_name+'.relief']
    h['relief']=@lang_hash['hightlight.'+_name+'.relief']
  end
  if @lang_hash['hightlight.'+_name+'.borderwidth']
    h['borderwidth']=@lang_hash['hightlight.'+_name+'.borderwidth']
  end
  @text.tag_configure(_name, h)
end

#do_tag_configure_global(_name) ⇒ Object



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'ext/ae-editor/ae-editor.rb', line 536

def do_tag_configure_global(_name)
  h = Hash.new
  if $arcadia['conf']['editor.hightlight.'+_name+'.color.foreground']
    h['foreground']=$arcadia['conf']['editor.hightlight.'+_name+'.color.foreground']
  end
  if $arcadia['conf']['editor.hightlight.'+_name+'.color.background']
    h['background']=$arcadia['conf']['editor.hightlight.'+_name+'.color.background']
  end
  if $arcadia['conf']['editor.hightlight.'+_name+'.style']== 'bold'
    h['font']=@font_bold
    @is_tag_bold[_name]= true
  end
  if $arcadia['conf']['editor.hightlight.'+_name+'.relief']
    h['relief']=$arcadia['conf']['editor.hightlight.'+_name+'.relief']
  end
  if $arcadia['conf']['editor.hightlight.'+_name+'.borderwidth']
    h['borderwidth']=$arcadia['conf']['editor.hightlight.'+_name+'.borderwidth']
  end
  @text.tag_configure(_name, h)
end

#file_extension(_filename = nil) ⇒ Object



1404
1405
1406
1407
1408
1409
# File 'ext/ae-editor/ae-editor.rb', line 1404

def file_extension(_filename=nil)
  if _filename
    _m = /(.*\.)(.*$)/.match(File.basename(_filename))
  end
  _ret = (_m && _m.length > 1)?_m[2]: nil
end

#find_and_set_tag(_re, _row, _txt, _tag, _tag_rem = nil) ⇒ Object



984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
# File 'ext/ae-editor/ae-editor.rb', line 984

def find_and_set_tag(_re, _row, _txt, _tag, _tag_rem = nil)
  m = _re.match(_txt)
  _end = 0
  if m && @is_tag_bold[_tag]
    @is_line_bold[_row]=true
  end
  #_old_txt = ''
  while m && (_txt=m.post_match)
    if !defined?(_old_txt) || _txt != _old_txt
      _old_txt = _txt 
      _ibegin = _row.to_s+'.'+(m.begin(0)+_end).to_s
      _end = m.end(0) + _end
      _iend = _row.to_s+'.'+(_end.to_s)
      if _tag_rem
        _tag_rem.each {|value|
          @text.tag_remove(value,_ibegin, _iend)
        }
      end
      @text.tag_add(_tag,_ibegin, _iend)
      if @op_only_first.include?(_tag)
        m = nil
      else
        m = _re.match(_txt)
      end
    else
      m = nil
    end
  end
end

#find_and_set_tag_ml(_re, _row, _txt, _tag, _tag_rem = nil) ⇒ Object



939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
# File 'ext/ae-editor/ae-editor.rb', line 939

def find_and_set_tag_ml(_re, _row, _txt, _tag, _tag_rem = nil)
  m = _re.match(_txt)
  _offset = 0
  _s_txt = _txt
  #_old_txt = ''
  while m && (_txt=m.post_match)
    if !defined?(_old_txt) || _txt != _old_txt

      apos =  pos_to_index(_s_txt, _offset+m.begin(0))
      _offset = _offset + m.end(0)
      
      
      _old_txt = _txt
      _r = _row + apos[0]
      _ibegin = _r.to_s+'.'+apos[1].to_s
      _iend = _r.to_s+'.'+(apos[1]+m.end(0)-m.begin(0)).to_s
      if _tag_rem
        _tag_rem.each {|value|
          @text.tag_remove(value,_ibegin, _iend)
        }
      end
      @text.tag_add(_tag,_ibegin, _iend)
      if @is_tag_bold[_tag]
        @is_line_bold[_r]=true
      end

      if @op_only_first.include?(_tag) && _txt
        #eliminino la prima riga a partire dal risultato
        _p = _txt.index("\n")+1
         if _p
            _txt = _txt[_p..-1]
            _offset = _offset + _p
         else
           m = nil
         end
      end
      m = _re.match(_txt)
      
    else
      m = nil
    end
  end
end

#hide_spacesObject



1092
1093
1094
1095
# File 'ext/ae-editor/ae-editor.rb', line 1092

def hide_spaces
  @text.tag_remove('spaces','1.0', 'end')
  @spaces_show = false
end

#hide_tabsObject



1087
1088
1089
1090
# File 'ext/ae-editor/ae-editor.rb', line 1087

def hide_tabs
  @text.tag_remove('tabs','1.0', 'end')
  @tabs_show = false
end

#highlight_zone(_zone) ⇒ Object



1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
# File 'ext/ae-editor/ae-editor.rb', line 1268

def highlight_zone(_zone)
  if !@highlight_zone[_zone]
    _b = @highlight_zone_length*(_zone - 1) 
    _e = @highlight_zone_length*(_zone) #+ 1
    for j in _b..._e
      rehighlightline(j)
    end
    @highlight_zone[_zone] = true
  end
end

#highlight_zone_new(_zone) ⇒ Object



1258
1259
1260
1261
1262
1263
1264
1265
# File 'ext/ae-editor/ae-editor.rb', line 1258

def highlight_zone_new(_zone)
  if !@highlight_zone[_zone]
    _b = @highlight_zone_length*(_zone - 1) 
    _e = @highlight_zone_length*(_zone) #+ 1
    rehighlightlines(_b,_e)
    @highlight_zone[_zone] = true
  end
end

#highlightline(_row, _line, _check_mod = false) ⇒ Object



1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
# File 'ext/ae-editor/ae-editor.rb', line 1164

def highlightline(_row, _line, _check_mod = false)
  if _check_mod 
    check_modify
  end
  _txt = _line
  _end = 0
  
  @op_to_end_line.each{|c|
    if @h_re[c]
      m_c = @h_re[c].match(_txt)
      if m_c then
        _ibegin = _row.to_s+'.'+(m_c.begin(0)).to_s
        _iend = _row.to_s+'.'+(_line.length - 1).to_s
        @text.tag_add(c,_ibegin, _iend)
        _txt = m_c.pre_match
      end
    end
  } if @lang_hash['re_op.to_line_end']

  arem = Array.new
  
    
  @h_classes.each{|c|
    if !@op_to_end_line.include?(c) && @h_re[c]
      find_and_set_tag(@h_re[c], _row, _txt, c, arem)
      arem << c
    end
  } if _txt.strip.length > 0  

  find_and_set_tag(/\t/, _row, _txt, 'tabs', arem) if @tabs_show 
  find_and_set_tag(/[ ^\t]\s*/, _row, _txt, 'spaces', arem) if @spaces_show 
end

#highlightlines(_row, _lines, _check_mod = false) ⇒ Object



1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
# File 'ext/ae-editor/ae-editor.rb', line 1130

def highlightlines(_row, _lines, _check_mod = false)
  if _check_mod 
    check_modify
  end
  _txt = _lines
  _end = 0
  
#    @op_to_end_line.each{|c|
#      if @h_re[c]
#        m_c = @h_re[c].match(_txt)
#        if m_c then
#          _ibegin = _row.to_s+'.'+(m_c.begin(0)).to_s
#          _iend = _row.to_s+'.'+(_line.length - 1).to_s
#          @text.tag_add(c,_ibegin, _iend)
#          _txt = m_c.pre_match
#        end
#      end
#    } if @lang_hash['re_op.to_line_end']

  arem = Array.new
  
    
  @h_classes.each{|c|
    if !@op_to_end_line.include?(c) && @h_re[c]
      find_and_set_tag_ml(@h_re[c], _row, _txt, c, arem)
      arem << c
    end
  } if _txt.strip.length > 0  

  find_and_set_tag_ml(/\t/, _row, _txt, 'tabs', arem) if @tabs_show 
  find_and_set_tag_ml(/[ ^\t]\s*/, _row, _txt, 'spaces', arem) if @spaces_show 
end

#hscroll(mode, wrap_mode = "char") ⇒ Object

horizontal scrollbar : ON/OFF



914
915
916
917
918
919
920
921
922
923
924
# File 'ext/ae-editor/ae-editor.rb', line 914

def hscroll(mode, wrap_mode="char")
  st = TkGrid.info(@h_scroll)
  if mode && st == [] then
    @h_scroll.grid('row'=>1, 'column'=>0, 'sticky'=>'ew')
    @text.configure('wrap'=> 'none')
  elsif !mode && st != [] then
    @h_scroll.ungrid
    @text.configure('wrap'=> wrap_mode)
  end
  self
end

#indentation_space_2_tabs(_n_space = 2) ⇒ Object



1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
# File 'ext/ae-editor/ae-editor.rb', line 1047

def indentation_space_2_tabs(_n_space=2)
  _row = 1
  @text.value.each{|_line|
    m = /\s*/.match(_line)
    _end = 0
    if m && m.begin(0)==0
      _s = m[0]
      if !_s.include?("\n") && !_s.include?("\t")
        _ibegin = _row.to_s+'.0'
        _iend = _row.to_s+'.'+m.end(0).to_s
        _n_tab = (_s.length / _n_space).round
        @text.delete(_ibegin, _iend)
        @text.insert(_ibegin,"\t"*_n_tab )
      end
    end
    _row = _row+1
  }
  check_modify    
end

#indentation_tabs_2_space(_n_space = 2) ⇒ Object



1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
# File 'ext/ae-editor/ae-editor.rb', line 1067

def indentation_tabs_2_space(_n_space=2)
  _row = 1
  @text.value.each{|_line|
    m = /\t*/.match(_line)
    _end = 0
    if m && m.begin(0)==0
      _s = m[0]
      if !_s.include?("\n")
        _ibegin = _row.to_s+'.0'
        _iend = _row.to_s+'.'+m.end(0).to_s
        @text.delete(_ibegin, _iend)
        @text.insert(_ibegin,"\s"*_s.length*_n_space )
      end
    end
    _row = _row+1
  }
  check_modify    
end

#init_editing(_ext = 'rb') ⇒ Object



1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
# File 'ext/ae-editor/ae-editor.rb', line 1375

def init_editing(_ext='rb')
  # find file lang
  _ext='' if _ext.nil?
  lang_file = File.dirname(__FILE__)+'/langs/'+_ext+'.lang'
  if File.exist?(lang_file)
    @lang_hash = properties_file2hash(lang_file)
  elsif File.exist?(lang_file+'.bind')
    b= properties_file2hash(lang_file+'.bind')
    lang_file_bind = File.dirname(__FILE__)+'/langs/'+b['bind']
    if b && File.exist?(lang_file_bind)
      @lang_hash = properties_file2hash(lang_file_bind)
    end
  else
    @lang = nil
  end
  if _ext=='rb'
    @fm = AGTkVSplittedFrames.new(@page_frame,150)
    @fm1 = AGTkVSplittedFrames.new(@fm.right_frame,60)
    initialize_tree(@fm.left_frame)
  else
    @fm1 = AGTkVSplittedFrames.new(@page_frame,60)
  end
  @fm1.splitter_frame.configure('relief'=>'flat')
  initialize_text(@fm1.right_frame)
  initialize_text_binding
  initialize_highlight
  initialize_line_number(@fm1.left_frame)
end

#initialize_highlightObject



476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'ext/ae-editor/ae-editor.rb', line 476

def initialize_highlight
  if @lang_hash.nil?
    @highlighting = false
    return
  end
  @highlighting = true
  @highlight_zone = Hash.new;
#    @highlight_zone_length = 45;
  @highlight_zone_length = 60;
  @last_line_begin = 0
  @last_line_end = 0
  @last_zone_begin=0;
  @last_zone_end=0;
  @is_line_bold = Hash.new
  @is_tag_bold = Hash.new

  @h_classes = @lang_hash['classes'].split(',')
  @h_re = Hash.new
  @op_to_end_line = Array.new
  @op_to_end_line.concat(@lang_hash['re_op.to_line_end'].split(',')) if @lang_hash['re_op.to_line_end']

  @op_only_first = Array.new
  @op_only_first.concat(@lang_hash['re_op.only_first'].split(',')) if @lang_hash['re_op.only_first']
  
  @h_classes.each{|c|
    do_tag_configure(c)
    @h_re[c]=Regexp::new(@lang_hash["re.#{c}"].strip) if @lang_hash["re.#{c}"]
  }

  ['sel','selected','tabs','spaces'].each{|_name|
    if @lang_hash['hightlight.'+_name+'.foreground']
      do_tag_configure(_name)
    else
      do_tag_configure_global(_name)
    end
  }
end

#initialize_line_number(_frame) ⇒ Object



421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'ext/ae-editor/ae-editor.rb', line 421

def initialize_line_number(_frame)
  @text_line_num = TkText.new(_frame){
    wrap  'none'
    relief 'flat'
    undo false
    takefocus 0
    insertofftime 0
    exportselection true
    autoseparators true
    cursor nil
    insertwidth 0
    background $arcadia['conf']['editor.line_number_panel.color.background']
    #background $arcadia['conf']['editor.color.background']
    foreground $arcadia['conf']['editor.line_number_panel.color.foreground']
    highlightcolor $arcadia['conf']['editor.line_number_panel.color.background']
    highlightthickness 0
    place(
      'x'=>0,
      'y'=>0,
      'relheight'=>1,
      'relwidth'=>1,
      'bordermode'=>'outside'
    )
  }
  delta = @font_metrics_bold[2][1]-@font_metrics[2][1]
  @text_line_num.tag_configure('bold_case', 'spacing1'=>delta)
  @text_line_num.tag_configure('breakpoint', 'background'=>'red','foreground'=>'yellow','borderwidth'=>1, 'relief'=>'raised')
  @text_line_num.tag_configure('sel', 
    'background'=>$arcadia['conf']['editor.line_number_panel.color.background'],
    'foreground'=>$arcadia['conf']['editor.line_number_panel.color.foreground'],
    'relief'=>'flat'
  )
  @text_line_num.bind("Double-ButtonPress-1", proc{|x,y|
    _index = @text_line_num.index("@#{x},#{y}")
    _line = @text_line_num.get(_index+' linestart',_index+' lineend').strip
    if @controller.breakpoint_lines_on_file(@file).include?(_line)
      @text_line_num.tag_remove('breakpoint',_index+' linestart',_index+' lineend')
      @controller.breakpoint_del(@file, _line)
    else
      @text_line_num.tag_add('breakpoint',_index+' linestart',_index+' lineend')
     # @text_line_num.tag_add('breakpoint',_index+' linestart',_index+' linestart + 1 chars')
      @controller.breakpoint_add(@file, _line)
    end
  },
  "%x %y")
  
  @text_line_num.configure('font', @font);
  @text_line_num.tag_configure('line_num',
    'foreground' => '#FFFFFF',
    'background' =>'#0000a0',
    'borderwidth'=>2,
    'relief'=>'raised'
  )
end

#initialize_text(_frame) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'ext/ae-editor/ae-editor.rb', line 127

def initialize_text(_frame)
  @v_scroll = TkScrollbar.new(_frame,
    'orient'=>'vertical',
    'relief'=>'flat'
  ).pack('side' => 'right', 'fill' => 'y')
  @text = TkText.new(@fm1.right_frame){|j|
    wrap  'none'
    relief 'flat'
    undo true
    insertofftime 200
    insertontime 200
    insertbackground $arcadia['conf']['editor.color.insertbackground']
    background $arcadia['conf']['editor.color.background']
    foreground $arcadia['conf']['editor.color.foreground']
    highlightcolor $arcadia['conf']['editor.color.background']
    highlightthickness 0
    insertwidth 3
    exportselection true
    autoseparators true
    padx 0
    tabs $arcadia['conf']['editor.tabs']
    place(
      'x'=>0,
      'y'=>0,
      'width' => -15,
      'relheight'=>1,
      'relwidth'=>1,
      'bordermode'=>'outside'
    )
  }
  @text.configure('font', @font);

  do_tag_configure_global('debug')
  @text.tag_configure('eval','foreground' => 'yellow', 'background' =>'red','borderwidth'=>1, 'relief'=>'raised')
  @text.tag_configure('errline','borderwidth'=>1, 'relief'=>'groove')
  #@text.tag_configure('debug', 'background' =>'#b9c6d9', 'borderwidth'=>1 ,'relief'=>'raise')
  @buffer = text_value
  pop_up_menu
end

#initialize_text_bindingObject



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'ext/ae-editor/ae-editor.rb', line 180

def initialize_text_binding
  @v_scroll.command(proc{|*args|
    @text.yview *args
  })
  @text.yscrollcommand(proc{|first,last| @v_scroll.set(first,last)
    self.do_line_update()
  })
  @text.tag_bind('selected', 'Enter', proc{@text.tag_remove('selected','1.0','end')})

  @text.bind("Enter", proc{check_file_last_access_time})
#    @text.bind("ButtonPress-1", proc{
#      _code = $arcadia['rad'].palette.give_me_code
#      @text.insert('insert', _code) if _code
#    })

  @text.bind("Control-KeyPress"){|e|
    case e.keysym
    when 'space'
      line, col = @text.index('insert').split('.')
      _file = create_temp_file
      #EditorContract.instance.complete_code(self, 'file'=>_file, 'line'=>line.to_s, 'col'=>col.to_s)
      begin
        event = Arcadia.process_event(CompleteCodeEvent.new(self, 'file'=>_file, 'row'=>line.to_s, 'col'=>col.to_s))
      ensure
        File.delete(_file) if File.exist?(_file)
      end
      @controller.raise_complete_code(event)
    when 'z'
      _b = @text.index('insert').split('.')[0].to_i
      @text.edit_undo
      _e = @text.index('insert').split('.')[0].to_i
      if @highlighting
        for j in _b..._e
          rehighlightline(j)
        end
      end
      break
    when 'c'
      @text.text_copy
      break
    when 'x'
      @text.text_cut
      break
    when 'v'
      _b = @text.index('insert').split('.')[0].to_i
      @text.text_paste
      _e = @text.index('insert').split('.')[0].to_i
      if @highlighting
        for j in _b..._e
          rehighlightline(j)
        end
      end
      break
    end
    case e.keysym
    when 's'
      save
    when 'f'
      _r = @text.tag_ranges('sel')
      if _r.length>0
        _text=@text.get(_r[0][0],_r[0][1])
        if _text.length > 0
          @find.e_what.text(_text)
        end
      else
      end
      @find.use(self)
      @find.e_what.focus
      @find.show
    when 'egrave'
      @text.insert('insert',"{")
    when 'plus'
      @text.insert('insert',"}")
    end
  }

  @text.bind("Control-Shift-KeyPress"){|e|
    case e.keysym
    when 'I'
      _r = @text.tag_ranges('sel')
      _row_begin = _r[0][0].split('.')[0].to_i
      _row_end = _r[_r.length - 1][1].split('.')[0].to_i
      n_space = $arcadia['conf']['editor.tab-replace-width-space'].to_i
      if n_space > 0
        suf = "\s"*n_space
      else
        suf = "\t"
      end

      for _row in _row_begin..._row_end
        @text.insert(_row.to_s+'.0',suf)
      end
    when 'U'
      _r = @text.tag_ranges('sel')
      _row_begin = _r[0][0].split('.')[0].to_i
      _row_end = _r[_r.length - 1][1].split('.')[0].to_i
      n_space = $arcadia['conf']['editor.tab-replace-width-space'].to_i
      if n_space > 0
        suf = "\s"*n_space
      else
        suf = "\t"
      end
      _l_suf = 	suf.length.to_s
      for _row in _row_begin..._row_end
        if @text.get(_row.to_s+'.0',_row.to_s+'.'+_l_suf) == suf
          @text.delete(_row.to_s+'.0',_row.to_s+'.'+_l_suf)
        end
      end
    when 'C'
      _r = @text.tag_ranges('sel')
      _row_begin = _r[0][0].split('.')[0].to_i
      _row_end = _r[_r.length - 1][1].split('.')[0].to_i

      for _row in _row_begin..._row_end
        if @text.get(_row.to_s+'.0',_row.to_s+'.1') == "#"
          @text.delete(_row.to_s+'.0',_row.to_s+'.1')
        else
          @text.insert(_row.to_s+'.0',"#")
        end
        rehighlightline(_row) if @highlighting
      end

    end
  }
  
  @text.bind("KeyPress"){|e|
    case e.keysym
    #when 'Return'
    when 'BackSpace'
      _index = @text.index('insert')
      _row, _col = _index.split('.')
      rehighlightline(_row.to_i) if @highlighting
    when 'Delete'
      _index = @text.index('insert')
      _row, _col = _index.split('.')
      rehighlightline(_row.to_i) if @highlighting
    when 'F5'
      save
      $arcadia['shell'].run(@file.to_s)
    when 'F3'
      @find.do_find_next
    when 'F1'
      line, col = @text.index('insert').split('.')
      _x, _y = @controller.xy_insert
      _file = create_temp_file
      begin
        Arcadia.process_event(DocCodeEvent.new(self, 'file'=>_file, 'row'=>line.to_s, 'col'=>col.to_s, 'xdoc'=>_x, 'ydoc'=>_y))
      ensure
        File.delete(_file) 	if File.exist?(_file)
      end
      #EditorContract.instance.doc_code(@controller, 'file'=>_file, 'line'=>line.to_s, 'col'=>col.to_s, 'xdoc'=>_x, 'ydoc'=>_y)
    when 'Tab'
      n_space = $arcadia['conf']['editor.tab-replace-width-space'].to_i
      _r = @text.tag_ranges('sel')
      if _r && _r[0]
        _row_begin = _r[0][0].split('.')[0].to_i
        _row_end = _r[_r.length - 1][1].split('.')[0].to_i
        if n_space > 0
          suf = "\s"*n_space
        else
          suf = "\t"
        end
        for _row in _row_begin..._row_end
          @text.insert(_row.to_s+'.0', suf)
        end
        break
      elsif n_space > 0
        @text.insert('insert', "\s"*n_space)
        break
      end
    end
  }

  @text.bind("KeyRelease"){|e|
    case e.keysym
      when 'Control_L','Return', 'Control_V', 'BackSpace', 'Delete'
        if modified?
          set_modify
        else
          reset_modify
        end
        do_line_update
      when 'Right','Left','Down', 'Up'
        # do nil
      else
        check_modify
    end
    
    case e.keysym
    when 'Return'
      _index = @text.index('insert')
      _row, _col = _index.split('.')
      _txt = @text.get((_row.to_i-1).to_s+'.0',_index)
      if _txt.length > 0
        m = /\s*/.match(_txt)
        if m
          if (m[0] != "\n")
            _sm = m[0]
            _sm = _sm.sub(/\n/,"")
            @text.insert('insert',_sm)
          end
        end
      end
      if _row.to_i + 1  ==  @text.index('end').split('.')[0].to_i
        do_line_update
      end
    else 
      if @highlighting && /\w/.match(e.keysym)
        rehighlightline(@text.index('insert').split('.')[0].to_i)
      end
    end
  }


  @text.bind("Shift-KeyPress"){|e|
    case e.keysym
    when 'Tab'
      _r = @text.tag_ranges('sel')
      if _r && _r[0]
        _row_begin = _r[0][0].split('.')[0].to_i
        _row_end = _r[_r.length - 1][1].split('.')[0].to_i
        
        n_space = $arcadia['conf']['editor.tab-replace-width-space'].to_i
        if n_space > 0
          suf = "\s"*n_space
        else
          suf = "\t"
          n_space = 1
        end
        for _row in _row_begin..._row_end
          if @text.get(_row.to_s+'.0',_row.to_s+'.'+n_space.to_s) == suf
            @text.delete(_row.to_s+'.0',_row.to_s+'.'+n_space.to_s)
          end
        end
        break
      end
    end
  }

end

#initialize_tree(_frame) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'ext/ae-editor/ae-editor.rb', line 52

def initialize_tree(_frame)
  @classbrowsing = true 
  @nb = Tk::BWidget::NoteBook.new(_frame){
    tabbevelsize 0
    internalborderwidth 0
    activeforeground 'red'
    activebackground 'yellow'
    borderwidth 1
    side $arcadia['conf']['editor.explorer_panel.tabs.side']
    font $arcadia['conf']['editor.tabs.font']
    pack('fill'=>'both', :padx=>0, :pady=>0, :expand => 'yes')
  }
  @nb_tab_exp = @nb.insert('end','exp' ,'text'=>'Source Tree' )
  @nb.raise('exp')
  _tree_goto = proc{|_self|
    _line = _self.selection_get[0]
    _index =_line.to_s+'.0'
    _hinner_text = @tree_exp.itemcget(_line,'text').strip
    _editor_line = @text.get(_index, _index+ '  lineend')
    if !_editor_line.include?(_hinner_text)
      Arcadia.new_msg(self, "... rebuild tree \n")
      if @tree_thread && @tree_thread.alive?
        @tree_thread.exit
      end
      @tree_thread = Thread.new{
        build_tree(_line)
        Tk.update
      }
      _line = _self.selection_get[0]
      _index =_line.to_s+'.0'
    end
    @text.see(_index)
    @text.tag_remove('selected','1.0','end')
    @text.tag_add('selected',_line.to_s+'.0',(_line+1).to_s+'.0')
  }
  @tree_exp = Tk::BWidget::Tree.new(@nb_tab_exp){
    background '#FFFFFF'
    relief 'flat'
    showlines false
    deltay 18
    dragenabled true
    selectcommand proc{ _tree_goto.call(self) } 
    place('relwidth' => 1,'relx' => 0,'x' => '0','y' => '0','relheight' => '1','rely' => 0,'height' => 1,'bordermode' => 'inside','width' => '50')
  }
  
  _c_explo = proc{|*args| @tree_exp.yview(*args)}
  _s_explo = TkScrollbar.new(@nb_tab_exp){|s|
    width 8
    command _c_explo
  }.pack('side'=>'right', 'fill'=>'y')
  @tree_exp.yscrollcommand proc{|first,last| _s_explo.set first,last}
  pop_up_menu_tree
end

#insert_popup_menu_item(_where, *args) ⇒ Object



894
895
896
# File 'ext/ae-editor/ae-editor.rb', line 894

def insert_popup_menu_item(_where, *args)
  @pop_up.insert(_where,*args)
end

#load_file(_filename = nil) ⇒ Object



1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
# File 'ext/ae-editor/ae-editor.rb', line 1411

def load_file(_filename = nil)
  #if filename is nil then open a new tab
  @file = _filename
  if _filename
    #init_editing(file_extension(_filename))
    File::open(_filename,'r'){ |file|
      @text.insert('end',file.readlines.collect!{| line | line.chomp+"\n" }.to_s)
    }
  end
  set_read_only(!File.stat(_filename).writable?)
  
  reset
  refresh
end

#mark_debug(_index) ⇒ Object



742
743
744
745
# File 'ext/ae-editor/ae-editor.rb', line 742

def mark_debug(_index)
  @text.tag_add('debug',_index +' linestart', _index +' +1 lines linestart')
  #@text.tag_add('debug',_index +' linestart', _index +' lineend')
end

#mark_selected(_index) ⇒ Object



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

def mark_selected(_index)
  @text.tag_remove('selected','1.0', 'end')
  @text.tag_add('selected',_index +' linestart', _index +' +1 lines linestart')
end

#modified?Boolean

Returns:

  • (Boolean)


1098
1099
1100
# File 'ext/ae-editor/ae-editor.rb', line 1098

def modified?
  return !(@buffer === text_value)
end

#pop_up_menuObject



557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# File 'ext/ae-editor/ae-editor.rb', line 557

def pop_up_menu
  @pop_up = TkMenu.new(
    :parent=>@text,
    :tearoff=>1,
    :title => 'Menu'
  )
  @pop_up.insert('end',
    :command,
    :label=>'Save as',
    :hidemargin => false,
    :command=> proc{save_as}
  )
  @pop_up.insert('end',
    :command,
    :label=>'Save',
    :hidemargin => false,
    :command=> proc{save}
  )

  @pop_up.insert('end',
    :command,
    :label=>'Close',
    :hidemargin => false,
    :command=> proc{@controller.close_editor(self)}
  )

  @pop_up.insert('end',
    :command,
    :label=>'Close others',
    :hidemargin => false,
    :command=> proc{@controller.close_others_editor(self)}
  )

  @pop_up.insert('end',
    :command,
    :label=>'Close all',
    :hidemargin => false,
    :command=> proc{@controller.close_all_editor(self)}
  )


  @pop_up.insert('end', :separator)

  @pop_up.insert('end',
    :command,
    :label=>'Color',
    :hidemargin => false,
    :command=> proc{
      @text.insert('insert',Tk.chooseColor)
    }
  )
  @pop_up.insert('end',
    :command,
    :label=>'Font',
    :hidemargin => false,
    :command=> proc{
      @text.insert('insert', $arcadia['action.get.font'].call)
    }
  )
  

  @pop_up.insert('end', :separator)

  #---- debug menu
  _sub_debug = TkMenu.new(
    :parent=>@pop_up,
    :tearoff=>0,
    :title => 'Debug'
  )

  _sub_debug.insert('end',
    :command,
    :label=>'Eval selected',
    :hidemargin => false,
    :command=> proc{
      _r = @text.tag_ranges('sel')
      if _r.length>0
        _text=@text.get(_r[0][0],_r[0][1])
        if _text.length > 0
          Arcadia.process_event(EvalExpressionEvent.new(self, 'expression'=>_text))
          #EditorContract.instance.eval_expression(self, 'text'=>_text)
        end
      end
    }
  )

  @pop_up.insert('end',
    :cascade,
    :label=>'Debug',
    :menu=>_sub_debug,
    :hidemargin => false
  )


  #---- code menu
  _sub_code = TkMenu.new(
    :parent=>@pop_up,
    :tearoff=>0,
    :title => 'Code'
  )

  _sub_code.insert('end',
    :command,
    :label=>'Set wrap',
    :hidemargin => false,
    :command=> proc{@text.configure('wrap'=>'word')}
  )

  _sub_code.insert('end',
    :command,
    :label=>'Set no wrap',
    :hidemargin => false,
    :command=> proc{@text.configure('wrap'=>'none')}
  )

  _sub_code.insert('end',
    :command,
    :label=>'Show tabs',
    :hidemargin => false,
    :command=> proc{show_tabs}
  )


  _sub_code.insert('end',
    :command,
    :label=>'Hide tabs',
    :hidemargin => false,
    :command=> proc{hide_tabs}
  )

  _sub_code.insert('end',
    :command,
    :label=>'Show spaces',
    :hidemargin => false,
    :command=> proc{show_spaces}
  )


  _sub_code.insert('end',
    :command,
    :label=>'Hide spaces',
    :hidemargin => false,
    :command=> proc{hide_spaces}
  )


  _sub_code.insert('end',
    :command,
    :label=>'Space to tabs indentation',
    :hidemargin => false,
    :command=> proc{indentation_space_2_tabs}
  )

  _sub_code.insert('end',
    :command,
    :label=>'Tabs to space indentation',
    :hidemargin => false,
    :command=> proc{indentation_tabs_2_space}
  )

  
  @pop_up.insert('end',
    :cascade,
    :label=>'Code',
    :menu=>_sub_code,
    :hidemargin => false
  )




  @text.bind("Button-3",
    proc{|x,y|
      _x = TkWinfo.pointerx(@text)
      _y = TkWinfo.pointery(@text)
      @pop_up.popup(_x,_y)
    },
  "%x %y")
end

#pop_up_menu_treeObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'ext/ae-editor/ae-editor.rb', line 106

def pop_up_menu_tree
  @pop_up_tree = TkMenu.new(
    :parent=>@tree_exp,
    :title => 'Menu tree'
  )
  @pop_up_tree.insert('end',
    :command,
    :label=>'Rebuild',
    :hidemargin => false,
    :command=> proc{build_tree}
  )
  @tree_exp.bind_append("Button-3",
    proc{|x,y|
      _x = TkWinfo.pointerx(@tree_exp)
      _y = TkWinfo.pointery(@tree_exp)
      @pop_up_tree.popup(_x,_y)
    },
  "%x %y")
end

#pos_to_index(_txt, _pos) ⇒ Object



1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
# File 'ext/ae-editor/ae-editor.rb', line 1115

def pos_to_index(_txt, _pos)
  _a= _txt[0.._pos].split("\n")
  if _a && _a.length > 0
    _row = _a.length
    if _a.length == 2
      _col = _a[-1].length - 1
    else
      _col = _pos
    end
    return [_row,_col]
  else
    return nil
  end
end

#refreshObject



1445
1446
1447
# File 'ext/ae-editor/ae-editor.rb', line 1445

def refresh
  build_tree if @classbrowsing
end

#rehighlightline(_row) ⇒ Object



1197
1198
1199
1200
1201
1202
1203
# File 'ext/ae-editor/ae-editor.rb', line 1197

def rehighlightline(_row)
  _ibegin = _row.to_s+'.0'
  _iend = (_row+1).to_s+'.0'
  @h_classes.each{|c| @text.tag_remove(c,_ibegin, _iend)}
  _line = @text.get(_ibegin, _iend)
  highlightline(_row, _line)
end

#rehighlightlines(_row_begin, _row_end) ⇒ Object



1205
1206
1207
1208
1209
1210
1211
# File 'ext/ae-editor/ae-editor.rb', line 1205

def rehighlightlines(_row_begin, _row_end)
  _ibegin = _row_begin.to_s+'.0'
  _iend = (_row_end+1).to_s+'.0'
  @h_classes.each{|c| @text.tag_remove(c,_ibegin, _iend)}
  _lines = @text.get(_ibegin, _iend)
  highlightlines(_row_begin, _lines)
end

#resetObject



1439
1440
1441
1442
1443
# File 'ext/ae-editor/ae-editor.rb', line 1439

def reset
  @buffer = text_value
  reset_modify
  @text.edit_reset
end

#reset_modifyObject



1109
1110
1111
1112
1113
# File 'ext/ae-editor/ae-editor.rb', line 1109

def reset_modify
  @controller.change_tab_reset_modify(@page_frame)
  @set_mod = false
  @file_last_access_time = File.mtime(@file) if @file
end

#row(_index = 'insert') ⇒ Object



1214
1215
1216
1217
1218
# File 'ext/ae-editor/ae-editor.rb', line 1214

def row(_index='insert')
  _row = @text.index(_index).split('.')[0].to_i
  #print "def row(_index='insert')",_row.to_s,"\n"
  return _row
end

#rowcol(_index, _gap_row = nil, _gap_col = nil) ⇒ Object



926
927
928
929
930
931
932
933
934
935
936
937
# File 'ext/ae-editor/ae-editor.rb', line 926

def rowcol(_index, _gap_row = nil, _gap_col = nil)
  _riga, _colonna = _index.split('.')
  if _gap_row == nil
    _riga = '1'
    _gap_row = 0
  end
  if _gap_col == nil
    _colonna = '0'
    _gap_col = 0
  end
  return (_riga.to_i + _gap_row).to_s + '.'+ (_colonna.to_i + _gap_col).to_s
end

#saveObject



1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
# File 'ext/ae-editor/ae-editor.rb', line 1321

def save
  if !@file
    save_as
  else
    f = File.new(@file, "w")
    begin
      if f
        f.syswrite(text_value)
        @buffer = text_value
        reset_modify
      end
    ensure
      f.close unless f.nil?
    end
    #EditorContract.instance.file_saved(self,'file' =>@file)
  end
end

#save_asObject



1339
1340
1341
1342
1343
1344
1345
1346
1347
# File 'ext/ae-editor/ae-editor.rb', line 1339

def save_as
  @file = Tk.getSaveFile("filetypes"=>[["Ruby Files", [".rb", ".rbw"]]])
  @file = nil if @file == ""  # cancelled
  if @file
    save
    @controller.change_file_name(@page_frame, @file)
    #EditorContract.instance.file_created(self, 'file'=>@file)
  end
end

#set_modifyObject



1102
1103
1104
1105
1106
1107
# File 'ext/ae-editor/ae-editor.rb', line 1102

def set_modify
  if !@set_mod
    @set_mod = true
    @controller.change_tab_set_modify(@page_frame)
  end
end

#set_read_only(_value) ⇒ Object



1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
# File 'ext/ae-editor/ae-editor.rb', line 1426

def set_read_only(_value)
  if @read_only != _value
    @read_only = _value
    if @read_only
      @text.configure('state'=>'disabled')
      @controller.change_tab_set_read_only(@page_frame)
    else
      @text.configure('state'=>'normal')
      @controller.change_tab_reset_read_only(@page_frame)
    end
  end
end

#show_chars_line(_row, _line, _re, _tag) ⇒ Object



1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
# File 'ext/ae-editor/ae-editor.rb', line 1034

def show_chars_line(_row, _line, _re, _tag)
  m = _re.match(_line)
  _end = 0
  while m
    _txt = m.post_match
    _ibegin = _row.to_s+'.'+(m.begin(0)+_end).to_s
    _end = m.end(0) + _end
    _iend = _row.to_s+'.'+(_end.to_s)
    @text.tag_add(_tag,_ibegin, _iend)
    m = _re.match(_txt)
  end
end

#show_spacesObject



1014
1015
1016
1017
1018
1019
1020
1021
# File 'ext/ae-editor/ae-editor.rb', line 1014

def show_spaces
  @spaces_show = true
  _row = 1
  @text.value.each{|_line|
    show_chars_line(_row, _line, /[ ^\t]\s*/, 'spaces')
    _row = _row+1
  }
end

#show_tabsObject



1024
1025
1026
1027
1028
1029
1030
1031
# File 'ext/ae-editor/ae-editor.rb', line 1024

def show_tabs
  @tabs_show = true
  _row = 1
  @text.value.each{|_line|
    show_chars_line(_row, _line, /\t/, 'tabs')
    _row = _row+1
  }
end

#text_insert(index, chars, *tags, &b) ⇒ Object



1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
# File 'ext/ae-editor/ae-editor.rb', line 1289

def text_insert(index, chars, *tags, &b)
  if block_given?
    instance_eval(&b)
  end
  _index = @text.index(index)
  _row, _col  = _index.split('.')
  _row = (_row.to_i - 1).to_s
  chars.each_line {|line|
    @text.insert(_row+'.0', line, *tags)
    if !defined?(m_begin)||(m_begin == nil)
      m_begin = /=begin/.match(line)
    end
    if @highlighting
      if m_begin &&(m_begin.begin(0)==0)
        _ibegin = _row+'.0'
        _iend = _row+'.'+(line.length - 1).to_s
        @text.tag_add('comment',_ibegin, _iend)
      else
        highlightline(_row.to_i, line, false)
      end
    end
    _row = (_row.to_i + 1).to_s
  }
  if defined?(_edit_reset)
    if _edit_reset
      @text.edit_reset
    end
  else
    @text.edit_reset
  end
end

#text_insert_indexObject



1285
1286
1287
# File 'ext/ae-editor/ae-editor.rb', line 1285

def text_insert_index
  @text.index('insert')
end

#text_see(_index = nil) ⇒ Object



1279
1280
1281
1282
1283
# File 'ext/ae-editor/ae-editor.rb', line 1279

def text_see(_index=nil)
  if _index
    @text.see(_index)
  end
end

#text_valueObject



898
899
900
# File 'ext/ae-editor/ae-editor.rb', line 898

def text_value
  return @text.value
end

#unmark_debug(_index) ⇒ Object



737
738
739
740
# File 'ext/ae-editor/ae-editor.rb', line 737

def unmark_debug(_index)
  @text.tag_remove('debug',_index +' linestart', _index +' +1 lines linestart')
  #@text.tag_remove('debug',_index+' linestart', _index+' lineend')
end

#vscroll(mode) ⇒ Object

vertical scrollbar : ON/OFF



903
904
905
906
907
908
909
910
911
# File 'ext/ae-editor/ae-editor.rb', line 903

def vscroll(mode)
  st = TkGrid.info(@v_scroll)
  if mode && st == [] then
    @v_scroll.grid('row'=>0, 'column'=>1, 'sticky'=>'ns')
  elsif !mode && st != [] then
    @v_scroll.ungrid
  end
  self
end