1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
--
-- ion/share/ioncorelib-mplexfns.lua -- Misc. functions for WMPlex:s
--
-- Copyright (c) Tuomo Valkonen 2004.
--
-- Ion is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License as published by
-- the Free Software Foundation; either version 2.1 of the License, or
-- (at your option) any later version.
--
-- Callback creation {{{
--DOC
-- Create a \type{WMPlex}-bindable function with arguments
-- (\code{mplex [, sub]}) that calls \var{fn} with parameter chosen
-- as the first match from the following steps:
-- \begin{enumerate}
-- \item \var{sub} if it is not nil.
-- \item The current input in \var{mplex} (see \fnref{WMPlex.current_input})
-- if one exists and \var{noinput} is not set.
-- \item The currently displayed object in \var{mplex}
-- (see \fnref{WMPlex.current}), if not nil.
-- \item \var{mplex} itself, if \var{noself} is not set.
-- \end{enumerate}
-- Additionally, if \var{cwincheck} is set, the function is only
-- called if the object selected above is of type \var{WClientWin}.
function make_mplex_sub_or_self_fn(fn, noself, noinput, cwincheck)
if not fn then
warn("nil parameter to make_mplex_sub_or_self_fn")
end
return function(mplex, tgt)
if not tgt and not noinput then
tgt=mplex:current_input()
end
if not tgt then
tgt=mplex:current()
end
if not tgt then
if noself then
return
end
tgt=mplex
end
if (not cwincheck) or obj_is(tgt, "WClientWin") then
fn(tgt)
end
end
end
--DOC
-- Create a \type{WMPlex}-bindable function with arguments
-- (\code{mplex [, sub]}) that calls \var{fn} with parameter chosen
-- as \var{sub} if it is not nil and otherwise \code{mplex:current()}.
--
-- Calling this function is equivalent to
-- \fnref{make_mplex_sub_or_self_fn}\code{(fn, true, true, false)}.
function make_mplex_sub_fn(fn)
return make_mplex_sub_or_self_fn(fn, true, true, false)
end
--DOC
-- Create a \type{WMPlex}-bindable function with arguments
-- (\code{mplex [, sub]}) that chooses parameter for \var{fn}
-- as \var{sub} if it is not nil and otherwise \code{mplex:current()},
-- and calls \var{fn} if the object chosen is of type \fnref{WClientWin}.
--
-- Calling this function is equivalent to
-- \fnref{make_mplex_sub_or_self_fn}\code{(fn, true, true, true)}.
function make_mplex_clientwin_fn(fn)
return make_mplex_sub_or_self_fn(fn, true, true, true)
end
-- }}}
-- Managed object indexing {{{
--DOC
-- Returns the index of \var{mgd} in \var{mplex}'s managed list or
-- -1 if not on list.
function WMPlex.managed_index(mplex, mgd)
local list=mplex:managed_list()
for idx, mgd2 in list do
if mgd2==mgd then
return idx
end
end
return -1
end
--DOC
-- Returns the index of \fnref{WMPlex.current} in a \var{mplex}'s
-- managed list or -1 if there is no current managed object.
function WMPlex.current_index(mplex)
return mplex:managed_index(mplex:current())
end
--DOC
-- Move currently viewed object left within mplex; same as
-- \code{mplex:move_left(mplex:current())}.
function WMPlex.move_current_to_next_index(mplex)
local c=mplex:current()
if c then mplex:move_to_next_index(c) end
end
--DOC
-- Move currently viewed object right within mplex; same as
-- \code{mplex:move_left(mplex:current())}.
function WMPlex.move_current_to_prev_index(mplex)
local c=mplex:current()
if c then mplex:move_to_prev_index(c) end
end
-- }}}
--{{{ Misc. functions
local function propagate_close(reg)
if obj_is(reg, "WClientWin") then
local l=reg:managed_list()
if l then
local r2=l[table.getn(l)]
if r2 then
return propagate_close(r2)
end
end
end
reg:close()
end
--DOC
-- Close a \type{WMPlex} or some child of it using \fnref{WRegion.close} as
-- chosen by \fnref{make_mplex_sub_or_self}, but also, when the chosen object
-- is a \type{WClientWin}, propagate the close call to transients managed
-- by the \type{WClientWin}.
WMPlex.close_sub_or_self=make_mplex_sub_or_self_fn(propagate_close)
-- }}}
|