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.



1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
# File 'ext/ae-editor/ae-editor.rb', line 1093

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
  @codeinsight = 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
  @file_info = Hash.new
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



1082
1083
1084
# File 'ext/ae-editor/ae-editor.rb', line 1082

def file
  @file
end

#file_infoObject (readonly)

Returns the value of attribute file_info.



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

def file_info
  @file_info
end

#highlightingObject (readonly)

Returns the value of attribute highlighting.



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

def highlighting
  @highlighting
end

#idObject

Returns the value of attribute id.



1084
1085
1086
# File 'ext/ae-editor/ae-editor.rb', line 1084

def id
  @id
end

#langObject (readonly)

Returns the value of attribute lang.



1090
1091
1092
# File 'ext/ae-editor/ae-editor.rb', line 1090

def lang
  @lang
end

#last_tmp_fileObject (readonly)

Returns the value of attribute last_tmp_file.



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

def last_tmp_file
  @last_tmp_file
end

#line_numbers_visibleObject

Returns the value of attribute line_numbers_visible.



1083
1084
1085
# File 'ext/ae-editor/ae-editor.rb', line 1083

def line_numbers_visible
  @line_numbers_visible
end

#outlineObject (readonly)

Returns the value of attribute outline.



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

def outline
  @outline
end

#page_frameObject (readonly)

Returns the value of attribute page_frame.



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

def page_frame
  @page_frame
end

#read_onlyObject (readonly)

Returns the value of attribute read_only.



1085
1086
1087
# File 'ext/ae-editor/ae-editor.rb', line 1085

def read_only
  @read_only
end

#rootObject (readonly)

Returns the value of attribute root.



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

def root
  @root
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#activate_complete_code_key_bindingObject



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

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)



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
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
# File 'ext/ae-editor/ae-editor.rb', line 1642

def activate_key_binding
  activate_complete_code_key_binding if @is_ruby

  @text.bind_append("Control-KeyPress"){|e|
    case e.keysym
    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 's'
      save
      #Tk.callback_break
    when 'f'
      find
    when 'egrave'
      @text.insert('insert',"{")
    when 'plus'
      @text.insert('insert',"}")
    when 'g'
      Arcadia.process_event(GoToLineBufferEvent.new(self))
    when 'n'
      Arcadia.process_event(NewBufferEvent.new(self))
    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
    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|
    @last_keypress = e.keysym
    case e.keysym
#      when 'BackSpace'
#        _index = @text.index('insert')
#        _row, _col = _index.split('.')
#        rehighlightlines(_row.to_i,_row.to_i) if @highlighting
#      when 'Delete'
#        _index = @text.index('insert')
#        _row, _col = _index.split('.')
#        rehighlightlines(_row.to_i, _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|
    @last_keyrelease = e.keysym
    #return if @last_keypress != e.keysym
    case e.keysym
#      when 'Up','Down'
#          refresh_outline
    when 'Left', 'Right'
      if Arcadia.instance.last_focused_text_widget != @text
        @text.select_throw
      end
    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
      if @highlighting
        rehighlightlines(_row.to_i, _row.to_i)
      end
    when 'Shift_L','Shift_R','Control_L','Control_R' ,'Prior', 'Next', 'Up','Down'
      # do nothing because od do_line_update
    else 
#        if ['BackSpace', 'Delete'].include?(e.keysym)
#          do_line_update
#        end
      if @highlighting
        row = @text.index('insert').split('.')[0].to_i
        rehighlightlines(row, row)
      end
    end
    check_modify if !['Shift_L','Shift_R','Control_L','Control_R','Up','Down','Left', 'Right', 'Prior', 'Next'].include?(e.keysym)      
  }


  @text.bind_append("Shift-KeyPress"){|e|
    @last_keypress = e.keysym
    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



2017
2018
2019
2020
2021
2022
2023
2024
# File 'ext/ae-editor/ae-editor.rb', line 2017

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



1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
# File 'ext/ae-editor/ae-editor.rb', line 1311

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



2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
# File 'ext/ae-editor/ae-editor.rb', line 2087

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



3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
# File 'ext/ae-editor/ae-editor.rb', line 3229

def check_file_last_access_time
  #@controller.activate
  if @file
    file_exist = File.exist?(@file)
    if @file_info['mtime'] && file_exist
      ftime = File.mtime(@file)
      if @file_info['mtime'] != 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_info['mtime'] = 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



3195
3196
3197
3198
3199
3200
3201
3202
3203
# File 'ext/ae-editor/ae-editor.rb', line 3195

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

#complete_codeObject



1301
1302
1303
1304
1305
1306
1307
1308
1309
# File 'ext/ae-editor/ae-editor.rb', line 1301

def complete_code
  @do_complete = @do_complete && @controller.accept_complete_code
  if @do_complete
    line, col = @text.index('insert').split('.')
    mss = SafeCompleteCode.new(self, line.to_i, col.to_i)
    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



1288
1289
1290
1291
1292
# File 'ext/ae-editor/ae-editor.rb', line 1288

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

#complete_code_endObject



1294
1295
1296
1297
1298
# File 'ext/ae-editor/ae-editor.rb', line 1294

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

#create_temp_fileObject



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

def create_temp_file
  if @file
    n=0
    while File.exist?("#{File.join(File.dirname(@file),'~~'+File.basename(@file))}#{'_'*n}")
      n+=1
    end
    _file = "#{File.join(File.dirname(@file),'~~'+File.basename(@file))}#{'_'*n}"
#      while File.exist?("~~#{@file}#{n*'_'}")
#        n+=1
#      end
#      _file = "~~#{@file}#{n*'_'}"
  else
    if @lang == 'java'
      m = Regexp::new(/(class[\s][\s]*)[A-Za-z0-9_]*[\s]*/).match(text_value)
      if m && m.length > 0
        a = m[0].split
        if a && a.length > 1            
          tmp_dir = "~~#{a[1].strip.downcase}"
          full_tmp_dir = File.join(Arcadia.instance.local_dir,tmp_dir) 
          Dir.mkdir(full_tmp_dir) if !File.exist?(full_tmp_dir)
          basename = File.join(tmp_dir,"#{a[1].strip}.java")            
        end
      end
      basename = "~~buffer.java" if basename.nil?        
    else
      n=0
      while File.exist?(File.join(Arcadia.instance.local_dir,"~~buffer#{n}"))
        n+=1
      end
      basename = "~~buffer#{n}"
    end
    _file = File.join(Arcadia.instance.local_dir, basename)
  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



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

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.join(File.dirname(@file),'~~'+File.basename(@file))}"
  else
    _file = File.join(Arcadia.instance.local_dir,'~~buffer')
  end
  f = File.new(_file, "w")
  begin
    if f
      f.syswrite(_custom_text)
    end
  ensure
    f.close unless f.nil?
  end
  _file
end

#ctags_stringObject



3274
3275
3276
# File 'ext/ae-editor/ae-editor.rb', line 3274

def ctags_string
  @controller.ctags_string
end

#decrease_indentObject



1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
# File 'ext/ae-editor/ae-editor.rb', line 1829

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



3327
3328
3329
3330
# File 'ext/ae-editor/ae-editor.rb', line 3327

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

#disactivate_key_bindingObject



1862
1863
1864
1865
1866
1867
1868
# File 'ext/ae-editor/ae-editor.rb', line 1862

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



1870
1871
1872
# File 'ext/ae-editor/ae-editor.rb', line 1870

def do_enter
  check_file_last_access_time
end

#do_line_updateObject



2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
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
2931
2932
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
# File 'ext/ae-editor/ae-editor.rb', line 2886

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 + @text_line_spacing3)  
                _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



2616
2617
2618
2619
2620
2621
# File 'ext/ae-editor/ae-editor.rb', line 2616

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

#do_tag_configure(_name) ⇒ Object



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

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
    Arcadia.runtime_error(e)
    #p "RuntimeError : #{e.message}"
  end
end

#do_tag_configure_global(_name) ⇒ Object



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

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
    Arcadia.runtime_error(e)
    #p "RuntimeError : #{e.message}"
  end
end

#do_upper_caseObject



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

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



2007
2008
2009
2010
2011
2012
2013
2014
2015
# File 'ext/ae-editor/ae-editor.rb', line 2007

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



1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
# File 'ext/ae-editor/ae-editor.rb', line 1848

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

#has_ctags?Boolean

Returns:

  • (Boolean)


3270
3271
3272
# File 'ext/ae-editor/ae-editor.rb', line 3270

def has_ctags?
  @controller.has_ctags
end

#hide_line_numbersObject



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

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

#hide_outlineObject



3322
3323
3324
3325
# File 'ext/ae-editor/ae-editor.rb', line 3322

def hide_outline
  #@outline.hide if defined?(@outline)
  @outline.hide if @outline
end

#hide_spacesObject



2822
2823
2824
2825
# File 'ext/ae-editor/ae-editor.rb', line 2822

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

#hide_tabsObject



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

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

#highlight_zone(_zone, _force_highlight = false) ⇒ Object



3080
3081
3082
3083
3084
3085
3086
3087
3088
# File 'ext/ae-editor/ae-editor.rb', line 3080

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      
    _b -=1 while @is_line_comment[_b-1]      
    rehighlightlines(_b,_e)
    @highlight_zone[_zone] = true
  end
end

#highlighted?Boolean

Returns:

  • (Boolean)


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

def highlighted?
  !@highlighting || (@last_line_end && @last_line_end > 0)
end

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



3016
3017
3018
3019
3020
3021
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
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
# File 'ext/ae-editor/ae-editor.rb', line 3016

def highlightlines(_row_begin, _row_end, _check_mod = false)
  if _check_mod 
    check_modify
  end
  is_comment = _row_begin == _row_end
  if _row_begin == _row_end && (@is_line_comment[_row_end-1] || @is_line_comment[_row_end+1])
    if  !['apostrophe','quotedbl'].include?(@last_keypress)
      refresh_visible_highlighting
      return  
    end
  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|      
    is_comment = is_comment && key == :comment
    break if is_comment
    to_tag = Array.new
    value.each{|ite|
      to_tag.concat(ite)
      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] = @is_tag_bold[key.to_s]
          @is_line_comment[row] = key == :comment
        end
      end
    }
#      to_tag.each{|p|
#        if @i.nil?
#          @one = p
#          @i = 1
#          next
#        else
#          @two = p
#          @i = nil
#        end
#        row_begin = @one.split('.')[0].to_i
#        row_end = @two.split('.')[0].to_i
#        for row in row_begin...row_end 
#          @is_line_comment[row] = key == :comment
#        end
#      }
    @text.tag_adds(key.to_s,to_tag)
  end
  refresh_visible_highlighting if is_comment

  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



2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
# File 'ext/ae-editor/ae-editor.rb', line 2635

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



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 2777

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



2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
# File 'ext/ae-editor/ae-editor.rb', line 2797

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

#initialize_editing(_ext = nil, _lang = nil) ⇒ Object



3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
# File 'ext/ae-editor/ae-editor.rb', line 3278

def initialize_editing(_ext=nil, _lang=nil)
  if _lang 
    @is_ruby = _lang=='ruby'
  else
    @is_ruby = _ext=='rb' || _ext=='rbw'
  end
  @classbrowsing = @is_ruby || has_ctags?
  @codeinsight = @is_ruby
  if _lang
    @lang_hash = @controller.language_hash_by_lang(_lang)
  else
    @lang_hash = @controller.language_hash_by_ext(_ext)
  end
  if @lang_hash
    @lang = @lang_hash['language']
  else
    @lang = 'ruby'
  end
#    @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



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

def initialize_highlight(_ext)
  @highlight_scanner = @controller.highlight_scanner(_ext)
  @is_line_bold = Hash.new
  @is_line_comment = 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



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

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'
    )
  }
  if Arcadia.conf("textline.spacing3")
    @text_line_spacing3 = Arcadia.conf("textline.spacing3").to_i
  else
    @text_line_spacing3 = 0
  end
  delta = (@font_metrics_bold[2][1]-@font_metrics[2][1]) + @text_line_spacing3
  @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



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

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
  @text.extend(TkInputThrow)
  begin
    @text_cursor = @text.cget('cursor')
  rescue RuntimeError => e
    Arcadia.runtime_error(e)
    #p "RuntimeError : #{e.message}"
  end
end

#initialize_text_bindingObject



1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
# File 'ext/ae-editor/ae-editor.rb', line 1874

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_append("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



2567
2568
2569
# File 'ext/ae-editor/ae-editor.rb', line 2567

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

#load_file(_filename = nil) ⇒ Object



3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
# File 'ext/ae-editor/ae-editor.rb', line 3332

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
      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



2557
2558
2559
2560
# File 'ext/ae-editor/ae-editor.rb', line 2557

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



2562
2563
2564
2565
# File 'ext/ae-editor/ae-editor.rb', line 2562

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)


2829
2830
2831
# File 'ext/ae-editor/ae-editor.rb', line 2829

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

#modified_by_others?Boolean

Returns:

  • (Boolean)


3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
# File 'ext/ae-editor/ae-editor.rb', line 3205

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

#modified_from_opening?Boolean

Returns:

  • (Boolean)


1115
1116
1117
# File 'ext/ae-editor/ae-editor.rb', line 1115

def modified_from_opening?
  @modified_from_opening
end

#new_file_name(_new_file) ⇒ Object



3181
3182
3183
3184
3185
3186
3187
3188
# File 'ext/ae-editor/ae-editor.rb', line 3181

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



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
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
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
# File 'ext/ae-editor/ae-editor.rb', line 2212

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'=> Arcadia.image_res(_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



2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
# File 'ext/ae-editor/ae-editor.rb', line 2854

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



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

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')
    else
      _line = @text.get("insert linestart",'insert lineend')
      ei = _line.index(_target)
      if !ei.nil?
        j=1
        pre_target = ''
        while ei-j>=0 && !["\s",'(','[','{'].include?(_line[ei-j..ei-j])
          pre_target = _line[ei-j..ei-j] + pre_target
          j+=1
        end
        _target= pre_target + _target
      end       
    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 _filter.length > 0 
      begin_index_for_delete = "insert - #{_filter.length}chars"
    else
      for_delete = @text.get(_begin_index,"insert")
      if for_delete && ['.','(','[','{','=','<','!','>'].include?(for_delete.strip[-1..-1])
        begin_index_for_delete = "insert"
      elsif for_delete && for_delete.include?('.')
        begin_index_for_delete = "insert - #{for_delete.split('.')[-1].length}chars"
      else
        begin_index_for_delete = _begin_index
      end 
    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_for_delete,'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_for_delete,'insert');
        @text.insert('insert',_candidates[0].split[0])
        complete_code_end
      end
  end
end

#refreshObject



3374
3375
3376
# File 'ext/ae-editor/ae-editor.rb', line 3374

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

#refresh_outlineObject



1891
1892
1893
1894
1895
# File 'ext/ae-editor/ae-editor.rb', line 1891

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

#refresh_visible_highlightingObject



2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
# File 'ext/ae-editor/ae-editor.rb', line 2994

def refresh_visible_highlighting
  line_begin_index = @text.index('@0,0')
  line_begin = line_begin_index.split('.')[0].to_i
  line_begin = @comment_line_begin if !@comment_line_begin.nil? && @comment_line_begin < line_begin
  line_end = @text.index('@0,'+TkWinfo.height(@text).to_s).split('.')[0].to_i + 1
  reset_highlight(line_begin)
  zone_begin = zone_of_row(line_begin)
  zone_end = zone_of_row(line_end)
  zone_begin.upto(zone_end){|z| highlight_zone(z)}
  highlight_zone(zone_of_row(line_end+1)) if @is_line_comment[line_end]
  
  #rehighlightlines(line_begin,line_end,true)
  if @is_line_comment[line_end]
    line_end.downto(line_begin){|l|
      @comment_line_begin = l if @is_line_comment[l]
    }
  else
    @comment_line_begin = nil
  end
end

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



2870
2871
2872
2873
2874
2875
# File 'ext/ae-editor/ae-editor.rb', line 2870

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



3261
3262
3263
3264
3265
3266
3267
3268
# File 'ext/ae-editor/ae-editor.rb', line 3261

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



2026
2027
2028
2029
2030
2031
2032
2033
# File 'ext/ae-editor/ae-editor.rb', line 2026

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



3368
3369
3370
3371
3372
# File 'ext/ae-editor/ae-editor.rb', line 3368

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

#reset_file_last_access_timeObject



3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
# File 'ext/ae-editor/ae-editor.rb', line 3218

def reset_file_last_access_time
  if @file
    if File.exist?(@file)
      @file_info['mtime'] = File.mtime(@file)
    else
      @file_info['mtime'] = nil
      @file = nil
    end
  end
end

#reset_highlight(_from_row = nil) ⇒ Object



2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
# File 'ext/ae-editor/ae-editor.rb', line 2070

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 }
    @is_line_comment.delete_if {|key, value| key >= invalidated_begin_zone }
    @highlight_zone.delete_if {|key, value| key >= invalidated_begin_zone }
  elsif @highlighting
    @is_line_bold.clear
    @is_line_comment.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



2845
2846
2847
2848
2849
2850
2851
2852
# File 'ext/ae-editor/ae-editor.rb', line 2845

def reset_modify(_reset_tab=true)
  @controller.change_tab_reset_modify(@page_frame) if _reset_tab
  @set_mod = false
  @file_info['mtime'] = File.mtime(@file) if @file
  #@file_last_access_time = File.mtime(@file) if @file
  @controller.refresh_status
  update_toolbar
end

#resize_line_numObject



2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
# File 'ext/ae-editor/ae-editor.rb', line 2960

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 || @need_recalc
      if @line_num_rx_e.nil? || @need_recalc
        @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_width_e.nil?
          @line_num_width_e = @font.split()[-1].strip.to_i
          @need_recalc = true            
#            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
        else
          @need_recalc = false   
        end
      end
      
      
      if @line_num_width_e && line_end_chars >0 
        need_width = (line_end_chars+1)*@line_num_width_e
        @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



2877
2878
2879
2880
# File 'ext/ae-editor/ae-editor.rb', line 2877

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

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



2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
# File 'ext/ae-editor/ae-editor.rb', line 2647

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



1897
1898
1899
1900
1901
1902
1903
1904
1905
# File 'ext/ae-editor/ae-editor.rb', line 1897

def run_buffer
  if !@file      
    @lang='ruby' if !@lang
    RunCmdEvent.new(self, {'file'=>'*CURR', 'persistent'=>false, 'lang'=>@lang}).go!
  else
    save if !@read_only && modified?
    RunCmdEvent.new(self, {'file'=>@file, 'lang'=>@lang}).go!
  end
end

#save(ignore_read_only = false) ⇒ Object



3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
# File 'ext/ae-editor/ae-editor.rb', line 3134

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



3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
# File 'ext/ae-editor/ae-editor.rb', line 3167

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



2833
2834
2835
2836
2837
2838
2839
# File 'ext/ae-editor/ae-editor.rb', line 2833

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



3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
# File 'ext/ae-editor/ae-editor.rb', line 3355

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



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

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



1141
1142
1143
1144
1145
1146
1147
# File 'ext/ae-editor/ae-editor.rb', line 1141

def show_hide_line_numbers
  if @line_numbers_visible
    hide_line_numbers
  else
    show_line_numbers
  end
end

#show_line_numbersObject



1125
1126
1127
1128
1129
1130
1131
1132
# File 'ext/ae-editor/ae-editor.rb', line 1125

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



3313
3314
3315
3316
3317
3318
3319
3320
# File 'ext/ae-editor/ae-editor.rb', line 3313

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

#show_spacesObject



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

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



2754
2755
2756
2757
2758
2759
2760
2761
# File 'ext/ae-editor/ae-editor.rb', line 2754

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



2841
2842
2843
# File 'ext/ae-editor/ae-editor.rb', line 2841

def tab_title
  @controller.tab_title(@page_frame)
end

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



3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
# File 'ext/ae-editor/ae-editor.rb', line 3100

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



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

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

#text_replace_selected_with(_text_for_replace = '') ⇒ Object



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

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



2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
# File 'ext/ae-editor/ae-editor.rb', line 2598

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



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

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

#text_selectedObject



2575
2576
2577
2578
2579
2580
2581
2582
# File 'ext/ae-editor/ae-editor.rb', line 2575

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



2571
2572
2573
# File 'ext/ae-editor/ae-editor.rb', line 2571

def text_value
  return @text.value
end

#text_value_linesObject



2736
2737
2738
2739
2740
2741
2742
# File 'ext/ae-editor/ae-editor.rb', line 2736

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


2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
# File 'ext/ae-editor/ae-editor.rb', line 2050

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



2552
2553
2554
2555
# File 'ext/ae-editor/ae-editor.rb', line 2552

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

#update_toolbarObject



3190
3191
3192
3193
# File 'ext/ae-editor/ae-editor.rb', line 3190

def update_toolbar
  save = Arcadia.toolbar_item('save')
  save.enable=@set_mod if save    
end

#vscroll(mode) ⇒ Object

vertical scrollbar : ON/OFF



2624
2625
2626
2627
2628
2629
2630
2631
2632
# File 'ext/ae-editor/ae-editor.rb', line 2624

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



1149
1150
1151
1152
1153
1154
1155
1156
1157
# File 'ext/ae-editor/ae-editor.rb', line 1149

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



2882
2883
2884
# File 'ext/ae-editor/ae-editor.rb', line 2882

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