blob: 95b7c0cc65778c78b38b07b9eca735d0120182fa (
plain)
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
|
-- Copyright 2007-2008 Mitchell mitchell<att>caladbolg.net. See LICENSE.
package.path = _HOME..'/core/?.lua;'..package.path
if not WIN32 then
package.cpath = _HOME..'/core/?.so;'..package.cpath
else
package.cpath = _HOME..'/core/?.dll;'..package.cpath
end
_THEME = ''
require 'iface'
require 'events'
require 'file_io'
if not MAC then
require 'lua_dialog'
end
---
-- Checks if the buffer being indexed is the currently focused buffer.
-- This is necessary because any buffer actions are performed in the focused
-- views' buffer, which may not be the buffer being indexed. Throws an error
-- if the check fails.
-- @param buffer The buffer in question.
function textadept.check_focused_buffer(buffer)
if type(buffer) ~= 'table' or not buffer.doc_pointer then
error('Buffer argument expected.', 2)
elseif textadept.focused_doc_pointer ~= buffer.doc_pointer then
error('The indexed buffer is not the focused one.', 2)
end
end
---
-- Displays a CocoaDialog of a specified type with given arguments returning
-- the result.
-- @param kind The CocoaDialog type.
-- @param ... A table of key, value arguments. Each key is a --key switch with
-- a "value" value. If value is nil, it is omitted and just the switch is
-- used.
-- @return string CocoaDialog result.
function cocoa_dialog(kind, opts)
local args = not MAC and { kind } or ''
for k, v in pairs(opts) do
if not MAC then
args[#args + 1] = '--'..k
if type(v) == 'string' then args[#args + 1] = v end
else
args = args..' --'..k
if type(v) == 'string' then args = args..' "'..v..'"' end
end
end
if not MAC then
return lua_dialog.run(args)
else
local cocoa_dialog = '/CocoaDialog.app/Contents/MacOS/CocoaDialog '
local p = io.popen(_HOME..cocoa_dialog..kind..args)
local out = p:read('*all') or ''
p:close()
return out
end
end
|