ion->notion
[notion/jeffpc.git] / ioncore / ioncore_misc.lua
blob7dc63535b1c00cd31a43dd000cff177d3ba5f9b3
1 --
2 -- ion/share/ioncore_misc.lua
3 --
4 -- Copyright (c) Tuomo Valkonen 2004-2009.
5 --
6 -- See the included file LICENSE for details.
7 --
9 local group_tmpl = { type="WGroupWS" }
11 local default_tmpl = { switchto=true }
13 local empty = { type="WGroupWS", managed={} }
15 local layouts={
16 empty = empty,
17 default = empty,
20 --DOC
21 -- Define a new workspace layout with name \var{name}, and
22 -- attach/creation parameters given in \var{tab}. The layout
23 -- "empty" may not be defined.
24 function ioncore.deflayout(name, tab)
25 assert(name ~= "empty")
27 if name=="default" and not tab then
28 layouts[name] = empty
29 else
30 layouts[name] = table.join(tab, group_tmpl)
31 end
32 end
34 --DOC
35 -- Get named layout (or all of the latter parameter is set,
36 -- but this is for internal use only).
37 function ioncore.getlayout(name, all)
38 if all then
39 return layouts
40 else
41 return layouts[name]
42 end
43 end
45 ioncore.set{_get_layout=ioncore.getlayout}
47 --DOC
48 -- Create new workspace on screen \var{scr}. The table \var{tmpl}
49 -- may be used to override parts of the layout named with \code{layout}.
50 -- If no \var{layout} is given, "default" is used.
51 function ioncore.create_ws(scr, tmpl, layout)
52 local lo=ioncore.getlayout(layout or "default")
54 assert(lo, TR("Unknown layout"))
56 return scr:attach_new(table.join(tmpl or default_tmpl, lo))
57 end
60 --DOC
61 -- Find an object with type name \var{t} managing \var{obj} or one of
62 -- its managers.
63 function ioncore.find_manager(obj, t)
64 while obj~=nil do
65 if obj_is(obj, t) then
66 return obj
67 end
68 obj=obj:manager()
69 end
70 end
73 --DOC
74 -- gettext+string.format
75 function ioncore.TR(s, ...)
76 return string.format(ioncore.gettext(s), ...)
77 end
80 --DOC
81 -- Attach tagged regions to \var{reg}. The method of attach
82 -- depends on the types of attached regions and whether \var{reg}
83 -- implements \code{attach_framed} and \code{attach}. If \var{param}
84 -- is not set, the default of \verb!{switchto=true}! is used.
85 -- The function returns \code{true} if all tagged regions were
86 -- succesfully attached, and \code{false} otherwisse.
87 function ioncore.tagged_attach(reg, param)
88 local errors=false
89 if not param then
90 param={switchto=true}
91 end
92 local tagged=function() return ioncore.tagged_first(true) end
93 for r in tagged do
94 local fn=((not obj_is(r, "WWindow") and reg.attach_framed)
95 or reg.attach)
97 if not (fn and fn(reg, r, param)) then
98 errors=true
99 end
101 return not errors