2 -- ion/mod_menu/mod_menu.lua -- Menu opening helper routines.
4 -- Copyright (c) Tuomo Valkonen 2004-2009.
6 -- See the included file LICENSE for details.
9 -- This is a slight abuse of the package.loaded variable perhaps, but
10 -- library-like packages should handle checking if they're loaded instead of
11 -- confusing the user with require/include differences.
12 if package
.loaded
["mod_menu"] then return end
14 if not ioncore
.load_module("mod_menu") then
18 local mod_menu
=_G
["mod_menu"]
19 local menudb
=_G
["ioncore"]
21 assert(mod_menu
and menudb
)
26 local function menu_(reg
, sub
, menu_or_name
, fn
, check
)
28 -- Check that no other menus are open in reg.
29 local ok
=reg
:managed_i(function(r
)
30 return not obj_is(r
, "WMenu")
37 menu
=menudb
.evalmenu(menu_or_name
, reg
, sub
)
39 return fn(reg
, function(e
) e
.func(reg
, sub
) end, menu
)
44 -- Display a menu in the lower-left corner of \var{mplex}.
45 -- The variable \var{menu_or_name} is either the name of a menu
46 -- defined with \fnref{mod_menu.defmenu} or directly a table similar
47 -- to ones passesd to this function. When this function is
48 -- called from a binding handler, \var{sub} should be set to
49 -- the second argument of to the binding handler (\var{_sub})
50 -- so that the menu handler will get the same parameters as the
51 -- binding handler. Extra options can be passed in the table
52 -- \var{param}. The initial entry can be specified as the field
53 -- \var{initial} as an integer starting from 1. Menus can be made
54 -- to use a bigger style by setting the field \var{big} to \code{true}.
55 function mod_menu
.menu(mplex
, sub
, menu_or_name
, param
)
56 local function menu_stdmenu(m
, s
, menu
)
57 return ioncore
.unsqueeze(mod_menu
.do_menu(m
, s
, menu
, param
))
59 return menu_(mplex
, sub
, menu_or_name
, menu_stdmenu
, true)
63 function mod_menu
.bigmenu(mplex
, sub
, menu_or_name
, initial
)
64 local param
={big
=true, initial
=initial
}
65 return mod_menu
.menu(mplex
, sub
, menu_or_name
, param
)
69 -- This function is similar to \fnref{mod_menu.menu}, but input
70 -- is grabbed and the key used to active the menu can be used to
71 -- cycle through menu entries.
72 function mod_menu
.grabmenu(mplex
, sub
, menu_or_name
, param
)
73 local function menu_grabmenu(m
, s
, menu
)
74 return mod_menu
.do_grabmenu(m
, s
, menu
, param
)
76 return menu_(mplex
, sub
, menu_or_name
, menu_grabmenu
, true)
80 function mod_menu
.biggrabmenu(mplex
, sub
, menu_or_name
, key
, initial
)
81 local function menu_biggrabmenu(m
, s
, menu
)
82 return mod_menu
.do_grabmenu(m
, s
, menu
, true, key
, initial
or 0)
84 return menu_(mplex
, sub
, menu_or_name
, menu_biggrabmenu
, true, initial
)
88 -- This function displays a drop-down menu and should only
89 -- be called from a mouse press handler. The parameters are
90 -- similar to those of \fnref{mod_menu.menu}.
91 function mod_menu
.pmenu(win
, sub
, menu_or_name
)
92 return menu_(win
, sub
, menu_or_name
, mod_menu
.do_pmenu
)
98 -- Mark ourselves loaded.
99 package
.loaded
["mod_menu"]=true
102 -- Load configuration file
103 dopath('cfg_menu', true)