File: show-examples.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 (47 lines) | stat: -rw-r--r-- 878 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
--[[
  Create a list of scripts from the examples directory
  and let the user select a script to open.
--]]

local filelist={}

local dirsep = geany.dirsep

local examples=geany.appinfo().scriptdir..dirsep.."examples"

function listfiles(dir)
  local stat=geany.stat(dir)
  if not (stat and stat.type=="d")
  then
   geany.message("Can't open folder:\n"..dir)
   return
  end
  for file in geany.dirlist(dir)
  do
    local path=dir..dirsep..file
    stat=geany.stat(path)
    if stat.type=="d"
    then
      listfiles(path) -- Recursive !
    else
     if stat.type=="r"
     then
      table.insert(filelist, path:sub(#examples+2))
     end
    end
  end
end


listfiles(examples)

if #filelist>0
then
  table.sort(filelist)
	geany.banner="Examples"
	local file=geany.choose("Choose a script to open:", filelist)

	if file then
		geany.open(examples..dirsep..file)
	end
end