File: help.lua

package info (click to toggle)
geany-plugins 2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,832 kB
  • sloc: ansic: 107,883; sh: 5,567; makefile: 1,531; sed: 16
file content (60 lines) | stat: -rw-r--r-- 1,524 bytes parent folder | download | duplicates (11)
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
--[[
  Tries to open the GeanyLua help file index in the user's web browser.
--]]


local DirSep = geany.dirsep
local HelpFile = DirSep.."geanylua-index.html"
local AppInfo = geany.appinfo()

local OwnHelpDir=AppInfo.scriptdir..DirSep.."support"

-- FIXME: expose GeanyLua's $DOCDIR to Lua scripts.
local DocDir=geany.dirname(AppInfo.docdir:gsub("html", ""):gsub("geany", "geany-plugins"))
local SysHelpDir=DocDir..DirSep.."geanylua"

local Browsers={ AppInfo.tools.browser,
                 "firefox", "mozilla", "opera",
                 "konqueror", "netscape", "iexplore"
               }

local FullName=nil


-- Search in user and sytem directory for help file
for i,Dir in pairs( { OwnHelpDir, SysHelpDir } )
do
  FullName=Dir..HelpFile
	local st=geany.stat(FullName)
	if (st) and (st.type == "r") --it exists and  it's a regular file
	then
    break
  else
    FullName=nil
	end
end



if FullName then
  if (DirSep=="\\") then
    -- windows hack
    OldDir=geany.wkdir()
    geany.wkdir(geany.dirname(FullName))
    local rv,msg=geany.launch(os.getenv("COMSPEC"),"/C","start",geany.basename(FullName))
    geany.wkdir(OldDir)
    if not rv then geany.message(msg) end
  else
    local url="file://"..FullName
    for i,Browser in pairs(Browsers) -- loop through possible browsers
    do
      rv,msg=geany.launch(Browser, url)
      if rv then break end
      geany.message(msg)
    end
  end
else
  geany.message("Error launching help",
     "Can't find help file in:\n "..OwnHelpDir.."\nor:\n"..SysHelpDir)
end