Re: The Future of the Side Pane/Project Manager

From: mitchell <mforal.n....at.gmail.com>
Date: Sun, 14 Mar 2010 13:59:06 -0700 (PDT)

Hi Robert,

> > Also as a proof-of-concept, I have used LuaFileSystem (lfs) to produce
> > a quick open file filter. It gets files in the current buffer's
> > directory, ta's current working directory, and any directories
> > specified in a global variable. I must say I'm very impressed.
>
> > That said, I'm strongly considering removing the pane completely in a
> > future version of ta. I do not wish to have it as a compile option
> > because I'd have to litter the C code with a bunch of #ifdef's, set a
> > global Lua variable, and litter init.lua et. al. with some if's in
> > order to skip load pm functionality -- it's too messy.
>
> Sounds very interesting, I never used the Project Manager too much,
> though being to able to see all open buffers at once was useful.
> Could you maybe post your proof-of-concept to try it out?

You will need the latest gcocoadialog from http://gcocoadialog.googlecode.com
and compile it into textadept. Then add the following file to your ta
path and 'require' it. You can use the Lua command entry to call
'textadept.io.snapopen()'

[sorry, I don't know how to attach via google groups]

local lfs = require 'lfs'
local max_depth = 3
local filter_ext = {
  bmp = true, tif = true, tiff = true, ps = true, png = true, mng =
true, ico = true, jpg = true,
  jpeg = true, gif = true, xcf = true, pdf = true, aac = true, flac =
true, mp3 = true,
  ogg = true, ra = true, ram = true, snd = true, wav = true, wma =
true, asf = true, asx = true,
  avi = true, divx = true, flv = true, mov = true, mp4 = true, mpeg =
true, mpg = true, qt = true,
  wmv = true, xvid = true, gdb = true, dll = true, ods = true, pps =
true, ppsx = true, ppt = true,
  xls = true, xlsx = true, otf = true, ttf = true, cab = true, la =
true, so = true, lo = true, o = true, exe = true,
  bat = true, ['7z'] = true, bz = true, bz2 = true, bzip = true, deb =
true, gz = true, gzip = true,
  rar = true, zip = true, tar = true, tbz = true, tbz2 = true, iso =
true, msi = true, part = true,
  torrent = true, doc = true, pyo = true, pyc = true, nfo = true, m4v
= true, rtf = true, ['in'] = true,
  gmo = true, toc = true, odt = true, dat = true, svg = true
}

function get_directory_contents(dir, list, depth)
  for file in lfs.dir(dir) do
    if not file:find('^%.%.?$') then -- ignore . and ..
      local path = dir..'/'..file
      local type = lfs.attributes(path, 'mode')
      if type == 'directory' and depth < 3 then
        get_directory_contents(path, list, depth + 1)
      elseif type == 'file' and not filter_ext[file:match('[^%.]+$')]
then
        list[path] = true
      end
    end
  end
end

function textadept.io.snapopen()
  local files = {}
  if buffer.filename then
    -- search buffer's directory and sub-directories
    get_directory_contents(buffer.filename:match('^(.+)[/\\]'), files,
0)
  end
  -- search cwd and sub-directories
  get_directory_contents(lfs.currentdir(), files, 0)
  if SNAPOPEN_DIRS then
    for dir in SNAPOPEN_DIRS:gmatch('[^;]+') do
      -- search user-specified directories and sub-directories
      get_directory_contents(dir, files, 0)
    end
  end
  local list = {}
  for file in pairs(files) do list[#list + 1] = file end
  local filenames =
    textadept.dialog('filteredlist',
                     '--title', locale.IO_OPEN_TITLE,
                     '--select-multiple',
                     '--string-output',
                     '--columns', 'File',
                     '--items', unpack(list)):match('^[^\r\n]+[\r\n]+(.
+)$')
  if filenames then
    for filename in filenames:gmatch('[^\r\n]+') do
      textadept.io.open(filename)
    end
  end
end
Received on Sun 14 Mar 2010 - 16:59:06 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:39:52 EST