summaryrefslogtreecommitdiff
path: root/tex/context/base/scrn-hlp.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2011-03-25 19:20:25 +0200
committerMarius <mariausol@gmail.com>2011-03-25 19:20:25 +0200
commit1455dd60b68c9140db1b9977c9e5ce372b772ec8 (patch)
treed2b7060a4d9891966a056dcf143ef20d43390561 /tex/context/base/scrn-hlp.lua
parent2a9554684f61df8db63dec6d4e874f49b25a212b (diff)
downloadcontext-1455dd60b68c9140db1b9977c9e5ce372b772ec8.tar.gz
beta 2011.03.25 18:03
Diffstat (limited to 'tex/context/base/scrn-hlp.lua')
-rw-r--r--tex/context/base/scrn-hlp.lua120
1 files changed, 120 insertions, 0 deletions
diff --git a/tex/context/base/scrn-hlp.lua b/tex/context/base/scrn-hlp.lua
new file mode 100644
index 000000000..81d68840b
--- /dev/null
+++ b/tex/context/base/scrn-hlp.lua
@@ -0,0 +1,120 @@
+if not modules then modules = { } end modules ['scrn-hlp'] = {
+ version = 1.001,
+ comment = "companion to scrn-hlp.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+
+local help = { }
+interactions.help = help
+
+local a_help = attributes.private("help")
+
+local has_attribute = node.has_attribute
+local copy_nodelist = node.copy_list
+local hpack_nodelist = node.hpack
+
+local register_list = nodes.pool.register
+
+local nodecodes = nodes.nodecodes
+
+local hlist_code = nodecodes.hlist
+local vlist_code = nodecodes.vlist
+
+local data, references = { }, { }
+
+local helpscript = [[
+ function Hide_All_Help(prefix) {
+ var n = 0
+ while (true) {
+ n += 1 ;
+ v = this.getField(prefix + n) ;
+ if (v) {
+ v.hidden = true ;
+ this.dirty = false ;
+ } else {
+ return ;
+ }
+ }
+ }
+]]
+
+local template = "javascript(Hide_All_Help{help:}),action(show{help:%s})"
+
+function help.register(number,name,box)
+ if helpscript then
+ interactions.javascripts.setpreamble("HelpTexts",helpscript)
+ helpscript = false
+ end
+ local b = copy_nodelist(tex.box[box])
+ register_list(b)
+ data[number] = b
+ if name and name ~= "" then
+ references[name] = number
+ structures.references.define("",name,format(template,number))
+ end
+end
+
+local function collect(head,used)
+ while head do
+ local id = head.id
+ if id == hlist_code then
+ local a = has_attribute(head,a_help)
+ if a then
+ if not used then
+ used = { a }
+ else
+ used[#used+1] = a
+ end
+ else
+ used = collect(head.list,used)
+ end
+ elseif id == vlist_code then
+ used = collect(head.list,used)
+ end
+ head = head.next
+ end
+ return used
+end
+
+function help.collect(box)
+ if next(data) then
+ return collect(tex.box[box].list)
+ end
+end
+
+commands.registerhelp = help.register
+
+function commands.collecthelp(box)
+ local used = help.collect(box)
+ if used then
+ local done = { }
+ context.startoverlay()
+ for i=1,#used do
+ local d = data[used[i]]
+ if d and not done[d] then
+ local box = hpack_nodelist(copy_nodelist(d))
+ context(false,box)
+ done[d] = true
+ else
+ -- error
+ end
+ end
+ context.stopoverlay()
+ end
+end
+
+function help.reference(name)
+ return references[name] or tonumber(name) or 0
+end
+
+function commands.helpreference(name)
+ context(references[name] or tonumber(name) or 0)
+end
+
+function commands.helpaction(name)
+ context(template,references[name] or tonumber(name) or 0)
+end