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.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'ext/ae-editor/ae-editor.rb', line 36

def initialize(_controller, _page_frame)
  @controller = _controller
  @page_frame = _page_frame
  @set_mod = false
#    @fm = AGTkVSplittedFrames.new(@page_frame,150)
#    @fm1 = AGTkVSplittedFrames.new(@fm.right_frame,60)
  @font = @controller.conf('font')
  @font_bold = @controller.conf('font.bold')
  @font_metrics = TkFont.new(@font).metrics
  @font_metrics_bold = TkFont.new(@font_bold).metrics
#    initialize_text
#    initialize_text_binding
#    initialize_highlight
#    initialize_line_number
#    initialize_tree
  @highlighting = false
  @classbrowsing = false
  @find = @controller.get_find
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



33
34
35
# File 'ext/ae-editor/ae-editor.rb', line 33

def file
  @file
end

#page_frameObject (readonly)

Returns the value of attribute page_frame.



34
35
36
# File 'ext/ae-editor/ae-editor.rb', line 34

def page_frame
  @page_frame
end

#rootObject (readonly)

Returns the value of attribute root.



35
36
37
# File 'ext/ae-editor/ae-editor.rb', line 35

def root
  @root
end

#textObject (readonly)

Returns the value of attribute text.



35
36
37
# File 'ext/ae-editor/ae-editor.rb', line 35

def text
  @text
end

Instance Method Details

#build_tree(_sel = nil) ⇒ Object



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

def build_tree(_sel=nil)
  if _sel
    _label_sel = @tree_exp.itemcget(_sel,'text')
  end
  #clear tree
  @tree_exp.delete(@nodes)
  @nodes.clear
  #(re)build tree
  _txt = @text.get('1.0','end')
  @root = build_tree_from_source(_txt)
  @selected = nil
  build_tree_from_node(@root, _label_sel)
  if @selected
    @tree_exp.selection_add(@selected.rif)
  end
end

#build_tree_from_node(_node, _label_match = nil) ⇒ Object



671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
# File 'ext/ae-editor/ae-editor.rb', line 671

def build_tree_from_node(_node, _label_match=nil)
  _sorted_sons = _node.sons.sort
  for inode in 0.._sorted_sons.length - 1
    _son = _sorted_sons[inode]
    if _son.kind == 'KClass'
      _window = TkLabel.new(@fm.left_frame){
        image  TkPhotoImage.new('dat' => TREE_NODE_CLASS_GIF)
        background($arcadia['conf']['editor.explorer_panel.tree.color.background'])
      }
    elsif _son.kind == 'KModule'
      _window = TkLabel.new(@fm.left_frame){
        image  TkPhotoImage.new('dat' => TREE_NODE_MODULE_GIF)
        background($arcadia['conf']['editor.explorer_panel.tree.color.background'])
      }
    elsif _son.kind == 'KDef'
      _window = TkLabel.new(@fm.left_frame){
        image  TkPhotoImage.new('dat' => TREE_NODE_DEF_GIF)
        background($arcadia['conf']['editor.explorer_panel.tree.color.background'])
      }
    elsif _son.kind == 'KDefClass'
      _window = TkLabel.new(@fm.left_frame){
        image  TkPhotoImage.new('dat' => TREE_NODE_DEFCLASS_GIF)
        background($arcadia['conf']['editor.explorer_panel.tree.color.background'])
      }
    end
    @tree_exp.insert('end', _son.parent.rif ,_son.rif, {
      'text' =>  _son.label ,
      'helptext' => _son.helptext,
      'font'=>$arcadia['conf']['editor.explorer_panel.tree.font'],
      'window'=> _window
    }
    )
    @nodes << _son.rif
    if (_label_match) && (_label_match.strip == _son.label.strip)
      @selected = _son
    end
    build_tree_from_node(_son, _label_match)
  end
end

#build_tree_from_source(_source) ⇒ Object



588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# File 'ext/ae-editor/ae-editor.rb', line 588

def build_tree_from_source(_source)
  _row = 1
  _liv = 0
  _livs = Array.new
  root = TreeNode.new(nil, 'KRoot'){|_node|
    _node.rif= 'root'
    _node.label=''
  }
  _livs[_liv]=root
  _source.each_line{|line|
    line = "\s"+line.split("#")[0]+"\s"
    m = /[\s\n\t\;]+(module|class|def|if|unless|begin|case|for|while|do)[\s\n\t\;]+/.match(line)
    if m
      index = m.post_match.strip.length - 1
      if m.post_match.strip[index,index]=='{'
        _row = _row +1
        next
      end
      _liv>=0? _liv = _liv + 1:_liv=1
      _pliv = _liv
      _parent = nil
      while (_parent == nil && _pliv>=0)
        _pliv = _pliv -1
        _parent = _livs[_pliv]
      end
      if _parent
        _helptext = m.post_match.strip
        _label = _helptext.split('<')[0]
        if _label == nil || _label.strip.length==0
          _label = _helptext
        end
        if (m[0].strip[0..4] == "class" && m.pre_match.strip.length==0)
          _kind = 'KClass'
        elsif (m[0].strip[0..4] == "class" && m.pre_match.strip.length>0)
          _row = _row +1
          _liv = _liv - 1
          next
        elsif (m[0].strip[0..5] == "module" && m.pre_match.strip.length==0)
          _kind = 'KModule'
        elsif (m[0].strip[0..5] == "module" && m.pre_match.strip.length>0)
          _row = _row +1
          _liv = _liv - 1
          next
        elsif ((m[0].strip[0..4] == "begin")||(m[0].strip[0..3] == "case") ||(m[0].strip[0..4] == "while") || (m[0].strip[0..2] == "for") || (m[0].strip[0..1] == "do") || ((m[0].strip[0..1] == "if" || m[0].strip[0..5] == "unless") && m.pre_match.strip.length==0))
          _row = _row +1
          next
        elsif ((m[0].strip[0..1] == "if" || m[0].strip[0..5] == "unless") && m.pre_match.strip.length>0)
          _row = _row +1
          _liv = _liv - 1
          next
        elsif (m[0].strip[0..2] == "def" && m.pre_match.strip.length==0)
          _kind = 'KDef'
          if _label.include?(_parent.label + '.')
            _kind = 'KDefClass'
          end
#          elsif (m[0].strip[0..10] == "attr_reader" && m.pre_match.strip.length==0)
#            _kind = 'KAttr_reader'
#            _liv = _liv - 1
#            _row = _row +1
        end

        @nodes << _row.to_s
        TreeNode.new(_parent, _kind){|_node|
          _node.label = _label
          _node.helptext = _helptext
          _node.rif = _row.to_s
          _livs[_pliv + 1]=_node
        }
      else
        _row = _row +1
        _liv = _liv - 1
        next
      end
    end
    m_end = /[\s\n\t\;]+end[\s\n\t\;]+/.match(line)
    if m_end
      _liv = _liv - 1
    end
    _row = _row +1
  }
  return root
end

#check_file_last_access_timeObject



994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
# File 'ext/ae-editor/ae-editor.rb', line 994

def check_file_last_access_time
  if @file && @file_last_access_time
  
    ftime = File.mtime(@file)
    if @file_last_access_time != ftime
      msg = 'File "'+@file+'" is changed! Reload?'
         if Tk.messageBox('icon' => 'error', 'type' => 'yesno',
           'title' => '(Arcadia) Libs', 'parent' => @text,
           'message' => msg) == 'yes'
            @text.delete('1.0','end')
					load_file(@file)
			  else
			    @file_last_access_time = ftime
         end
    end
  end
end

#do_line_updateObject



876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
# File 'ext/ae-editor/ae-editor.rb', line 876

def do_line_update
  #renum in @text_line_num the portion of visibled screen  of @text
  if @text_line_num
    incr = 1 + (@font_metrics[2][1]+@font_metrics_bold[2][1]) / 4
    line_begin = @text.index('@0,0').split('.')[0].to_i
    line_end = @text.index('@0,'+TkWinfo.height(@text).to_s).split('.')[0].to_i + 1
    # breakpoint
    b = @controller.breakpoint_lines_on_file(@file)
    @text_line_num.delete('1.0','end')
    for j in line_begin...line_end
      nline = j.to_s.rjust(6)
      _index = @text_line_num.index('end')
      if @hightliting && @is_line_bold[j]
        @text_line_num.insert('end', nline+"\n",'bold_case')
      else
        @text_line_num.insert('end', nline+"\n")
      end
      if b.include?(j.to_s)
        @text_line_num.tag_add('breakpoint',_index+' -1 lines',_index+' -1 lines + 1 chars')
      end
    end
    
    if @highlighting
      _zone_begin = ((line_begin) / @highlight_zone_length).to_i + 1
      _zone_end = ((line_end) / @highlight_zone_length).to_i + 1

      (_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
  end
end

#do_tag_configure(_name) ⇒ Object



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'ext/ae-editor/ae-editor.rb', line 463

def do_tag_configure(_name)
  h = Hash.new
  if $arcadia['conf']['editor.hightlight.'+_name+'.color.foreground']
    h['foreground']=$arcadia['conf']['editor.hightlight.'+_name+'.color.foreground']
  end
  if $arcadia['conf']['editor.hightlight.'+_name+'.color.background']
    h['background']=$arcadia['conf']['editor.hightlight.'+_name+'.color.background']
  end
  if $arcadia['conf']['editor.hightlight.'+_name+'.style']== 'bold'
    h['font']=@font_bold
    @is_tag_bold[_name]= true
  end
  if $arcadia['conf']['editor.hightlight.'+_name+'.relief']
    h['relief']=$arcadia['conf']['editor.hightlight.'+_name+'.relief']
  end
  if $arcadia['conf']['editor.hightlight.'+_name+'.borderwidth']
    h['borderwidth']=$arcadia['conf']['editor.hightlight.'+_name+'.borderwidth']
  end
  @text.tag_configure(_name, h)
end

#file_extension(_filename = nil) ⇒ Object



1030
1031
1032
1033
1034
1035
# File 'ext/ae-editor/ae-editor.rb', line 1030

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

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



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

def find_and_set_tag(_re, _row, _txt, _tag, _tag_rem = nil)
  m = _re.match(_txt)
  _end = 0
  if m && @is_tag_bold[_tag]
    @is_line_bold[_row]=true
  end
  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)
    if _tag_rem
      _tag_rem.each {|value|
        @text.tag_remove(value,_ibegin, _iend)
      }
    end
    @text.tag_add(_tag,_ibegin, _iend)
    m = _re.match(_txt)
  end
end

#highlight_zone(_zone) ⇒ Object



915
916
917
918
919
920
921
922
923
924
# File 'ext/ae-editor/ae-editor.rb', line 915

def highlight_zone(_zone)
  if !@highlight_zone[_zone]
    _b = @highlight_zone_length*(_zone - 1) 
    _e = @highlight_zone_length*(_zone) + 1
    for j in _b..._e
      rehighlightline(j)
    end
    @highlight_zone[_zone] = true
  end
end

#highlightline(_row, _line, _check_mod = false) ⇒ Object



822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
# File 'ext/ae-editor/ae-editor.rb', line 822

def highlightline(_row, _line, _check_mod = false)
  if _check_mod && modified?
    set_modify
  end
  _txt = _line
  _end = 0

  #if line is a comment
  m_c = /#/.match(_txt)
  if m_c then
    _ibegin = _row.to_s+'.'+(m_c.begin(0)).to_s
    _iend = _row.to_s+'.'+(_line.length - 1).to_s
    @text.tag_add('comment',_ibegin, _iend)
    _txt = m_c.pre_match
  end
  arem = Array.new
  if _txt.strip.length > 0
    find_and_set_tag(@re_number, _row, _txt, 'number')
    arem << 'number'
    find_and_set_tag(@re_method_name, _row, _txt, 'method_name',arem)
    arem << 'method_name'
    find_and_set_tag(@re_class_name, _row, _txt, 'class_name',arem)
    arem << 'class_name'
    find_and_set_tag(@re_module_name, _row, _txt, 'module_name',arem)
    arem << 'module_name'
    find_and_set_tag(@re_keyword, _row, _txt, 'keyword',arem)
    arem << 'keyword'
    find_and_set_tag(@re_instance_variable, _row, _txt, 'instance_variable',arem)
    arem << 'instance_variable'
    find_and_set_tag(@re_operator, _row, _txt, 'operator')
    arem << 'operator'
    find_and_set_tag(@re_string, _row, _txt, 'string', arem)
  end
end

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

horizontal scrollbar : ON/OFF



748
749
750
751
752
753
754
755
756
757
758
# File 'ext/ae-editor/ae-editor.rb', line 748

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

#init_editing(_ext = 'rb') ⇒ Object



1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
# File 'ext/ae-editor/ae-editor.rb', line 1012

def init_editing(_ext='rb')
  case _ext
    when 'rb'
      @fm = AGTkVSplittedFrames.new(@page_frame,150)
   			 @fm1 = AGTkVSplittedFrames.new(@fm.right_frame,60)
       initialize_text(@fm1.right_frame)
    		initialize_text_binding
	    initialize_highlight
	    initialize_line_number(@fm1.left_frame)
	    initialize_tree(@fm.left_frame)
    else
   			 @fm1 = AGTkVSplittedFrames.new(@page_frame,60)
       initialize_text(@fm1.right_frame)
    		initialize_text_binding
	    initialize_line_number(@fm1.left_frame)
  end
end

#initialize_highlightObject



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'ext/ae-editor/ae-editor.rb', line 413

def initialize_highlight
  @highlighting = true
  @highlight_zone = Hash.new;
#    @highlight_zone_length = 45;
  @highlight_zone_length = 8;
  @last_line_begin = 0
  @last_line_end = 0
  @last_zone_begin=0;
  @last_zone_end=0;
  @is_line_bold = Hash.new
  @is_tag_bold = Hash.new

  @keyword = ['__FILE__', 'and', 'def', 'end', 'in', 'or', 'self', 'unless',
    '__LINE__', 'begin', 'defined?', 'ensure', 'module', 'redo', 'super', 'until',
    'BEGIN', 'break', 'do', 'false', 'next', 'rescue', 'then', 'when',
    'END', 'case', 'else', 'for', 'nil', 'retry', 'true', 'while',
  'alias', 'class', 'elsif', 'if', 'not', 'return', 'undef', 'yield','require']
  _re_string = ''
  @keyword.each{|word|
    if _re_string.length > 0
      _re_string << '|'
    end
    if ['class','module','def'].include?(word)
      _re_string << '([\s]*'+word+'[\s])'
    else
      _re_string << '\b('+word+')([.,+\(\s])'
    end
  }
  @re_keyword = Regexp::new(_re_string)
  @re_instance_variable = /([\s]*@)[A-Za-z0-9_]*/
  @re_string = /'([\/A-Za-z0-9_@+\-!?=<>\[\]\{\}\(\).\s]*)'|"([\/A-Za-z0-9_@+\-!?=<>\[\]\{\}\(\).\s]*)"/
  @re_number = /\d/
  @re_operator = /[\(\)\[\]\(\)\{\}.:;,=><|]/
  @re_method_name = /(def[\s][\s]*)[A-Za-z0-9_]*/
  @re_class_name = /(class[\s][\s]*)[A-Za-z0-9_]*/
  @re_module_name = /(module[\s][\s]*)[A-Za-z0-9_]*/
  do_tag_configure('keyword')
  do_tag_configure('method_name')
  do_tag_configure('instance_variable')
  do_tag_configure('class_name')
  do_tag_configure('module_name')
  do_tag_configure('comment')
  do_tag_configure('string')
  do_tag_configure('number')
  do_tag_configure('sel')
  do_tag_configure('selected')
  do_tag_configure('operator')

end

#initialize_line_number(_frame) ⇒ Object



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'ext/ae-editor/ae-editor.rb', line 371

def initialize_line_number(_frame)
  @text_line_num = TkText.new(_frame){
    wrap  'none'
    relief 'flat'
    undo false
    takefocus 0
    insertofftime 0
    exportselection true
    autoseparators true
    background $arcadia['conf']['editor.line_number_panel.color.background']
    foreground $arcadia['conf']['editor.line_number_panel.color.foreground']
    place(
      'x'=>0,
      'y'=>0,
      'relheight'=>1,
      'relwidth'=>1,
      'bordermode'=>'outside'
    )
  }
  delta = @font_metrics_bold[2][1]-@font_metrics[2][1]
  @text_line_num.tag_configure('bold_case', 'spacing1'=>delta)
  @text_line_num.tag_configure('breakpoint', 'background'=>'red','borderwidth'=>1, 'relief'=>'raised')
  @text_line_num.bind("Double-ButtonPress-1", proc{
    _index = @text_line_num.index('insert')
    _line = @text_line_num.get(_index+' linestart',_index+' lineend').strip
    if @controller.breakpoint_lines_on_file(@file).include?(_line)
      @text_line_num.tag_remove('breakpoint',_index+' linestart',_index+' lineend')
      @controller.breakpoint_del(@file, _line)
    else
      @text_line_num.tag_add('breakpoint',_index+' linestart',_index+' linestart + 1 chars')
      @controller.breakpoint_add(@file, _line)
    end
  })
  @text_line_num.configure('font', @font);
  @text_line_num.tag_configure('line_num',
    'foreground' => '#FFFFFF',
    'background' =>'#0000a0',
    'borderwidth'=>2,
    'relief'=>'raised'
  )
end

#initialize_text(_frame) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'ext/ae-editor/ae-editor.rb', line 110

def initialize_text(_frame)
   @v_scroll = TkScrollbar.new(_frame,
     'orient'=>'vertical',
     'relief'=>'flat'
   ).pack('side' => 'right', 'fill' => 'y')
   @text = TkText.new(@fm1.right_frame){|j|
     wrap  'none'
     relief 'flat'
     undo true
     insertofftime 200
     insertontime 200
     insertbackground $arcadia['conf']['editor.color.insertbackground']
     background $arcadia['conf']['editor.color.background']
     foreground $arcadia['conf']['editor.color.foreground']
     insertwidth 3
     exportselection true
     autoseparators true
     padx 0
     tabs $arcadia['conf']['editor.tab-chars']
     place(
       'x'=>0,
       'y'=>0,
       'width' => -15,
       'relheight'=>1,
       'relwidth'=>1,
       'bordermode'=>'outside'
     )
   }
   @text.configure('font', @font);

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

#initialize_text_bindingObject



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'ext/ae-editor/ae-editor.rb', line 147

def initialize_text_binding
   @v_scroll.command(proc{|*args|
     @text.yview *args
   })
   @text.yscrollcommand(proc{|first,last| @v_scroll.set(first,last)
     self.do_line_update()
   })
   @text.tag_bind('selected', 'Enter', proc{@text.tag_remove('selected','1.0','end')})

   @text.bind("Enter", proc{check_file_last_access_time})
   @text.bind("ButtonPress-1", proc{
     _code = $arcadia['palette'].give_me_code
     @text.insert('insert', _code) if _code
   })

   @text.bind("Control-KeyPress"){|e|
     case e.keysym
     when 'space'
       line, col = @text.index('insert').split('.')
       _file = @file+'~~'
       f = File.new(@file+'~~', "w")
       begin
         if f
           f.syswrite(text_value)
         end
       ensure
         f.close unless f.nil?
       end
         
         

       EditorContract.instance.complete_code(EditorContract::TEditorObj.new(self, 'file'=>_file, 'line'=>line.to_s, 'col'=>col.to_s))
     when 'z'
       _b = @text.index('insert').split('.')[0].to_i
       @text.edit_undo
       _e = @text.index('insert').split('.')[0].to_i
       if @highlighting
         for j in _b..._e
           rehighlightline(j)
         end
       end
       break
     when 'c'
       @text.text_copy
       break
     when 'x'
       @text.text_cut
       break
     when 'v'
       _b = @text.index('insert').split('.')[0].to_i
       @text.text_paste
       _e = @text.index('insert').split('.')[0].to_i
       if @highlighting
         for j in _b..._e
           rehighlightline(j)
         end
       end
       break
     end
     case e.keysym
     when 's'
       save
     when 'f'
       _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
     when 'egrave'
       @text.insert('insert',"{")
     when 'plus'
       @text.insert('insert',"}")
     end
   }

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

       for _row in _row_begin..._row_end
         @text.insert(_row.to_s+'.0',"\s\s")
       end
     when 'U'
       _r = @text.tag_ranges('sel')
       _row_begin = _r[0][0].split('.')[0].to_i
       _row_end = _r[_r.length - 1][1].split('.')[0].to_i

       for _row in _row_begin..._row_end
         if @text.get(_row.to_s+'.0',_row.to_s+'.2') == "\s\s"
           @text.delete(_row.to_s+'.0',_row.to_s+'.2')
         end
       end
     when 'C'
       _r = @text.tag_ranges('sel')
       _row_begin = _r[0][0].split('.')[0].to_i
       _row_end = _r[_r.length - 1][1].split('.')[0].to_i

       for _row in _row_begin..._row_end
         if @text.get(_row.to_s+'.0',_row.to_s+'.1') == "#"
           @text.delete(_row.to_s+'.0',_row.to_s+'.1')
         else
           @text.insert(_row.to_s+'.0',"#")
         end
         rehighlightline(_row) if @highlighting
       end

     end
   }
   @text.bind("KeyPress"){|e|
     case e.keysym
     when 'Return'
     when 'BackSpace'
       _index = @text.index('insert')
       _row, _col = _index.split('.')
       rehighlightline(_row.to_i) if @highlighting
     when 'Delete'
       _index = @text.index('insert')
       _row, _col = _index.split('.')
       rehighlightline(_row.to_i) if @highlighting
     when 'F5'
       save
       $arcadia['shell'].run(@file.to_s)
     when 'F3'
       @find.do_find_next
     when 'Tab'
       _r = @text.tag_ranges('sel')
       if _r && _r[0]
         _row_begin = _r[0][0].split('.')[0].to_i
         _row_end = _r[_r.length - 1][1].split('.')[0].to_i
         n_space = $arcadia['conf']['editor.tab-replace-width-space'].to_i
         if n_space > 0
           suf = "\s"*n_space
         else
           suf = "\t"
         end
         for _row in _row_begin..._row_end
           @text.insert(_row.to_s+'.0', suf)
         end
       break
       end
     end
   }

   @text.bind("Shift-KeyPress"){|e|
     case e.keysym
     when 'Tab'
       _r = @text.tag_ranges('sel')
       if _r && _r[0]
         _row_begin = _r[0][0].split('.')[0].to_i
         _row_end = _r[_r.length - 1][1].split('.')[0].to_i
         
         n_space = $arcadia['conf']['editor.tab-replace-width-space'].to_i
         if n_space > 0
           suf = "\s"*n_space
         else
           suf = "\t"
           n_space = 1
         end
         for _row in _row_begin..._row_end
           if @text.get(_row.to_s+'.0',_row.to_s+'.'+n_space.to_s) == suf
             @text.delete(_row.to_s+'.0',_row.to_s+'.'+n_space.to_s)
           end
         end
         break
       end
     end
   }

   @text.bind("KeyRelease"){|e|
     case e.keysym
       when 'Control_L','Return', 'Control_V', 'BackSpace', 'Delete'
         if modified?
           set_modify
         else
           reset_modify
         end
         do_line_update
       when 'Right','Left','Down', 'Up'
         # do nil
       else
         if modified?
           if !@set_mod
             set_modify
           end
         else
           reset_modify
         end
     end
     case e.keysym
     when 'Return'
       _index = @text.index('insert')
       _row, _col = _index.split('.')
       _txt = @text.get((_row.to_i-1).to_s+'.0',_index)
       if _txt.length > 0
         m = /\s*/.match(_txt)
         if m
           if (m[0] != "\n")
             _sm = m[0]
             _sm = _sm.sub(/\n/,"")
             @text.insert('insert',_sm)
           end
         end
       end
       if _row.to_i + 1  ==  @text.index('end').split('.')[0].to_i
         do_line_update
       end
     else 
       if @highlighting && /\w/.match(e.keysym)
         rehighlightline(@text.index('insert').split('.')[0].to_i)
       end
     end
   }


end

#initialize_tree(_frame) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'ext/ae-editor/ae-editor.rb', line 56

def initialize_tree(_frame)
  @classbrowsing = true 
  @nb = Tk::BWidget::NoteBook.new(_frame){
    tabbevelsize 0
    internalborderwidth 0
    activeforeground 'red'
    activebackground 'yellow'
    borderwidth 1
    side $arcadia['conf']['editor.tabs.side']
    font $arcadia['conf']['editor.tabs.font']
    pack('fill'=>'both', :padx=>0, :pady=>0, :expand => 'yes')
  }
  @nb_tab_exp = @nb.insert('end','exp' ,'text'=>'Source Tree' )
  @nb.raise('exp')
  _tree_goto = proc{|_self|
    _line = _self.selection_get[0]
    _index =_line.to_s+'.0'
    _hinner_text = @tree_exp.itemcget(_line,'text').strip
    _editor_line = @text.get(_index, _index+ '  lineend')
    if !_editor_line.include?(_hinner_text)
      MsgContract.instance.out_simple(self, "... rebuild tree \n")
      if @tree_thread && @tree_thread.alive?
        @tree_thread.exit
      end
      @tree_thread = Thread.new{
        build_tree(_line)
        Tk.update
      }
      _line = _self.selection_get[0]
      _index =_line.to_s+'.0'
    end
    @text.see(_index)
    @text.tag_remove('selected','1.0','end')
    @text.tag_add('selected',_line.to_s+'.0',(_line+1).to_s+'.0')
  }
  @tree_exp = Tk::BWidget::Tree.new(@nb_tab_exp){
    background '#FFFFFF'
    relief 'flat'
    showlines false
    deltay 18
    dragenabled true
    selectcommand proc{ _tree_goto.call(self) } 
    place('relwidth' => 1,'relx' => 0,'x' => '0','y' => '0','relheight' => '1','rely' => 0,'height' => 1,'bordermode' => 'inside','width' => '50')
  }
  @nodes = Array.new
  _c_explo = proc{|*args| @tree_exp.yview(*args)}
  _s_explo = TkScrollbar.new(@nb_tab_exp){|s|
    width 8
    command _c_explo
  }.pack('side'=>'right', 'fill'=>'y')
  @tree_exp.yscrollcommand proc{|first,last| _s_explo.set first,last}

end

#insert_popup_menu_item(_where, *args) ⇒ Object



728
729
730
# File 'ext/ae-editor/ae-editor.rb', line 728

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

#load_file(_filename = nil) ⇒ Object



1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
# File 'ext/ae-editor/ae-editor.rb', line 1037

def load_file(_filename = nil)
  #if filename is nil then open a new tab
  @file = _filename
  if _filename
    #init_editing(file_extension(_filename))
    File::open(_filename,'r'){ |file|
      @text.insert('end',file.readlines.collect!{| line | line.chomp+"\n" }.to_s)
    }
  end
  reset
  refresh
end

#mark_debug(_index) ⇒ Object



577
578
579
580
# File 'ext/ae-editor/ae-editor.rb', line 577

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



582
583
584
585
# File 'ext/ae-editor/ae-editor.rb', line 582

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

#modified?Boolean

def find_next_and_set_tag(_re, _row, _col, _txt, _tag)

  m = _re.match(_txt)
  if m
    _txt = m.post_match
    _ibegin = _row.to_s+'.'+(m.begin(0)+_end).to_s
    _col = m.end(0)+ _col
    _iend = _row.to_s+'.'+(_col.to_s)
    @text.tag_add(_tag,_ibegin, _iend)
  end
end

Returns:

  • (Boolean)


805
806
807
# File 'ext/ae-editor/ae-editor.rb', line 805

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

#pop_up_menuObject



484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'ext/ae-editor/ae-editor.rb', line 484

def pop_up_menu
  @pop_up = TkMenu.new(
    :parent=>@text,
    :tearoff=>1,
    :title => 'Menu'
  )
  @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',
#      :command,
#      :label=>'New',
#      :hidemargin => false,
#      :command=> proc{@controller.open_buffer()}
#    )
#    @pop_up.insert('end',
#      :command,
#      :label=>'Open',
#      :hidemargin => false,
#      :command=> proc{ @controller.open_file(Tk.getOpenFile)}
#    )
#    @pop_up.insert('end',
#      :command,
#      :label=>'Close',
#      :hidemargin => false,
#      :command=> proc{
#        @controller.close_editor(self)
#      }
#    )

  @pop_up.insert('end',
    :command,
    :label=>'Color',
    :hidemargin => false,
    :command=> proc{
      @text.insert('insert',Tk.chooseColor)
    }
  )
  @pop_up.insert('end',
    :command,
    :label=>'Font',
    :hidemargin => false,
    :command=> proc{
      @text.insert('insert', $arcadia['action.get.font'].call)
    }
  )
#    @pop_up.insert('end',
#      :command,
#      :label=>'Eval Toplevel',
#      :hidemargin => false,
#      :command=> proc{
#        _r = @text.tag_ranges('sel')
#        _ibegin = _r[_r.length - 1][0]
#        _iend = _r[_r.length - 1][1]
#        _cod = @text.get(_ibegin, _iend)
#        Revparsel.new(_cod, @file)
#        @text.tag_add('eval',_ibegin, _iend)
#        _reset = proc{
#          _message = 'Replace code with new '+$arcadia['objic'].active.agobj_start.i_name+'?'
#          _r = TkDialog2.new('message'=>_message, 'buttons'=>['Yes','No','Cancel']).show()
#          if _r == '0'
#            @text.tag_remove('eval',_ibegin, _iend)
#            @text.delete(_ibegin, _iend)
#            text_insert(_ibegin,$arcadia['objic'].active.objects2code.to_s){_edit_reset=false}
#            @text.tag_remove('sel','1.0', 'end')
#            $arcadia['objic'].del($arcadia['objic'].active)
#          end
#        }
#        @text.tag_bind('eval',"Double-ButtonPress-1",_reset)
#      }
#    )
  @text.bind("Button-3",
    proc{|x,y|
      _x = TkWinfo.pointerx(@text)
      _y = TkWinfo.pointery(@text)
      @pop_up.popup(_x,_y)
    },
  "%x %y")
end

#refreshObject



1056
1057
1058
# File 'ext/ae-editor/ae-editor.rb', line 1056

def refresh
  build_tree if @classbrowsing
end

#rehighlightline(_row) ⇒ Object



857
858
859
860
861
862
863
864
865
866
867
868
# File 'ext/ae-editor/ae-editor.rb', line 857

def rehighlightline(_row)
  _ibegin = _row.to_s+'.0'
  _iend = (_row+1).to_s+'.0'
  @text.tag_remove('keyword',_ibegin, _iend)
  @text.tag_remove('comment',_ibegin, _iend)
  @text.tag_remove('string',_ibegin, _iend)
  @text.tag_remove('number',_ibegin, _iend)
  @text.tag_remove('operator',_ibegin, _iend)
  @text.tag_remove('capitalize',_ibegin, _iend)
  _line = @text.get(_ibegin, _iend)
  highlightline(_row, _line)
end

#resetObject



1050
1051
1052
1053
1054
# File 'ext/ae-editor/ae-editor.rb', line 1050

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

#reset_modifyObject



816
817
818
819
820
# File 'ext/ae-editor/ae-editor.rb', line 816

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

#row(_index = 'insert') ⇒ Object



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

def row(_index='insert')
  _row = @text.index(_index).split('.')[0].to_i
  print "def row(_index='insert')",_row.to_s,"\n"
  return _row
end

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



760
761
762
763
764
765
766
767
768
769
770
771
# File 'ext/ae-editor/ae-editor.rb', line 760

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

#saveObject



968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
# File 'ext/ae-editor/ae-editor.rb', line 968

def save
  if !@file
    save_as
  else
    f = File.new(@file, "w")
    begin
      if f
        f.syswrite(text_value)
        @buffer = text_value
        reset_modify
      end
    ensure
      f.close unless f.nil?
    end
  end
end

#save_asObject



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

def save_as
  @file = Tk.getSaveFile
  if @file
    save
    @controller.change_file_name(@page_frame, @file)
  end
end

#set_modifyObject



809
810
811
812
813
814
# File 'ext/ae-editor/ae-editor.rb', line 809

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

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



936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
# File 'ext/ae-editor/ae-editor.rb', line 936

def text_insert(index, chars, *tags, &b)
  if block_given?
    instance_eval(&b)
  end
  _index = @text.index(index)
  _row, _col  = _index.split('.')
  _row = (_row.to_i - 1).to_s
  chars.each_line {|line|
    @text.insert(_row+'.0', line, *tags)
    if !defined?(m_begin)||(m_begin == nil)
      m_begin = /=begin/.match(line)
    end
    if @highlighting
      if m_begin &&(m_begin.begin(0)==0)
        _ibegin = _row+'.0'
        _iend = _row+'.'+(line.length - 1).to_s
        @text.tag_add('comment',_ibegin, _iend)
      else
        highlightline(_row.to_i, line, false)
      end
    end
    _row = (_row.to_i + 1).to_s
  }
  if defined?(_edit_reset)
    if _edit_reset
      @text.edit_reset
    end
  else
    @text.edit_reset
  end
end

#text_insert_indexObject



932
933
934
# File 'ext/ae-editor/ae-editor.rb', line 932

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

#text_see(_index = nil) ⇒ Object



926
927
928
929
930
# File 'ext/ae-editor/ae-editor.rb', line 926

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

#text_valueObject



732
733
734
# File 'ext/ae-editor/ae-editor.rb', line 732

def text_value
  return @text.value
end

#unmark_debug(_index) ⇒ Object



573
574
575
# File 'ext/ae-editor/ae-editor.rb', line 573

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

#vscroll(mode) ⇒ Object

vertical scrollbar : ON/OFF



737
738
739
740
741
742
743
744
745
# File 'ext/ae-editor/ae-editor.rb', line 737

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