aboutsummaryrefslogtreecommitdiff
path: root/core/ext/pm/file_browser.lua
diff options
context:
space:
mode:
Diffstat (limited to 'core/ext/pm/file_browser.lua')
-rw-r--r--core/ext/pm/file_browser.lua64
1 files changed, 64 insertions, 0 deletions
diff --git a/core/ext/pm/file_browser.lua b/core/ext/pm/file_browser.lua
new file mode 100644
index 00000000..9acf9bec
--- /dev/null
+++ b/core/ext/pm/file_browser.lua
@@ -0,0 +1,64 @@
+-- Copyright 2007 Mitchell mitchell<att>caladbolg.net. See LICENSE.
+
+---
+-- File browser for the Textadept project manager.
+-- It is enabled by providing the absolute path to a directory in the project
+-- manager entry field.
+module('textadept.pm.browsers.file', package.seeall)
+
+function matches(entry_text)
+ return entry_text:sub(1, 1) == '/'
+end
+
+function get_contents_for(full_path)
+ local dirpath = table.concat(full_path, '/')
+ local out = io.popen('ls -1p "'..dirpath..'"'):read('*all')
+ if #out == 0 then
+ error('No such directory: '..dirpath)
+ return {}
+ end
+ local dir = {}
+ for entry in out:gmatch('[^\n]+') do
+ if entry:sub(-1, -1) == '/' then
+ local name = entry:sub(1, -2)
+ dir[name] = {
+ parent = true,
+ display_text = name,
+ pixbuf = 'gtk-directory'
+ }
+ else
+ dir[entry] = { display_text = entry }
+ end
+ end
+ return dir
+end
+
+function perform_action(selected_item)
+ local filepath = table.concat(selected_item, '/')
+ textadept.io.open(filepath)
+ view:focus()
+end
+
+function get_context_menu(selected_item)
+ return { '_Change Directory', 'File _Details' }
+end
+
+function perform_menu_action(menu_item, selected_item)
+ local filepath = table.concat(selected_item, '/')
+ if menu_item == 'Change Directory' then
+ textadept.pm.entry_text = filepath
+ textadept.pm.activate()
+ elseif menu_item == 'File Details' then
+ local out = io.popen('ls -dhl "'..filepath..'"'):read('*all')
+ local perms, num_dirs, owner, group, size, mod_date =
+ out:match('^(%S+) (%S+) (%S+) (%S+) (%S+) (%S+ %S)')
+ out = 'File details for:\n'..filepath..'\n'..
+ 'Perms:\t'..perms..'\n'..
+ '#Dirs:\t'..num_dirs..'\n'..
+ 'Owner:\t'..owner..'\n'..
+ 'Group:\t'..group..'\n'..
+ 'Size:\t'..size..'\n'..
+ 'Date:\t'..mod_date
+ text_input(out, nil, false, 250, 250)
+ end
+end