aboutsummaryrefslogtreecommitdiff
path: root/core/gui.lua
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2011-01-19 23:09:24 -0500
committermitchell <70453897+667e-11@users.noreply.github.com>2011-01-19 23:09:24 -0500
commitbfe8c3cc714fd122b5945ddc83b9d27ca97e26fb (patch)
tree1fecefdf30e754580f3cf804031836e01fa3d1c7 /core/gui.lua
parent98c6ba37e86c9ef6fe52c89e02462eb72a7ae790 (diff)
downloadtextadept-bfe8c3cc714fd122b5945ddc83b9d27ca97e26fb.tar.gz
textadept-bfe8c3cc714fd122b5945ddc83b9d27ca97e26fb.zip
Added gui.filteredlist() shortcut function for gui.dialog('filteredlist', ...).
Diffstat (limited to 'core/gui.lua')
-rw-r--r--core/gui.lua31
1 files changed, 21 insertions, 10 deletions
diff --git a/core/gui.lua b/core/gui.lua
index ee0daafe..ed609929 100644
--- a/core/gui.lua
+++ b/core/gui.lua
@@ -52,23 +52,34 @@ end
function gui.print(...) gui._print(L('[Message Buffer]'), ...) end
-- LuaDoc is in core/.gui.luadoc.
+function gui.filteredlist(title, columns, items, int_return, ...)
+ local out = gui.dialog('filteredlist',
+ '--title', title,
+ '--button1', 'gtk-ok',
+ '--button2', 'gtk-cancel',
+ '--no-newline',
+ int_return and '' or '--string-output',
+ '--columns', columns,
+ '--items', items,
+ unpack{...})
+ local patt = int_return and '(%-?%d+)\n(%d+)$' or '([^\n]+)\n([^\n]+)$'
+ local response, value = out:match(patt)
+ if response == (int_return and '1' or 'gtk-ok') then
+ return not int_return and value or tonumber(value)
+ end
+end
+
+-- LuaDoc is in core/.gui.luadoc.
function gui.switch_buffer()
- local items = {}
+ local columns, items = { 'Name', 'File' }, {}
for _, buffer in ipairs(_BUFFERS) do
local filename = buffer.filename or buffer._type or L('Untitled')
local dirty = buffer.dirty and '*' or ''
items[#items + 1] = dirty..filename:match('[^/\\]+$')
items[#items + 1] = filename
end
- local response = gui.dialog('filteredlist',
- '--title', L('Switch Buffers'),
- '--button1', 'gtk-ok',
- '--button2', 'gtk-cancel',
- '--no-newline',
- '--columns', 'Name', 'File',
- '--items', items)
- local ok, i = response:match('(%-?%d+)\n(%d+)$')
- if ok == '1' then view:goto_buffer(tonumber(i) + 1, true) end
+ local i = gui.filteredlist(L('Switch Buffers'), columns, items, true)
+ if i then view:goto_buffer(i + 1, true) end
end
local connect = _G.events.connect