From 47b8c0db856c48abbcbcb5635deaa5c2cc41427e Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Sat, 23 Feb 2008 18:13:24 -0500 Subject: Eliminated Zenity dependency; replaced with my CocoaDialog clone (lua_dialog). --- core/events.lua | 10 +++++----- core/ext/find.lua | 6 +++++- core/file_io.lua | 36 +++++++++++++++++++----------------- core/init.lua | 20 ++++++++++++++++++++ 4 files changed, 49 insertions(+), 23 deletions(-) (limited to 'core') 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' -- cgit v1.2.3