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.



953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
# File 'ext/ae-editor/ae-editor.rb', line 953

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
  @line_numbers_visible = @controller.conf('line-numbers') == 'yes'
  @id = -1
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



944
945
946
# File 'ext/ae-editor/ae-editor.rb', line 944

def file
  @file
end

#highlightingObject (readonly)

Returns the value of attribute highlighting.



951
952
953
# File 'ext/ae-editor/ae-editor.rb', line 951

def highlighting
  @highlighting
end

#idObject

Returns the value of attribute id.



946
947
948
# File 'ext/ae-editor/ae-editor.rb', line 946

def id
  @id
end

#last_tmp_fileObject (readonly)

Returns the value of attribute last_tmp_file.



952
953
954
# File 'ext/ae-editor/ae-editor.rb', line 952

def last_tmp_file
  @last_tmp_file
end

#line_numbers_visibleObject

Returns the value of attribute line_numbers_visible.



945
946
947
# File 'ext/ae-editor/ae-editor.rb', line 945

def line_numbers_visible
  @line_numbers_visible
end

#outlineObject (readonly)

Returns the value of attribute outline.



950
951
952
# File 'ext/ae-editor/ae-editor.rb', line 950

def outline
  @outline
end

#page_frameObject (readonly)

Returns the value of attribute page_frame.



948
949
950
# File 'ext/ae-editor/ae-editor.rb', line 948

def page_frame
  @page_frame
end

#read_onlyObject (readonly)

Returns the value of attribute read_only.



947
948
949
# File 'ext/ae-editor/ae-editor.rb', line 947

def read_only
  @read_only
end

#rootObject (readonly)

Returns the value of attribute root.



949
950
951
# File 'ext/ae-editor/ae-editor.rb', line 949

def root
  @root
end

#textObject (readonly)

Returns the value of attribute text.



949
950
951
# File 'ext/ae-editor/ae-editor.rb', line 949

def text
  @text
end

Instance Method Details

#activate_complete_code_key_bindingObject



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

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)



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
1558
1559
1560
1561
1562
1563
1564
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
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
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
# File 'ext/ae-editor/ae-editor.rb', line 1445

def activate_key_binding
  activate_complete_code_key_binding if @is_ruby

  @text.bind_append("Control-KeyPress"){|e|
    case e.keysym
#      when 'z'
#        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
#        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 'r'
#        begin
#          @text.edit_redo
#        rescue RuntimeError => e
#          throw e unless e.to_s.include? "nothing to redo" # this is ok--we've done redo back to the beginning
#          break
#        end
#        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)
#        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'
      decrease_indent
#        _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','ISO_Left_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



1864
1865
1866
1867
1868
1869
1870
1871
# File 'ext/ae-editor/ae-editor.rb', line 1864

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



1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
# File 'ext/ae-editor/ae-editor.rb', line 1141

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



1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
# File 'ext/ae-editor/ae-editor.rb', line 1932

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



3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
# File 'ext/ae-editor/ae-editor.rb', line 3022

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?'
        ans = Tk.messageBox('icon' => 'error', 'type' => 'yesno',
          'title' => '(Arcadia) Libs', 'parent' => @text,
          'message' => msg)
        if ans == '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



2989
2990
2991
2992
2993
2994
2995
2996
# File 'ext/ae-editor/ae-editor.rb', line 2989

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

#complete_codeObject



1131
1132
1133
1134
1135
1136
1137
1138
1139
# File 'ext/ae-editor/ae-editor.rb', line 1131

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



1118
1119
1120
1121
1122
# File 'ext/ae-editor/ae-editor.rb', line 1118

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

#complete_code_endObject



1124
1125
1126
1127
1128
# File 'ext/ae-editor/ae-editor.rb', line 1124

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

#create_temp_fileObject



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

def create_temp_file
  if @file
    n=0
    while File.exist?("#{@file}#{n*'_'}~~")
      n+=1
    end
    _file = "#{@file}#{n*'_'}~~"
  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
  @last_tmp_file = _file
  _file
end

#create_temp_file_for_completion(_row) ⇒ Object



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

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

#decrease_indentObject



1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
# File 'ext/ae-editor/ae-editor.rb', line 1682

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

#destroy_outlineObject



3096
3097
3098
3099
# File 'ext/ae-editor/ae-editor.rb', line 3096

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

#disactivate_key_bindingObject



1715
1716
1717
1718
1719
1720
1721
# File 'ext/ae-editor/ae-editor.rb', line 1715

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



1723
1724
1725
# File 'ext/ae-editor/ae-editor.rb', line 1723

def do_enter
  check_file_last_access_time
end

#do_line_updateObject



2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
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
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
# File 'ext/ae-editor/ae-editor.rb', line 2725

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'
      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
      if @line_numbers_visible
        # breakpoint
        b = @controller.breakpoint_lines_on_file(@file)
        
        @text_line_num.delete('1.0','end')
        _rx, _ry, _width, _heigth = @text.bbox(line_begin_index);
        
        if _ry && _ry < 0 
          real_line_end = line_end + 1
        else
          real_line_end = line_end
        end
        #@fm1
        _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_width_b, w_heigth_b = @text.bbox("#{(j).to_s}.0");
            w_rx_e, w_ry_e, w_width_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
        resize_line_num
      end
    end
    refresh_outline if Tk.focus==@text
end

#do_lower_caseObject



2458
2459
2460
2461
2462
2463
# File 'ext/ae-editor/ae-editor.rb', line 2458

def do_lower_case
  _text = text_selected
  if _text.length > 0
    text_replace_selected_with(_text.downcase)
  end
end

#do_tag_configure(_name) ⇒ Object



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

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
  begin
    @text.tag_configure(_name, h)
  rescue RuntimeError => e
    p "RuntimeError : #{e.message}"
  end
end

#do_tag_configure_global(_name) ⇒ Object



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

def do_tag_configure_global(_name)
  h = Hash.new

  if Arcadia.conf('editor.hightlight.'+_name+'.foreground')
    h['foreground']=Arcadia.conf('editor.hightlight.'+_name+'.foreground')
  elsif Arcadia.conf('hightlight.'+_name+'.foreground')
    h['foreground']=Arcadia.conf('hightlight.'+_name+'.foreground')
  end
  
  if Arcadia.conf('editor.hightlight.'+_name+'.background')
    h['background']=Arcadia.conf('editor.hightlight.'+_name+'.background')
  elsif Arcadia.conf('hightlight.'+_name+'.background')
    h['background']=Arcadia.conf('hightlight.'+_name+'.background')
  end

  if Arcadia.conf('editor.hightlight.'+_name+'.style')== 'bold'
    h['font']=@font_bold
    @is_tag_bold[_name]= true
  elsif Arcadia.conf('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')
  elsif Arcadia.conf('hightlight.'+_name+'.relief')
    h['relief']=Arcadia.conf('hightlight.'+_name+'.relief')
  end
  
  if Arcadia.conf('editor.hightlight.'+_name+'.borderwidth')
    h['borderwidth']=Arcadia.conf('editor.hightlight.'+_name+'.borderwidth')
  elsif Arcadia.conf('hightlight.'+_name+'.borderwidth')
    h['borderwidth']=Arcadia.conf('hightlight.'+_name+'.borderwidth')
  end
  
  begin
    @text.tag_configure(_name, h)
  rescue RuntimeError => e
    p "RuntimeError : #{e.message}"
  end
end

#do_upper_caseObject



2451
2452
2453
2454
2455
2456
# File 'ext/ae-editor/ae-editor.rb', line 2451

def do_upper_case
  _text = text_selected
  if _text.length > 0
    text_replace_selected_with(_text.upcase)
  end
end

#file_line_to_text_line_num_line(_line) ⇒ Object



1854
1855
1856
1857
1858
1859
1860
1861
1862
# File 'ext/ae-editor/ae-editor.rb', line 1854

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



1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
# File 'ext/ae-editor/ae-editor.rb', line 1701

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_line_numbersObject



986
987
988
989
990
991
# File 'ext/ae-editor/ae-editor.rb', line 986

def hide_line_numbers
  if @line_numbers_visible
    @fm1.hide_left
    @line_numbers_visible = false
  end
end

#hide_outlineObject



3092
3093
3094
# File 'ext/ae-editor/ae-editor.rb', line 3092

def hide_outline
  @outline.hide if @outline
end

#hide_spacesObject



2664
2665
2666
2667
# File 'ext/ae-editor/ae-editor.rb', line 2664

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

#hide_tabsObject



2659
2660
2661
2662
# File 'ext/ae-editor/ae-editor.rb', line 2659

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

#highlight_zone(_zone, _force_highlight = false) ⇒ Object



2880
2881
2882
2883
2884
2885
2886
2887
# File 'ext/ae-editor/ae-editor.rb', line 2880

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



2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
# File 'ext/ae-editor/ae-editor.rb', line 2834

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



2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
# File 'ext/ae-editor/ae-editor.rb', line 2477

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



2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
# File 'ext/ae-editor/ae-editor.rb', line 2619

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



2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
# File 'ext/ae-editor/ae-editor.rb', line 2639

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') ⇒ Object



3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
# File 'ext/ae-editor/ae-editor.rb', line 3062

def init_editing(_ext='rb')
  @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,0,5,false,false)
  @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



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

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



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

def initialize_line_number(_frame)
  @text_line_num = TkText.new(_frame, Arcadia.style('textline')){
    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.extend(TkAutoPostMenu)
  _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



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

def initialize_text(_frame)
  @text = TkArcadiaText.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']
  }
  _self_editor = self
  class << @text
    attr_accessor :editor
    def tag_adds(tag, *args)
      tk_send_without_enc('tag', 'add', _get_eval_enc_str(tag), 
                          *args.flatten)
      self
    end
    
    def do_upper_case
      @editor.do_upper_case if @editor
    end
  
    def do_lower_case
      @editor.do_lower_case if @editor
    end
  end
  @text.editor = self
  #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.extend(TkScrollableWidget).show
  begin
    @text_cursor = @text.cget('cursor')
  rescue RuntimeError => e
    p "RuntimeError : #{e.message}"
  end
end

#initialize_text_bindingObject



1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
# File 'ext/ae-editor/ae-editor.rb', line 1727

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



2409
2410
2411
# File 'ext/ae-editor/ae-editor.rb', line 2409

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

#load_file(_filename = nil) ⇒ Object



3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
# File 'ext/ae-editor/ae-editor.rb', line 3101

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(false)
    refresh
  ensure
    @loading=false
  end
end

#mark_debug(_index) ⇒ Object



2399
2400
2401
2402
# File 'ext/ae-editor/ae-editor.rb', line 2399

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



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

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)


2671
2672
2673
# File 'ext/ae-editor/ae-editor.rb', line 2671

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

#modified_by_others?Boolean

Returns:

  • (Boolean)


2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
# File 'ext/ae-editor/ae-editor.rb', line 2998

def modified_by_others?
  ret = false 
  if @file_last_access_time && @file 
    if File.exist?(@file)
      ftime = File.mtime(@file)
      ret = @file_last_access_time != ftime
    else
      ret = true
    end
  end
  ret
end

#modified_from_opening?Boolean

Returns:

  • (Boolean)


973
974
975
# File 'ext/ae-editor/ae-editor.rb', line 973

def modified_from_opening?
  @modified_from_opening
end

#new_file_name(_new_file) ⇒ Object



2980
2981
2982
2983
2984
2985
2986
2987
# File 'ext/ae-editor/ae-editor.rb', line 2980

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

#pop_up_menuObject



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
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
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
2354
2355
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
2390
2391
2392
# File 'ext/ae-editor/ae-editor.rb', line 2054

def pop_up_menu
  @pop_up = TkMenu.new(
    :parent=>@text,
    :tearoff=>0,
    :title => 'Menu'
  )
  @pop_up.extend(TkAutoPostMenu)
  @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)
      @text.insert('insert',Tk::BWidget::SelectColor::Dialog.new.create)
    }
  )

  @pop_up.insert('end',
    :command,
    :label=>'View color 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},
            'bg'=>_data,
            'relief'=>'groove')
          TkTextWindow.new(@text, _r[0][1], 'window'=> _b)
        end
      end
    }
  )

  @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 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.extend(TkAutoPostMenu)
  _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.extend(TkAutoPostMenu)
  _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{do_upper_case}
  )

  _sub_code.insert('end',
    :command,
    :label=>'Selection to downcase',
    :hidemargin => false,
    :command=> proc{do_lower_case}
  )



  _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(1, 'label'=>File.basename(@file)) if @file
      @pop_up.entryconfigure(0, 'label'=>File.basename(@file)) if @file
      @pop_up.popup(_x,_y)
    },
  "%x %y")
end

#pos_to_index(_txt, _pos) ⇒ Object



2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
# File 'ext/ae-editor/ae-editor.rb', line 2693

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



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

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, _width, 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}.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.extend(TkScrollableWidget).show(0,0) 
        @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



3144
3145
3146
# File 'ext/ae-editor/ae-editor.rb', line 3144

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

#refresh_outlineObject



1744
1745
1746
1747
1748
# File 'ext/ae-editor/ae-editor.rb', line 1744

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



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

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



3053
3054
3055
3056
3057
3058
3059
3060
# File 'ext/ae-editor/ae-editor.rb', line 3053

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



1873
1874
1875
1876
1877
1878
1879
1880
# File 'ext/ae-editor/ae-editor.rb', line 1873

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

#reset(_reset_tab = true) ⇒ Object



3138
3139
3140
3141
3142
# File 'ext/ae-editor/ae-editor.rb', line 3138

def reset(_reset_tab=true)
  @buffer = text_value
  reset_modify(_reset_tab)
  @text.edit_reset
end

#reset_file_last_access_timeObject



3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
# File 'ext/ae-editor/ae-editor.rb', line 3011

def reset_file_last_access_time
  if @file
    if File.exist?(@file)
      @file_last_access_time = File.mtime(@file)
    else
      @file_last_access_time = nil
      @file = nil
    end
  end
end

#reset_highlight(_from_row = nil) ⇒ Object



1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
# File 'ext/ae-editor/ae-editor.rb', line 1917

def reset_highlight(_from_row=nil)
  if _from_row &&  @highlighting
    invalidated_begin_zone= zone_of_row(_from_row)
    @is_line_bold.delete_if {|key, value| key >= invalidated_begin_zone }
    @highlight_zone.delete_if {|key, value| key >= invalidated_begin_zone }
  elsif @highlighting
    @is_line_bold.clear
    @highlight_zone.clear 
  end
  @last_line_begin=0
  @last_line_end=0
  @last_zone_begin=0
  @last_zone_end=0
end

#reset_modify(_reset_tab = true) ⇒ Object



2687
2688
2689
2690
2691
# File 'ext/ae-editor/ae-editor.rb', line 2687

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

#resize_line_numObject



2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
# File 'ext/ae-editor/ae-editor.rb', line 2799

def resize_line_num
  if TkWinfo.mapped?(@text_line_num)
    if @last_line_end_chars.nil?
      @last_line_end_chars = 0
    end
    _line_end=row('end')
    line_end_chars  = _line_end.to_s.length  
    if @last_line_end_chars != line_end_chars
      if @line_num_rx_e.nil?
        @line_num_rx_e, @line_num_ry_e, @line_num_width_e, @line_num_heigth_e = @text_line_num.bbox("0.1 lineend - 1 chars");
        if @line_num_rx_e.nil?
          @line_num_rx_e = 0
        end
        if @line_num_width_e.nil?
          linfo_x, linfo_y, linfo_w, linfo_h, linfo_b  = @text_line_num.dlineinfo('0.1')
          if linfo_w
            @line_num_width_e = linfo_w.to_f/(line_end_chars+1.5)
          end
        end
      end
      
      
      if @line_num_rx_e && @line_num_width_e && line_end_chars >0 
        actual_width = @line_num_rx_e + @line_num_width_e
        need_width = (line_end_chars+1)*@line_num_width_e
        delta = actual_width - need_width
        @fm1.resize_left(need_width)
        @last_line_end_chars = line_end_chars
      else
        @last_line_end_chars = -1
      end
    end
  end
end

#row(_index = 'insert') ⇒ Object



2716
2717
2718
2719
# File 'ext/ae-editor/ae-editor.rb', line 2716

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

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



2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
# File 'ext/ae-editor/ae-editor.rb', line 2489

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



1750
1751
1752
1753
1754
1755
1756
1757
# File 'ext/ae-editor/ae-editor.rb', line 1750

def run_buffer
  if !@file
    Arcadia.process_event(RunCmdEvent.new(self, {'file'=>'*CURR', 'runner_name'=>'ruby_file', 'persistent'=>false}))
  else
    save if !@read_only
    Arcadia.process_event(RunCmdEvent.new(self, {'file'=>@file}))
  end
end

#save(ignore_read_only = false) ⇒ Object



2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
# File 'ext/ae-editor/ae-editor.rb', line 2933

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



2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
# File 'ext/ae-editor/ae-editor.rb', line 2966

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)
    @last_tmp_file = nil if @last_tmp_file != nil
    Arcadia.process_event(OpenBufferEvent.new(self,'file'=>file))
    @controller.do_buffer_raise(@controller.page_name(@page_frame))
    #EditorContract.instance.file_created(self, 'file'=>@file)
  end
end

#set_modifyObject



2675
2676
2677
2678
2679
2680
2681
# File 'ext/ae-editor/ae-editor.rb', line 2675

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



3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
# File 'ext/ae-editor/ae-editor.rb', line 3125

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



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

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_hide_line_numbersObject



993
994
995
996
997
998
999
# File 'ext/ae-editor/ae-editor.rb', line 993

def show_hide_line_numbers
  if @line_numbers_visible
    hide_line_numbers
  else
    show_line_numbers
  end
end

#show_line_numbersObject



977
978
979
980
981
982
983
984
# File 'ext/ae-editor/ae-editor.rb', line 977

def show_line_numbers
  if !@line_numbers_visible
    #@fm1.hide_right
    @fm1.show_left
    @line_numbers_visible = true
    do_line_update
  end
end

#show_outlineObject



3083
3084
3085
3086
3087
3088
3089
3090
# File 'ext/ae-editor/ae-editor.rb', line 3083

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

#show_spacesObject



2586
2587
2588
2589
2590
2591
2592
2593
# File 'ext/ae-editor/ae-editor.rb', line 2586

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



2596
2597
2598
2599
2600
2601
2602
2603
# File 'ext/ae-editor/ae-editor.rb', line 2596

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

#tab_titleObject



2683
2684
2685
# File 'ext/ae-editor/ae-editor.rb', line 2683

def tab_title
  @controller.tab_title(@page_frame)
end

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



2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
# File 'ext/ae-editor/ae-editor.rb', line 2899

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



2895
2896
2897
# File 'ext/ae-editor/ae-editor.rb', line 2895

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

#text_replace_selected_with(_text_for_replace = '') ⇒ Object



2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
# File 'ext/ae-editor/ae-editor.rb', line 2426

def text_replace_selected_with(_text_for_replace='')
  _r = @text.tag_ranges('sel')
  if _r.length>0
    bl = _r[0][0].split('.')[0].to_i
    @text.delete(_r[0][0],_r[0][1])
    @text.insert(_r[0][0],_text_for_replace)
    el = @text.index('insert').split('.')[0].to_i
    if highlighting
      reset_highlight(bl)
      rehighlightlines(bl,el,true)
    end
  end
end

#text_replace_value_with(_text_for_replace = '') ⇒ Object



2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
# File 'ext/ae-editor/ae-editor.rb', line 2440

def text_replace_value_with(_text_for_replace='')
  pos_index = @text.index('insert') 
  @text.delete('1.0','end')
  reset_highlight if @highlighting
  @text.insert('end',_text_for_replace)
  do_line_update
  @text.see(pos_index)
  @text.set_insert(pos_index)
  check_modify
end

#text_see(_index = nil) ⇒ Object



2889
2890
2891
2892
2893
# File 'ext/ae-editor/ae-editor.rb', line 2889

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

#text_selectedObject



2417
2418
2419
2420
2421
2422
2423
2424
# File 'ext/ae-editor/ae-editor.rb', line 2417

def text_selected
  _text = ''
  _r = @text.tag_ranges('sel')
  if _r.length>0
    _text=@text.get(_r[0][0],_r[0][1])
  end
  _text
end

#text_valueObject



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

def text_value
  return @text.value
end

#text_value_linesObject



2578
2579
2580
2581
2582
2583
2584
# File 'ext/ae-editor/ae-editor.rb', line 2578

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


1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
# File 'ext/ae-editor/ae-editor.rb', line 1897

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 @file && @controller.breakpoint_lines_on_file(@file).include?(_line)
      #remove_tag_breakpoint(_index)
      @controller.breakpoint_del(@file, _line, @id)
    elsif @file.nil? && @controller.breakpoint_lines_on_file("__TMP__#{@id}").include?(_line)
      #remove_tag_breakpoint(_index)
      @controller.breakpoint_del(@file, _line, @id)
    else
      @text_line_num.tag_remove('current',_i1,_i2)
      #add_tag_breakpoint(_index)
      @controller.breakpoint_add(@file, _line, @id)
    end
  end
end

#unmark_debug(_index) ⇒ Object



2394
2395
2396
2397
# File 'ext/ae-editor/ae-editor.rb', line 2394

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



2466
2467
2468
2469
2470
2471
2472
2473
2474
# File 'ext/ae-editor/ae-editor.rb', line 2466

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



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

def xy_insert
  _index_now = @text.index('insert')
  _rx, _ry, _width, _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



2721
2722
2723
# File 'ext/ae-editor/ae-editor.rb', line 2721

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