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.


1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
# File 'ext/ae-editor/ae-editor.rb', line 1334

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
  @buffer_info = Hash.new
  @file_loaded = false
  @edit_initialized = false
  @start_index='1.0'
end

Instance Attribute Details

#buffer_infoObject (readonly)

Returns the value of attribute buffer_info


1330
1331
1332
# File 'ext/ae-editor/ae-editor.rb', line 1330

def buffer_info
  @buffer_info
end

#edit_initializedObject (readonly)

Returns the value of attribute edit_initialized


1333
1334
1335
# File 'ext/ae-editor/ae-editor.rb', line 1333

def edit_initialized
  @edit_initialized
end

#fileObject

Returns the value of attribute file


1320
1321
1322
# File 'ext/ae-editor/ae-editor.rb', line 1320

def file
  @file
end

#file_loadedObject (readonly)

Returns the value of attribute file_loaded


1332
1333
1334
# File 'ext/ae-editor/ae-editor.rb', line 1332

def file_loaded
  @file_loaded
end

#highlightingObject (readonly)

Returns the value of attribute highlighting


1327
1328
1329
# File 'ext/ae-editor/ae-editor.rb', line 1327

def highlighting
  @highlighting
end

#idObject

Returns the value of attribute id


1323
1324
1325
# File 'ext/ae-editor/ae-editor.rb', line 1323

def id
  @id
end

#langObject (readonly)

Returns the value of attribute lang


1329
1330
1331
# File 'ext/ae-editor/ae-editor.rb', line 1329

def lang
  @lang
end

#last_tmp_fileObject (readonly)

Returns the value of attribute last_tmp_file


1328
1329
1330
# File 'ext/ae-editor/ae-editor.rb', line 1328

def last_tmp_file
  @last_tmp_file
end

#line_numbers_visibleObject

Returns the value of attribute line_numbers_visible


1322
1323
1324
# File 'ext/ae-editor/ae-editor.rb', line 1322

def line_numbers_visible
  @line_numbers_visible
end

#outlineObject (readonly)

Returns the value of attribute outline


1331
1332
1333
# File 'ext/ae-editor/ae-editor.rb', line 1331

def outline
  @outline
end

#page_frameObject (readonly)

Returns the value of attribute page_frame


1325
1326
1327
# File 'ext/ae-editor/ae-editor.rb', line 1325

def page_frame
  @page_frame
end

#read_onlyObject (readonly)

Returns the value of attribute read_only


1324
1325
1326
# File 'ext/ae-editor/ae-editor.rb', line 1324

def read_only
  @read_only
end

#rootObject (readonly)

Returns the value of attribute root


1326
1327
1328
# File 'ext/ae-editor/ae-editor.rb', line 1326

def root
  @root
end

#start_indexObject

Returns the value of attribute start_index


1321
1322
1323
# File 'ext/ae-editor/ae-editor.rb', line 1321

def start_index
  @start_index
end

#textObject (readonly)

Returns the value of attribute text


1326
1327
1328
# File 'ext/ae-editor/ae-editor.rb', line 1326

def text
  @text
end

Instance Method Details

#activate_complete_code_key_bindingObject


1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
# File 'ext/ae-editor/ae-editor.rb', line 1865

def activate_complete_code_key_binding
  @n_complete_task = 0
  # key binding for complete code
  @text.bind_append("Control-KeyPress", "%K"){|_keysym|
    case _keysym
    when 'space'
      if @n_complete_task == 0
        @do_complete = true
        complete_code
      end
    end
  }
  
  @text.bind_append("KeyPress", "%K"){|_keysym|
    if _keysym == "Escape"
      if @n_complete_task == 0
        @do_complete = true
        complete_code
      end
    else
      @do_complete = false
    end
  }    
  case @lang 
    when 'ruby'
      @text.bind_append("KeyRelease", "%K"){|_keysym|
        case _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
end

#activate_key_bindingObject

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


1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
# File 'ext/ae-editor/ae-editor.rb', line 1911

def activate_key_binding
  activate_complete_code_key_binding #if @is_ruby

  @text.bind_append("Control-KeyPress", "%K"){|_keysym|
    case _keysym
    when 'o'  
      if @file
        _dir = File.dirname(@file)
      else
        _dir = MonitorLastUsedDir.get_last_dir
      end
      _file = Arcadia.select_file_dialog(_dir)
      Arcadia.process_event(OpenBufferEvent.new(self,'file'=>_file)) if _file
      Tk.callback_break
      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", "%K"){|_keysym|
    case _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", "%K"){|_keysym|
    @last_keypress = _keysym
    case _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'
      @controller.get_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", "%K"){|_keysym|
    @last_keyrelease = _keysym
    #return if @last_keypress != e.keysym
    case _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')
      _previous_index = @text.index('insert -2 chars')
      _row, _col = _index.split('.')
      _previous_row, _previous_col = _previous_index.split('.')
      if _previous_row != _row
        _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/,"")
              if _col.strip != '0'
                i0 = "#{_row.strip}.0"
                i1 = "#{_index} lineend"
                dirty = @text.get(i0,i1)
                if dirty && dirty.strip.length == 0
                  @text.delete(i0,i1)
                end
              end    
              @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
      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?(_keysym)      
  }


  @text.bind_append("Shift-KeyPress", "%K"){|_keysym|
    @last_keypress = _keysym
    case _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_bookmark(_line) ⇒ Object


2367
2368
2369
2370
2371
2372
2373
2374
# File 'ext/ae-editor/ae-editor.rb', line 2367

def add_tag_bookmark(_line)
    rel_line = file_line_to_text_line_num_line(_line)
    if rel_line
      i1 = "#{rel_line}.2"
      i2 = i1+' lineend'
      @text_line_num.tag_add('bookmark',i1,i2)
    end
end

#add_tag_breakpoint(_line) ⇒ Object


2329
2330
2331
2332
2333
2334
2335
2336
# File 'ext/ae-editor/ae-editor.rb', line 2329

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


1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
# File 'ext/ae-editor/ae-editor.rb', line 1571

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


2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
# File 'ext/ae-editor/ae-editor.rb', line 2403

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


3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
# File 'ext/ae-editor/ae-editor.rb', line 3592

def check_file_last_access_time
  if @file
    file_exist = File.exist?(@file)
    if @buffer_info['mtime'] && file_exist
      ftime = File.mtime(@file)
      if @buffer_info['mtime'] != ftime
        msg = Arcadia.text('ext.editor.text.d.file_changed.msg', [@file])
        title = Arcadia.text('ext.editor.text.d.file_changed.title')
        ans = Arcadia.hinner_dialog(self, 'type'=>'yes_no', 'msg'=> msg, 'title' => title, 'level' => 'error')
        if ans == 'yes'
          reload
        else
          @buffer_info['mtime'] = ftime
        end
      end
    elsif !file_exist
      msg = Arcadia.text('ext.editor.text.d.file_deleted.msg', [@file])
      title = Arcadia.text('ext.editor.text.d.file_deleted.title')
      if Arcadia.hinner_dialog(self, 'type'=>'yes_no', 'msg'=> msg, 'title' => title, 'level' => 'error')  == 'yes'
        save
      else
        @file = nil
        @buffer = ''
        set_modify
      end
    end
  end
end

#check_modifyObject


3558
3559
3560
3561
3562
3563
3564
3565
3566
# File 'ext/ae-editor/ae-editor.rb', line 3558

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

#complete_codeObject


1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
# File 'ext/ae-editor/ae-editor.rb', line 1556

def complete_code
  @do_complete = @do_complete && @controller.accept_complete_code
  if @do_complete
    line, col = @text.index('insert').split('.')
    case @lang
      when 'ruby'
        mss = RubyCompleteCode.new(self, line.to_i, col.to_i)
      else
        mss = CompleteCode.new(self, line.to_i, col.to_i)
    end
    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


1543
1544
1545
1546
1547
# File 'ext/ae-editor/ae-editor.rb', line 1543

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

#complete_code_endObject


1549
1550
1551
1552
1553
# File 'ext/ae-editor/ae-editor.rb', line 1549

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

#create_temp_fileObject


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

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?        
    elsif @lang == 'ruby'
      n=0
      while File.exist?(File.join(Arcadia.instance.local_dir,"~~buffer#{n}.rb"))
        n+=1
      end
      basename = "~~buffer#{n}.rb"
    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


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

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


3634
3635
3636
# File 'ext/ae-editor/ae-editor.rb', line 3634

def ctags_string
  @controller.ctags_string
end

#decrease_indentObject


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

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


3688
3689
3690
3691
# File 'ext/ae-editor/ae-editor.rb', line 3688

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

#destroy_textObject


3693
3694
3695
3696
# File 'ext/ae-editor/ae-editor.rb', line 3693

def destroy_text
  @text.destroy if @text
  @text = nil
end

#disactivate_key_bindingObject


2146
2147
2148
2149
2150
2151
2152
# File 'ext/ae-editor/ae-editor.rb', line 2146

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


2154
2155
2156
2157
2158
# File 'ext/ae-editor/ae-editor.rb', line 2154

def do_enter
  check_file_last_access_time
  find = @controller.get_find
  find.use(self) if find
end

#do_line_updateObject


3223
3224
3225
3226
3227
3228
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
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
# File 'ext/ae-editor/ae-editor.rb', line 3223

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)
        # bookmark
        bm = @controller.bookmark_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
          if bm.include?(j.to_s)
            add_tag_bookmark(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


2937
2938
2939
2940
2941
2942
# File 'ext/ae-editor/ae-editor.rb', line 2937

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

#do_tag_configure(_name) ⇒ Object


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

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


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

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


2930
2931
2932
2933
2934
2935
# File 'ext/ae-editor/ae-editor.rb', line 2930

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


2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
# File 'ext/ae-editor/ae-editor.rb', line 2318

def file_line_to_text_line_num_line(_line)
  return 0 if @text_line_num.nil?
  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


2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
# File 'ext/ae-editor/ae-editor.rb', line 2132

def find
  _r = @text.tag_ranges('sel')
  if _r.length>0
    _text=@text.get(_r[0][0],_r[0][1])
    if _text.length > 0
      @controller.get_find.e_what.value=_text
    end
  else
  end
  @controller.get_find.use(self)
  @controller.get_find.e_what.focus
  @controller.get_find.show
end

#has_ctags?Boolean

Returns:

  • (Boolean)

3630
3631
3632
# File 'ext/ae-editor/ae-editor.rb', line 3630

def has_ctags?
  @controller.has_ctags
end

#hide_line_numbersObject


1382
1383
1384
1385
1386
1387
# File 'ext/ae-editor/ae-editor.rb', line 1382

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

#hide_outlineObject


3683
3684
3685
3686
# File 'ext/ae-editor/ae-editor.rb', line 3683

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

#hide_spacesObject


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

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

#hide_tabsObject


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

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

#highlight_zone(_zone, _force_highlight = false) ⇒ Object


3423
3424
3425
3426
3427
3428
3429
3430
3431
# File 'ext/ae-editor/ae-editor.rb', line 3423

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)

1367
1368
1369
# File 'ext/ae-editor/ae-editor.rb', line 1367

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

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


3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
# File 'ext/ae-editor/ae-editor.rb', line 3359

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


2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
# File 'ext/ae-editor/ae-editor.rb', line 2956

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


3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
# File 'ext/ae-editor/ae-editor.rb', line 3098

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


3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
# File 'ext/ae-editor/ae-editor.rb', line 3118

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


3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
# File 'ext/ae-editor/ae-editor.rb', line 3638

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,0,false,false)
  @fm1.splitter_frame.configure('relief'=>'flat')
  @fm1.bind_append("Enter", proc{@controller.activate})    
  initialize_text(@fm1.right_frame)
  initialize_highlight(_ext)
  initialize_line_number(@fm1.left_frame)
  initialize_text_binding
end

#initialize_highlight(_ext) ⇒ Object


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

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


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

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('bookmark', 'background'=>'blue','foreground'=>'yellow','borderwidth'=>1, 'relief'=>'raised')
  @text_line_num.tag_configure('bookmark', 'background'=>'white','foreground'=>'red','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_resized = false
  @text_line_num.bind("Map", proc{resize_line_num if !@text_line_num_resized })
  
  
  #@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(
  _pop_up = Arcadia.wf.menu(
    :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=> Arcadia.text('ext.editor.text_line.menu.toggle_breakpoint'),
    :hidemargin => false,
    :command=> proc{ 
      if defined?(@text_line_num_current_index)
        toggle_breakpoint(@text_line_num_current_index)
      end
    }
  )

  _pop_up.insert('end',
    :command,
    :label=> Arcadia.text('ext.file_history.toggle_bookmark'),
    :hidemargin => false,
    :command=> proc{ 
      if defined?(@text_line_num_current_index)
        row = @text_line_num.get(@text_line_num_current_index+' linestart',@text_line_num_current_index+' lineend').strip
        ToggleBookmarkEvent.new(self,
          'file'=>@file, 
          'from_row'=>row, 
          'to_row'=>row,
          'persistent'=>File.exists?(@file),
          'id'=>@id).go!
      end
    }
  )


  @text_line_num.bind("Button-3",
    proc{
      _x = TkWinfo.pointerx(@text_line_num)
      _y = TkWinfo.pointery(@text_line_num)
      _pop_up.entryconfigure(0,'label'=> Arcadia.text('ext.editor.text_line.menu.title', [@text_line_num_current_line]))

      _pop_up.popup(_x,_y)
    })

end

#initialize_text(_frame) ⇒ Object


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

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
  @edit_initialized = true
end

#initialize_text_bindingObject


2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
# File 'ext/ae-editor/ae-editor.rb', line 2160

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>"){
    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


2888
2889
2890
# File 'ext/ae-editor/ae-editor.rb', line 2888

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

#load_file(_filename = nil) ⇒ Object


3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
# File 'ext/ae-editor/ae-editor.rb', line 3699

def load_file(_filename = nil)
  #if filename is nil then open a new tab
  @loading=true
  initialize_editing(Arcadia.file_extension(_filename) || 'rb') if !@edit_initialized
  @dos_line_endings=false
  begin
    @file = _filename
    if _filename
      File::open(_filename,'rb'){ |file|
        if Arcadia.conf('encoding')
          @text.insert('end',file.readlines.collect!{| line | Tk.EncodedString(line.chomp, Arcadia.conf('encoding'))}.join("\n"))
        else
          @text.insert('end',file.readlines.collect!{| line | line.chomp}.join("\n"))
        end
        #@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
    @file_loaded = true
    set_read_only(!File.stat(_filename).writable?)
    reset(false)
    refresh
  ensure
    @loading=false
  end
end

#load_file_if_not_loadedObject


3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
# File 'ext/ae-editor/ae-editor.rb', line 3728

def load_file_if_not_loaded
  if @file && !@file_loaded
    load_file(@file)
    if @start_index
      vl = visible_lines
      if vl && vl > 0
        text_see("#{@start_index} + #{vl/2 -1} lines")
      else
        text_see(@start_index) 
      end
    end
    do_line_update
    @need_recalc=true
    resize_line_num
  end
end

#mark_debug(_index) ⇒ Object


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

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


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

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

#mkdir_recursive(_dir) ⇒ Object


3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
# File 'ext/ae-editor/ae-editor.rb', line 3511

def mkdir_recursive(_dir)
  dir_seg = _dir.split(File::SEPARATOR)
  incr_dir = ""
  res = ""
  0.upto(dir_seg.length-1){|j|
    if res == File::SEPARATOR
      res=res+dir_seg[j]
    elsif res.length == 0 && dir_seg[j].length == 0
      res=File::SEPARATOR+dir_seg[j]
    elsif res.length == 0 && dir_seg[j].length > 0
      res=dir_seg[j]
    else
      res=res+File::SEPARATOR+dir_seg[j]
    end
    Dir.mkdir(res) if !File.exists?(res)
  }
end

#modified?Boolean

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

Returns:

  • (Boolean)

3150
3151
3152
# File 'ext/ae-editor/ae-editor.rb', line 3150

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

#modified_by_others?Boolean

Returns:

  • (Boolean)

3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
# File 'ext/ae-editor/ae-editor.rb', line 3568

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

#modified_from_opening?Boolean

Returns:

  • (Boolean)

1363
1364
1365
# File 'ext/ae-editor/ae-editor.rb', line 1363

def modified_from_opening?
  @modified_from_opening
end

#new_file_name(_new_file) ⇒ Object


3543
3544
3545
3546
3547
3548
3549
3550
3551
# File 'ext/ae-editor/ae-editor.rb', line 3543

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

end

#pop_up_menuObject


2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
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
2798
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
2833
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
# File 'ext/ae-editor/ae-editor.rb', line 2528

def pop_up_menu
  #@pop_up = TkMenu.new(
  @pop_up = Arcadia.wf.menu(
    :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=>Arcadia.text('ext.editor.text.menu.save'),
    :hidemargin => false,
    :command=> proc{save}
  )

  @pop_up.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.save_as'),
    :hidemargin => false,
    :command=> proc{save_as}
  )

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

  @pop_up.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.close'),
    :hidemargin => false,
    :command=> proc{@controller.close_editor(self)}
  )

  @pop_up.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.close_others'),
    :hidemargin => false,
    :command=> proc{@controller.close_others_editor(self)}
  )

  @pop_up.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.close_all'),
    :hidemargin => false,
    :command=> proc{@controller.close_all_editor(self)}
  )

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

  @pop_up.insert('end',
    :command,
    :label=> Arcadia.text('ext.editor.text.menu.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=>Arcadia.text('ext.editor.text.menu.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=>Arcadia.text('ext.editor.text.menu.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=>Arcadia.text('ext.editor.text.menu.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=>Arcadia.text('ext.editor.text.menu.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=>Arcadia.text('ext.editor.text.menu.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=>Arcadia.text('ext.editor.text.menu.font'),
    :hidemargin => false,
    :command=> proc{
      @text.insert('insert', $arcadia['action.get.font'].call)
    }
  )
  
  @pop_up.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.data_from_file'),
    :hidemargin => false,
    :command=>       proc{
      file = Arcadia.select_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=>Arcadia.text('ext.editor.text.menu.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=>Arcadia.text('ext.editor.text.menu.data_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 = Arcadia.save_file_dialog
          #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(
  _sub_debug = Arcadia.wf.menu(
    :parent=>@pop_up,
    :tearoff=>0,
    :title => 'Debug'
  )
  #_sub_debug.extend(TkAutoPostMenu)
  #_sub_debug.configure(Arcadia.style('menu'))
  _sub_debug.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.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=>Arcadia.text('ext.editor.text.menu.debug'),
    :menu=>_sub_debug,
    :hidemargin => false
  )


  #---- code menu
  #_sub_code = TkMenu.new(
  _sub_code = Arcadia.wf.menu(
    :parent=>@pop_up,
    :tearoff=>0,
    :title => 'Code'
  )
  #_sub_code.extend(TkAutoPostMenu)
  #_sub_code.configure(Arcadia.style('menu'))
  _sub_code.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.set_wrap'),
    :hidemargin => false,
    :command=> proc{@text.configure('wrap'=>'word');@text.hide_h_scroll}
  )

  _sub_code.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.set_nowrap'),
    :hidemargin => false,
    :command=> proc{@text.configure('wrap'=>'none');@text.show_h_scroll}
  )

  _sub_code.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.to_uppercase'),
    :hidemargin => false,
    :command=> proc{do_upper_case}
  )

  _sub_code.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.to_downcase'),
    :hidemargin => false,
    :command=> proc{do_lower_case}
  )



  _sub_code.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.show_tabs'),
    :hidemargin => false,
    :command=> proc{show_tabs}
  )


  _sub_code.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.hide_tabs'),
    :hidemargin => false,
    :command=> proc{hide_tabs}
  )

  _sub_code.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.show_spaces'),
    :hidemargin => false,
    :command=> proc{show_spaces}
  )


  _sub_code.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.hide_spaces'),
    :hidemargin => false,
    :command=> proc{hide_spaces}
  )


  _sub_code.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.space_to_tab'),
    :hidemargin => false,
    :command=> proc{indentation_space_2_tabs}
  )

  _sub_code.insert('end',
    :command,
    :label=>Arcadia.text('ext.editor.text.menu.tab_to_space'),
    :hidemargin => false,
    :command=> proc{indentation_tabs_2_space}
  )

  
  @pop_up.insert('end',
    :cascade,
    :label=>Arcadia.text('ext.editor.text.menu.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


3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
# File 'ext/ae-editor/ae-editor.rb', line 3176

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


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
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
# File 'ext/ae-editor/ae-editor.rb', line 1595

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.[email protected]
      _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_complete = @text.index("insert - #{_filter.length}chars")
    else
      processing_string = @text.get(_begin_index,"insert")
      if processing_string && ['.','(','[','{','=','<','!','>'].include?(processing_string.strip[-1..-1])
        begin_index_for_complete = @text.index("insert")
      elsif processing_string && processing_string.include?('.')
        begin_index_for_complete = @text.index("insert - #{processing_string.split('.')[-1].length}chars")
      else
        begin_index_for_complete = _begin_index
      end 
    end

    if _candidates.length >= 1 
        #_rx, _ry, _width, heigth = @text.bbox(_begin_index);
        _rx, _ry, _width, heigth = @text.bbox(begin_index_for_complete);
        _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} #{TkTextListBox::SEP} #{_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)
            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
            if @text.get("#{begin_index_for_complete} linestart", "#{begin_index_for_complete} wordstart").strip == "" ||
               @text.get("#{begin_index_for_complete} wordstart", "#{begin_index_for_complete} wordstart + 1 chars") != " "
              @text.delete("#{begin_index_for_complete} wordstart",'insert')
            else 
              @text.delete("#{begin_index_for_complete} wordstart + 1 chars",'insert')
            end
            # 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 = @text.get(begin_index_for_complete, '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', "%K"){|_keysym|
          # todo
          case _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','underscore'
              if _keysym == 'equal'
                ch = '='
              elsif _keysym == 'greater'
                ch = '>'
              elsif _keysym == 'underscore'
                ch = '_'
              else
                ch = _keysym
              end
              @text.insert('insert',ch)
              _buffer = _buffer + ch
              _update_list.call(_buffer)
              Tk.callback_break
            else
              if _keysym.length > 1 
                p ">#{_keysym}<"
                Tk.callback_break
              end
          end
        }
        @raised_listbox.bind_append('KeyPress', "%K"){|_keysym|
          case _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 _keysym == 'less'
                ch = '<'
              elsif _keysym == 'space'
                ch = ''
              else
                ch = _keysym
              end
              @text.insert('insert',ch)
              _buffer = _buffer + ch
              _update_list.call(_buffer)
              Tk.callback_break
            when 'BackSpace'
              if _buffer.length > _buffer_ini_length
                  if @text.index('insert').split('.')[0] == _row
                    @text.delete("insert -1 chars" ,'insert')
                  end
                  _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', "%K"){|_keysym|
          case _keysym
            when 'Return'
              _insert_selected_value.call
          end
        }
      elsif _candidates.length == 1 && _candidates[0].length>0
        @text.delete(begin_index_for_complete,'insert');
        @text.insert('insert',_candidates[0].split[0])
        complete_code_end
      end
  end
end

#refreshObject


3764
3765
3766
# File 'ext/ae-editor/ae-editor.rb', line 3764

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

#refresh_outlineObject


2177
2178
2179
2180
2181
# File 'ext/ae-editor/ae-editor.rb', line 2177

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

#refresh_visible_highlightingObject


3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
# File 'ext/ae-editor/ae-editor.rb', line 3337

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


3192
3193
3194
3195
3196
3197
# File 'ext/ae-editor/ae-editor.rb', line 3192

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


3621
3622
3623
3624
3625
3626
3627
3628
# File 'ext/ae-editor/ae-editor.rb', line 3621

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_bookmark(_line) ⇒ Object


2376
2377
2378
2379
2380
2381
2382
2383
2384
# File 'ext/ae-editor/ae-editor.rb', line 2376

def remove_tag_bookmark(_line)
    return if @text_line_num.nil?
    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('bookmark',i1,i2)
    end
end

#remove_tag_breakpoint(_line) ⇒ Object


2338
2339
2340
2341
2342
2343
2344
2345
# File 'ext/ae-editor/ae-editor.rb', line 2338

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


3758
3759
3760
3761
3762
# File 'ext/ae-editor/ae-editor.rb', line 3758

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

#reset_file_last_access_timeObject


3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
# File 'ext/ae-editor/ae-editor.rb', line 3581

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

#reset_highlight(_from_row = nil) ⇒ Object


2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
# File 'ext/ae-editor/ae-editor.rb', line 2386

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


3166
3167
3168
3169
3170
3171
3172
3173
3174
# File 'ext/ae-editor/ae-editor.rb', line 3166

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

#resize_line_numObject


3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
# File 'ext/ae-editor/ae-editor.rb', line 3302

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
    @text_line_num_resized = true
  end
end

#row(_index = 'insert') ⇒ Object


3199
3200
3201
3202
# File 'ext/ae-editor/ae-editor.rb', line 3199

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

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


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

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


2183
2184
2185
2186
2187
2188
2189
2190
2191
# File 'ext/ae-editor/ae-editor.rb', line 2183

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


3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
# File 'ext/ae-editor/ae-editor.rb', line 3477

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' => Arcadia.text('ext.editor.text.d.save_read-only.title', [@file]),
    'msg' =>Arcadia.text('ext.editor.text.d.save_read-only.msg', [@file]),
    'level' =>'warning')
    if r=="yes"
      save true
    end
  else
    mkdir_recursive(File.dirname(@file)) if !File.exists?(File.dirname(@file))
    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


3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
# File 'ext/ae-editor/ae-editor.rb', line 3529

def save_as
  file = Arcadia.save_file_dialog
  #Tk.getSaveFile("filetypes"=>[["Ruby Files", [".rb", ".rbw"]],["All Files", [".*"]]])
  file = nil if file == ""  # cancelled
  if file
    new_file_name(file)
    save
    @last_tmp_file = nil if @last_tmp_file != nil
    @file_loaded = true
    Arcadia.process_event(OpenBufferEvent.new(self,'file'=>file))
    @controller.do_buffer_raise(@controller.page_name(@page_frame))
  end
end

#set_controller(_controller) ⇒ Object


1359
1360
1361
# File 'ext/ae-editor/ae-editor.rb', line 1359

def set_controller(_controller)
  @controller=_controller
end

#set_modifyObject


3154
3155
3156
3157
3158
3159
3160
# File 'ext/ae-editor/ae-editor.rb', line 3154

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


3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
# File 'ext/ae-editor/ae-editor.rb', line 3745

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


3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
# File 'ext/ae-editor/ae-editor.rb', line 3085

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


1389
1390
1391
1392
1393
1394
1395
# File 'ext/ae-editor/ae-editor.rb', line 1389

def show_hide_line_numbers
  if @line_numbers_visible
    hide_line_numbers
  else
    show_line_numbers
  end
end

#show_line_numbersObject


1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
# File 'ext/ae-editor/ae-editor.rb', line 1371

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

#show_outlineObject


3674
3675
3676
3677
3678
3679
3680
3681
# File 'ext/ae-editor/ae-editor.rb', line 3674

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


3065
3066
3067
3068
3069
3070
3071
3072
# File 'ext/ae-editor/ae-editor.rb', line 3065

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


3075
3076
3077
3078
3079
3080
3081
3082
# File 'ext/ae-editor/ae-editor.rb', line 3075

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


3162
3163
3164
# File 'ext/ae-editor/ae-editor.rb', line 3162

def tab_title
  @controller.tab_title(@page_frame)
end

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


3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
# File 'ext/ae-editor/ae-editor.rb', line 3443

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


3439
3440
3441
# File 'ext/ae-editor/ae-editor.rb', line 3439

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

#text_replace_selected_with(_text_for_replace = '') ⇒ Object


2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
# File 'ext/ae-editor/ae-editor.rb', line 2905

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


2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
# File 'ext/ae-editor/ae-editor.rb', line 2919

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


3433
3434
3435
3436
3437
# File 'ext/ae-editor/ae-editor.rb', line 3433

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

#text_selectedObject


2896
2897
2898
2899
2900
2901
2902
2903
# File 'ext/ae-editor/ae-editor.rb', line 2896

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


2892
2893
2894
# File 'ext/ae-editor/ae-editor.rb', line 2892

def text_value
  return @text.value
end

#text_value_linesObject


3057
3058
3059
3060
3061
3062
3063
# File 'ext/ae-editor/ae-editor.rb', line 3057

def text_value_lines
  if String.method_defined?(:lines)
    return @text.value.lines
  else
    return @text.value
  end
end

#toggle_breakpoint(_index = nil) ⇒ Object


2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
# File 'ext/ae-editor/ae-editor.rb', line 2347

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


2873
2874
2875
2876
# File 'ext/ae-editor/ae-editor.rb', line 2873

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


3553
3554
3555
3556
# File 'ext/ae-editor/ae-editor.rb', line 3553

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

#visible_line_beginObject


3208
3209
3210
3211
3212
# File 'ext/ae-editor/ae-editor.rb', line 3208

def visible_line_begin
  line_begin_index = @text.index('@0,0')
  line_begin = line_begin_index.split('.')[0].to_i
  line_begin
end

#visible_line_endObject


3214
3215
3216
3217
# File 'ext/ae-editor/ae-editor.rb', line 3214

def visible_line_end
  line_end = @text.index('@0,'+TkWinfo.height(@text).to_s).split('.')[0].to_i + 1
  line_end
end

#visible_linesObject


3219
3220
3221
# File 'ext/ae-editor/ae-editor.rb', line 3219

def visible_lines
  visible_line_end - visible_line_begin
end

#vscroll(mode) ⇒ Object

vertical scrollbar : ON/OFF


2945
2946
2947
2948
2949
2950
2951
2952
2953
# File 'ext/ae-editor/ae-editor.rb', line 2945

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


1397
1398
1399
1400
1401
1402
1403
1404
1405
# File 'ext/ae-editor/ae-editor.rb', line 1397

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


3204
3205
3206
# File 'ext/ae-editor/ae-editor.rb', line 3204

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