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

Methods included from Configurable

#properties_file2hash, properties_group, #resolve_link, #resolve_properties_link

Constructor Details

#initialize(_controller, _page_frame) ⇒ AgEditor

Returns a new instance of AgEditor.



630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'ext/ae-editor/ae-editor.rb', line 630

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 = Arcadia.conf('edit.font')
  @font_bold = "#{Arcadia.conf('edit.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
  @loading=false
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



626
627
628
# File 'ext/ae-editor/ae-editor.rb', line 626

def file
  @file
end

#page_frameObject (readonly)

Returns the value of attribute page_frame.



628
629
630
# File 'ext/ae-editor/ae-editor.rb', line 628

def page_frame
  @page_frame
end

#read_onlyObject (readonly)

Returns the value of attribute read_only.



627
628
629
# File 'ext/ae-editor/ae-editor.rb', line 627

def read_only
  @read_only
end

#rootObject (readonly)

Returns the value of attribute root.



629
630
631
# File 'ext/ae-editor/ae-editor.rb', line 629

def root
  @root
end

#textObject (readonly)

Returns the value of attribute text.



629
630
631
# File 'ext/ae-editor/ae-editor.rb', line 629

def text
  @text
end

Instance Method Details

#activate_complete_code_key_bindingObject



1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
# File 'ext/ae-editor/ae-editor.rb', line 1109

def activate_complete_code_key_binding
  @n_complete_task = 0
  # key binding for complete code
  @text.bind_append("Control-KeyPress"){|e|
    case e.keysym
    when 'space'
      if @n_complete_task == 0
        @do_complete = true
        complete_code
      end
    end
  }
  
  @text.bind_append("KeyPress"){|e|
    @do_complete = false
  }    

  @text.bind_append("KeyRelease"){|e|
    case e.keysym
      when 'period'
        _focus_line = @text.get('insert linestart','insert')
        if _focus_line.strip[0..0] != '#'
          Thread.new do
            @do_complete = true
            sleep(1)
            if @do_complete && @n_complete_task == 0
              complete_code
            end
          end
        end
    end
  }

end

#activate_key_bindingObject



1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
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
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
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
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
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
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
# File 'ext/ae-editor/ae-editor.rb', line 1144

def activate_key_binding
  activate_complete_code_key_binding if @is_ruby
  @text.bind_append("Control-KeyPress"){|e|
    case e.keysym
#      when 'space'
#        @do_complete = true
#        complete_code.call
    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'
      find
    when 'egrave'
      @text.insert('insert',"{")
    when 'plus'
      @text.insert('insert',"}")
    end
  }

  @text.bind_append("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_append("KeyPress"){|e|
    #@do_complete = false
    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'
      run_buffer
    when 'F3'
      @find.do_find_next
    when 'F1'
      line, col = @text.index('insert').split('.')
      _x, _y = 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_append("KeyRelease"){|e|
    case e.keysym
#        when 'period'
#          @do_complete = true
#          #Thread.new do
#            complete_code.call
#          #end
      when 'Control_L','Return', 'Control_V', 'BackSpace', 'Delete'
        do_line_update
    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
    check_modify
  }


  @text.bind_append("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

#add_tag_breakpoint(_line) ⇒ Object



1505
1506
1507
1508
1509
1510
1511
1512
# File 'ext/ae-editor/ae-editor.rb', line 1505

def add_tag_breakpoint(_line)
    rel_line = file_line_to_text_line_num_line(_line)
    if rel_line
      i1 = "#{rel_line}.0"
      i2 = i1+' + 2 chars'
      @text_line_num.tag_add('breakpoint',i1,i2)
    end
end

#arity_to_str(_arity = 0) ⇒ Object



851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
# File 'ext/ae-editor/ae-editor.rb', line 851

def arity_to_str(_arity=0)
  ret = ''
  jolly_args = _arity < 0
  if jolly_args 
    _arity = _arity.abs - 1
  end
  j = _arity
  while j > 0
    if ret.strip.length > 0
      ret = "#{ret},"
    end
    ret = "#{ret}arg#{_arity-j+1}"
    j = j-1
  end
  if jolly_args 
    if ret.strip.length > 0
      ret = "#{ret},"
    end
    ret = "#{ret}*"
  end    
  ret    
end

#build_tree(_sel = nil) ⇒ Object



2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
# File 'ext/ae-editor/ae-editor.rb', line 2057

def build_tree(_sel=nil)
  #Arcadia.console(self,"msg"=>"build for #{@file}")
  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)
  @root = SourceStructure.new(_txt).root
  
  @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

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.strip == “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


2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
# File 'ext/ae-editor/ae-editor.rb', line 2024

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
    }.update(Arcadia.style('treeitem'))
    )
    if (_label_match) && (_label_match.strip == _son.label.strip)
      @selected = _son
    end
    build_tree_from_node(_son, _label_match)
  end
end

#check_file_last_access_timeObject



2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
# File 'ext/ae-editor/ae-editor.rb', line 2627

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')
          reset_highlight
          load_file(@file)
        else
          @file_last_access_time = ftime
        end
    end
  end
end

#check_modifyObject



2619
2620
2621
2622
2623
2624
2625
# File 'ext/ae-editor/ae-editor.rb', line 2619

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

#complete_codeObject



841
842
843
844
845
846
847
848
849
# File 'ext/ae-editor/ae-editor.rb', line 841

def complete_code
  @do_complete = @do_complete && @controller.accept_complete_code
  if @do_complete
    line, col = @text.index('insert').split('.')
    mss = SafeCompleteCode.new(text_value, line.to_i, col.to_i, @file)
    candidates = mss.candidates
    raise_complete_code(candidates, line.to_s, col.to_s, mss.filter) if candidates && candidates.length > 0 
  end
end

#complete_code_beginObject



828
829
830
831
832
# File 'ext/ae-editor/ae-editor.rb', line 828

def complete_code_begin
  @n_complete_task = 1
  @text.configure('cursor'=> 'hand2')
  #disactivate_key_binding
end

#complete_code_endObject



834
835
836
837
838
# File 'ext/ae-editor/ae-editor.rb', line 834

def complete_code_end
  @text.configure('cursor'=> @text_cursor)
  #activate_key_binding
  @n_complete_task = 0
end

#create_temp_fileObject



776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
# File 'ext/ae-editor/ae-editor.rb', line 776

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

#create_temp_file_for_completion(_row) ⇒ Object



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
# File 'ext/ae-editor/ae-editor.rb', line 793

def create_temp_file_for_completion(_row)
  _custom_text = ""
  text_value_array = text_value.split("\n")
  text_value_array.each_with_index{|line,j|
    # 1) includiano i require e la riga da includere
    if line.include?("require") || j.to_i == _row.to_i-1
      _custom_text = "#{_custom_text}#{line}\n"
      #p "inserisco=>#{line} alla riga=>#{j}"
    elsif j.to_i == _row.to_i-2
      _custom_text = "#{_custom_text}$SAFE = 3\n"
    else
      _custom_text = "#{_custom_text}\n"
      #p "inserisco=>blank alla riga=>#{j}"
    end
    #p "riga:#{j}"
    break if j.to_i >= _row.to_i - 1
  }
  Arcadia.console(self, 'msg'=>_custom_text)

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

#disactivate_key_bindingObject



1364
1365
1366
1367
1368
1369
1370
1371
# File 'ext/ae-editor/ae-editor.rb', line 1364

def disactivate_key_binding
  @text.bind_remove('KeyPress')
  @text.bind_remove('KeyRelease')
  @text.bind_remove('Control-KeyPress')
  @text.bind_remove('Control-Shift-KeyPress')
  @text.bind_remove('Shift-KeyPress')

end

#do_line_updateObject



2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
# File 'ext/ae-editor/ae-editor.rb', line 2421

def do_line_update
  #re num in @text_line_num the portion of visibled screen  of @text
    #Arcadia.console(self, 'msg'=>"do_line_update loading ..")
    return if @loading
    #Arcadia.console(self, 'msg'=>"do_line_update")
    if @text_line_num
      line_begin_index = @text.index('@0,0')
      line_begin = line_begin_index.split('.')[0].to_i
      line_end = @text.index('@0,'+TkWinfo.height(@text).to_s).split('.')[0].to_i + 1
      wrap_on = @text.cget("wrap") != 'none'
      # breakpoint
      b = @controller.breakpoint_lines_on_file(@file)
      if @highlighting
        _zone_begin = ((line_begin) / @highlight_zone_length).to_i + 1
        _zone_end = ((line_end) / @highlight_zone_length).to_i + 1
        #Arcadia.new_msg(self, "for lines #{line_begin}..#{line_end} \n
        _zone_begin=#{_zone_begin} ; _zone_end=#{_zone_end}")
        (_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
      
      @text_line_num.delete('1.0','end')

      _rx, _ry, _widht, _heigth = @text.bbox(line_begin_index);
#          _rx2, _ry2, _widht2, _heigth2 = @text.bbox(line_begin_index+" +1 lines");
#        if _rx2
#          _coef = _ry2-_ry-_heigth       
#        end
#        if _ry < 0 
#          nline = (line_begin + 1).to_s.rjust(line_end.to_s.length+2)
#          @text_line_num.tag_configure('start_case', 'spacing1'=>(_heigth+_ry))
#          @text_line_num.insert('end', "#{nline}\n",'normal_case','start_case')
#          real_line_begin = line_begin + 2
#        else
#          real_line_begin = line_begin
#        end
      
      if _ry && _ry < 0 
        real_line_end = line_end + 1
#          x = (_heigth+_ry)/_heigth
#          @text_line_num.yview_scroll(-(_heigth+_ry),"pixels")
        
      else
        real_line_end = line_end
      end

      _tags = Array.new
      for j in line_begin...real_line_end
        nline = j.to_s.rjust(line_end.to_s.length+2)
        _index = @text_line_num.index('end')
        _tags.clear
        if @highlighting && @is_line_bold[j]
          _tags << 'bold_case'
        else
          _tags << 'normal_case'
        end
        
        if wrap_on
          w_rx_b, w_ry_b, w_widht_b, w_heigth_b = @text.bbox("#{(j).to_s}.0");
          w_rx_e, w_ry_e, w_widht_e, w_heigth_e = @text.bbox("#{(j).to_s}.0 lineend");
          if w_ry_e && w_ry_b 
            delta = w_ry_e - w_ry_b
            if delta > 1   
              _tag = "wrap_case_#{j}"
              @text_line_num.tag_configure(_tag, 'spacing3'=>delta)  
              _tags << _tag
            end
          end
        end

        @text_line_num.insert(_index, "#{nline}\n",_tags)
#          if @highlighting && @is_line_bold[j]
#            @text_line_num.insert('end', "#{nline}\n",'bold_case')
#          else
#            @text_line_num.insert('end', "#{nline}\n",'normal_case')
#          end
        if b.include?(j.to_s)
          add_tag_breakpoint(j)
          #add_tag_breakpoint(_index)
          #p "aggiungo tag break on line #{j} on index ->#{_index}"
          #add_tag_breakpoint(_index+' -1 lines')
        end
      end
      if _ry && _ry < 0 
        #Arcadia.console(self, 'msg'=>"scrollo -> #{-(_heigth+_ry)}")
        #Arcadia.console(self, 'msg'=>"_coef -> #{_coef}")

#          @text_line_num.yview_scroll((_heigth+_ry),"pixels")
#          @text_line_num.yview_scroll((-_ry+3),"pixels")
        @text_line_num.yview_scroll(_ry.abs+3,"pixels")
      end
    end
end

#do_tag_configure(_name) ⇒ Object



1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
# File 'ext/ae-editor/ae-editor.rb', line 1605

def do_tag_configure(_name)
  h = Hash.new
  if @lang_hash['hightlight.'+_name+'.foreground']
    h['foreground']=@lang_hash['hightlight.'+_name+'.foreground']
  end
  if @lang_hash['hightlight.'+_name+'.background']
    h['background']=@lang_hash['hightlight.'+_name+'.background']
  end
  if @lang_hash['hightlight.'+_name+'.style']== 'bold'
    h['font']=@font_bold
    @is_tag_bold[_name]= true
  else
    @is_tag_bold[_name]= false
  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



1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
# File 'ext/ae-editor/ae-editor.rb', line 1629

def do_tag_configure_global(_name)
  h = Hash.new
  if $arcadia['conf']['editor.hightlight.'+_name+'.foreground']
    h['foreground']=$arcadia['conf']['editor.hightlight.'+_name+'.foreground']
  end
  if $arcadia['conf']['editor.hightlight.'+_name+'.background']
    h['background']=$arcadia['conf']['editor.hightlight.'+_name+'.background']
  end
  if $arcadia['conf']['editor.hightlight.'+_name+'.style']== 'bold'
    h['font']=@font_bold
    @is_tag_bold[_name]= true
  else
    @is_tag_bold[_name]= false
  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



2705
2706
2707
2708
2709
2710
# File 'ext/ae-editor/ae-editor.rb', line 2705

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

#file_line_to_text_line_num_line(_line) ⇒ Object



1495
1496
1497
1498
1499
1500
1501
1502
1503
# File 'ext/ae-editor/ae-editor.rb', line 1495

def file_line_to_text_line_num_line(_line)
  rel_line = nil
  line_begin = @text_line_num.get('1.0','1.end').strip.to_i
  line_end = @text_line_num.index('end').split('.')[0].to_i+line_begin
  if _line.to_i >= line_begin && _line.to_i <= line_end
    rel_line = _line.to_i - line_begin +1
  end  
  rel_line
end

#findObject



1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
# File 'ext/ae-editor/ae-editor.rb', line 1350

def find
  _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
end

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



2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
# File 'ext/ae-editor/ae-editor.rb', line 2176

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



2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
# File 'ext/ae-editor/ae-editor.rb', line 2131

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_outlineObject



2701
2702
2703
# File 'ext/ae-editor/ae-editor.rb', line 2701

def hide_outline
  @tree_scroll_wrapper.hide if @tree_scroll_wrapper
end

#hide_spacesObject



2284
2285
2286
2287
# File 'ext/ae-editor/ae-editor.rb', line 2284

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

#hide_tabsObject



2279
2280
2281
2282
# File 'ext/ae-editor/ae-editor.rb', line 2279

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

#highlight_zone(_zone, _force_highlight = false) ⇒ Object



2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
# File 'ext/ae-editor/ae-editor.rb', line 2532

def highlight_zone(_zone, _force_highlight=false)
  if !@highlight_zone[_zone] || _force_highlight
    _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



2522
2523
2524
2525
2526
2527
2528
2529
# File 'ext/ae-editor/ae-editor.rb', line 2522

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



2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
# File 'ext/ae-editor/ae-editor.rb', line 2356

def highlightline(_row, _line, _check_mod = false)
  #p "highlightline #{_row} _line=#{_line}"
  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)
        #p "tag_add  found #{c}"
        _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



2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
# File 'ext/ae-editor/ae-editor.rb', line 2322

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



2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
# File 'ext/ae-editor/ae-editor.rb', line 2106

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



2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
# File 'ext/ae-editor/ae-editor.rb', line 2239

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



2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
# File 'ext/ae-editor/ae-editor.rb', line 2259

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', _w1 = 150, _w2 = 60) ⇒ Object



2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
# File 'ext/ae-editor/ae-editor.rb', line 2673

def init_editing(_ext='rb', _w1=150, _w2=60)
  @is_ruby = _ext=='rb'||_ext=='rbw'
  @lang_hash = languages_hash(_ext)
#    if !_ext.nil? && @is_ruby
#      @fm = AGTkVSplittedFrames.new(@page_frame,_w1)
#      @fm1 = AGTkVSplittedFrames.new(@fm.right_frame,_w2)
#      initialize_tree(@controller.frame(1).hinner_frame)
#      initialize_tree(@fm.left_frame)
#    else
#      @fm1 = AGTkVSplittedFrames.new(@page_frame,_w2)
#    end
  @fm1 = AGTkVSplittedFrames.new(@page_frame,@page_frame,_w2)
  @fm1.splitter_frame.configure('relief'=>'flat')
  initialize_text(@fm1.right_frame)
  initialize_highlight
  initialize_line_number(@fm1.left_frame)
  initialize_text_binding
end

#initialize_highlightObject



1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
# File 'ext/ae-editor/ae-editor.rb', line 1565

def initialize_highlight
  @is_line_bold = Hash.new
  @is_tag_bold = Hash.new
  do_tag_configure_global('debug')
  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



1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
# File 'ext/ae-editor/ae-editor.rb', line 1401

def initialize_line_number(_frame)
  @text_line_num = TkText.new(_frame, Arcadia.style('linepanel')){
    wrap  'none'
    #relief 'flat'
    undo false
    takefocus 0
    insertofftime 0
    exportselection true
    autoseparators true
    cursor nil
    insertwidth 0
    font Arcadia.conf('edit.font')
    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('normal_case', 'justify'=>'right')
  @text_line_num.tag_configure('bold_case', 'spacing3'=>delta, 'justify'=>'right')
  @text_line_num.tag_configure('breakpoint', 'background'=>'red','foreground'=>'yellow','borderwidth'=>1, 'relief'=>'raised')
  @text_line_num.tag_configure('current', 
    'background'=>Arcadia.conf("activebackground"),
    'foreground'=>Arcadia.conf("activeforeground"),
    '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
      toggle_breakpoint(_index)
    }, "%x %y")

  @text_line_num.bind("ButtonPress-1", proc{|x,y|
    _index = @text_line_num.index("@#{x},#{y}")
    _line = @text_line_num.get(_index+' linestart',_index+' lineend').strip
    @text_line_num_current_index = _index
    @text_line_num_current_line = _line
    @text_line_num.tag_remove('current',"0.1","end")
    @text_line_num.tag_add('current',_index+' linestart',_index+' lineend')
    @text_line_num.tag_raise('breakpoint')
    },
  "%x %y")
  
  #@text_line_num.configure('font', @font);
  @text_line_num.tag_configure('line_num',
    'foreground' => '#FFFFFF',
    'background' =>'#0000a0',
    'borderwidth'=>2,
    'relief'=>'raised'
  )
  
  #--- menu
  _pop_up = TkMenu.new(
    :parent=>@text_line_num,
    :tearoff=>0,
    :title => 'Menu'
  )
  _pop_up.configure(Arcadia.style('menu'))
  #Arcadia.instance.main_menu.update_style(@pop_up)
  _title_item = _pop_up.insert('end',
    :command,
    :label=>'...',
    :state=>'disabled',
    :background=>Arcadia.conf('titlelabel.background'),
    :hidemargin => true
  )

  _pop_up.insert('end',
    :command,
    :label=>'Toggle breakpoint',
    :hidemargin => false,
    :command=> proc{ 
      if defined?(@text_line_num_current_index)
        toggle_breakpoint(@text_line_num_current_index)
      end
    }
  )

  @text_line_num.bind("Button-3",
    proc{|*x|
      _x = TkWinfo.pointerx(@text_line_num)
      _y = TkWinfo.pointery(@text_line_num)
      _pop_up.entryconfigure(0,'label'=>"line #{@text_line_num_current_line}")

      _pop_up.popup(_x,_y)
    })
  
end

#initialize_text(_frame) ⇒ Object



729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# File 'ext/ae-editor/ae-editor.rb', line 729

def initialize_text(_frame)
#    @v_scroll = TkScrollbar.new(_frame,{
#      'orient'=>'vertical'}.update(Arcadia.style('scrollbar'))
#    ).pack('side' => 'right', 'fill' => 'y')
  @text = TkScrollText.new(_frame, Arcadia.style('edit')){|j|
    wrap  'none'
    undo true
    insertofftime 200
    insertontime 200
    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'
#      )
  }
  
#    class << @text
#        def do_yscrollcommand(first,last)
#          super
#          do_line_update()
#        end
#    end

# @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
  @text.show
  @text.show_v_scroll
  @text.show_h_scroll
  @text_cursor = @text.cget('cursor')

end

#initialize_text_bindingObject



1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
# File 'ext/ae-editor/ae-editor.rb', line 1373

def initialize_text_binding
  @text.add_yscrollcommand(proc{|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("<Modified>"){|e|
    check_modify
  }
  activate_key_binding
  @text.bind_append("1",proc{Arcadia.process_event(InputEnterEvent.new(self,'receiver'=>@text))})
end

#initialize_tree(_frame) ⇒ Object



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
# File 'ext/ae-editor/ae-editor.rb', line 670

def initialize_tree(_frame)
  @classbrowsing = @is_ruby
  _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.console(self, 'msg'=>"... 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(_frame, Arcadia.style('treepanel')){
    showlines false
    deltay 18
    dragenabled true
    selectcommand proc{ _tree_goto.call(self) } 
  }
  @tree_scroll_wrapper = TkScrollWidget.new(@tree_exp)
  @tree_scroll_wrapper.show
  @tree_scroll_wrapper.show_v_scroll
  @tree_scroll_wrapper.show_h_scroll
  pop_up_menu_tree
end

#insert_popup_menu_item(_where, *args) ⇒ Object



2086
2087
2088
# File 'ext/ae-editor/ae-editor.rb', line 2086

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

#languages_hash(_ext = nil) ⇒ Object



2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
# File 'ext/ae-editor/ae-editor.rb', line 2646

def languages_hash(_ext=nil)
  @@langs_hash = Hash.new if !defined?(@@langs_hash)
  return nil if _ext.nil?
  if @@langs_hash[_ext].nil?
    #_ext='' if _ext.nil?
    lang_file = File.dirname(__FILE__)+'/langs/'+_ext+'.lang'
    if File.exist?(lang_file)
      @@langs_hash[_ext] = properties_file2hash(lang_file)
    elsif File.exist?(lang_file+'.bind')
      b= properties_file2hash(lang_file+'.bind')
      if b 
        if @@langs_hash[b['bind']].nil?
          lang_file_bind = File.dirname(__FILE__)+'/langs/'+b['bind']+".lang"
          if File.exist?(lang_file_bind)
            @@langs_hash[b['bind']]=properties_file2hash(lang_file_bind)
            @@langs_hash[_ext]=@@langs_hash[b['bind']]
          end
        else
          @@langs_hash[_ext]=@@langs_hash[b['bind']]
        end
      end
    end
    self.resolve_properties_link(@@langs_hash[_ext], Arcadia.instance['conf']) if @@langs_hash[_ext]
  end
  @@langs_hash[_ext]
end

#load_file(_filename = nil) ⇒ Object



2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
# File 'ext/ae-editor/ae-editor.rb', line 2712

def load_file(_filename = nil)
  #if filename is nil then open a new tab
  @loading=true
  begin
    @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)
        #@text.insert('end',file.read)
      }
    end
    set_read_only(!File.stat(_filename).writable?)
    reset
    refresh
  ensure
    @loading=false
  end
end

#mark_debug(_index) ⇒ Object



1931
1932
1933
1934
# File 'ext/ae-editor/ae-editor.rb', line 1931

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



1936
1937
1938
1939
# File 'ext/ae-editor/ae-editor.rb', line 1936

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)


2290
2291
2292
# File 'ext/ae-editor/ae-editor.rb', line 2290

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

#pop_up_menuObject



1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
# File 'ext/ae-editor/ae-editor.rb', line 1652

def pop_up_menu
  @pop_up = TkMenu.new(
    :parent=>@text,
    :tearoff=>0,
    :title => 'Menu'
  )
  @pop_up.configure(Arcadia.style('menu'))
  
  @pop_up.insert('end',
    :command,
    :state=>'disabled',
    :background=>Arcadia.conf('titlelabel.background'),
    :font => "#{Arcadia.conf('menu.font')} bold",
    :hidemargin => true
  )

  
  #Arcadia.instance.main_menu.update_style(@pop_up)
  @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', :separator)

  @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=>'Copy',
    :hidemargin => false,
    :command=> proc{
      @text.event_generate("Control-KeyPress",:keysym=>'c')
      @text.event_generate("Control-KeyRelease",:keysym=>'c')
    }
  )

  @pop_up.insert('end',
    :command,
    :label=>'Cut',
    :hidemargin => false,
    :command=> proc{
      @text.event_generate("Control-KeyPress",:keysym=>'x')
      @text.event_generate("Control-KeyRelease",:keysym=>'x')
    }
  )


  @pop_up.insert('end',
    :command,
    :label=>'Paste',
    :hidemargin => false,
    :command=> proc{
      @text.event_generate("Control-KeyPress",:keysym=>'v')
      @text.event_generate("Control-KeyRelease",:keysym=>'v')
    }
  )


  @pop_up.insert('end',
    :command,
    :label=>'Undo',
    :hidemargin => false,
    :command=> proc{
      @text.event_generate("Control-KeyPress",:keysym=>'z')
      @text.event_generate("Control-KeyRelease",:keysym=>'z')
    }
  )


  @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',
    :command,
    :label=>'Data image',
    :hidemargin => false,
    :command=> proc{
      file = Tk.getOpenFile
      if file
        require 'base64'
        f = File.open(file,"rb")
        data = f.read
        f.close
        encoded = Base64.encode64( data )
        @text.insert('insert', File.basename(file).gsub('.gif','_gif').gsub('-','_').upcase + "=<<EOS\n")
        @text.insert('insert', "#{encoded}")
        @text.insert('insert', "EOS\n")
      end
    }
  )

  @pop_up.insert('end',
    :command,
    :label=>'View image from data',
    :hidemargin => false,
    :command=> proc{
      _r = @text.tag_ranges('sel')
      if _r.length>0
        _data=@text.get(_r[0][0],_r[0][1])
        if _data.length > 0

          _b = TkButton.new(@text, 
            'command'=>proc{_b.destroy},
            'image'=> TkPhotoImage.new('data' => _data),
            'relief'=>'groove')
          TkTextWindow.new(@text, _r[0][1], 'window'=> _b)
        end
      end
    }
  )

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

  #---- debug menu
  _sub_debug = TkMenu.new(
    :parent=>@pop_up,
    :tearoff=>0,
    :title => 'Debug'
  )
  _sub_debug.configure(Arcadia.style('menu'))
  _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.configure(Arcadia.style('menu'))
  _sub_code.insert('end',
    :command,
    :label=>'Set wrap',
    :hidemargin => false,
    :command=> proc{@text.configure('wrap'=>'word');@text.hide_h_scroll}
  )

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

  _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(@controller.conf('popup.bind.shortcut'),
    proc{|x,y|
      _x = TkWinfo.pointerx(@text)
      _y = TkWinfo.pointery(@text)
      @pop_up.entryconfigure(0, 'label'=>File.basename(@file)) if @file
      @pop_up.popup(_x,_y)
    },
  "%x %y")
end

#pop_up_menu_treeObject



706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
# File 'ext/ae-editor/ae-editor.rb', line 706

def pop_up_menu_tree
  @pop_up_tree = TkMenu.new(
    :parent=>@tree_exp,
    :title => 'Menu tree'
  )
  @pop_up_tree.configure(Arcadia.style('menu'))
  #Arcadia.instance.main_menu.update_style(@pop_up_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



2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
# File 'ext/ae-editor/ae-editor.rb', line 2307

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

#raise_complete_code(_candidates, _row, _col, _filter = '') ⇒ Object



875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
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
982
983
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
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
# File 'ext/ae-editor/ae-editor.rb', line 875

def raise_complete_code(_candidates, _row, _col, _filter='')
  @raised_listbox_frame.destroy if @raised_listbox_frame != nil
  #@raised_listbox.destroy if @raised_listbox != nil
  _index_call = _row+'.'+_col
  _index_now = @text.index('insert')
  if _index_call == _index_now 
    _target = @text.get('insert - 1 chars wordstart','insert')
    if _target.strip == '('
      _target = @text.get('insert - 2 chars wordstart','insert')
    end
      if _target.strip.length > 0 && _target != '.'
        extra_len = _target.length.+@
        _begin_index = _index_now<<' - '<<extra_len.to_s<<' chars'
        @text.tag_add('sel', _begin_index, _index_now)
      else
        _begin_index = _index_now
        extra_len = 0
      end
      if _candidates.length >= 1 
          _rx, _ry, _widht, heigth = @text.bbox(_begin_index);
          _x = _rx + TkWinfo.rootx(@text)  
          _y = _ry + TkWinfo.rooty(@text)  + @font_metrics[2][1]
          _xroot = _x - TkWinfo.rootx(Arcadia.instance.layout.root)  
          _yroot = _y - TkWinfo.rooty(Arcadia.instance.layout.root)  
          
          _max_height = TkWinfo.screenheight(Arcadia.instance.layout.root) - _y - 5
          self.complete_code_begin
          
      #    @raised_listbox_frame = TkResizingTitledFrame.new(Arcadia.instance.layout.root)
          @raised_listbox_frame = TkFrame.new(Arcadia.instance.layout.root, {
            :padx=>"1",
            :pady=>"1",
            :background=> Arcadia.conf("foreground")
          })
          
          @raised_listbox = TkTextListBox.new(@raised_listbox_frame, {
            :takefocus=>true, 
            :selectbackground=>Arcadia.conf('hightlight.1.background'),
            :selectforeground=>Arcadia.conf('hightlight.1.foreground')}.update(Arcadia.style('listbox'))
          )
          _char_height = @font_metrics[2][1]
          _width = 0
          _docs_entries = Hash.new
          _item_num = 0
          _update_list = proc{|_in|
              _in.strip!
              @raised_listbox.clear
              _length = 0
              _candidates.each{|value|
                _doc = value.strip
                _class, _key, _arity = _doc.split('#')
                if _key && _arity
                  args = arity_to_str(_arity.to_i)
                  if args.length > 0
                    _key = "#{_key}(#{args})"
                  end
                end
                
                if _key && _class && _key.strip.length > 0 && _class.strip.length > 0 
                  _item = "#{_key.strip} - #{_class.strip}"
                elsif _key && _key.strip.length > 0
                  _item = "#{_key.strip}"
                else
                  _key = "#{_doc.strip}"
                  _item = "#{_doc.strip}"
                end
                if _in.nil? || _in.strip.length == 0 || _item[0.._in.length-1] == _in 
                #|| _item[0.._in.length-1].downcase == _in
                  _docs_entries[_item]= _doc
         #         @raised_listbox.insert('end', _item)
                  @raised_listbox.add(_item)
                  _temp_length = _item.length
                  _length = _temp_length if _temp_length > _length 
                  _item_num = _item_num+1 
                  _last_valid_key = _key
                end
              }
              _width = _length*8
              @raised_listbox.select(1)
 #             p "_update_list end-->#{Time.new}"

              Tk.event_generate(@raised_listbox, "1") if TkWinfo.mapped?(@raised_listbox)
          }

          _insert_selected_value = proc{
            #_value = @raised_listbox.get('active').split('-')[0].strip
            if @raised_listbox.selected_line && @raised_listbox.selected_line.strip.length>0
              _value = @raised_listbox.selected_line.split('-')[0].strip
              @raised_listbox_frame.grab("release")
              @raised_listbox_frame.destroy
              #_menu.destroy
              @text.focus
              @text.delete(_begin_index,'insert')
              @text.insert('insert',_value.strip)
              complete_code_end
              
              _to_search = 'arg1'
              _argindex = @text.search(_to_search,_begin_index)
              if !(_argindex && _argindex.length>0)
                _to_search = '*'
                _argindex = @text.search(_to_search,_begin_index)
              end
              if _argindex && _argindex.length>0
                _argrow, _argcol = _argindex.split('.')
                if _argrow.to_i == _row.to_i
                  _argindex_sel_end = _argrow.to_i.to_s+'.'+(_argcol.to_i+_to_search.length).to_i.to_s
                  @text.tag_add('sel', _argindex,_argindex_sel_end)
                  @text.set_insert(_argindex)
                end
              end
            end
            
            Tk.callback_break
          }
          _update_list.call(_filter)
          if _item_num == 0
            @raised_listbox_frame.destroy
            self.complete_code_end
            return
          elsif _item_num == 1 
            _insert_selected_value.call
            return
          end
          _width = _width + 10
          #_height = (candidates.length+1)*_char_height
          _height = 15*_char_height
          _height = _max_height if _height > _max_height
          
          _buffer = @text.get(_begin_index, 'insert')
          _buffer_ini_length = _buffer.length
          @raised_listbox_frame.place('x'=>_xroot,'y'=>_yroot, 'width'=>_width, 'height'=>_height)
          @raised_listbox.show(0,0,'inside')
          @raised_listbox.show_v_scroll
          @raised_listbox.focus
          #@raised_listbox.activate(0)
          @raised_listbox.select(1)
          @raised_listbox_frame.grab("set")
       #   Tk.event_generate(@raised_listbox, "1")
       
       
          @raised_listbox.bind_append("Double-ButtonPress-1", 
            proc{|x,y| 
              _index = @raised_listbox.index("@#{x},#{y}")
              _line = _index.split('.')[0].to_i
              @raised_listbox.select(_line)
              _insert_selected_value.call
                }, "%x %y")
          @raised_listbox.bind_append('Shift-KeyPress'){|e|
            # todo
            case e.keysym
              when 'parenleft'
                @text.insert('insert','(')
                _buffer = _buffer + '('
                _item_num = 0
                _update_list.call(_buffer)
                if _item_num == 1
                  _insert_selected_value.call
                end
                Tk.callback_break
              when 'A'..'Z','equal','greater'
                if e.keysym == 'equal'
                  ch = '='
                elsif e.keysym == 'greater'
                  ch = '>'
                else
                  ch = e.keysym
                end
                @text.insert('insert',ch)
                _buffer = _buffer + ch
                _update_list.call(_buffer)
                Tk.callback_break
              else
                if e.keysym.length > 1 
                  p ">#{e.keysym}<"
                  Tk.callback_break
                end
            end
          }
          @raised_listbox.bind_append('KeyPress'){|e|
            case e.keysym
              when 'Escape'
                @raised_listbox.grab("release")
                @raised_listbox_frame.destroy
                complete_code_end
                @text.focus
                #_menu.destroy
                Tk.callback_break
#                when 'Return'
#                  _insert_selected_value.call
              when 'F1'
                _key = @raised_listbox.selected_line.split('-')[0].strip
                _x, _y = xy_insert
                Arcadia.process_event(DocCodeEvent.new(self, 'doc_entry'=>_docs_entries[_key], 'xdoc'=>_x, 'ydoc'=>_y))
                #EditorContract.instance.doc_code(self, 'doc_entry'=>_docs_entries[_key], 'xdoc'=>_x, 'ydoc'=>_y)
              when 'a'..'z','less','space'
                if e.keysym == 'less'
                  ch = '<'
                elsif e.keysym == 'space'
                  ch = ''
                else
                  ch = e.keysym
                end
                @text.insert('insert',ch)
                _buffer = _buffer + ch
                _update_list.call(_buffer)
                Tk.callback_break
              when 'BackSpace'
                if _buffer.length > _buffer_ini_length
                  @text.delete("#{_begin_index} + #{_buffer.length-1} chars" ,'insert')
                  _buffer = _buffer[0..-2]
                  Tk.update
                  _update_list.call(_buffer)
                  Tk.callback_break
                end
              when 'Next', 'Prior'
              else
                Tk.callback_break
            end
          }
          @raised_listbox.bind_append('KeyRelease'){|e|
            case e.keysym
              when 'Return'
                _insert_selected_value.call
            end
          }
        elsif _candidates.length == 1 && _candidates[0].length>0
          @text.delete(_begin_index,'insert');
          @text.insert('insert',_candidates[0].split[0])
          complete_code_end
        end
    end
end

#refreshObject



2751
2752
2753
# File 'ext/ae-editor/ae-editor.rb', line 2751

def refresh
  build_tree if @classbrowsing #&& !is_exp_hide?
end

#rehighlightline(_row) ⇒ Object



2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
# File 'ext/ae-editor/ae-editor.rb', line 2391

def rehighlightline(_row)
  _ibegin = _row.to_s+'.0'
  _iend = (_row+1).to_s+'.0'
  #p "rehighlightline _ibegin=#{_ibegin}"
  #p "rehighlightline _iend=#{_iend}"
  #p "_line = #{@text.get(_ibegin, _iend)}"
  @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



2402
2403
2404
2405
2406
2407
2408
# File 'ext/ae-editor/ae-editor.rb', line 2402

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

#remove_tag_breakpoint(_line) ⇒ Object



1514
1515
1516
1517
1518
1519
1520
1521
# File 'ext/ae-editor/ae-editor.rb', line 1514

def remove_tag_breakpoint(_line)
    rel_line = file_line_to_text_line_num_line(_line)
    if rel_line
      i1 = "#{rel_line}.0"
      i2 = i1+' lineend'
      @text_line_num.tag_remove('breakpoint',i1,i2)
    end
end

#resetObject



2745
2746
2747
2748
2749
# File 'ext/ae-editor/ae-editor.rb', line 2745

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

#reset_highlightObject



1555
1556
1557
1558
1559
1560
1561
1562
1563
# File 'ext/ae-editor/ae-editor.rb', line 1555

def reset_highlight
  @is_line_bold.clear
  @is_tag_bold.clear
  @highlight_zone.clear
  @last_line_begin=0
  @last_line_end=0
  @last_zone_begin=0
  @last_zone_end=0
end

#reset_modifyObject



2301
2302
2303
2304
2305
# File 'ext/ae-editor/ae-editor.rb', line 2301

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



2411
2412
2413
2414
2415
# File 'ext/ae-editor/ae-editor.rb', line 2411

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



2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
# File 'ext/ae-editor/ae-editor.rb', line 2118

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

#run_bufferObject



1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
# File 'ext/ae-editor/ae-editor.rb', line 1387

def run_buffer
  if !@file
    _file = create_temp_file
    begin
      Arcadia.process_event(RunRubyFileEvent.new(self, 'file'=>_file, 'persistent'=>false))
    ensure
      File.delete(_file) if File.exist?(_file)
    end
  else
    save if !@read_only
    Arcadia.process_event(RunRubyFileEvent.new(self, 'file'=>@file, 'persistent'=>true))
  end
end

#saveObject



2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
# File 'ext/ae-editor/ae-editor.rb', line 2585

def save
  if !@file
    save_as
  elsif @read_only
    Arcadia.dialog(self, 
      'type' => 'ok',
      'title' =>"#{@file}:read-only", 
      'msg' =>"The file : #{@file} is read-only!",
      'level' =>'warning')
  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



2609
2610
2611
2612
2613
2614
2615
2616
2617
# File 'ext/ae-editor/ae-editor.rb', line 2609

def save_as
  @file = Tk.getSaveFile("filetypes"=>[["Ruby Files", [".rb", ".rbw"]],["All Files", [".*"]]])
  @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



2294
2295
2296
2297
2298
2299
# File 'ext/ae-editor/ae-editor.rb', line 2294

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

#set_read_only(_value) ⇒ Object



2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
# File 'ext/ae-editor/ae-editor.rb', line 2732

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



2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
# File 'ext/ae-editor/ae-editor.rb', line 2226

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_outlineObject



2692
2693
2694
2695
2696
2697
2698
2699
# File 'ext/ae-editor/ae-editor.rb', line 2692

def show_outline
  if @tree_scroll_wrapper
    @tree_scroll_wrapper.show
  else
    initialize_tree(@controller.frame(1).hinner_frame)
    build_tree
  end
end

#show_spacesObject



2206
2207
2208
2209
2210
2211
2212
2213
# File 'ext/ae-editor/ae-editor.rb', line 2206

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



2216
2217
2218
2219
2220
2221
2222
2223
# File 'ext/ae-editor/ae-editor.rb', line 2216

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



2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
# File 'ext/ae-editor/ae-editor.rb', line 2553

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



2549
2550
2551
# File 'ext/ae-editor/ae-editor.rb', line 2549

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

#text_see(_index = nil) ⇒ Object



2543
2544
2545
2546
2547
# File 'ext/ae-editor/ae-editor.rb', line 2543

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

#text_valueObject



2090
2091
2092
# File 'ext/ae-editor/ae-editor.rb', line 2090

def text_value
  return @text.value
end

#toggle_breakpoint(_index = nil) ⇒ Object

def remove_tag_breakpoint(_index=nil)

    _i1 = _index+' linestart'
    _i2 = _index+' lineend'
    #p "Editor: _i1:#{_i1}  _i2:#{_i2}"
    @text_line_num.tag_remove('breakpoint',_i1,_i2)
end


1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
# File 'ext/ae-editor/ae-editor.rb', line 1538

def toggle_breakpoint(_index=nil)
  if !_index.nil?
    _line = @text_line_num.get(_index+' linestart',_index+' lineend').strip
    _i1 = _index+' linestart'
    _i2 = _i1+' + 2 chars'
    
    if @controller.breakpoint_lines_on_file(@file).include?(_line)
      #remove_tag_breakpoint(_index)
      @controller.breakpoint_del(@file, _line)
    else
      @text_line_num.tag_remove('current',_i1,_i2)
      #add_tag_breakpoint(_index)
      @controller.breakpoint_add(@file, _line)
    end
  end
end

#unmark_debug(_index) ⇒ Object



1926
1927
1928
1929
# File 'ext/ae-editor/ae-editor.rb', line 1926

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



2095
2096
2097
2098
2099
2100
2101
2102
2103
# File 'ext/ae-editor/ae-editor.rb', line 2095

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

#xy_insertObject

def is_exp_hide?

  if @fm.nil?
    return true
  else
    @fm.is_left_hide?
  end
end


659
660
661
662
663
664
665
666
667
# File 'ext/ae-editor/ae-editor.rb', line 659

def xy_insert
  _index_now = @text.index('insert')
  _rx, _ry, _widht, _heigth = @text.bbox(_index_now);
  _x = _rx + TkWinfo.rootx(@text)  
  _y = _ry + TkWinfo.rooty(@text)  + @font_metrics[2][1]
  _xroot = _x - TkWinfo.rootx(Arcadia.instance.layout.root)  
  _yroot = _y - TkWinfo.rooty(Arcadia.instance.layout.root)  
  return _xroot, _yroot
end

#zone_of_row(_row) ⇒ Object



2417
2418
2419
# File 'ext/ae-editor/ae-editor.rb', line 2417

def zone_of_row(_row)
  ((_row) / @highlight_zone_length).to_i + 1
end