From e13f265fac4434850647aab3e7a502eb9b69b517 Mon Sep 17 00:00:00 2001 From: sammyette Date: Sun, 11 Dec 2022 21:38:58 -0400 Subject: [PATCH] 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 --- data/core/commands/doc.lua | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index d5c37c9..6d32219 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -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)