Class: ArcadiaMainMenu

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

Defined Under Namespace

Classes: UserItem

Constant Summary collapse

SUF =
'user_menu'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ArcadiaUserControl

#items

Constructor Details

#initialize(root) ⇒ ArcadiaMainMenu

Returns a new instance of ArcadiaMainMenu.


1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
# File 'lib/a-core.rb', line 1678

def initialize(root)
  # Creating Menubar
  @menubar = Arcadia.wf.menu(root)
#    @menubar = TkMenu.new(root)
  begin
#      if !OS.mac?
#        @menubar.configure(Arcadia.style('menu').delete_if {|key, value| key=='tearoff'}) 
#        @menubar.extend(TkAutoPostMenu)
#        @menubar.event_posting_on
#      end
    root['menu'] = @menubar
    @menu_contexts = {}
  rescue RuntimeError => e
    Arcadia.runtime_error(e)
  end
end

Instance Attribute Details

Returns the value of attribute menubar


1645
1646
1647
# File 'lib/a-core.rb', line 1645

def menubar
  @menubar
end

Class Method Details


1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
# File 'lib/a-core.rb', line 1714

def ArcadiaMainMenu.sub_menu(_menu, _title=nil)
  s_i = -1
  if _title
    i_end = _menu.index('end')
    if i_end
      0.upto(i_end){|j|
        type = _menu.menutype(j)
        if type != 'separator'
          l = _menu.entrycget(j,'label')
          if l == _title && type == 'cascade'
            s_i = j
            break
          end
        end
      }
    end
  end
  if s_i > -1
    sub = _menu.entrycget(s_i, 'menu')
  else
    sub = nil
  end
  sub  
end

Instance Method Details

#get_menu_context(_menubar, _context, _underline = nil) ⇒ Object


1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
# File 'lib/a-core.rb', line 1695

def get_menu_context(_menubar, _context, _underline=nil)
  m = @menu_contexts[_context]
  if !m.nil? 
    m
  else
    topmenu = Arcadia.wf.menu(_menubar)
#      topmenu = TkMenu.new(_menubar)
#      if !OS.mac?
#        topmenu.configure(Arcadia.style('menu'))
#        topmenu.extend(TkAutoPostMenu)
#      end
    opt = {:menu => topmenu, :label => _context}
    opt[:underline]=_underline if _underline
    _menubar.add(:cascade, opt)
    @menu_contexts[_context] = topmenu
    topmenu
  end
end

#get_sub_menu(menu_context, folder = nil) ⇒ Object


1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
# File 'lib/a-core.rb', line 1739

def get_sub_menu(menu_context, folder=nil)
  sub = ArcadiaMainMenu.sub_menu(menu_context, folder)
  if sub.nil?
    sub = Arcadia.wf.menu(:tearoff=>0)
#      sub = TkMenu.new(
#      :tearoff=>0
#      )
#      if !OS.mac?
#        sub.configure(Arcadia.style('menu'))
#        sub.extend(TkAutoPostMenu)
#      end
    #update_style(sub)
    menu_context.insert('end',
    :cascade,
    :label=>folder,
    :menu=>sub,
    :hidemargin => false
    )
  end
  sub
end

#make_menu(_menu, context_path, context_underline = nil) ⇒ Object


1766
1767
1768
1769
1770
1771
1772
1773
# File 'lib/a-core.rb', line 1766

def make_menu(_menu, context_path, context_underline=nil)
  folders = context_path.split('/')
  sub = _menu
  folders.each{|folder|
    sub = get_sub_menu(sub, folder)
  }
  sub
end

#make_menu_in_menubar(_menubar, _context, context_path, context_underline = nil) ⇒ Object


1761
1762
1763
1764
# File 'lib/a-core.rb', line 1761

def make_menu_in_menubar(_menubar, _context, context_path, context_underline=nil)
  context_menu = get_menu_context(_menubar, _context, context_underline)
  make_menu(context_menu, context_path, context_underline)
end

#new_item(_sender, _args = nil) ⇒ Object


1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
# File 'lib/a-core.rb', line 1775

def new_item(_sender, _args= nil)
  return if _args.nil?

  if _args['context_caption']
    conte = _args['context_caption']
  else
    conte = _args['context']
  end
  if _args['rif'] == 'main'
    _args['menu']=make_menu_in_menubar(@menubar, conte, _args['context_path'], _args['context_underline'])
  else
    if Arcadia.menu_root(_args['rif'])
      _args['menu']=make_menu(Arcadia.menu_root(_args['rif']), _args['context_path'], _args['context_underline'])
    else
      msg = Arcadia.text("main.e.adding_new_menu_item.msg", [_args['name'], _args['rif']])
      Arcadia.dialog(self,
      'type'=>'ok',
      'title' => Arcadia.text("main.e.adding_new_menu_item.title",[self.class::SUF]),
      'msg'=>msg,
      'level'=>'error')

      _args['menu']=make_menu_in_menubar(@menubar, conte, _args['context_path'], _args['context_underline'])
    end
  end
  super(_sender, _args)
end