Skip to content

Commit

Permalink
feat: alert user via nagview if file cannot be saved (lite-xl#1230)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
TorchedSammy authored Dec 12, 2022
1 parent 68595e4 commit e13f265
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions data/core/commands/doc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e13f265

Please sign in to comment.