From fbc722360864470cfe5fc2afafd148e874f40c71 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Mon, 11 Oct 2010 15:11:02 -0400 Subject: gui.dialog() can take tables of strings as arguments. --- core/.gui.luadoc | 4 +++- core/gui.lua | 2 +- modules/textadept/mime_types.lua | 2 +- modules/textadept/snapopen.lua | 2 +- src/lua_interface.c | 14 ++++++++++++-- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/core/.gui.luadoc b/core/.gui.luadoc index 04869e70..eecc6c1d 100644 --- a/core/.gui.luadoc +++ b/core/.gui.luadoc @@ -79,6 +79,8 @@ function switch_buffer() end --- -- Displays a CocoaDialog of a specified type with the given string arguments. --- Each argument is like a string in Lua's 'arg' table. +-- Each argument is like a string in Lua's 'arg' table. Tables of strings are +-- allowed as arguments and are expanded in place. This is useful for +-- filteredlist dialogs with many items. -- @return string CocoaDialog result. function dialog(kind, ...) end diff --git a/core/gui.lua b/core/gui.lua index 9f49be19..3baba198 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -66,7 +66,7 @@ function gui.switch_buffer() '--button2', 'gtk-cancel', '--no-newline', '--columns', 'Name', 'File', - '--items', unpack(items)) + '--items', items) local i = tonumber(out:match('%-?%d+$')) if i and i >= 0 then view:goto_buffer(i + 1, true) end end diff --git a/modules/textadept/mime_types.lua b/modules/textadept/mime_types.lua index 3bed5a8a..5d19228c 100644 --- a/modules/textadept/mime_types.lua +++ b/modules/textadept/mime_types.lua @@ -290,7 +290,7 @@ function select_lexer() '--no-newline', '--string-output', '--columns', 'Name', - '--items', unpack(lexers)) + '--items', lexers) local response, lexer = out:match('([^\n]+)\n([^\n]+)$') if response and response ~= 'gtk-cancel' then buffer:set_lexer(lexer) end end diff --git a/modules/textadept/snapopen.lua b/modules/textadept/snapopen.lua index d1f7f3d4..dfc80db3 100644 --- a/modules/textadept/snapopen.lua +++ b/modules/textadept/snapopen.lua @@ -115,7 +115,7 @@ function open(paths, filter, exclusive) '--button2', 'gtk-cancel', '--no-newline', '--columns', 'File', - '--items', unpack(list)) + '--items', list) local response, index = out:match('^(%d+)[\r\n]+(%d+)') if response == '1' then io.open_file(list[tonumber(index) + 1]) end end diff --git a/src/lua_interface.c b/src/lua_interface.c index d954e06e..3c94c6fc 100644 --- a/src/lua_interface.c +++ b/src/lua_interface.c @@ -1130,9 +1130,19 @@ static int l_cf_view_goto_buffer(lua_State *lua) { static int l_cf_gui_dialog(lua_State *lua) { GCDialogType type = gcocoadialog_type(luaL_checkstring(lua, 1)); - int argc = lua_gettop(lua) - 1; + int i, j, k, n = lua_gettop(lua) - 1, argc = n; + for (i = 2; i < n + 2; i++) + if (lua_type(lua, i) == LUA_TTABLE) argc += lua_objlen(lua, i) - 1; const char *argv[argc]; - for (int i = 0; i < argc; i++) argv[i] = luaL_checkstring(lua, i + 2); + for (i = 0, j = 2; j < n + 2; j++) + if (lua_type(lua, j) == LUA_TTABLE) { + int len = lua_objlen(lua, j); + for (int k = 1; k <= len; k++) { + lua_rawgeti(lua, j, k); + argv[i++] = luaL_checkstring(lua, j + 1); + lua_pop(lua, 1); + } + } else argv[i++] = luaL_checkstring(lua, j); char *out = gcocoadialog(type, argc, argv); lua_pushstring(lua, out); free(out); -- cgit v1.2.3