Added ability to register on_doc_close hooks. (#220)
This commit is contained in:
parent
63a613fe17
commit
476404c21a
|
@ -563,6 +563,22 @@ function core.on_doc_save(filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
core.doc_close_hooks = {}
|
||||||
|
function core.add_close_hook(fn)
|
||||||
|
core.doc_close_hooks[#core.doc_close_hooks + 1] = fn
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function core.on_doc_close(doc)
|
||||||
|
core.log_quiet("Closed doc \"%s\"", doc:get_name())
|
||||||
|
|
||||||
|
for _, hook in ipairs(core.doc_close_hooks) do
|
||||||
|
hook(doc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function quit_with_function(quit_fn, force)
|
local function quit_with_function(quit_fn, force)
|
||||||
if force then
|
if force then
|
||||||
delete_temp_files()
|
delete_temp_files()
|
||||||
|
@ -918,7 +934,7 @@ function core.step()
|
||||||
local doc = core.docs[i]
|
local doc = core.docs[i]
|
||||||
if #core.get_views_referencing_doc(doc) == 0 then
|
if #core.get_views_referencing_doc(doc) == 0 then
|
||||||
table.remove(core.docs, i)
|
table.remove(core.docs, i)
|
||||||
core.log_quiet("Closed doc \"%s\"", doc:get_name())
|
core.on_doc_close(doc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue