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.



1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
# File 'lib/a-core.rb', line 1584

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.



1551
1552
1553
# File 'lib/a-core.rb', line 1551

def menubar
  @menubar
end

Class Method Details



1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
# File 'lib/a-core.rb', line 1620

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



1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
# File 'lib/a-core.rb', line 1601

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



1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
# File 'lib/a-core.rb', line 1645

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



1672
1673
1674
1675
1676
1677
1678
1679
# File 'lib/a-core.rb', line 1672

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



1667
1668
1669
1670
# File 'lib/a-core.rb', line 1667

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



1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
# File 'lib/a-core.rb', line 1681

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