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,7 +480,23 @@ command.add(nil, {
["treeview:delete"] = function() ["treeview:delete"] = function()
local filename = view.hovered_item.abs_filename local filename = view.hovered_item.abs_filename
local relfilename = view.hovered_item.filename
local file_info = system.get_file_info(filename) local file_info = system.get_file_info(filename)
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 if file_info.type == "dir" then
local deleted, error, path = common.rm(filename, true) local deleted, error, path = common.rm(filename, true)
if not deleted then if not deleted then
@ -496,6 +512,9 @@ command.add(nil, {
end end
core.reschedule_project_scan() core.reschedule_project_scan()
core.log("Deleted \"%s\"", filename) core.log("Deleted \"%s\"", filename)
end
end
)
end, end,
["treeview:open-in-system"] = function() ["treeview:open-in-system"] = function()