diff options
author | 2009-07-08 19:39:26 -0400 | |
---|---|---|
committer | 2009-07-08 19:39:26 -0400 | |
commit | a8e87e8efd47676ff0f04fbfba14be189b169ebb (patch) | |
tree | e04ec88b6ad70d43b39e0c2700a86affc316fa88 /core | |
parent | 9827462bc8ac4ecc6009f2285c2397bf6ff64777 (diff) | |
download | textadept-a8e87e8efd47676ff0f04fbfba14be189b169ebb.tar.gz textadept-a8e87e8efd47676ff0f04fbfba14be189b169ebb.zip |
Replace lua_dialog with gcocoadialog.
Diffstat (limited to 'core')
-rw-r--r-- | core/.textadept.lua | 12 | ||||
-rw-r--r-- | core/events.lua | 18 | ||||
-rw-r--r-- | core/ext/find.lua | 25 | ||||
-rw-r--r-- | core/ext/pm/file_browser.lua | 13 | ||||
-rw-r--r-- | core/ext/pm/modules_browser.lua | 42 | ||||
-rw-r--r-- | core/file_io.lua | 56 | ||||
-rw-r--r-- | core/init.lua | 29 |
7 files changed, 83 insertions, 112 deletions
diff --git a/core/.textadept.lua b/core/.textadept.lua index 0f2b02d9..d0247f60 100644 --- a/core/.textadept.lua +++ b/core/.textadept.lua @@ -119,14 +119,10 @@ function _print(buffer_type, ...) -- Prints messages to the Textadept message buffer. -- Opens a new buffer (if one hasn't already been opened) for printing messages. -- @param ... Message strings. -function textadept.print(...) end +function print(...) end --- --- Displays a CocoaDialog of a specified type with given arguments returning --- the result. --- @param kind The CocoaDialog type. --- @param opts 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. +-- Displays a CocoaDialog of a specified type with the given string arguments. +-- Each argument is like a string in Lua's 'arg' table. -- @return string CocoaDialog result. -function cocoa_dialog(kind, opts) +function dialog(kind, ...) diff --git a/core/events.lua b/core/events.lua index 28e446c9..afaffd5f 100644 --- a/core/events.lua +++ b/core/events.lua @@ -85,6 +85,7 @@ module('textadept.events', package.seeall) -- pm_menu_clicked(menu_id, selected_item) -- menu_id: the numeric ID for the menu item. -- selected_item: identical to 'full_path' for 'pm_contents_request' event. +-- pm_view_filled() -- find(text, next) -- text: the text to find. -- next: flag indicating whether or not the search direction is forward. @@ -458,14 +459,15 @@ add_handler('quit', any = true end end - if any then - if cocoa_dialog('yesno-msgbox', { - title = locale.EVENTS_QUIT_TITLE, - text = locale.EVENTS_QUIT_TEXT, - ['informative-text'] = - string.format(locale.EVENTS_QUIT_MSG, table.concat(list, '\n')), - ['no-newline'] = true - }) ~= '2' then return false end + if any and + textadept.dialog('yesno-msgbox', + '--title', locale.EVENTS_QUIT_TITLE, + '--text', locale.EVENTS_QUIT_TEXT, + '--informative-text', + string.format(locale.EVENTS_QUIT_MSG, + table.concat(list, '\n')), + '--no-newline') ~= '2' then + return false end return true end) diff --git a/core/ext/find.lua b/core/ext/find.lua index c97cefd3..1f3dfa99 100644 --- a/core/ext/find.lua +++ b/core/ext/find.lua @@ -79,13 +79,13 @@ local function find_(text, next, flags, nowrap, wrapped) else -- find in files local utf8_dir = - cocoa_dialog('fileselect', { - title = locale.FIND_IN_FILES_TITLE, - text = locale.FIND_IN_FILES_TEXT, - ['select-only-directories'] = true, - ['with-directory'] = (buffer.filename or ''):match('^.+[/\\]'), - ['no-newline'] = true - }) + textadept.dialog('fileselect', + '--title', locale.FIND_IN_FILES_TITLE, + '--text', locale.FIND_IN_FILES_TEXT, + '--select-only-directories', + '--with-directory', + (buffer.filename or ''):match('^.+[/\\]') or '', + '--no-newline') if #utf8_dir > 0 then if not find.lua then text = text:gsub('([().*+?^$%%[%]-])', '%%%1') end if not find.match_case then text = text:lower() end @@ -182,12 +182,11 @@ local function replace(rtext) function(code) local ret, val = pcall(loadstring('return '..code)) if not ret then - cocoa_dialog('ok-msgbox', { - title = locale.FIND_ERROR_DIALOG_TITLE, - text = locale.FIND_ERROR_DIALOG_TEXT, - ['informative-text'] = val:gsub('"', '\\"'), - ['no-cancel'] = true - }) + textadept.dialog('ok-msgbox', + '--title', locale.FIND_ERROR_DIALOG_TITLE, + '--text', locale.FIND_ERROR_DIALOG_TEXT, + '--informative-text', val:gsub('"', '\\"'), + '--no-cancel') error() end return val diff --git a/core/ext/pm/file_browser.lua b/core/ext/pm/file_browser.lua index 8bff30f0..95587500 100644 --- a/core/ext/pm/file_browser.lua +++ b/core/ext/pm/file_browser.lua @@ -77,13 +77,12 @@ function perform_menu_action(menu_id, selected_item) os.date(date_format, attr.access), os.date(date_format, attr.modification), os.date(date_format, attr.change)) - cocoa_dialog('textbox', { - ['informative-text'] = - string.format(locale.PM_BROWSER_FILE_INFO_TEXT, utf8_filepath), - text = out, - button1 = locale.PM_BROWSER_FILE_INFO_OK, - editable = false - }) + textadept.dialog('textbox', + '--informative-text', + string.format(locale.PM_BROWSER_FILE_INFO_TEXT, + utf8_filepath), + '--text', out, + '--button1', locale.PM_BROWSER_FILE_INFO_OK) elseif menu_id == ID.SHOW_DOT_FILES then show_dot_files = not show_dot_files textadept.pm.activate() diff --git a/core/ext/pm/modules_browser.lua b/core/ext/pm/modules_browser.lua index 8472ee0d..839fbce9 100644 --- a/core/ext/pm/modules_browser.lua +++ b/core/ext/pm/modules_browser.lua @@ -133,16 +133,18 @@ end function perform_menu_action(menu_id, selected_item) if menu_id == ID.NEW then local status, module_name = - cocoa_dialog('standard-inputbox', { - ['title'] = locale.PM_BROWSER_MODULE_NEW_TITLE, - ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_INFO_TEXT - }):match('^(%d)%s+([^\n]+)%s+$') + textadept.dialog('standard-inputbox', + '--title', locale.PM_BROWSER_MODULE_NEW_TITLE, + '--informative-text', + locale.PM_BROWSER_MODULE_NEW_INFO_TEXT + ):match('^(%d)%s+([^\n]+)%s+$') if status ~= '1' then return end local status, lang_name = - cocoa_dialog('standard-inputbox', { - ['title'] = locale.PM_BROWSER_MODULE_NEW_LANG_TITLE, - ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_LANG_INFO_TEXT - }):match('^(%d)%s+([^\n]+)%s+$') + textadept.dialog('standard-inputbox', + '--title', locale.PM_BROWSER_MODULE_NEW_LANG_TITLE, + '--informative-text', + locale.PM_BROWSER_MODULE_NEW_LANG_INFO_TEXT + ):match('^(%d)%s+([^\n]+)%s+$') if status ~= '1' then return end local module_dir = _HOME..'/modules/'..module_name if lfs.mkdir(module_dir) then @@ -162,22 +164,22 @@ function perform_menu_action(menu_id, selected_item) f:write(out) f:close() else - cocoa_dialog('ok-msgbox', { - ['text'] = locale.PM_BROWSER_MODULE_NEW_ERROR, - ['informative-text'] = locale.PM_BROWSER_MODULE_NEW_ERROR_TEXT, - ['no-cancel'] = true - }) + textadept.dialog('ok-msgbox', + '--text', locale.PM_BROWSER_MODULE_NEW_ERROR, + '--informative-text', + locale.PM_BROWSER_MODULE_NEW_ERROR_TEXT, + '--no-cancel') return end elseif menu_id == ID.DELETE then local module_name = selected_item[2] - if cocoa_dialog('yesno-msgbox', { - ['text'] = locale.PM_BROWSER_MODULE_DELETE_TITLE, - ['informative-text'] = - string.format(locale.PM_BROWSER_MODULE_DELETE_TEXT, module_name), - ['no-cancel'] = true, - ['no-newline'] = true - }) == '1' then + if textadept.dialog('yesno-msgbox', + '--text', locale.PM_BROWSER_MODULE_DELETE_TITLE, + '--informative-text', + string.format(locale.PM_BROWSER_MODULE_DELETE_TEXT, + module_name), + '--no-cancel', + '--no-newline') == '1' then local function remove_directory(dirpath) for name in lfs.dir(dirpath) do if not name:find('^%.%.?$') then os.remove(dirpath..'/'..name) end diff --git a/core/file_io.lua b/core/file_io.lua index 2052da73..4634f8f6 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -148,14 +148,13 @@ end -- @usage textadept.io.open(utf8_encoded_filename) function open(utf8_filenames) utf8_filenames = - utf8_filenames or cocoa_dialog('fileselect', { - title = locale.IO_OPEN_TITLE, - text = locale.IO_OPEN_TEXT, - -- in Windows, dialog:get_filenames() is unavailable; only allow single - -- selection - ['select-multiple'] = not WIN32 or nil, - ['with-directory'] = (buffer.filename or ''):match('.+[/\\]') - }) + utf8_filenames or + textadept.dialog('fileselect', + '--title', locale.IO_OPEN_TITLE, + '--text', locale.IO_OPEN_TEXT, + '--select-multiple', + '--with-directory', + (buffer.filename or ''):match('.+[/\\]') or '') for filename in utf8_filenames:gmatch('[^\n]+') do open_helper(filename) end end @@ -246,12 +245,13 @@ function save_as(buffer, utf8_filename) textadept.check_focused_buffer(buffer) if not utf8_filename then utf8_filename = - cocoa_dialog('filesave', { - title = locale.IO_SAVE_TITLE, - ['with-directory'] = (buffer.filename or ''):match('.+[/\\]'), - ['with-file'] = (buffer.filename or ''):match('[^/\\]+$'), - ['no-newline'] = true - }) + textadept.dialog('filesave', + '--title', locale.IO_SAVE_TITLE, + '--with-directory', + (buffer.filename or ''):match('.+[/\\]') or '', + '--with-file', + (buffer.filename or ''):match('[^/\\]+$') or '', + '--no-newline') end if #utf8_filename > 0 then buffer.filename = utf8_filename @@ -283,12 +283,14 @@ end -- @usage buffer:close() function close(buffer) textadept.check_focused_buffer(buffer) - if buffer.dirty and cocoa_dialog('yesno-msgbox', { - title = locale.IO_CLOSE_TITLE, - text = locale.IO_CLOSE_TEXT, - ['informative-text'] = locale.IO_CLOSE_MSG, - ['no-newline'] = true - }) ~= '2' then return false end + if buffer.dirty and + textadept.dialog('yesno-msgbox', + '--title', locale.IO_CLOSE_TITLE, + '--text', locale.IO_CLOSE_TEXT, + '--informative-text', locale.IO_CLOSE_MSG, + '--no-newline') ~= '2' then + return false + end buffer:delete() return true end @@ -347,13 +349,13 @@ local function update_modified_file() local attributes = lfs.attributes(filename) if not attributes then return end if buffer.modification_time < attributes.modification then - if cocoa_dialog('yesno-msgbox', { - title = locale.IO_RELOAD_TITLE, - text = locale.IO_RELOAD_TEXT, - ['informative-text'] = string.format(locale.IO_RELOAD_MSG, utf8_filename), - ['no-cancel'] = true, - ['no-newline'] = true - }) == '1' then + if textadept.dialog('yesno-msgbox', + '--title', locale.IO_RELOAD_TITLE, + '--text', locale.IO_RELOAD_TEXT, + '--informative-text', + string.format(locale.IO_RELOAD_MSG, utf8_filename), + '--no-cancel', + '--no-newline') == '1' then buffer:reload() else buffer.modification_time = attributes.modification diff --git a/core/init.lua b/core/init.lua index 73fdebac..77ae0238 100644 --- a/core/init.lua +++ b/core/init.lua @@ -27,9 +27,6 @@ require 'iface' require 'locale' require 'events' require 'file_io' -if not MAC then - require 'lua_dialog' -end rawset = nil -- do not allow modifications which could compromise stability @@ -79,29 +76,3 @@ end -- LuaDoc is in core/.textadept.lua. function textadept.print(...) textadept._print(locale.MESSAGE_BUFFER, ...) end - --- LuaDoc is in core/.textadept.lua. -function cocoa_dialog(kind, opts) - local args = { kind } - for k, v in pairs(opts) do - args[#args + 1] = '--'..k - if k == 'items' and kind:find('dropdown') then - if not MAC then - for item in v:gmatch('"(.-)"%s+') do args[#args + 1] = item end - else - args[#args + 1] = v - end - elseif type(v) == 'string' then - args[#args + 1] = not MAC and v or '"'..v..'"' - 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..table.concat(args, ' ')) - local out = p:read('*all') - p:close() - return out - end -end |