feat: add ui.confirm.remove and ui.confirm.trash, deprecate trash.require_confirm (#1887)
* Implement turning off y/n prompt for file deletion * Refactor different prompt configs to single ui table * Remove unused fields * add ui.confirm doc, format/tidy * trash.require_confirm -> ui.confirm.trash * Fix nil value trash field Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
@@ -698,7 +698,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||
},
|
||||
trash = {
|
||||
cmd = "gio trash",
|
||||
require_confirm = true,
|
||||
},
|
||||
live_filter = {
|
||||
prefix = "[FILTER]: ",
|
||||
@@ -714,6 +713,12 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||
notify = {
|
||||
threshold = vim.log.levels.INFO,
|
||||
},
|
||||
ui = {
|
||||
confirm = {
|
||||
remove = true,
|
||||
trash = true,
|
||||
},
|
||||
},
|
||||
log = {
|
||||
enable = false,
|
||||
truncate = false,
|
||||
|
||||
@@ -73,34 +73,45 @@ function M.fn(node)
|
||||
if node.name == ".." then
|
||||
return
|
||||
end
|
||||
local prompt_select = "Remove " .. node.name .. " ?"
|
||||
local prompt_input = prompt_select .. " y/n: "
|
||||
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
|
||||
utils.clear_prompt()
|
||||
if item_short == "y" then
|
||||
if node.nodes ~= nil and not node.link_to then
|
||||
local success = remove_dir(node.absolute_path)
|
||||
if not success then
|
||||
return notify.error("Could not remove " .. node.name)
|
||||
end
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
else
|
||||
local success = vim.loop.fs_unlink(node.absolute_path)
|
||||
if not success then
|
||||
return notify.error("Could not remove " .. node.name)
|
||||
end
|
||||
events._dispatch_file_removed(node.absolute_path)
|
||||
clear_buffer(node.absolute_path)
|
||||
|
||||
local function do_remove()
|
||||
if node.nodes ~= nil and not node.link_to then
|
||||
local success = remove_dir(node.absolute_path)
|
||||
if not success then
|
||||
return notify.error("Could not remove " .. node.name)
|
||||
end
|
||||
notify.info(node.absolute_path .. " was properly removed.")
|
||||
if M.enable_reload then
|
||||
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
else
|
||||
local success = vim.loop.fs_unlink(node.absolute_path)
|
||||
if not success then
|
||||
return notify.error("Could not remove " .. node.name)
|
||||
end
|
||||
events._dispatch_file_removed(node.absolute_path)
|
||||
clear_buffer(node.absolute_path)
|
||||
end
|
||||
end)
|
||||
notify.info(node.absolute_path .. " was properly removed.")
|
||||
if M.enable_reload then
|
||||
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
|
||||
end
|
||||
end
|
||||
|
||||
if M.config.ui.confirm.remove then
|
||||
local prompt_select = "Remove " .. node.name .. " ?"
|
||||
local prompt_input = prompt_select .. " y/n: "
|
||||
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
|
||||
utils.clear_prompt()
|
||||
if item_short == "y" then
|
||||
do_remove()
|
||||
end
|
||||
end)
|
||||
else
|
||||
do_remove()
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config = {}
|
||||
M.config.ui = opts.ui or {}
|
||||
M.enable_reload = not opts.filesystem_watchers.enable
|
||||
M.close_window = opts.actions.remove_file.close_window
|
||||
end
|
||||
|
||||
@@ -32,8 +32,8 @@ function M.fn(node)
|
||||
if M.config.trash.cmd == nil then
|
||||
M.config.trash.cmd = "trash"
|
||||
end
|
||||
if M.config.trash.require_confirm == nil then
|
||||
M.config.trash.require_confirm = true
|
||||
if M.config.ui.confirm.trash == nil then
|
||||
M.config.ui.confirm.trash = true
|
||||
end
|
||||
else
|
||||
notify.warn "Trash is currently a UNIX only feature!"
|
||||
@@ -87,7 +87,7 @@ function M.fn(node)
|
||||
end
|
||||
end
|
||||
|
||||
if M.config.trash.require_confirm then
|
||||
if M.config.ui.confirm.trash then
|
||||
local prompt_select = "Trash " .. node.name .. " ?"
|
||||
local prompt_input = prompt_select .. " y/n: "
|
||||
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
|
||||
@@ -103,6 +103,7 @@ end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config = {}
|
||||
M.config.ui = opts.ui or {}
|
||||
M.config.trash = opts.trash or {}
|
||||
M.enable_reload = not opts.filesystem_watchers.enable
|
||||
end
|
||||
|
||||
@@ -27,6 +27,9 @@ local function refactored(opts)
|
||||
|
||||
-- 2023/01/01
|
||||
utils.move_missing_val(opts, "update_focused_file", "debounce_delay", opts, "view", "debounce_delay", true)
|
||||
|
||||
-- 2023/01/08
|
||||
utils.move_missing_val(opts, "trash", "require_confirm", opts, "ui.confirm", "trash", true)
|
||||
end
|
||||
|
||||
local function removed(opts)
|
||||
|
||||
Reference in New Issue
Block a user