]> git.decadent.org.uk Git - ion3.git/blob - ioncore/ioncore_tabnum.lua
[svn-upgrade] Integrating new upstream version, ion3 (20070506)
[ion3.git] / ioncore / ioncore_tabnum.lua
1 --
2 -- ion/share/ioncore_tabnum.lua -- Ioncore tab numbering support
3 -- 
4 -- Copyright (c) Tuomo Valkonen 2007.
5 --
6 -- See the included file LICENSE for details.
7 --
8
9 ioncore.tabnum={}
10
11 local framestate={}
12
13 local function do_show(frame)
14     frame:set_grattr('numbered', 'set')
15     framestate[frame]='set'
16 end
17
18 --DOC
19 -- Show tab numbers on \var{frame}, clearing them when submap
20 -- grab is released the next time. If \var{delay} is given, in
21 -- milliseconds, the numbers are not actually displayed until this
22 -- time has passed.
23 function ioncore.tabnum.show(frame, delay)
24     if delay and delay>0 then
25         local tmr=ioncore.create_timer()
26         framestate[frame]=tmr
27         tmr:set(delay, function() do_show(frame) end)
28     else
29         do_show(frame)
30     end
31 end
32
33 --DOC
34 -- Clear all tab numbers set by \fnref{ioncore.tabnum.show}.
35 function ioncore.tabnum.clear()
36     local st=framestate
37     framestate={}
38     
39     for f, s in pairs(st) do
40         if s=='set' then
41             f:set_grattr('numbered', 'unset')
42         elseif obj_is(s, "WTimer") then
43             s:reset()
44         end
45     end
46 end
47
48 ioncore.get_hook("ioncore_submap_ungrab_hook")
49     :add(ioncore.tabnum.clear)