Class: AgEditor

Inherits:
Object
  • Object
show all
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.



875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
# File 'ext/ae-editor/ae-editor.rb', line 875

def initialize(_controller, _page_frame)
  @controller = _controller
  @page_frame = _page_frame
  @set_mod = false
  @modified_from_opening=false
  @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
  @tabs_show = false
  @spaces_show = false
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



869
870
871
# File 'ext/ae-editor/ae-editor.rb', line 869

def file
  @file
end

#highlightingObject (readonly)

Returns the value of attribute highlighting.



874
875
876
# File 'ext/ae-editor/ae-editor.rb', line 874

def highlighting
  @highlighting
end

#outlineObject (readonly)

Returns the value of attribute outline.



873
874
875
# File 'ext/ae-editor/ae-editor.rb', line 873

def outline
  @outline
end

#page_frameObject (readonly)

Returns the value of attribute page_frame.



871
872
873
# File 'ext/ae-editor/ae-editor.rb', line 871

def page_frame
  @page_frame
end

#read_onlyObject (readonly)

Returns the value of attribute read_only.



870
871
872
# File 'ext/ae-editor/ae-editor.rb', line 870

def read_only
  @read_only
end

#rootObject (readonly)

Returns the value of attribute root.



872
873
874
# File 'ext/ae-editor/ae-editor.rb', line 872

def root
  @root
end

#textObject (readonly)

Returns the value of attribute text.



872
873
874
# File 'ext/ae-editor/ae-editor.rb', line 872

def text
  @text
end

Instance Method Details

#activate_complete_code_key_bindingObject



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

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|
    if e.keysym == "Escape"
      if @n_complete_task == 0
        @do_complete = true
        complete_code
      end
    else
      @do_complete = false
    end
  }    

  @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

setup all key bindings (normal, +control, etc)



1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
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
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
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
# File 'ext/ae-editor/ae-editor.rb', line 1329

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
      begin
        @text.edit_undo
      rescue RuntimeError => e
        throw e unless e.to_s.include? "nothing to undo" # this is ok--we've done undo back to the beginning
        break
      end
      #_e = @text.index('insert').split('.')[0].to_i
      if @highlighting
        _b = @text.index('@0,0').split('.')[0].to_i
        _e = @text.index('@0,'+TkWinfo.height(@text).to_s).split('.')[0].to_i + 1
        rehighlightlines(_b,_e)
      end
      break
    when 'o'  
      if @file
        _dir = File.dirname(@file)
      else
        _dir = MonitorLastUsedDir.get_last_dir
      end
      Arcadia.process_event(OpenBufferEvent.new(self,'file'=>Tk.getOpenFile('initialdir'=>_dir)))
      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
        rehighlightlines(_b,_e)
#          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',"}")
    when 'g'
      Arcadia.process_event(GoToLineBufferEvent.new(self))
    when 'n'
      $arcadia['main.action.new_file'] # necessary? Is there an event for this?
    when 'w'
      Arcadia.process_event(CloseCurrentTabEvent.new(self))
    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
      rehighlightlines(_row_begin, _row_end) if @highlighting
    when 'F'
      Arcadia.process_event(AckInFilesEvent.new(self))
    end
  }
  
  @text.bind_append("KeyPress"){|e|
    #@do_complete = false
    case e.keysym
    #when 'Return'
    when 'BackSpace'
      _index = @text.index('insert')
      _row, _col = _index.split('.')
      rehighlightlines(_row.to_i,_row.to_i) if @highlighting
#      rehighlightline(_row.to_i) if @highlighting
    when 'Delete'
      _index = @text.index('insert')
      _row, _col = _index.split('.')
      rehighlightlines(_row.to_i, _row.to_i) if @highlighting
#      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 'Up','Down'
        refresh_outline
    when 'Left', 'Right'
    
    when 'Return' #,'Control_L', 'Control_V', 'BackSpace', 'Delete'
      _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 ['Control_L', 'Control_V', 'BackSpace', 'Delete'].include?(e.keysym)
        do_line_update
      end
      if @highlighting && /\w/.match(e.keysym)
  #      rehighlightline(@text.index('insert').split('.')[0].to_i)
        row = @text.index('insert').split('.')[0].to_i
        rehighlightlines(row, row)
      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



1729
1730
1731
1732
1733
1734
1735
1736
# File 'ext/ae-editor/ae-editor.rb', line 1729

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



1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
# File 'ext/ae-editor/ae-editor.rb', line 1021

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

#change_highlight(_ext) ⇒ Object



1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
# File 'ext/ae-editor/ae-editor.rb', line 1788

def change_highlight(_ext)
  new_highlight_scanner = @controller.highlight_scanner(_ext)
  if new_highlight_scanner != @highlight_scanner
    @highlight_scanner.classes.each{|c|
      @text.tag_remove(c,'1.0', 'end')
      @text.tag_delete(c)
      @is_tag_bold.delete(c)
    }
    @highlight_scanner = new_highlight_scanner
    reset_highlight
    if @highlight_scanner
      @highlight_scanner.classes.each{|c|
        do_tag_configure(c)
      }
      @highlighting = true
    else
      @highlighting = false
    end
  end
end

#check_file_last_access_timeObject



2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
# File 'ext/ae-editor/ae-editor.rb', line 2736

def check_file_last_access_time
  if @file
    file_exist = File.exist?(@file)
    if @file_last_access_time && file_exist
      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'
          reload
          
        else
          @file_last_access_time = ftime
        end
      end
    elsif !file_exist
      msg = 'Appears that file "'+@file+'" was deleted by other process! Do you want to resave it?'
      if Tk.messageBox('icon' => 'error', 'type' => 'yesno',
        'title' => '(Arcadia) editor', 'parent' => @text,
        'message' => msg) == 'yes'
        save
      else
        @file = nil
        @buffer = ''
        set_modify
      end
    end
  end
end

#check_modifyObject



2727
2728
2729
2730
2731
2732
2733
2734
# File 'ext/ae-editor/ae-editor.rb', line 2727

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

#complete_codeObject



1011
1012
1013
1014
1015
1016
1017
1018
1019
# File 'ext/ae-editor/ae-editor.rb', line 1011

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



998
999
1000
1001
1002
# File 'ext/ae-editor/ae-editor.rb', line 998

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

#complete_code_endObject



1004
1005
1006
1007
1008
# File 'ext/ae-editor/ae-editor.rb', line 1004

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

#create_temp_fileObject



942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
# File 'ext/ae-editor/ae-editor.rb', line 942

def create_temp_file
  if @file
    _file = @file+'~~'
  else
    n=0
    while File.exist?(File.join(Arcadia.instance.local_dir,"buffer#{n}~~"))
      n+=1
    end
    _file = File.join(Arcadia.instance.local_dir,"buffer#{n}~~")
  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



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

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

#destroy_outlineObject



2810
2811
2812
2813
# File 'ext/ae-editor/ae-editor.rb', line 2810

def destroy_outline
  @outline.destroy if @outline
  @outline = nil
end

#disactivate_key_bindingObject



1574
1575
1576
1577
1578
1579
1580
1581
# File 'ext/ae-editor/ae-editor.rb', line 1574

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_enterObject



1583
1584
1585
# File 'ext/ae-editor/ae-editor.rb', line 1583

def do_enter
  check_file_last_access_time
end

#do_line_updateObject



2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
# File 'ext/ae-editor/ae-editor.rb', line 2499

def do_line_update
  #re num in @text_line_num the portion of visibled screen  of @text
    return if @loading
    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);
      
      if _ry && _ry < 0 
        real_line_end = line_end + 1
      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 b.include?(j.to_s)
          add_tag_breakpoint(j)
        end
      end
      if _ry && _ry < 0 
        @text_line_num.yview_scroll(_ry.abs+2,"pixels")
      end
    end
    refresh_outline if Tk.focus==@text
#      if TkWinfo.mapped?(@text_line_num)
#        x,y,w,h = @text.bbox("#{(line_end).to_s}.3");
#        @fm1.splitter_frame.go(w,0)
#        @fm1.do_resize
#      end
end

#do_tag_configure(_name) ⇒ Object



1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
# File 'ext/ae-editor/ae-editor.rb', line 1839

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

#do_tag_configure_global(_name) ⇒ Object



1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
# File 'ext/ae-editor/ae-editor.rb', line 1863

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



2815
2816
2817
2818
2819
2820
# File 'ext/ae-editor/ae-editor.rb', line 2815

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



1719
1720
1721
1722
1723
1724
1725
1726
1727
# File 'ext/ae-editor/ae-editor.rb', line 1719

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

show the “find in file” dialog



1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
# File 'ext/ae-editor/ae-editor.rb', line 1560

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

#hide_outlineObject



2806
2807
2808
# File 'ext/ae-editor/ae-editor.rb', line 2806

def hide_outline
  @outline.hide if @outline
end

#hide_spacesObject



2442
2443
2444
2445
# File 'ext/ae-editor/ae-editor.rb', line 2442

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

#hide_tabsObject



2437
2438
2439
2440
# File 'ext/ae-editor/ae-editor.rb', line 2437

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

#highlight_zone(_zone, _force_highlight = false) ⇒ Object



2622
2623
2624
2625
2626
2627
2628
2629
# File 'ext/ae-editor/ae-editor.rb', line 2622

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

#highlightlines(_row_begin, _row_end, _check_mod = false) ⇒ Object



2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
# File 'ext/ae-editor/ae-editor.rb', line 2576

def highlightlines(_row_begin, _row_end, _check_mod = false)
  if _check_mod 
    check_modify
  end
  #_row_begin = _row_begin+1
  _ibegin = _row_begin.to_s+'.0'
  _iend = (_row_end+1).to_s+'.0'
  @highlight_scanner.classes.each{|c| @text.tag_remove(c,_ibegin, _iend)}
  _lines = @text.get(_ibegin, _iend)
  tags_map = @highlight_scanner.highlight_tags(_row_begin,_lines)
  tags_map.each do |key,value|      
    to_tag = Array.new
    value.each{|ite|
      to_tag.concat(ite)
      if @is_tag_bold[key.to_s]
        if ite.length==2
          row_begin = ite[0].split('.')[0].to_i
          row_end = ite[1].split('.')[0].to_i
          for row in row_begin..row_end 
            @is_line_bold[row]=true
          end
        end
#          ite.each{|p|
#            row_begin = p[0].split('.')[0].to_i
#            row_end = p[1].split('.')[0].to_i
#            for row in row_begin...row_end 
#              @is_line_bold[row]=true
#            end
#          }
      end
    }
    @text.tag_adds(key.to_s,to_tag)
  end
  if @tabs_show || @spaces_show
    if !defined?(@rescanner)
      if @lang_hash['scanner']!='re'
        @rescanner = ReHighlightScanner.new(@lang_hash) if !defined?(@rescanner)
      else
        @rescanner = @highlight_scanner
      end
    end
    @rescanner.highlight_tags(_row_begin,_lines,['tabs']) if @tabs_show
    @rescanner.highlight_tags(_row_begin,_lines,['spaces']) if @spaces_show
  end
end

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

horizontal scrollbar : ON/OFF



2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
# File 'ext/ae-editor/ae-editor.rb', line 2255

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



2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
# File 'ext/ae-editor/ae-editor.rb', line 2397

def indentation_space_2_tabs(_n_space=2)
  _row = 1
  text_value_lines.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



2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
# File 'ext/ae-editor/ae-editor.rb', line 2417

def indentation_tabs_2_space(_n_space=2)
  _row = 1
  text_value_lines.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



2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
# File 'ext/ae-editor/ae-editor.rb', line 2776

def init_editing(_ext='rb', _w1=150, _w2=60)
  @is_ruby = _ext=='rb'|| _ext=='rbw'
  @classbrowsing = @is_ruby
  @lang_hash = @controller.languages_hash(_ext)
#    @highlight_scanner = @controller.highlight_scanner(_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(_ext)
  initialize_line_number(@fm1.left_frame)
  initialize_text_binding
end

#initialize_highlight(_ext) ⇒ Object



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

def initialize_highlight(_ext)
  @highlight_scanner = @controller.highlight_scanner(_ext)
  @is_line_bold = Hash.new
  @is_tag_bold = Hash.new
  do_tag_configure_global('debug')
  if @lang_hash.nil? || @highlight_scanner.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;
  @highlight_scanner.classes.each{|c|
    do_tag_configure(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



1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
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
# File 'ext/ae-editor/ae-editor.rb', line 1625

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



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

def initialize_text(_frame)
  @text = TkScrollText.new(_frame, Arcadia.style('text')){|j|
    wrap  'none'
    undo true
#      insertofftime 200
#      insertontime 200
#      highlightthickness 0
#      insertwidth 3
    exportselection true
    autoseparators true
    padx 0
    tabs $arcadia['conf']['editor.tabs']
  }

  class << @text
    def tag_adds(tag, *args)
      tk_send_without_enc('tag', 'add', _get_eval_enc_str(tag), 
                          *args.flatten)
      self
    end
  end

  #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



1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
# File 'ext/ae-editor/ae-editor.rb', line 1587

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{do_enter})

  @text.bind("<Modified>"){|e|
    check_modify
  }
  activate_key_binding
  @text.bind_append("1"){
    Arcadia.process_event(InputEnterEvent.new(self,'receiver'=>@text))
    refresh_outline
  }
end

#insert_popup_menu_item(_where, *args) ⇒ Object



2235
2236
2237
# File 'ext/ae-editor/ae-editor.rb', line 2235

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

#load_file(_filename = nil) ⇒ Object



2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
# File 'ext/ae-editor/ae-editor.rb', line 2822

def load_file(_filename = nil)
  #if filename is nil then open a new tab
  @loading=true
  @dos_line_endings=false
  begin
    @file = _filename
    if _filename
      #init_editing(file_extension(_filename))
      File::open(_filename,'rb'){ |file|
        @text.insert('end',file.readlines.collect!{| line | line.chomp}.join("\n"))
        #@text.insert('end',file.read)
      }
     File.open(_filename, 'rb') { |file|
       @dos_line_endings=true if file.read.include?("\r\n") # pesky windows line endings
     }
    end
    set_read_only(!File.stat(_filename).writable?)
    reset
    refresh
  ensure
    @loading=false
  end
end

#mark_debug(_index) ⇒ Object



2225
2226
2227
2228
# File 'ext/ae-editor/ae-editor.rb', line 2225

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



2230
2231
2232
2233
# File 'ext/ae-editor/ae-editor.rb', line 2230

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

#modified?Boolean

modify in this instance means the (…) in the tab header of each file

Returns:

  • (Boolean)


2449
2450
2451
# File 'ext/ae-editor/ae-editor.rb', line 2449

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

#modified_from_opening?Boolean

Returns:

  • (Boolean)


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

def modified_from_opening?
  @modified_from_opening
end

#new_file_name(_new_file) ⇒ Object



2719
2720
2721
2722
2723
2724
2725
# File 'ext/ae-editor/ae-editor.rb', line 2719

def new_file_name(_new_file)
  @file =_new_file
  base_name= File.basename(_new_file)
  if base_name.include?('.')
    self.change_highlight(base_name.split('.')[-1])
  end
end

#pop_up_menuObject



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
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
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
2056
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
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
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
2174
2175
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
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
# File 'ext/ae-editor/ae-editor.rb', line 1886

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 from file',
    :hidemargin => false,
    :command=>       proc{
      file = Arcadia.open_file_dialog
      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',
    :command,
    :label=>'Data image to file',
    :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
          file = Tk.getSaveFile("filetypes"=>[["Image", [".gif"]],["All Files", [".*"]]])
          if file
            require 'base64'
            decoded = Base64.decode64(_data)
            f = File.new(file, "w")
            begin
              if f
                f.syswrite(decoded)
              end
            ensure
              f.close unless f.nil?
            end
          end
        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=>'Selection to uppercase',
    :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
          @text.delete(_r[0][0],_r[0][1])
          @text.insert(_r[0][0],_text.upcase)
        end
      end
    }
  )

  _sub_code.insert('end',
    :command,
    :label=>'Selection to downcase',
    :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
          @text.delete(_r[0][0],_r[0][1])
          @text.insert(_r[0][0],_text.downcase)
        end
      end
    }
  )



  _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

#pos_to_index(_txt, _pos) ⇒ Object



2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
# File 'ext/ae-editor/ae-editor.rb', line 2467

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



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
1107
1108
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
1143
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
# File 'ext/ae-editor/ae-editor.rb', line 1045

def raise_complete_code(_candidates, _row, _col, _filter='')
  @raised_listbox_frame.destroy if @raised_listbox_frame != 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')

            # workaround for @ char
            _value = _value.strip
            if _value[0..0] !=_target[0..0] && _value[1..1] == _target[0..0]
              _value = _value[1..-1]
            end
            @text.insert('insert',_value)
            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 + 30
        #_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



2865
2866
2867
# File 'ext/ae-editor/ae-editor.rb', line 2865

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

#refresh_outlineObject



1604
1605
1606
1607
1608
# File 'ext/ae-editor/ae-editor.rb', line 1604

def refresh_outline
  if @outline
    Tk.after(1,proc{ @outline.update_row(self.row)})
  end
end

#rehighlightlines(_row_begin, _row_end, _check_mod = false) ⇒ Object



2483
2484
2485
2486
2487
2488
# File 'ext/ae-editor/ae-editor.rb', line 2483

def rehighlightlines(_row_begin, _row_end, _check_mod=false)
  _ibegin = _row_begin.to_s+'.0'
  _iend = (_row_end+1).to_s+'.0'
  @highlight_scanner.classes.each{|c| @text.tag_remove(c,_ibegin, _iend)}
  highlightlines(_row_begin, _row_end, _check_mod)
end

#reloadObject



2767
2768
2769
2770
2771
2772
2773
2774
# File 'ext/ae-editor/ae-editor.rb', line 2767

def reload
  pos_index = @text.index('insert') 
  @text.delete('1.0','end')
  reset_highlight if @highlighting
  load_file(@file)
  @text.see(pos_index)
  @text.set_insert(pos_index)
end

#remove_tag_breakpoint(_line) ⇒ Object



1738
1739
1740
1741
1742
1743
1744
1745
# File 'ext/ae-editor/ae-editor.rb', line 1738

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



2859
2860
2861
2862
2863
# File 'ext/ae-editor/ae-editor.rb', line 2859

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

#reset_highlightObject



1779
1780
1781
1782
1783
1784
1785
1786
# File 'ext/ae-editor/ae-editor.rb', line 1779

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

#reset_modifyObject



2461
2462
2463
2464
2465
# File 'ext/ae-editor/ae-editor.rb', line 2461

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



2490
2491
2492
2493
# File 'ext/ae-editor/ae-editor.rb', line 2490

def row(_index='insert')
  _row = @text.index(_index).split('.')[0].to_i
  return _row
end

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



2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
# File 'ext/ae-editor/ae-editor.rb', line 2267

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



1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
# File 'ext/ae-editor/ae-editor.rb', line 1610

def run_buffer
  if !@file
    _file = create_temp_file
    begin
      _event = Arcadia.process_event(RunRubyFileEvent.new(self, 'file'=>_file, 'persistent'=>false))
    ensure
      _event.add_finalize_callback(proc{File.delete(_file) if File.exist?(_file)})
     # 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

#save(ignore_read_only = false) ⇒ Object



2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
# File 'ext/ae-editor/ae-editor.rb', line 2675

def save ignore_read_only = false
  if !@file
    save_as
  elsif @read_only && !ignore_read_only
    r=Arcadia.dialog(self,
    'type' => 'yes_no_cancel',
    'title' =>"#{@file}:read-only",
    'msg' =>"The file : #{@file} is read-only! -- save anyway?",
    'level' =>'warning')
    if r=="yes"
      save true
    end
  else
    f = File.new(@file, "wb")
    begin
      if f
 to_write = text_value
 if @dos_line_endings
   # we stripped these out, previously...
   # for now assume they want them all this way, no mixing and matching...
   to_write = to_write.gsub("\n", "\r\n")
 end
        f.syswrite(to_write)
        @buffer = text_value
        reset_modify
      end
    ensure
      f.close unless f.nil?
    end
    #EditorContract.instance.file_saved(self,'file' =>@file)
  end
end

#save_asObject



2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
# File 'ext/ae-editor/ae-editor.rb', line 2708

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

#set_modifyObject



2453
2454
2455
2456
2457
2458
2459
# File 'ext/ae-editor/ae-editor.rb', line 2453

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

#set_read_only(_value) ⇒ Object



2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
# File 'ext/ae-editor/ae-editor.rb', line 2846

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



2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
# File 'ext/ae-editor/ae-editor.rb', line 2384

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



2797
2798
2799
2800
2801
2802
2803
2804
# File 'ext/ae-editor/ae-editor.rb', line 2797

def show_outline
  if @outline
    @outline.show
  else
    @outline=AgEditorOutline.new(self,@controller.frame(1).hinner_frame,@controller.outline_bar)
    @outline.build_tree
  end
end

#show_spacesObject



2364
2365
2366
2367
2368
2369
2370
2371
# File 'ext/ae-editor/ae-editor.rb', line 2364

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

#show_tabsObject



2374
2375
2376
2377
2378
2379
2380
2381
# File 'ext/ae-editor/ae-editor.rb', line 2374

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

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



2641
2642
2643
2644
2645
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
2672
# File 'ext/ae-editor/ae-editor.rb', line 2641

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)
        highlightlines(_row.to_i, _row.to_i, 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



2637
2638
2639
# File 'ext/ae-editor/ae-editor.rb', line 2637

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

#text_see(_index = nil) ⇒ Object



2631
2632
2633
2634
2635
# File 'ext/ae-editor/ae-editor.rb', line 2631

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

#text_valueObject



2239
2240
2241
# File 'ext/ae-editor/ae-editor.rb', line 2239

def text_value
  return @text.value
end

#text_value_linesObject



2356
2357
2358
2359
2360
2361
2362
# File 'ext/ae-editor/ae-editor.rb', line 2356

def text_value_lines
  if String.method_defined?(:lines)
    return @text.value.lines
  else
    return @text.value
  end
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


1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
# File 'ext/ae-editor/ae-editor.rb', line 1762

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



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

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



2244
2245
2246
2247
2248
2249
2250
2251
2252
# File 'ext/ae-editor/ae-editor.rb', line 2244

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



897
898
899
900
901
902
903
904
905
# File 'ext/ae-editor/ae-editor.rb', line 897

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



2495
2496
2497
# File 'ext/ae-editor/ae-editor.rb', line 2495

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