aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/events.lua10
-rw-r--r--core/ext/find.lua6
-rw-r--r--core/file_io.lua36
-rw-r--r--core/init.lua20
-rw-r--r--modules/textadept/editing.lua11
-rw-r--r--modules/textadept/macros.lua22
6 files changed, 68 insertions, 37 deletions
diff --git a/core/events.lua b/core/events.lua
index f9f6d484..1fb1ab42 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -372,11 +372,11 @@ add_handler('quit',
end
end
if any then
- list = list..'\nQuit without saving?'
- if os.execute('zenity --question --title Alert '..
- '--text "'..list..'"') ~= 0 then
- return false
- end
+ if tonumber( cocoa_dialog( 'yesno-msgbox', {
+ title = 'Save?',
+ text = 'Save changes before quitting?',
+ ['informative-text'] = list..'\nYou will have to save changes manually.'
+ } ) ) ~= 2 then return false end
end
textadept.io.save_session()
return true
diff --git a/core/ext/find.lua b/core/ext/find.lua
index 803e31a9..3b571857 100644
--- a/core/ext/find.lua
+++ b/core/ext/find.lua
@@ -96,7 +96,11 @@ function find.replace(rtext)
function(code)
local ret, val = pcall( loadstring('return '..code) )
if not ret then
- os.execute('zenity --error --text "'..val:gsub('"', '\\"')..'"')
+ cocoa_dialog( 'msgbox', {
+ title = 'Error',
+ text = 'An error occured:',
+ ['informative-text'] = val:gsub('"', '\\"')
+ } )
error()
end
return val
diff --git a/core/file_io.lua b/core/file_io.lua
index 29d7d535..ed2b8c55 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -44,13 +44,13 @@ end
-- specified, the user is prompted to open files from a dialog.
-- @usage textadept.io.open(filename)
function open(filenames)
- if not filenames then
- local directory = '--filename="'..(buffer.filename or '')..'"'
- local p = io.popen('zenity --file-selection --multiple '..directory)
- filenames = p:read('*all')
- p:close()
- end
- for filename in filenames:gmatch('[^|\n]+') do open_helper(filename) end
+ filenames = filenames or cocoa_dialog( 'fileselect', {
+ title = 'Open',
+ text = 'Select a file(s) to open',
+ ['select-multiple'] = true,
+ ['with-directory'] = (buffer.filename or ''):match('.+/')
+ } )
+ for filename in filenames:gmatch('[^\n]+') do open_helper(filename) end
end
---
@@ -100,14 +100,15 @@ end
function save_as(buffer, filename)
textadept.check_focused_buffer(buffer)
if not filename then
- local directory = '--filename="'..(buffer.filename or '')..'"'
- local p = io.popen('zenity --file-selection --save '..directory..
- ' --confirm-overwrite')
- filename = p:read('*all')
- p:close()
+ filename = cocoa_dialog( 'filesave', {
+ title = 'Save',
+ ['with-directory'] = buffer.filename:match('.+/'),
+ ['with-file'] = buffer.filename:match('[^/]+$'),
+ ['no-newline'] = true
+ } )
end
if #filename > 0 then
- buffer.filename = filename:sub(1, -2) -- chomp
+ buffer.filename = filename
buffer:save()
events.handle('file_saved_as', filename)
end
@@ -136,10 +137,11 @@ end
-- @usage buffer:close()
function close(buffer)
textadept.check_focused_buffer(buffer)
- if buffer.dirty and os.execute('zenity --question --title Alert '..
- '--text "Close without saving?"') ~= 0 then
- return false
- end
+ if buffer.dirty and tonumber( cocoa_dialog( 'yesno-msgbox', {
+ title = 'Save?',
+ text = 'Save changes before closing?',
+ ['informative-text'] = 'You will have to save changes manually.'
+ } ) ) ~= 2 then return false end
buffer:delete()
return true
end
diff --git a/core/init.lua b/core/init.lua
index f699b8e0..d2eff849 100644
--- a/core/init.lua
+++ b/core/init.lua
@@ -14,6 +14,26 @@ function textadept.check_focused_buffer(buffer)
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 = ''
+ for k, v in pairs(opts) do
+ args = args..' --'..k
+ if type(v) == 'string' then args = args..' "'..v..'"' end
+ end
+ local p = io.popen('CocoaDialog '..kind..args)
+ local out = p:read('*all')
+ p:close()
+ return out
+end
+
package.path = package.path..';'.._HOME..'/core/?.lua'
require 'iface'
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index 76a98f3b..6395faf2 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -219,11 +219,12 @@ end
function goto_line(line)
local buffer = buffer
if not line then
- local p = io.popen('zenity --entry --title "Go To" '..
- '--text "Line Number:"')
- line = p:read('*all')
- p:close()
- if line == '' then return end
+ line = cocoa_dialog( 'standard-inputbox', {
+ title = 'Go To',
+ text = 'Line Number:',
+ ['no-newline'] = true
+ } ):match('%d+$')
+ if not line then return end
line = tonumber(line)
end
buffer:ensure_visible_enforce_policy(line - 1)
diff --git a/modules/textadept/macros.lua b/modules/textadept/macros.lua
index 1502d5d5..2514256a 100644
--- a/modules/textadept/macros.lua
+++ b/modules/textadept/macros.lua
@@ -66,9 +66,11 @@ function stop_recording()
recording = false
local textadept = textadept
local bf, bp = textadept.buffer_functions, textadept.buffer_properties
- local p = io.popen('zenity --entry --text "Macro name:"')
- local macro_name = p:read('*all'):sub(1, -2)
- p:close()
+ local macro_name = cocoa_dialog( 'standard-inputbox', {
+ title = 'Save Macro',
+ text = 'Macro name:',
+ ['no-newline'] = true
+ } )
if #macro_name > 0 then
for _, command in ipairs(current) do
@@ -84,7 +86,7 @@ function stop_recording()
end
end
end
- list[macro_name] = current
+ list[ macro_name:match('[^\n]+') ] = current
save()
textadept.statusbar_text = 'Macro saved'
textadept.events.handle('macro_saved')
@@ -106,11 +108,13 @@ end
function play(macro_name)
if not macro_name then
local macro_list = ''
- for name in pairs(list) do macro_list = macro_list..name..' ' end
- local p = io.popen('zenity --list --text "Select a Macro" --column Name '..
- macro_list)
- macro_name = p:read('*all'):sub(1, -2)
- p:close()
+ for name in pairs(list) do macro_list = macro_list..'"'..name..'"'..' ' end
+ macro_name = cocoa_dialog( 'standard-dropdown', {
+ title = 'Select a Macro',
+ text = 'Macro name:',
+ items = macro_list,
+ ['no-newline'] = true
+ } )
end
local macro = list[macro_name]
if not macro then return end