scrn-hlp.lua /size: 3839 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
scrn-hlp
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to scrn-hlp.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
local
tonumber
=
tonumber
10 11
local
help
=
{
}
12
interactions
.
help
=
help
13 14
local
context
=
context
15
local
implement
=
interfaces
.
implement
16 17
local
formatters
=
string
.
formatters
18 19
local
a_help
=
attributes
.
private
(
"
help
"
)
20 21
local
copy_node_list
=
node
.
copy_list
22
local
hpack_node_list
=
node
.
hpack
23 24
local
register_list
=
nodes
.
pool
.
register
25 26
local
texgetbox
=
tex
.
getbox
27 28
local
nodecodes
=
nodes
.
nodecodes
29 30
local
hlist_code
=
nodecodes
.
hlist
31
local
vlist_code
=
nodecodes
.
vlist
32 33
local
data
,
references
=
{
}
,
{
}
34 35
local
helpscript
=
[[
36 function Hide_All_Help(prefix) { 37 var n = 0 38 while (true) { 39 n += 1 ; 40 v = this.getField(prefix + n) ; 41 if (v) { 42 v.hidden = true ; 43 this.dirty = false ; 44 } else { 45 return ; 46 } 47 } 48 } 49
]]
50 51
local
template
=
"
javascript(Hide_All_Help{help:}),action(show{help:%s})
"
52 53
local
function
register
(
specification
)
54
local
number
=
specification
.
number
55
local
name
=
specification
.
name
56
local
box
=
specification
.
box
57
if
number
and
name
and
box
then
58
if
helpscript
then
59
interactions
.
javascripts
.
setpreamble
(
"
HelpTexts
"
,
helpscript
)
60
helpscript
=
false
61
end
62
local
b
=
copy_node_list
(
texgetbox
(
box
)
)
63
register_list
(
b
)
64
data
[
number
]
=
b
65
if
name
and
name
~
=
"
"
then
66
references
[
name
]
=
number
67
structures
.
references
.
define
(
"
"
,
name
,
formatters
[
template
]
(
number
)
)
68
end
69
end
70
end
71 72
local
function
collectused
(
head
,
used
)
73
while
head
do
74
local
id
=
head
.
id
75
if
id
=
=
hlist_code
then
76
local
a
=
head
[
a_help
]
77
if
a
then
78
if
not
used
then
79
used
=
{
a
}
80
else
81
used
[
#
used
+
1
]
=
a
82
end
83
else
84
used
=
collectused
(
head
.
list
,
used
)
85
end
86
elseif
id
=
=
vlist_code
then
87
used
=
collectused
(
head
.
list
,
used
)
88
end
89
head
=
head
.
next
90
end
91
return
used
92
end
93 94
local
function
collect
(
box
)
95
if
next
(
data
)
then
96
return
collectused
(
texgetbox
(
box
)
.
list
)
97
end
98
end
99 100
local
function
reference
(
name
)
101
return
references
[
name
]
or
tonumber
(
name
)
or
0
102
end
103 104
help
.
register
=
register
105
help
.
collect
=
collect
106
help
.
reference
=
reference
107 108
implement
{
109
name
=
"
registerhelp
"
,
110
actions
=
register
,
111
arguments
=
{
112
{
113
{
"
number
"
,
"
integer
"
}
,
114
{
"
name
"
}
,
115
{
"
box
"
,
"
integer
"
}
116
}
117
}
118
}
119 120
implement
{
121
name
=
"
collecthelp
"
,
122
arguments
=
"
integer
"
,
123
actions
=
function
(
box
)
124
local
used
=
collect
(
box
)
125
if
used
then
126
local
done
=
{
}
127
context
.
startoverlay
(
)
128
for
i
=
1
,
#
used
do
129
local
d
=
data
[
used
[
i
]
]
130
if
d
and
not
done
[
d
]
then
131
local
box
=
hpack_node_list
(
copy_node_list
(
d
)
)
132
context
(
false
,
box
)
133
done
[
d
]
=
true
134
else
135
-- error
136
end
137
end
138
context
.
stopoverlay
(
)
139
end
140
end
141
}
142 143
implement
{
144
name
=
"
helpreference
"
,
145
arguments
=
"
string
"
,
146
actions
=
function
(
name
)
147
context
(
reference
(
name
)
)
148
end
149
}
150 151
implement
{
152
name
=
"
helpaction
"
,
153
arguments
=
"
string
"
,
154
actions
=
function
(
name
)
155
context
(
template
,
reference
(
name
)
)
156
end
157
}
158