feat: alert user via nagview if file cannot be saved (#1230)
* feat: alert user via nagview if file cannot be saved it will prompt the user to choose whether they want to save to another location and perform the save as command * refactor: change defer draw call to thread * feat: log error when attempting to save doc
This commit is contained in:
parent
68595e4c7c
commit
e13f265fac
|
@ -3,6 +3,7 @@ local command = require "core.command"
|
|||
local common = require "core.common"
|
||||
local config = require "core.config"
|
||||
local translate = require "core.doc.translate"
|
||||
local style = require "core.style"
|
||||
local DocView = require "core.docview"
|
||||
local tokenizer = require "core.tokenizer"
|
||||
|
||||
|
@ -36,9 +37,24 @@ local function save(filename)
|
|||
filename = core.normalize_to_project_dir(filename)
|
||||
abs_filename = core.project_absolute_path(filename)
|
||||
end
|
||||
doc():save(filename, abs_filename)
|
||||
local saved_filename = doc().filename
|
||||
core.log("Saved \"%s\"", saved_filename)
|
||||
local ok, err = pcall(doc().save, doc(), filename, abs_filename)
|
||||
if ok then
|
||||
local saved_filename = doc().filename
|
||||
core.log("Saved \"%s\"", saved_filename)
|
||||
else
|
||||
core.error(err)
|
||||
core.nag_view:show("Saving failed", string.format("Could not save \"%s\" do you want to save to another location?", doc().filename), {
|
||||
{ font = style.font, text = "No", default_no = true },
|
||||
{ font = style.font, text = "Yes" , default_yes = true }
|
||||
}, function(item)
|
||||
if item.text == "Yes" then
|
||||
core.add_thread(function()
|
||||
-- we need to run this in a thread because of the odd way the nagview is.
|
||||
command.perform("doc:save-as")
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
local function cut_or_copy(delete)
|
||||
|
|
Loading…
Reference in New Issue