Class: AgMultiEditor

Inherits:
ArcadiaExt show all
Includes:
Autils, Configurable
Defined in:
ext/ae-editor/ae-editor.rb

Instance Attribute Summary collapse

Attributes inherited from ArcadiaExt

#arcadia

Instance Method Summary collapse

Methods included from Configurable

#properties_file2hash, properties_group, #resolve_link, #resolve_properties_link

Methods included from Autils

#full_in_path_command, #is_windows?

Methods inherited from ArcadiaExt

#conf, #conf_array, #exec, #float_frame, #frame, #frame_def_visible?, #frame_visible?, #initialize, #maximize, #maximized?, #resize

Constructor Details

This class inherits a constructor from ArcadiaExt

Instance Attribute Details

#breakpointsObject (readonly)

Returns the value of attribute breakpoints.



3054
3055
3056
# File 'ext/ae-editor/ae-editor.rb', line 3054

def breakpoints
  @breakpoints
end

#outline_barObject (readonly)

Returns the value of attribute outline_bar.



3056
3057
3058
# File 'ext/ae-editor/ae-editor.rb', line 3056

def outline_bar
  @outline_bar
end

#splitted_frameObject (readonly)

Returns the value of attribute splitted_frame.



3055
3056
3057
# File 'ext/ae-editor/ae-editor.rb', line 3055

def splitted_frame
  @splitted_frame
end

Instance Method Details

#accept_complete_codeObject



3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
# File 'ext/ae-editor/ae-editor.rb', line 3926

def accept_complete_code
  @ok_complete = true
  if !defined?(@ok_complete)
  
msg =<<EOS
"Complete code" is actually based on rcodetools 
that exec code for retreave candidades. 
So it can be dangerous for example if you write system call. 
Do you want to activate it?
EOS
    @ok_complete = Arcadia.dialog(self, 
      'level'=>'warning',
      'type'=>'yes_no', 
      'title' => '(Arcadia) Complete code', 
      'msg'=>msg.upcase)=='yes'
    
  end
  return @ok_complete
end

#bookmark_add(_file, _index) ⇒ Object



3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
# File 'ext/ae-editor/ae-editor.rb', line 3545

def bookmark_add(_file, _index)
  if @bookmarks == nil
    @bookmarks = Array.new
    @bookmarks_index = - 1 
  else
    _cur_file, _cur_index = @bookmarks[@bookmarks_index]
    if _cur_file == _file && _cur_index == _index
      #@arcadia.outln('uguale ----> '+_file+':'+_index)
      return 
    end
    @bookmarks = @bookmarks[0..@bookmarks_index]
  end
  @bookmarks << [_file, _index]
  @bookmarks_index = @bookmarks.length - 1
  #@arcadia.outln('add ----> '+_file+':'+_index)
end

#bookmark_clearObject



3562
3563
3564
3565
# File 'ext/ae-editor/ae-editor.rb', line 3562

def bookmark_clear
  @bookmarks.clear
  @bookmarks_index = - 1
end

#bookmark_move(_n = 0) ⇒ Object



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

def bookmark_move(_n=0)
  @bookmarks_index = @bookmarks_index + _n
  #Tk.messageBox('message'=>@bookmarks_index.to_s)
  _file, _index = @bookmarks[@bookmarks_index]
  _line, _col = _index.split('.') if _index
  open_file(_file, _index)
  #openfile(@bookmarks[@bookmarks_index])
end

#bookmark_nextObject



3567
3568
3569
3570
# File 'ext/ae-editor/ae-editor.rb', line 3567

def bookmark_next
  return if @bookmarks == nil || @bookmarks_index >= @bookmarks.length - 1
  bookmark_move(+1)
end

#bookmark_prevObject



3582
3583
3584
3585
# File 'ext/ae-editor/ae-editor.rb', line 3582

def bookmark_prev
  return if @bookmarks == nil || @bookmarks_index <= 0
  bookmark_move(-1)
end

#breakpoint_add(_file, _line) ⇒ Object



3483
3484
3485
# File 'ext/ae-editor/ae-editor.rb', line 3483

def breakpoint_add(_file,_line)
  Arcadia.process_event(SetBreakpointEvent.new(self, 'file'=>_file, 'row'=>_line, 'active'=>1))
end

#breakpoint_del(_file, _line) ⇒ Object



3487
3488
3489
# File 'ext/ae-editor/ae-editor.rb', line 3487

def breakpoint_del(_file,_line)
  Arcadia.process_event(UnsetBreakpointEvent.new(self, 'file'=>_file, 'row'=>_line))
end

#breakpoint_lines_on_file(_file) ⇒ Object



3491
3492
3493
3494
3495
3496
3497
3498
3499
# File 'ext/ae-editor/ae-editor.rb', line 3491

def breakpoint_lines_on_file(_file)
  result = Array.new
  @breakpoints.each{|value|
    if value[:file]==_file
      result << value[:line]
    end
  }
  return result
end

#can_close_editor?(_editor) ⇒ Boolean

Returns:

  • (Boolean)


3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
# File 'ext/ae-editor/ae-editor.rb', line 3854

def can_close_editor?(_editor)
  ret = true
  if _editor.modified?
    filename = page_name(_editor.page_frame)
    message = @main_frame.enb.itemcget(filename, 'text')+"\n modified. Save?"
    r=Arcadia.dialog(self,
        'type'=>'yes_no_cancel', 
        'level'=>'warning',
        'title'=> 'Confirm saving', 
        'msg'=>message)
    if r=="yes"
      _editor.save
      ret = !_editor.modified?
    elsif r=="cancel"
      ret = false
    end
  end
  ret
end

#change_file(_old_file, _new_file) ⇒ Object



3647
3648
3649
3650
3651
3652
3653
# File 'ext/ae-editor/ae-editor.rb', line 3647

def change_file(_old_file, _new_file)
  _tab_name=tab_file_name(_old_file)
  _tab = @main_frame.enb.get_frame(_tab_name)
  e =  @tabs_editor[_tab_name]
  e.new_file_name(_new_file) if e
  change_file_name(_tab, _new_file)
end

#change_file_name(_tab, _new_file) ⇒ Object



3655
3656
3657
3658
3659
3660
# File 'ext/ae-editor/ae-editor.rb', line 3655

def change_file_name(_tab, _new_file)
  _new_label = File.basename(_new_file)
  change_tab_title(_tab, _new_label)
  change_tab_icon(_tab, _new_label)
  @tabs_file[page_name(_tab)] = _new_file
end

#change_outline(_e, _raised = false) ⇒ Object



3701
3702
3703
3704
3705
3706
3707
3708
# File 'ext/ae-editor/ae-editor.rb', line 3701

def change_outline(_e, _raised=false)
  _raised = _raised || frame(1).raised?
  if !@batch_files && _raised
    @last_outline_e.hide_outline if @last_outline_e
    _e.show_outline
    @last_outline_e = _e
  end
end

#change_tab_icon(_tab, _new_text) ⇒ Object



3643
3644
3645
# File 'ext/ae-editor/ae-editor.rb', line 3643

def change_tab_icon(_tab, _new_text)
  @main_frame.enb.itemconfigure(page_name(_tab), 'image'=> Arcadia.file_icon(_new_text))
end

#change_tab_reset_modify(_tab) ⇒ Object



3631
3632
3633
3634
3635
3636
3637
# File 'ext/ae-editor/ae-editor.rb', line 3631

def change_tab_reset_modify(_tab)
  #_new_name = @main_frame.enb.itemcget(@tabs_name[_tab], 'text').gsub!("(...)",'')
  _new_name = @main_frame.enb.itemcget(page_name(_tab), 'text').gsub!("(...)",'')
  if _new_name
    change_tab_title(_tab, _new_name)
  end
end

#change_tab_reset_read_only(_tab) ⇒ Object



3614
3615
3616
3617
3618
3619
# File 'ext/ae-editor/ae-editor.rb', line 3614

def change_tab_reset_read_only(_tab)
  _new_name = unname_read_only(@main_frame.enb.itemcget(page_name(_tab), 'text'))
  if _new_name
    change_tab_title(_tab, _new_name)
  end
end

#change_tab_set_modify(_tab) ⇒ Object



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

def change_tab_set_modify(_tab)
  _new_name = '(...)'+@main_frame.enb.itemcget(page_name(_tab), 'text')
  change_tab_title(_tab, _new_name)
end

#change_tab_set_read_only(_tab) ⇒ Object



3609
3610
3611
3612
# File 'ext/ae-editor/ae-editor.rb', line 3609

def change_tab_set_read_only(_tab)
  _new_name = name_read_only(@main_frame.enb.itemcget(page_name(_tab), 'text'))
  change_tab_title(_tab, _new_name)
end

#change_tab_title(_tab, _new_text) ⇒ Object



3639
3640
3641
# File 'ext/ae-editor/ae-editor.rb', line 3639

def change_tab_title(_tab, _new_text)
  @main_frame.enb.itemconfigure(page_name(_tab), 'text'=> _new_text)
end

#close_all_editor(_editor, _mod = true) ⇒ Object



3846
3847
3848
3849
3850
3851
3852
# File 'ext/ae-editor/ae-editor.rb', line 3846

def close_all_editor(_editor, _mod=true)
  @batch_files = true
		@tabs_editor.values.each do |_e|
		    close_editor(_e)
		end
  @batch_files = false
end

#close_editor(_editor, _force = false) ⇒ Object



3874
3875
3876
3877
3878
3879
3880
3881
# File 'ext/ae-editor/ae-editor.rb', line 3874

def close_editor(_editor, _force=false)
  if _force || can_close_editor?(_editor)
    _editor.destroy_outline
    close_tab(_editor.page_frame)
  else
    return
  end
end

#close_file(_filename) ⇒ Object



3913
3914
3915
3916
# File 'ext/ae-editor/ae-editor.rb', line 3913

def close_file(_filename)
  _e = @tabs_editor[tab_name(_filename)]
  close_editor(_e) if _e
end

#close_others_editor(_editor, _mod = true) ⇒ Object



3838
3839
3840
3841
3842
3843
3844
# File 'ext/ae-editor/ae-editor.rb', line 3838

def close_others_editor(_editor, _mod=true)
  @batch_files = true
		@tabs_editor.values.each do |_e|
		    close_editor(_e) if _e != _editor
		end
  @batch_files = false
end

#close_raisedObject



3473
3474
3475
3476
3477
3478
3479
3480
3481
# File 'ext/ae-editor/ae-editor.rb', line 3473

def close_raised
  _e = @tabs_editor[@main_frame.enb.raise]
  close_editor(_e) if _e

  #_page = @main_frame.enb.raise
  #_editor = @tabs_editor[_page]
  #_row = _editor.text_insert_index.split('.')[0].strip.to_i
  #close_editor(_editor)
end

#close_tab(_page_frame) ⇒ Object

def close_editor(_editor, _mod=true)

  if ((_mod)&&(_editor.modified?))
    _message = @main_frame.enb.itemcget(page_name(_editor.page_frame), 'text')+"\n modified. Save?"
    _r = TkDialog2.new('message'=>_message, 'buttons'=>['Ok','No','Cancel']).show()
    if _r == 0
      _editor.save
    elsif _r == 1
      close_tab(_editor.page_frame)
    elsif _r == 2
      return
    end
  else
    close_tab(_editor.page_frame)
  end
  #EditorContract.instance.file_closed(self, 'file'=>_editor.file)
end


3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
# File 'ext/ae-editor/ae-editor.rb', line 3901

def close_tab(_page_frame)
  _name = page_name(_page_frame)
  @tabs_editor.delete(_name)
  _index = @main_frame.enb.index(_name)
  @main_frame.enb.delete(_name)
  if !@main_frame.enb.pages.empty?
    @main_frame.enb.raise(@main_frame.enb.pages[_index-1]) if TkWinfo.mapped?(@main_frame.enb)
  else
    frame.top_text('') if TkWinfo.mapped?(frame.hinner_frame)
  end
end

#create_findObject



3430
3431
3432
3433
3434
# File 'ext/ae-editor/ae-editor.rb', line 3430

def create_find
  @find = Finder.new(@arcadia.layout.root, self)
  @find.on_close=proc{@find.hide}
  @find.hide
end

#debug_beginObject



3662
3663
3664
3665
3666
3667
3668
# File 'ext/ae-editor/ae-editor.rb', line 3662

def debug_begin
  if @editors_in_debug != nil
    @editors_in_debug.clear
  else
    @editors_in_debug = Array.new
  end
end

#debug_endObject



3670
3671
3672
3673
3674
3675
3676
# File 'ext/ae-editor/ae-editor.rb', line 3670

def debug_end
  #debug_reset
  @editors_in_debug.each{|e|
    close_editor(e)
    #p "close editor #{e.file}"
  }
end

#debug_resetObject



3678
3679
3680
3681
3682
# File 'ext/ae-editor/ae-editor.rb', line 3678

def debug_reset
  if @last_index && @last_e
    @last_e.unmark_debug(@last_index)
  end
end

#do_buffer_raise(_name, _title = '...') ⇒ Object



3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
# File 'ext/ae-editor/ae-editor.rb', line 3710

def do_buffer_raise(_name, _title='...')
  _index = @main_frame.enb.index(_name)
  _new_caption = '...'
  if _index != -1
    #_name = @main_frame.enb.pages(_index)
    #_tab = get_tab_from_name(_name)
    #@main_frame.enb.raise(_name)
    _e = @tabs_editor[_name]
    change_outline(_e) if _e
    if _e && _e.file != nil
      _new_caption = _e.file
      @find.use(_e)
      _e.check_file_last_access_time
    else
      _new_caption = _title
    end
  end
  if @arcadia.layout.headed?
    frame.top_text(_new_caption)
    #@arcadia.layout.domain(@arcadia['conf'][@name+'.frame'])['root'].top_text(_new_caption)
  end
  _title = @tabs_file[_name] != nil ? File.basename(@tabs_file[_name]) :_name
  Arcadia.broadcast_event(BufferRaisedEvent.new(self,'title'=>_title, 'file'=>@tabs_file[_name]))
  #EditorContract.instance.buffer_raised(self, 'title'=>_title, 'file'=>@tabs_file[_name])
end

#editor_exist?(_filename) ⇒ Boolean

Returns:

  • (Boolean)


3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
# File 'ext/ae-editor/ae-editor.rb', line 3736

def editor_exist?(_filename)
  _basefilename = File.basename(_filename)
  #_basename = _basefilename.split('.')[0]+'_'+_basefilename.split('.')[1]
  
  _name = self.tab_file_name(_filename)
  _index = @main_frame.enb.index(_name)
  if _index == -1
    _index = @main_frame.enb.index(name_read_only(_name))
  end
  return _index != -1
end

#get_findObject



3426
3427
3428
# File 'ext/ae-editor/ae-editor.rb', line 3426

def get_find
  @find
end

#get_tab_from_name(_name = nil) ⇒ Object



3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
# File 'ext/ae-editor/ae-editor.rb', line 3588

def get_tab_from_name(_name=nil)
  return @main_frame.enb.get_frame(_name)
#    if _name
#      @tabs_name.each{
#        |key,value|
#        if value.to_s==_name.to_s
#          return key
#        end
#      }
#      return nil
#    end
end

#highlight_scanner(_ext = nil) ⇒ Object



3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
# File 'ext/ae-editor/ae-editor.rb', line 3131

def highlight_scanner(_ext=nil)
  return nil if _ext.nil?
  scanner = nil
  @highlight_scanner_hash = Hash.new if !defined?(@highlight_scanner_hash)
  lh = languages_hash(_ext)
  if lh && lh['language'] && lh['scanner']  
    if @highlight_scanner_hash[lh['language']].nil?
      case lh['scanner']
        when 'coderay'
          @highlight_scanner_hash[lh['language']]=CoderayHighlightScanner.new(lh)
        when 're'
          @highlight_scanner_hash[lh['language']]=ReHighlightScanner.new(lh)
      end
    end
    scanner = @highlight_scanner_hash[lh['language']]
  end
  scanner
end

#languages_hash(_ext = nil) ⇒ Object



3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
# File 'ext/ae-editor/ae-editor.rb', line 3150

def languages_hash(_ext=nil)
  @@langs_hash = Hash.new if !defined?(@@langs_hash)
  return nil if _ext.nil?
  if @@langs_hash[_ext].nil?
    #_ext='' if _ext.nil?
    lang_file = File.dirname(__FILE__)+'/langs/'+_ext+'.lang'
    if File.exist?(lang_file)
      @@langs_hash[_ext] = properties_file2hash(lang_file)
    elsif File.exist?(lang_file+'.bind')
      b= properties_file2hash(lang_file+'.bind')
      if b 
        if @@langs_hash[b['bind']].nil?
          lang_file_bind = File.dirname(__FILE__)+'/langs/'+b['bind']+".lang"
          if File.exist?(lang_file_bind)
            @@langs_hash[b['bind']]=properties_file2hash(lang_file_bind)
            @@langs_hash[_ext]=@@langs_hash[b['bind']]
          end
        else
          @@langs_hash[_ext]=@@langs_hash[b['bind']]
        end
      end
    end
    if @@langs_hash[_ext] && @@langs_hash[_ext]['@include'] != nil
      include_file = "#{File.dirname(__FILE__)}/langs/#{@@langs_hash[_ext]['@include']}"
      if File.exist?(include_file)
        include_hash = properties_file2hash(include_file)
        @@langs_hash[_ext] = include_hash.merge(@@langs_hash[_ext])
      end
    end 
    self.resolve_properties_link(@@langs_hash[_ext], Arcadia.instance['conf']) if @@langs_hash[_ext]
  end
  @@langs_hash[_ext]
end

#name_read_only(_name) ⇒ Object



3601
3602
3603
# File 'ext/ae-editor/ae-editor.rb', line 3601

def name_read_only(_name)
  '[READ-ONLY] '+_name
end

#on_after_build(_event) ⇒ Object



3101
3102
3103
# File 'ext/ae-editor/ae-editor.rb', line 3101

def on_after_build(_event)
  self.open_last_files
end

#on_after_debug(_event) ⇒ Object



3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
# File 'ext/ae-editor/ae-editor.rb', line 3308

def on_after_debug(_event)
  "on_after_debug #{_event}"
  case _event
    when StepDebugEvent
      if _event.command == :quit_yes 
        self.debug_end
      elsif _event.command == :quit_no 
        @last_e.mark_debug(@last_index) if @last_e
      end
#      when SetBreakpointEvent
#        if _event.active == 1
#          @breakpoints << {:file=>_event.file,:line=>_event.row}
#          _e = @tabs_editor[tab_file_name(_event.file)]
#          _e.add_tag_breakpoint(_event.row) if _e
#        end
    when UnsetBreakpointEvent
      #p "ae-editor : UnsetBreakpointEvent file : #{_event.file}"
      #p "ae-editor : UnsetBreakpointEvent _event.row : #{_event.row}"
      @breakpoints.delete_if{|b| (b[:file]==_event.file && b[:line]==_event.row)}
      _e = @tabs_editor[tab_file_name(_event.file)]
      _e.remove_tag_breakpoint(_event.row) if _e
  end
end

#on_after_focus(_event) ⇒ Object



3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
# File 'ext/ae-editor/ae-editor.rb', line 3116

def on_after_focus(_event)
  if raised && _event.focus_widget == raised.text
    if [CutTextEvent, PasteTextEvent].include?(_event.class)
      if raised.highlighting
        line_begin_index = raised.text.index('@0,0')
        line_begin = line_begin_index.split('.')[0].to_i
        line_end = raised.text.index('@0,'+TkWinfo.height(raised.text).to_s).split('.')[0].to_i + 1
        raised.rehighlightlines(line_begin,line_end,true)
      else
        raised.check_modify
      end      
    end
  end
end

#on_before_build(_event) ⇒ Object



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

def on_before_build(_event)
  @breakpoints =Array.new
  @tabs_file =Hash.new
  @tabs_editor =Hash.new
  Arcadia.attach_listener(self, BufferEvent)
  Arcadia.attach_listener(self, DebugEvent)
  Arcadia.attach_listener(self, RunRubyFileEvent)
 # Arcadia.attach_listener(self, StartDebugEvent)
  Arcadia.attach_listener(self, FocusEvent)
end

#on_before_debug(_event) ⇒ Object



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

def on_before_debug(_event)
  "on_before_debug #{_event}"
  case _event
    when StartDebugEvent
      _filename = _event.file
      if _filename.nil?
        current_editor = self.raised
        _event.file=current_editor.file if current_editor
      end
      self.debug_begin
    when SetBreakpointEvent
      if _event.active == 1
        @breakpoints << {:file=>_event.file,:line=>_event.row}
        _e = @tabs_editor[tab_file_name(_event.file)]
        if _e
          _index =_event.row+'.0'
          _line = _e.text.get(_index, _index+ '  lineend')
          _event.line_code = _line.strip if _line
          _e.add_tag_breakpoint(_event.row) 
        else
          # TODO: 
          _line = File.readlines(_event.file)[_event.row.to_i-1]
          _event.line_code = _line.strip if _line
        end
      end
  end  
end

#on_before_run_ruby_file(_event) ⇒ Object



3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
# File 'ext/ae-editor/ae-editor.rb', line 3069

def on_before_run_ruby_file(_event)
  _filename = _event.file
  if _filename.nil?
    current_editor = self.raised
     if current_editor
       if current_editor.file
         _event.file = current_editor.file
         _event.persistent = true
       else
         _event.file = current_editor.create_temp_file
       end
     end
  end
end

#on_before_step_debug(_event) ⇒ Object

case _event.signature

    when DebugContract::DEBUG_BEGIN
      self.debug_begin
    when DebugContract::DEBUG_END
      self.debug_end
    when DebugContract::DEBUG_STEP
      if _event.context.file
        self.open_file_in_debug(_event.context.file, _event.context.line)
      end
  end
end


3276
3277
3278
# File 'ext/ae-editor/ae-editor.rb', line 3276

def on_before_step_debug(_event)
  debug_reset
end

#on_buffer(_event) ⇒ Object

def on_before_buffer(_event)

Arcadia.new_error_msg(self, "on_before_buffer #{_event.class}")
end


3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
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
3422
3423
3424
# File 'ext/ae-editor/ae-editor.rb', line 3345

def on_buffer(_event)
  #Arcadia.new_error_msg(self, "on_buffer #{_event.class}")
  case _event
    when NewBufferEvent
      self.open_buffer
    when OpenBufferEvent
      if _event.file
        if _event.row
          _index = _event.row.to_s+'.0' 
        end
        if _event.kind_of?(OpenBufferTransientEvent) && conf('close-last-if-not-modified')=="yes"
          if defined?(@last_transient_file) && !@last_transient_file.nil? && @last_transient_file != _event.file
            _e = @tabs_editor[tab_name(@last_transient_file)]
            if _e && !_e.modified_from_opening?
              close_editor(_e)
            end
          end
          if !editor_exist?(_event.file)
            @last_transient_file = _event.file
          else
            @last_transient_file = nil
          end
        end
        self.open_file(_event.file, _index)
      elsif _event.text
        if _event.title 
          _tab_name = self.tab_name(_event.title)
          self.open_buffer(_tab_name, _event.title)
          _e = @tabs_editor[_tab_name]
          _e.text_insert('end',_event.text)
          _e.reset
          _e.refresh
          #add_reverse_item(_e)
        end
      else
        _event.file = Arcadia.open_file_dialog
        self.open_file(_event.file)
      end
    when CloseBufferEvent
      if _event.file 
        self.close_file(_event.file)
      end
    when SaveAsBufferEvent
      if _event.file == nil
        self.raised.save_as
      else
        self.save_as_file(_event.file)          
      end
      _event.new_file = self.raised.file
    when SaveBufferEvent
      if _event.file == nil && _event.title == nil 
        self.raised.save
      elsif _event.file != nil
        self.save_file(_event.file)
      elsif _event.title != nil
        self.save_file(_event.title)
      end
    when SearchBufferEvent
      if _event.what == nil
        @find.show
      end
    when GoToLineBufferEvent
      if _event.line == nil
        @find.show_go_to_line_dialog
      end
    when CloseCurrentTabEvent
       close_raised
    when PrettifyTextEvent
      require 'rbeautify.rb' # gem
      self.raised.save # so we can beautify it kludgely here...
      path = raised.file
      RBeautify.beautify_file(path)
      self.raised.reload
    when MoveBufferEvent
      if _event.old_file && _event.new_file && editor_exist?(_event.old_file)
        #close_file(_event.old_file)
        change_file(_event.old_file, _event.new_file)          
      end
  end
end

#on_build(_event) ⇒ Object

def on_before_start_debug(_event)

  _filename = _event.file
  if _filename.nil?
    current_editor = self.raised
    _event.file =current_editor.file if current_editor
  end
end


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

def on_build(_event)
  @main_frame = AgMultiEditorView.new(self.frame.hinner_frame)
  @outline_bar = AgEditorOutlineToolbar.new(self.frame(1).hinner_frame, self)
  create_find # this is the "find within current file" one
  pop_up_menu
  
  #self.open_last_files
end

#on_debug_step_info(_event) ⇒ Object



3332
3333
3334
3335
3336
3337
3338
3339
# File 'ext/ae-editor/ae-editor.rb', line 3332

def on_debug_step_info(_event)
  #Arcadia.new_debug_msg(self, "file: #{_event.file}:#{_event.row}")
  #Arcadia.console(self, :msg=> "ae-editor -> DebugStepInfoEvent")
  if _event.file
    self.open_file_in_debug(_event.file, _event.row)
  end
  Tk.update
end

#on_exit_query(_event) ⇒ Object



3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
# File 'ext/ae-editor/ae-editor.rb', line 3105

def on_exit_query(_event)
  _event.can_exit=true
  @tabs_editor.each_value{|editor|
    _event.can_exit = can_close_editor?(editor)
    if !_event.can_exit
      _event.break
      break 
    end
  }
end

#on_finalize(_event) ⇒ Object



3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
# File 'ext/ae-editor/ae-editor.rb', line 3441

def on_finalize(_event)
  @batch_files = true
  _files =''
  _raised = self.raised
  Arcadia.persistent('editor.files.last', _raised.file) if _raised
  @tabs_editor.each_value{|editor|
    if editor.file != nil
      #_insert_index = editor.text.index('insert')
      _insert_index = editor.text.index('@0,0')
      _files=_files+'|' if _files.strip.length > 0
      _files=_files + "#{editor.file};#{_insert_index}"
    end
    #p editor.text.dump_tag('0.1',editor.text.index('end'))
    close_editor(editor,true)
  }
  Arcadia.persistent('editor.files.open', _files)
#    _breakpoints = '';
#    @breakpoints.each{|point|
#      if point[:file] != nil
#        _breakpoints=_breakpoints+'|' if _breakpoints.strip.length > 0
#        _breakpoints=_breakpoints + "#{point[:file]}@@@#{point[:line]}"
#      end
#    }
#    Arcadia.persistent('editor.debug_breakpoints', _breakpoints)
  @batch_files = true
end

#on_layout_raising_frame(_event) ⇒ Object



3501
3502
3503
3504
3505
3506
# File 'ext/ae-editor/ae-editor.rb', line 3501

def on_layout_raising_frame(_event)
  if _event.extension_name == "editor" && _event.frame_name=="editor_outline"
    _e = raised
    change_outline(_e, true) if  _e
  end
end

#open_buffer(_buffer_name = nil, _title = nil, w1 = 150) ⇒ Object



3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
# File 'ext/ae-editor/ae-editor.rb', line 3797

def open_buffer(_buffer_name = nil, _title = nil, w1=150)
  _index = @main_frame.enb.index(_buffer_name)
  if _buffer_name == nil
  		_buffer_name = tab_name('new')
  		_title_new = '*new'
  end
  
  if _index != -1
    _tab = @main_frame.enb.get_frame(_buffer_name)
    @main_frame.enb.raise(_buffer_name) if frame_visible?
  else
    _n = 1
    while @main_frame.enb.index(_buffer_name) != -1
      _title_new = '*new'+_n.to_s
      _buffer_name = tab_name('new')+_n.to_s
      _n =_n+1
    end
    if _title == nil
      _title =  _title_new
    end
    _tab = @main_frame.enb.insert('end', _buffer_name ,
      'text'=> _title,
      'image'=> Arcadia.file_icon(_title),
      'background'=> Arcadia.style("tabpanel.background"),
      'foreground'=> Arcadia.style("tabpanel.foreground"),
      'raisecmd'=>proc{do_buffer_raise(_buffer_name, _title)}
    )
    _e = AgEditor.new(self, _tab)
    ext = _e.file_extension(_title)
    ext='rb' if ext.nil?
    _e.init_editing(ext, w1)
    _e.text.set_focus
    #@tabs_file[_buffer_name]= nil
    @tabs_editor[_buffer_name]=_e
  end
  @main_frame.enb.move(_buffer_name, 1)
  @main_frame.enb.raise(_buffer_name) if frame_visible?
  @main_frame.enb.see(_buffer_name)
  return _tab
end

#open_file(_filename = nil, _text_index = '1.0', _mark_selected = true, _exp = true) ⇒ Object



3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
# File 'ext/ae-editor/ae-editor.rb', line 3768

def open_file(_filename = nil, _text_index='1.0', _mark_selected=true, _exp=true)
  return if _filename == nil || !File.exist?(_filename) || File.ftype(_filename) != 'file'
  _basefilename = File.basename(_filename)
  _tab_name = self.tab_file_name(_filename)
  _index = @main_frame.enb.index(_tab_name)
  _exist_buffer = _index != -1
  
  if _exist_buffer
    open_buffer(_tab_name)
  else
    @tabs_file[_tab_name]= _filename
    if _exp
      open_buffer(_tab_name, _basefilename)
    else
      open_buffer(_tab_name, _basefilename,0)
    end
    @tabs_editor[_tab_name].reset_highlight
    @tabs_editor[_tab_name].load_file(_filename)
  end
  
  if _text_index != nil && _text_index != '1.0'
    @tabs_editor[_tab_name].text_see(_text_index)
    @tabs_editor[_tab_name].mark_selected(_text_index) if _mark_selected 
  end

  return @tabs_editor[_tab_name]
end

#open_file_in_debug(_filename = nil, _line = nil) ⇒ Object



3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
# File 'ext/ae-editor/ae-editor.rb', line 3684

def open_file_in_debug(_filename=nil, _line=nil)
  #debug_reset
  if _filename && _line
    @last_index = _line.to_s+'.0'
    _editor_exist = editor_exist?(_filename)
    @last_e = open_file(_filename, @last_index, false, false)
    #@last_e.hide_exp
    @last_e.mark_debug(@last_index) if @last_e
    if !_editor_exist
      @editors_in_debug <<  @last_e
      # workaround for hightlight
      #p "add editor for close #{_filename}"
      @last_e.do_line_update
    end
  end
end

#open_last_filesObject

def update(_kind,_name)

  if _kind == 'RAISE' && _name == 'editor'
    _e = raised
    change_outline(_e) if  _e
  end
end


3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
# File 'ext/ae-editor/ae-editor.rb', line 3515

def open_last_files
  @batch_files = true
  if Arcadia.persistent('editor.files.open')
    _files_index =Arcadia.persistent('editor.files.open').split("|")
    _files_index.each do |value| 
      _file,_index = value.split(';')
      if _file && _index
        open_file(_file,_index,false)
      else
        open_file(_file)
      end
    end
  end
  @batch_files = false
  to_raise_file = Arcadia.persistent('editor.files.last')
  if to_raise_file
    raise_file(to_raise_file,0)
  else
    _first_page = @main_frame.enb.pages(0) if @main_frame.enb.pages.length > 0
    if _first_page
      @main_frame.enb.raise(_first_page) if frame_def_visible?
      @main_frame.enb.see(_first_page)
    end
  end
  frame(1)
  #@arcadia.layout.add_observer(self)
  Arcadia.attach_listener(self, LayoutRaisingFrameEvent)
  self
end

#page_name(_page_frame) ⇒ Object



3627
3628
3629
# File 'ext/ae-editor/ae-editor.rb', line 3627

def page_name(_page_frame)
  TkWinfo.appname(_page_frame).sub('f','')
end

#pop_up_menuObject



3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
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
# File 'ext/ae-editor/ae-editor.rb', line 3185

def pop_up_menu
  @pop_up = TkMenu.new(
    :parent=>@main_frame.enb,
    :tearoff=>0,
    :title => 'Menu'
  )
  @pop_up.configure(Arcadia.style('menu'))
  #Arcadia.instance.main_menu.update_style(@pop_up)


  @c = @pop_up.insert('end',
    :command,
    :label=>'Close',
    #:font => conf('font'),
    :hidemargin => false,
    :command=> proc{
      if @selected_tab_name_from_popup != nil
        _e = @tabs_editor[@selected_tab_name_from_popup]
        self.close_editor(_e) if _e
      end
    }
  )
  @c = @pop_up.insert('end',
    :command,
    :label=>'Close others',
    #:font => conf('font'),
    :hidemargin => false,
    :command=> proc{
      if @selected_tab_name_from_popup != nil
        _e = @tabs_editor[@selected_tab_name_from_popup]
        self.close_others_editor(_e)
      end
    }
  )
  @c = @pop_up.insert('end',
    :command,
    :label=>'Close all',
    #:font => conf('font'),
    :hidemargin => false,
    :command=> proc{
      if @selected_tab_name_from_popup != nil
        _e = @tabs_editor[@selected_tab_name_from_popup]
        self.close_all_editor(_e)
      end
    }
  )

  @pop_up.insert('end',
    :command,
    :label=>'...',
    :state=>'disabled',
    :background=>Arcadia.conf('titlelabel.background'),
    :font => "#{Arcadia.conf('menu.font')} bold",
    :hidemargin => false
  )

  @main_frame.enb.tabbind("Button-3",
    proc{|*x|
      _x = TkWinfo.pointerx(@main_frame.enb)
      _y = TkWinfo.pointery(@main_frame.enb)
      @selected_tab_name_from_popup = x[0].split(':')[0]
      _index = @main_frame.enb.index(@selected_tab_name_from_popup)
      if _index == -1 
        @selected_tab_name_from_popup = 'ff'+@selected_tab_name_from_popup
        _index = @main_frame.enb.index(@selected_tab_name_from_popup)
      end

      if _index != -1 
        _file = @tabs_file[(@selected_tab_name_from_popup)] # full path of file
        @pop_up.entryconfigure(3, 'label'=> _file)
        @pop_up.popup(_x,_y+10)
      end
    })
end

#raise_file(_filename = nil, _pos = nil) ⇒ Object



3759
3760
3761
3762
3763
3764
3765
3766
# File 'ext/ae-editor/ae-editor.rb', line 3759

def raise_file(_filename=nil, _pos=nil)
  if _filename && frame_def_visible?
    tab_name=self.tab_file_name(_filename)
    @main_frame.enb.move(tab_name,_pos) if _pos
    @main_frame.enb.raise(tab_name)
    @main_frame.enb.see(tab_name)
  end    
end

#raisedObject



3468
3469
3470
3471
# File 'ext/ae-editor/ae-editor.rb', line 3468

def raised
  _page = @main_frame.enb.raise
  return @tabs_editor[_page]
end

#save_as_file(_filename) ⇒ Object



3922
3923
3924
# File 'ext/ae-editor/ae-editor.rb', line 3922

def save_as_file(_filename)
  @tabs_editor[tab_name(_filename)].save_as
end

#save_file(_filename) ⇒ Object



3918
3919
3920
# File 'ext/ae-editor/ae-editor.rb', line 3918

def save_file(_filename)
  @tabs_editor[tab_name(_filename)].save
end

#start_findObject



3436
3437
3438
3439
# File 'ext/ae-editor/ae-editor.rb', line 3436

def start_find
  _e = raised
  _e.find if _e
end

#tab_file_name(_filename = "") ⇒ Object



3753
3754
3755
3756
3757
# File 'ext/ae-editor/ae-editor.rb', line 3753

def tab_file_name(_filename="")
  _fstr = File.expand_path(_filename)
  _fstr =  _filename if _fstr == nil
  tab_name(_fstr)
end

#tab_name(_str = "") ⇒ Object



3748
3749
3750
3751
# File 'ext/ae-editor/ae-editor.rb', line 3748

def tab_name(_str="")
  #_str = _str.downcase if is_windows?
  'ff'+_str.downcase.gsub("/","_").gsub(".","_").gsub(":","_").gsub("\\","_")
end

#unname_read_only(_name) ⇒ Object



3605
3606
3607
# File 'ext/ae-editor/ae-editor.rb', line 3605

def unname_read_only(_name)
  return _name.gsub("[READ-ONLY] ",'')
end