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:
sammyette 2022-12-11 21:38:58 -04:00 committed by GitHub
parent 68595e4c7c
commit e13f265fac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 3 deletions

View File

@ -3,6 +3,7 @@ local command = require "core.command"
local common = require "core.common" local common = require "core.common"
local config = require "core.config" local config = require "core.config"
local translate = require "core.doc.translate" local translate = require "core.doc.translate"
local style = require "core.style"
local DocView = require "core.docview" local DocView = require "core.docview"
local tokenizer = require "core.tokenizer" local tokenizer = require "core.tokenizer"
@ -36,9 +37,24 @@ local function save(filename)
filename = core.normalize_to_project_dir(filename) filename = core.normalize_to_project_dir(filename)
abs_filename = core.project_absolute_path(filename) abs_filename = core.project_absolute_path(filename)
end end
doc():save(filename, abs_filename) local ok, err = pcall(doc().save, doc(), filename, abs_filename)
if ok then
local saved_filename = doc().filename local saved_filename = doc().filename
core.log("Saved \"%s\"", saved_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 end
local function cut_or_copy(delete) local function cut_or_copy(delete)