Class: ArcadiaMainMenu

Inherits:
ArcadiaUserControl show all
Defined in:
lib/a-core.rb

Defined Under Namespace

Classes: UserItem

Constant Summary collapse

SUF =
'user_menu'

Instance Method Summary collapse

Methods inherited from ArcadiaUserControl

#items

Constructor Details

#initialize(menu) ⇒ ArcadiaMainMenu

Returns a new instance of ArcadiaMainMenu.



704
705
706
707
708
709
710
711
712
713
714
# File 'lib/a-core.rb', line 704

def initialize(menu)
  # create main menu
  @menu = menu
  build
  @menu.configure(Arcadia.style('menu'))
#    menu.foreground('black')
#    menu.activeforeground('#6679f1')
#    menu.relief('flat')
#    menu.borderwidth(0)
#    menu.font(Arcadia.conf('main.mainmenu.font'))
end

Instance Method Details

#buildObject



790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
# File 'lib/a-core.rb', line 790

def build
  menu_spec_file = [
    ['File', 0],
    ['Open', proc{Arcadia.process_event(OpenBufferEvent.new(self,'file'=>Tk.getOpenFile))}, 0],
    ['New', $arcadia['main.action.new_file'], 0],
    #['Save', proc{EditorContract.instance.save_file_raised(self)},0],
    ['Save', proc{Arcadia.process_event(SaveBufferEvent.new(self))},0],
    ['Save as ...', proc{Arcadia.process_event(SaveAsBufferEvent.new(self))},0],
    '---',
    ['Quit', $arcadia['action.on_exit'], 0]]
    menu_spec_edit = [['Edit', 0],
    ['Cut', $arcadia['main.action.edit_cut'], 2],
    ['Copy', $arcadia['main.action.edit_copy'], 0],
    ['Paste', $arcadia['main.action.edit_paste'], 0]]
    menu_spec_search = [['Search', 0],
    ['Find ...', proc{Arcadia.process_event(SearchBufferEvent.new(self))}, 2],
    ['Find in files...', proc{Arcadia.process_event(SearchInFilesEvent.new(self))}, 2],
    ['Go to line ...', proc{Arcadia.process_event(GoToLineBufferEvent.new(self))}, 2]]
    menu_spec_view = [['View', 0],['Show/Hide Toolbar', proc{$arcadia.show_hide_toolbar}, 2]]
    menu_spec_tools = [['Tools', 0],
    ['Keys-test', $arcadia['action.test.keys'], 2]
  ]
  menu_spec_help = [['Help', 0],
  ['About', $arcadia['action.show_about'], 2],]
  @menu.add_menu(menu_spec_file)
  @menu.add_menu(menu_spec_edit)
  @menu.add_menu(menu_spec_search)
  @menu.add_menu(menu_spec_view)
  @menu.add_menu(menu_spec_tools)
  @menu.add_menu(menu_spec_help)

  #@menu.bind_append("1", proc{
#      chs = TkWinfo.children(@menu)
#      hh = 25
#      @last_post = nil
#      chs.each{|ch|
#        ch.bind_append("Enter", proc{|x,y,rx,ry| 
#          @last_post.unpost if @last_post
#          ch.menu.post(x-rx,y-ry+hh)
#          @last_post=ch.menu}, "%X %Y %x %y")
#        ch.bind_append("Leave", proc{
#          @last_post.unpost if @last_post
#        })
#      }
  #})
end

#get_menu(_menubar, _context, context_path) ⇒ Object



767
768
769
770
771
772
773
774
775
# File 'lib/a-core.rb', line 767

def get_menu(_menubar, _context, context_path)
  context_menu = get_menu_context(_menubar, _context)
  folders = context_path.split('/')
  sub = context_menu
  folders.each{|folder|
    sub = get_sub_menu(sub, folder)
  }
  sub
end

#get_menu_context(_menubar, _context) ⇒ Object



716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
# File 'lib/a-core.rb', line 716

def get_menu_context(_menubar, _context)
  menubuttons =  _menubar[0..-1]
  # cerchiamo il context
  m_i = -1
  menubuttons.each_with_index{|mb, i|
    _t = mb[0].cget('text')
    if _t==_context
      m_i = i 
      break
    end
  }
  if m_i > -1
    _menubar[m_i][1]
  else
    _menubar.add_menu([[_context],[]])[1].delete(0)
  end
end

#get_sub_menu(menu_context, folder = nil) ⇒ Object



734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'lib/a-core.rb', line 734

def get_sub_menu(menu_context, folder=nil)
  if folder
    s_i = -1 
    i_end = menu_context.index('end')
    if i_end
      0.upto(i_end){|j|
        l = menu_context.entrycget(j,'label')
        if l == folder
         s_i = j
         break
        end
      }
    end
  end
  if s_i > -1 && menu_context.menutype(s_i) == 'cascade'
    sub = menu_context.entrycget(s_i, 'menu')
  else
    sub = TkMenu.new(
      :parent=>@pop_up,
      :tearoff=>0
    )
    sub.configure(Arcadia.style('menu'))
    #update_style(sub)
    menu_context.insert('end',
      :cascade,
      :label=>folder,
      :menu=>sub,
      :hidemargin => false
    )
  end
  sub
end

#new_item(_sender, _args = nil) ⇒ Object



778
779
780
781
782
783
784
785
786
787
# File 'lib/a-core.rb', line 778

def new_item(_sender, _args= nil)
  return if _args.nil?
  if _args['context_caption']
    conte = _args['context_caption']
  else
    conte = _args['context']
  end
  _args['menu']=get_menu(@menu, conte, _args['context_path'])
  super(_sender, _args)
end