diff options
-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 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 9 | ||||
-rw-r--r-- | src/Makefile | 6 | ||||
-rw-r--r-- | src/lua_interface.c | 14 | ||||
-rw-r--r-- | src/textadept.c | 9 | ||||
-rw-r--r-- | src/textadept.h | 1 |
12 files changed, 112 insertions, 122 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 diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index ee312df0..5556e110 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -266,11 +266,10 @@ function goto_line(line) local buffer = buffer if not line then line = - cocoa_dialog('standard-inputbox', { - title = locale.M_TEXTADEPT_EDITING_GOTO_TITLE, - text = locale.M_TEXTADEPT_EDITING_GOTO_TEXT, - ['no-newline'] = true - }) + textadept.dialog('standard-inputbox', + '--title', locale.M_TEXTADEPT_EDITING_GOTO_TITLE, + '--text', locale.M_TEXTADEPT_EDITING_GOTO_TEXT, + '--no-newline') line = tonumber(line:match('%-?%d+$')) if not line or line < 0 then return end end diff --git a/src/Makefile b/src/Makefile index 52fb26fe..d9ede43c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,7 @@ .SUFFIXES: .c .o .h .a -INCLUDEDIRS=-Iscintilla-st/include -Ilua/include +INCLUDEDIRS=-Iscintilla-st/include -Ilua/include -Igcocoadialog ifdef DEBUG CXXFLAGS=-DDEBUG -g -DGTK -DSCI_LEXER -W -Wall -Wno-sign-compare else @@ -32,8 +32,10 @@ all: textadept g++ $(GTKFLAGS) $(INCLUDEDIRS) $(CXXFLAGS) -c $< -o $@ $(LUA_OBJS): lua/src/*.c gcc $(INCLUDEDIRS) -DLUA_USE_LINUX $(CXXFLAGS) -c lua/src/*.c +gcocoadialog.o: gcocoadialog/gcocoadialog.c + gcc $(GTKFLAGS) $(INCLUDEDIRS) $(CXXFLAGS) -c gcocoadialog/gcocoadialog.c textadept:\ - textadept.o lua_interface.o $(LUA_OBJS) \ + textadept.o lua_interface.o $(LUA_OBJS) gcocoadialog.o \ scintilla-st/gtk/LexLPeg.o scintilla-st/bin/scintilla.a g++ $(GTKLIBS) $(EXPORTLUASYMS) -DGTK $^ -o $@ mv textadept ../ diff --git a/src/lua_interface.c b/src/lua_interface.c index b8101e20..d48919bb 100644 --- a/src/lua_interface.c +++ b/src/lua_interface.c @@ -64,6 +64,7 @@ static int l_cf_buffer_delete(lua_State *lua), l_cf_view_split(lua_State *lua), l_cf_view_unsplit(lua_State *lua), l_cf_ta_buffer_new(lua_State *lua), + l_cf_ta_dialog(lua_State *lua), l_cf_ta_get_split_table(lua_State *lua), l_cf_ta_goto_window(lua_State *lua), l_cf_view_goto_buffer(lua_State *lua), @@ -138,6 +139,7 @@ bool l_init(int argc, char **argv, bool reinit) { l_cfunc(lua, l_cf_ce_show_completions, "show_completions"); l_mt(lua, "_ce_mt", l_ce_mt_index, l_ce_mt_newindex); lua_setfield(lua, -2, "command_entry"); + l_cfunc(lua, l_cf_ta_dialog, "dialog"); l_cfunc(lua, l_cf_ta_get_split_table, "get_split_table"); l_cfunc(lua, l_cf_ta_goto_window, "goto_view"); l_cfunc(lua, l_cf_ta_gtkmenu, "gtkmenu"); @@ -1279,6 +1281,18 @@ static int l_cf_view_goto_buffer(lua_State *lua) { return 0; } +static int l_cf_ta_dialog(lua_State *lua) { + enum GCDialogs type = gcocoadialog_type(luaL_checkstring(lua, 1)); + int argc = lua_gettop(lua) - 1; + const char **argv = static_cast<const char**>(malloc(argc * sizeof(char *))); + for (int i = 0; i < argc; i++) argv[i] = luaL_checkstring(lua, i + 2); + char *out = gcocoadialog(type, argc, argv); + lua_pushstring(lua, out); + free(out); + free(argv); + return 1; +} + static int l_cf_ta_goto_window(lua_State *lua) { return l_cf_ta_goto_(lua, focused_editor, false); } diff --git a/src/textadept.c b/src/textadept.c index cec9cb3c..00ed9a44 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -1,9 +1,12 @@ // Copyright 2007-2009 Mitchell mitchell<att>caladbolg.net. See LICENSE. #include "textadept.h" -#if WIN32 -#include <Windows.h> -#elif MAC +#if !(WIN32 || MAC) +#include <unistd.h> +#elif WIN32 +#include "Windows.h" +#define strcasecmp _stricmp +#else #include <Carbon/Carbon.h> #include "ige-mac-menu.h" #define CFURL_TO_STR(u) \ diff --git a/src/textadept.h b/src/textadept.h index 73064fdf..1a5e60e1 100644 --- a/src/textadept.h +++ b/src/textadept.h @@ -15,6 +15,7 @@ #include <ScintillaWidget.h> extern "C" { +#include <gcocoadialog.h> #include <lua.h> #include <lualib.h> #include <lauxlib.h> |