diff options
Diffstat (limited to 'tex/context/base/l-pdfview.lua')
-rw-r--r-- | tex/context/base/l-pdfview.lua | 286 |
1 files changed, 143 insertions, 143 deletions
diff --git a/tex/context/base/l-pdfview.lua b/tex/context/base/l-pdfview.lua index 643d538e7..80033900f 100644 --- a/tex/context/base/l-pdfview.lua +++ b/tex/context/base/l-pdfview.lua @@ -1,143 +1,143 @@ -if not modules then modules = { } end modules ['l-pdfview'] = {
- version = 1.001,
- comment = "companion to mtx-context.lua",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
--- Todo: figure out pdfopen/pdfclose on linux. Calling e.g. okular directly
--- doesn't work in linux when issued from scite as it blocks the editor (no
--- & possible or so). Unfortunately pdfopen keeps changing with not keeping
--- downward compatibility (command line arguments and so).
-
--- no 2>&1 any more, needs checking on windows
-
-local format, concat = string.format, table.concat
-
-pdfview = pdfview or { }
-
-local opencalls, closecalls, allcalls, runner
-
-if os.type == "windows" then
-
- opencalls = {
- ['default'] = "pdfopen --rxi --file",
- ['acrobat'] = "pdfopen --rxi --file",
- ['fullacrobat'] = "pdfopen --axi --file",
- ['okular'] = 'start "test" "c:/data/system/kde/bin/okular.exe" --unique', -- todo!
- ['sumatra'] = 'start "test" "c:/data/system/sumatrapdf/sumatrapdf.exe" -reuse-instance',
- ['okular'] = 'start "test" "okular.exe" --unique',
- ['sumatra'] = 'start "test" "sumatrapdf.exe" -reuse-instance -bg-color 0xCCCCCC',
- }
- closecalls= {
- ['default'] = "pdfclose --file",
- ['acrobat'] = "pdfclose --file",
- ['okular'] = false,
- ['sumatra'] = false,
- }
- allcalls = {
- ['default'] = "pdfclose --all",
- ['acrobat'] = "pdfclose --all",
- ['okular'] = false,
- ['sumatra'] = false,
- }
-
- pdfview.method = "acrobat"
-
- runner = function(...)
--- os.spawn(...)
- os.execute(...)
- end
-
-else
-
- opencalls = {
- ['default'] = "pdfopen", -- we could pass the default here
- ['okular'] = 'okular --unique'
- }
- closecalls= {
- ['default'] = "pdfclose --file",
- ['okular'] = false,
- }
- allcalls = {
- ['default'] = "pdfclose --all",
- ['okular'] = false,
- }
-
- pdfview.method = "okular"
-
- runner = function(...)
- os.spawn(...)
- end
-
-end
-
-directives.register("pdfview.method", function(v)
- pdfview.method = (opencalls[v] and v) or 'default'
-end)
-
-function pdfview.setmethod(method)
- if method and opencalls[method] then
- pdfview.method = method
- end
-end
-
-function pdfview.methods()
- return concat(table.sortedkeys(opencalls), " ")
-end
-
-function pdfview.status()
- return format("pdfview methods: %s, current method: %s (directives_pdfview_method)",pdfview.methods(),tostring(pdfview.method))
-end
-
--- local openedfiles = { }
-
-local function fullname(name)
- return file.addsuffix(name,"pdf")
-end
-
-function pdfview.open(...)
- local opencall = opencalls[pdfview.method]
- if opencall then
- local t = { ... }
- for i=1,#t do
- local name = fullname(t[i])
- if io.exists(name) then
- runner(format('%s "%s"', opencall, name))
- -- openedfiles[name] = true
- end
- end
- end
-end
-
-function pdfview.close(...)
- local closecall = closecalls[pdfview.method]
- if closecall then
- local t = { ... }
- for i=1,#t do
- local name = fullname(t[i])
- -- if openedfiles[name] then
- runner(format('%s "%s"', closecall, name))
- -- openedfiles[name] = nil
- -- else
- -- pdfview.closeall()
- -- break
- -- end
- end
- end
-end
-
-function pdfview.closeall()
- local allcall = allcalls[pdfview.method]
- if allcall then
- runner(format('%s', allcall))
- end
- -- openedfiles = { }
-end
-
---~ pdfview.open("t:/document/show-exa.pdf")
---~ os.sleep(3)
---~ pdfview.close("t:/document/show-exa.pdf")
-
-return pdfview
+if not modules then modules = { } end modules ['l-pdfview'] = { + version = 1.001, + comment = "companion to mtx-context.lua", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- Todo: figure out pdfopen/pdfclose on linux. Calling e.g. okular directly +-- doesn't work in linux when issued from scite as it blocks the editor (no +-- & possible or so). Unfortunately pdfopen keeps changing with not keeping +-- downward compatibility (command line arguments and so). + +-- no 2>&1 any more, needs checking on windows + +local format, concat = string.format, table.concat + +pdfview = pdfview or { } + +local opencalls, closecalls, allcalls, runner + +if os.type == "windows" then + + opencalls = { + ['default'] = "pdfopen --rxi --file", + ['acrobat'] = "pdfopen --rxi --file", + ['fullacrobat'] = "pdfopen --axi --file", + ['okular'] = 'start "test" "c:/data/system/kde/bin/okular.exe" --unique', -- todo! + ['sumatra'] = 'start "test" "c:/data/system/sumatrapdf/sumatrapdf.exe" -reuse-instance', + ['okular'] = 'start "test" "okular.exe" --unique', + ['sumatra'] = 'start "test" "sumatrapdf.exe" -reuse-instance -bg-color 0xCCCCCC', + } + closecalls= { + ['default'] = "pdfclose --file", + ['acrobat'] = "pdfclose --file", + ['okular'] = false, + ['sumatra'] = false, + } + allcalls = { + ['default'] = "pdfclose --all", + ['acrobat'] = "pdfclose --all", + ['okular'] = false, + ['sumatra'] = false, + } + + pdfview.method = "acrobat" + + runner = function(...) +-- os.spawn(...) + os.execute(...) + end + +else + + opencalls = { + ['default'] = "pdfopen", -- we could pass the default here + ['okular'] = 'okular --unique' + } + closecalls= { + ['default'] = "pdfclose --file", + ['okular'] = false, + } + allcalls = { + ['default'] = "pdfclose --all", + ['okular'] = false, + } + + pdfview.method = "okular" + + runner = function(...) + os.spawn(...) + end + +end + +directives.register("pdfview.method", function(v) + pdfview.method = (opencalls[v] and v) or 'default' +end) + +function pdfview.setmethod(method) + if method and opencalls[method] then + pdfview.method = method + end +end + +function pdfview.methods() + return concat(table.sortedkeys(opencalls), " ") +end + +function pdfview.status() + return format("pdfview methods: %s, current method: %s (directives_pdfview_method)",pdfview.methods(),tostring(pdfview.method)) +end + +-- local openedfiles = { } + +local function fullname(name) + return file.addsuffix(name,"pdf") +end + +function pdfview.open(...) + local opencall = opencalls[pdfview.method] + if opencall then + local t = { ... } + for i=1,#t do + local name = fullname(t[i]) + if io.exists(name) then + runner(format('%s "%s"', opencall, name)) + -- openedfiles[name] = true + end + end + end +end + +function pdfview.close(...) + local closecall = closecalls[pdfview.method] + if closecall then + local t = { ... } + for i=1,#t do + local name = fullname(t[i]) + -- if openedfiles[name] then + runner(format('%s "%s"', closecall, name)) + -- openedfiles[name] = nil + -- else + -- pdfview.closeall() + -- break + -- end + end + end +end + +function pdfview.closeall() + local allcall = allcalls[pdfview.method] + if allcall then + runner(format('%s', allcall)) + end + -- openedfiles = { } +end + +--~ pdfview.open("t:/document/show-exa.pdf") +--~ os.sleep(3) +--~ pdfview.close("t:/document/show-exa.pdf") + +return pdfview |