~ubuntu-branches/debian/sid/geany-plugins/sid

« back to all changes in this revision

Viewing changes to geanylua/examples/scripting/show-examples.lua

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-07-10 22:56:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090710225641-xc1126t7pq0jmpos
Tags: upstream-0.17.1
ImportĀ upstreamĀ versionĀ 0.17.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--[[
 
2
  Create a list of scripts from the examples directory
 
3
  and let the user select a script to open.
 
4
--]]
 
5
 
 
6
local filelist={}
 
7
 
 
8
local dirsep = geany.dirsep
 
9
 
 
10
local examples=geany.appinfo().scriptdir..dirsep.."examples"
 
11
 
 
12
function listfiles(dir)
 
13
  local stat=geany.stat(dir)
 
14
  if not (stat and stat.type=="d")
 
15
  then
 
16
   geany.message("Can't open folder:\n"..dir)
 
17
   return
 
18
  end
 
19
  for file in geany.dirlist(dir)
 
20
  do
 
21
    local path=dir..dirsep..file
 
22
    stat=geany.stat(path)
 
23
    if stat.type=="d"
 
24
    then
 
25
      listfiles(path) -- Recursive !
 
26
    else
 
27
     if stat.type=="r"
 
28
     then
 
29
      table.insert(filelist, path:sub(#examples+2))
 
30
     end
 
31
    end
 
32
  end
 
33
end
 
34
 
 
35
 
 
36
listfiles(examples)
 
37
 
 
38
if #filelist>0
 
39
then
 
40
  table.sort(filelist)
 
41
        geany.banner="Examples"
 
42
        local file=geany.choose("Choose a script to open:", filelist)
 
43
 
 
44
        if file then
 
45
                geany.open(examples..dirsep..file)
 
46
        end
 
47
end