Class: AgMultiEditorView

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of AgMultiEditorView.



3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
# File 'ext/ae-editor/ae-editor.rb', line 3772

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

#usetabsObject (readonly)

attr_reader :enb



3771
3772
3773
# File 'ext/ae-editor/ae-editor.rb', line 3771

def usetabs
  @usetabs
end

Instance Method Details

#add_menu_button(_name, _buffer_string) ⇒ Object



3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
# File 'ext/ae-editor/ae-editor.rb', line 3987

def add_menu_button(_name, _buffer_string)
  @buffer_menu_button = @frame.root.add_menu_button(
    _name, 'files', nil, 'right', 
    {
    #'relief'=>:flat, 
    # 'borderwidth'=>1, 
     'compound'=> 'left',
#     'anchor'=>'w',
#     'font'=> "#{Arcadia.conf('titlelabel.font')} italic",
#     'activebackground'=>Arcadia.conf('titlelabel.background'),
#     'foreground' => Arcadia.conf('titlecontext.foreground'),
     'textvariable'=> _buffer_string
    }
  )
end

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



3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
# File 'ext/ae-editor/ae-editor.rb', line 3945

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, @parent)
  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



3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
# File 'ext/ae-editor/ae-editor.rb', line 3970

def delete_page(_name, _delete_adapter=true)
  if @usetabs
    @enb.delete(_name)
  end
  adapter_frame = @pages.delete(_name)['frame']
  if _delete_adapter
    frame = adapter_frame.frame
    adapter_frame.detach_frame
    adapter_frame.destroy
    frame.destroy
#      adapter_frame.frame.destroy if adapter_frame.frame
#      adapter_frame.destroy
  end
  @raised_page = nil if @raised_page == _name
  Tk.update
end

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

Returns:

  • (Boolean)


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

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

Returns:

  • (Boolean)


3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
# File 'ext/ae-editor/ae-editor.rb', line 3885

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



3896
3897
3898
3899
3900
3901
3902
3903
3904
# File 'ext/ae-editor/ae-editor.rb', line 3896

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



3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
# File 'ext/ae-editor/ae-editor.rb', line 3785

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



4074
4075
4076
4077
4078
4079
# File 'ext/ae-editor/ae-editor.rb', line 4074

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

#move_here(_name) ⇒ Object



3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
# File 'ext/ae-editor/ae-editor.rb', line 3838

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



4015
4016
4017
# File 'ext/ae-editor/ae-editor.rb', line 4015

def page(_name)
  @pages[_name]
end

#page_bind(_event, _proc) ⇒ Object



4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
# File 'ext/ae-editor/ae-editor.rb', line 4003

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")   
    @buffer_menu_button.bind_remove("Button-3") if @buffer_menu_button  
  else
    @frame.root.top_text_bind_append("Button-3", _proc)
    @buffer_menu_button.bind_append("Button-3", _proc) if @buffer_menu_button   
  end    
end

#page_frame(_name) ⇒ Object



4019
4020
4021
4022
4023
4024
4025
# File 'ext/ae-editor/ae-editor.rb', line 4019

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

#page_name(_frame) ⇒ Object



4027
4028
4029
4030
4031
4032
4033
4034
# File 'ext/ae-editor/ae-editor.rb', line 4027

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



3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
# File 'ext/ae-editor/ae-editor.rb', line 3914

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



3906
3907
3908
3909
3910
3911
3912
# File 'ext/ae-editor/ae-editor.rb', line 3906

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

#raise(_page = nil) ⇒ Object



4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
# File 'ext/ae-editor/ae-editor.rb', line 4036

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

Returns:

  • (Boolean)


4063
4064
4065
# File 'ext/ae-editor/ae-editor.rb', line 4063

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

#root_frameObject



3867
3868
3869
3870
3871
3872
3873
# File 'ext/ae-editor/ae-editor.rb', line 3867

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

#see(_page) ⇒ Object



4067
4068
4069
4070
4071
4072
# File 'ext/ae-editor/ae-editor.rb', line 4067

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

#switch_2_notabsObject



3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
# File 'ext/ae-editor/ae-editor.rb', line 3824

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

def initialize_notabs

  @frame_notabs = TkFrame.new(@frame.hinner_frame, Arcadia.style('panel')){
    pack('fill'=>'both', :padx=>0, :pady=>0, :expand => 'yes')
  }
end


3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
# File 'ext/ae-editor/ae-editor.rb', line 3810

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