Class: AgMultiEditorView

Inherits:
Object
  • Object
show all
Defined in:
ext/ae-editor/ae-editor.rb

Instance Method Summary collapse

Constructor Details

#initialize(_parent = nil, _frame = nil, _usetabs = true) ⇒ AgMultiEditorView

attr_reader :enb



3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
# File 'ext/ae-editor/ae-editor.rb', line 3425

def initialize(_parent=nil, _frame=nil, _usetabs=true)
  @parent = _parent
  @frame = _frame
  
  @usetabs = _usetabs
  if @usetabs
    initialize_tabs
  end
  @pages = {}
  @page_binds = {}
  @raised_page=nil
  @raised_page_usetabs=@usetabs
end

Instance Method Details

#add_page(_name, _file, _title, _image, _raise_proc, _adapter = nil) ⇒ Object



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

def add_page(_name, _file, _title, _image, _raise_proc, _adapter=nil)
#   p "add_page _name=#{_name}  _file=#{_file}, _title=#{_title}"
  if @usetabs
    frame = @enb.insert(0, _name ,
      'text'=> _title,
      'image'=> _image,
      'background'=> Arcadia.style("tabpanel")["background"],
      'foreground'=> Arcadia.style("tabpanel")["foreground"],
      'raisecmd'=>_raise_proc
    )
  else
    frame = TkFrame.new(@frame.hinner_frame) #.pack('fill'=>'both', :padx=>0, :pady=>0, :expand => 'yes')
  end
  if _adapter.nil?
    adapted_frame = TkFrameAdapter.new(Arcadia.layout.root)
#      adapted_frame = TkFrameAdapter.new(@frame.hinner_frame)
  else
    adapted_frame = _adapter
  end
  adapted_frame.attach_frame(frame)
  adapted_frame.raise
  @pages[_name]={'frame'=>adapted_frame, 'file'=>_file, 'text'=>_title, 'image' => _image, 'raisecmd'=>_raise_proc}
  adapted_frame
end

#delete_page(_name, _delete_adapter = true) ⇒ Object



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

def delete_page(_name, _delete_adapter=true)
  if @usetabs
    @enb.delete(_name)
  end
  adapter_frame = @pages.delete(_name)['frame']
  if _delete_adapter
    adapter_frame.frame.destroy if adapter_frame.frame
    adapter_frame.destroy
  end 
end

#exist_buffer?(_name, _sender = self) ⇒ Boolean



3523
3524
3525
3526
3527
3528
3529
3530
3531
# File 'ext/ae-editor/ae-editor.rb', line 3523

def exist_buffer?(_name, _sender=self)
  to_ret = false
  if @usetabs
    to_ret = @enb.index(_name) != -1
  else
    to_ret = @pages.include?(_name)
  end
  to_ret   
end

#exist_buffer_in_others?(_name) ⇒ Boolean



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

def exist_buffer_in_others?(_name)
  to_ret = false
  @parent.instances.each{|i|
    if i != @parent
      to_ret = i.main_frame.exist_buffer?(_name)
      break if to_ret  
    end
  }
  to_ret   
end

#index(_name) ⇒ Object



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

def index(_name)
  if @usetabs
    @enb.index(_name)
  else
    _index = @pages.values.index(@pages[_name])
    _index = -1 if _index.nil?
    _index
  end
end

#initialize_tabsObject



3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
# File 'ext/ae-editor/ae-editor.rb', line 3439

def initialize_tabs
  @enb = Tk::BWidget::NoteBook.new(@frame.hinner_frame, Arcadia.style('tabpanel')){
    tabbevelsize 0
    internalborderwidth 2
    side Arcadia.conf('editor.tabs.side')
    font Arcadia.conf('editor.tabs.font')
    pack('fill'=>'both', :padx=>0, :pady=>0, :expand => 'yes')
  }
  refresh_after_map = proc{
    if !@enb.pages.empty?
      if @enb.raise.nil? || @enb.raise.strip.length == 0
        @enb.raise(@enb.pages[0]) 
        @enb.see(@enb.pages[0])
      end
    end
  }
  @enb.bind_append("Map",refresh_after_map)
end

#move(_name, _pos) ⇒ Object



3698
3699
3700
3701
3702
3703
# File 'ext/ae-editor/ae-editor.rb', line 3698

def move(_name, _pos)
  if @usetabs
    @enb.move(_name,_pos) if _pos
  else
  end
end

#move_here(_name) ⇒ Object



3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
# File 'ext/ae-editor/ae-editor.rb', line 3486

def move_here(_name)
  value = nil
  old_instance = nil
  @parent.instances.each{|i|
    if i != @parent
      value = i.main_frame.page(_name)
      if value != nil
        old_instance = i
        break 
      end
    end
  }
  if value != nil
    value['frame'].detach_frame      
    editor = old_instance.editor_by_page_name(_name)
    editor.set_controller(@parent)
    @parent.register_editor(editor, _name, editor.file)
    old_instance.close_buffer(_name, true)
    add_page(_name, value['file'], value['text'], value['image'], proc{@parent.do_buffer_raise(_name, value['text'])}, value['frame'])
    is_file = value['file'] != nil && File.exists?(value['file'])
    if is_file
      @parent.add_buffer_menu_item(value['file'], is_file, @parent)
    else
      @parent.add_buffer_menu_item(value['text'], is_file, @parent)
    end
    raise(_name)
  end
end

#page(_name) ⇒ Object



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

def page(_name)
  @pages[_name]
end

#page_bind(_event, _proc) ⇒ Object



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

def page_bind(_event, _proc)
  @page_binds[_event] = _proc
  if @usetabs
    @enb.tabbind_append("Button-3",_proc)
    @frame.root.top_text_bind_remove("Button-3")   
  else
    @frame.root.top_text_bind_append("Button-3", _proc)   
  end    
end

#page_frame(_name) ⇒ Object



3643
3644
3645
3646
3647
3648
3649
# File 'ext/ae-editor/ae-editor.rb', line 3643

def page_frame(_name)
  if @usetabs
    @enb.get_frame(_name)
  else
    @pages[_name]['frame'] if @pages[_name]
  end    
end

#page_name(_frame) ⇒ Object



3651
3652
3653
3654
3655
3656
3657
3658
# File 'ext/ae-editor/ae-editor.rb', line 3651

def page_name(_frame)
  res = nil
  @pages.each{|k,v|
    res = k if v['frame'] == _frame
    break if !res.nil?
  }
  res
end

#page_title(_name, _title = nil, _image = nil) ⇒ Object



3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
# File 'ext/ae-editor/ae-editor.rb', line 3562

def page_title(_name, _title=nil, _image=nil)
  return nil if _name.nil? or _name.strip.length == 0
  @pages[_name]['text'] = _title if _title != nil
  @pages[_name]['image'] = _image if _image != nil
  title = _title
  if @usetabs
    if _title.nil? && _image.nil?
      title = @enb.itemcget(_name, 'text')
    else
      args = {}
      if _title != nil
        args['text']=_title
      end 
      if _image != nil
        args['image']=_image
      end
      @enb.itemconfigure(_name, args)      
    end
  else
    if _title.nil? && _image.nil?
      title = @pages[_name]['text'] if @pages[_name]
    end
  end
  #@frame.root.top_text(page(_name)['text'], page(_name)['image']) if page(_name) && raised?(_name)
  if page(_name) && raised?(_name)
    @frame.root.top_text(@parent.top_text_string, page(_name)['image']) 
    @parent.make_buffer_string(page(_name)['text'])
  end
  title
end

#pagesObject



3554
3555
3556
3557
3558
3559
3560
# File 'ext/ae-editor/ae-editor.rb', line 3554

def pages
  if @usetabs
    @enb.pages
  else
    @pages.keys
  end
end

#raise(_page = nil) ⇒ Object



3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
# File 'ext/ae-editor/ae-editor.rb', line 3660

def raise(_page=nil)
  if @usetabs
    if _page.nil?
      @raised_page = @enb.raise
    else
      @enb.raise(_page)
      @enb.see(_page)        
      @raised_page = _page
    end
  else
    if _page.nil?
      @raised_page
    elsif @raised_page != _page || @raised_page_usetabs != @usetabs 
      if @raised_page
 #         @pages[@raised_page]['frame'].unpack if @pages[@raised_page]
        @pages[@raised_page]['frame'].unmap("pack") if @pages[@raised_page]
      end
      @raised_page = _page
      @pages[_page]['frame'].map("pack")
#      @pages[_page]['frame'].pack('fill'=>'both', :padx=>0, :pady=>0, :expand => 'yes')
      @pages[_page]['raisecmd'].call
    end
  end
  @raised_page_usetabs=@usetabs
  @raised_page
end

#raised?(_name) ⇒ Boolean



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

def raised?(_name)
  @raised_page==_name
end

#root_frameObject



3515
3516
3517
3518
3519
3520
3521
# File 'ext/ae-editor/ae-editor.rb', line 3515

def root_frame
  if @usetabs
    @enb
  else
    @frame.hinner_frame
  end
end

#see(_page) ⇒ Object



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

def see(_page)
  if @usetabs
    @enb.see(_page) 
  else
  end
end

#switch_2_notabsObject



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

def switch_2_notabs
  raised = raise
  @usetabs = false
  @pages.each{|name, value|
    value['frame'].detach_frame
    add_page(name, value['file'], value['text'], value['image'], value['raisecmd'], value['frame'])
  }
  @enb.destroy
  raise(raised)
  @page_binds.each{|event, proc| 
    page_bind(event, proc)
  }    
end

#switch_2_tabsObject



3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
# File 'ext/ae-editor/ae-editor.rb', line 3458

def switch_2_tabs
  raised = raise
  @usetabs = true
  initialize_tabs
  @pages.each{|name, value|
    oldframe = value['frame'].frame
    value['frame'].detach_frame
    oldframe.destroy
    add_page(name, value['file'], value['text'], value['image'], value['raisecmd'], value['frame'])
  }
  raise(raised)
  @page_binds.each{|event, proc| page_bind(event, proc)}    
end