Added delete confirmation using NagView.

This commit is contained in:
jgmdev 2021-07-12 11:33:14 -04:00
parent a4d5622eda
commit afa0c175e8
1 changed files with 33 additions and 14 deletions

View File

@ -480,22 +480,41 @@ command.add(nil, {
["treeview:delete"] = function()
local filename = view.hovered_item.abs_filename
local relfilename = view.hovered_item.filename
local file_info = system.get_file_info(filename)
if file_info.type == "dir" then
local deleted, error, path = common.rm(filename, true)
if not deleted then
core.error("Error: %s - \"%s\" ", error, path)
return
local file_type = file_info.type == "dir" and "Directory" or "File"
-- Ask before deleting
local opt = {
{ font = style.font, text = "Yes", default_yes = true },
{ font = style.font, text = "No" , default_no = true }
}
core.nag_view:show(
string.format("Delete %s", file_type),
string.format(
"Are you sure you want to delete the %s?\n%s: %s",
file_type:lower(), file_type, relfilename
),
opt,
function(item)
if item.text == "Yes" then
if file_info.type == "dir" then
local deleted, error, path = common.rm(filename, true)
if not deleted then
core.error("Error: %s - \"%s\" ", error, path)
return
end
else
local removed, error = os.remove(filename)
if not removed then
core.error("Error: %s - \"%s\"", error, filename)
return
end
end
core.reschedule_project_scan()
core.log("Deleted \"%s\"", filename)
end
end
else
local removed, error = os.remove(filename)
if not removed then
core.error("Error: %s - \"%s\"", error, filename)
return
end
end
core.reschedule_project_scan()
core.log("Deleted \"%s\"", filename)
)
end,
["treeview:open-in-system"] = function()