diff options
author | 2014-11-26 09:59:23 -0500 | |
---|---|---|
committer | 2014-11-26 09:59:23 -0500 | |
commit | b21e66a3cd20e088149926ecdf5710dabd1ec03b (patch) | |
tree | 526ee6f2265f75740d258f77464d501a76b8ccbc /core | |
parent | e8ef57a0f5401fe5469220a6f85a085100344f97 (diff) | |
download | textadept-b21e66a3cd20e088149926ecdf5710dabd1ec03b.tar.gz textadept-b21e66a3cd20e088149926ecdf5710dabd1ec03b.zip |
Allow connection to `events.QUIT` without requiring index of 1.
Diffstat (limited to 'core')
-rw-r--r-- | core/events.lua | 7 | ||||
-rw-r--r-- | core/ui.lua | 7 |
2 files changed, 9 insertions, 5 deletions
diff --git a/core/events.lua b/core/events.lua index c63e98a8..afa851f9 100644 --- a/core/events.lua +++ b/core/events.lua @@ -206,8 +206,11 @@ local M = {} -- * _`alt`_: The "Alt"/"Option" modifier key is held down. -- @field QUIT (string) -- Emitted when quitting Textadept. --- When connecting to this event, connect with an index of 1 or the handler --- will be ignored. +-- When connecting to this event, connect with an index of 1 if the handler +-- needs to run before Textadept closes all open buffers. If a handler returns +-- `true`, Textadept does not quit. It is not recommended to return `false` +-- from a quit handler, as that may interfere with Textadept's normal shutdown +-- procedure. -- Emitted by [`quit()`](). -- @field REPLACE (string) -- Emitted to replace selected (found) text. diff --git a/core/ui.lua b/core/ui.lua index bb6f7e4f..f90c5626 100644 --- a/core/ui.lua +++ b/core/ui.lua @@ -386,12 +386,13 @@ events_connect(events.QUIT, function() list[#list + 1] = filename:iconv('UTF-8', _CHARSET) end end - return #list < 1 or ui.dialogs.msgbox{ + local cancel = #list > 0 and ui.dialogs.msgbox{ title = _L['Quit without saving?'], text = _L['The following buffers are unsaved:'], informative_text = table.concat(list, '\n'), icon = 'gtk-dialog-question', button1 = _L['_Cancel'], button2 = _L['Quit _without saving'] - } == 2 + } ~= 2 + if cancel then return true end -- prevent quit end) -- Keeps track of and switches back to the previous buffer after buffer close. @@ -412,7 +413,7 @@ if CURSES then events.connect(events.QUIT, function() io.stdout:write("\x1b[?1002l") -- disable mouse mode io.stdout:flush() - end, 1) + end) end -- Retrieves the view or split at the given terminal coordinates. |