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:
parent
5b554a9e2d
commit
ccb6d8a518
@ -374,7 +374,6 @@ Subsequent calls to setup will replace the previous configuration.
|
|||||||
},
|
},
|
||||||
trash = {
|
trash = {
|
||||||
cmd = "gio trash",
|
cmd = "gio trash",
|
||||||
require_confirm = true,
|
|
||||||
},
|
},
|
||||||
live_filter = {
|
live_filter = {
|
||||||
prefix = "[FILTER]: ",
|
prefix = "[FILTER]: ",
|
||||||
@ -390,6 +389,12 @@ Subsequent calls to setup will replace the previous configuration.
|
|||||||
notify = {
|
notify = {
|
||||||
threshold = vim.log.levels.INFO,
|
threshold = vim.log.levels.INFO,
|
||||||
},
|
},
|
||||||
|
ui = {
|
||||||
|
confirm = {
|
||||||
|
remove = true,
|
||||||
|
trash = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
log = {
|
log = {
|
||||||
enable = false,
|
enable = false,
|
||||||
truncate = false,
|
truncate = false,
|
||||||
@ -993,10 +998,6 @@ Configuration options for trashing.
|
|||||||
The default is shipped with glib2 which is a common linux package.
|
The default is shipped with glib2 which is a common linux package.
|
||||||
Type: `string`, Default: `"gio trash"`
|
Type: `string`, Default: `"gio trash"`
|
||||||
|
|
||||||
*nvim-tree.trash.require_confirm*
|
|
||||||
Show a prompt before trashing takes place.
|
|
||||||
Type: `boolean`, Default: `true`
|
|
||||||
|
|
||||||
*nvim-tree.actions*
|
*nvim-tree.actions*
|
||||||
Configuration for various actions.
|
Configuration for various actions.
|
||||||
|
|
||||||
@ -1146,6 +1147,20 @@ Configuration for notification.
|
|||||||
`INFO:` information only e.g. file copy path confirmation.
|
`INFO:` information only e.g. file copy path confirmation.
|
||||||
`DEBUG:` not used.
|
`DEBUG:` not used.
|
||||||
|
|
||||||
|
*nvim-tree.ui*
|
||||||
|
General UI configuration.
|
||||||
|
|
||||||
|
*nvim-tree.ui.confirm*
|
||||||
|
Confirmation prompts.
|
||||||
|
|
||||||
|
*nvim-tree.ui.confirm.remove*
|
||||||
|
Prompt before removing.
|
||||||
|
Type: `boolean`, Default: `true`
|
||||||
|
|
||||||
|
*nvim-tree.ui.confirm.trash* (previously `trash.require_confirm`)
|
||||||
|
Prompt before trashing.
|
||||||
|
Type: `boolean`, Default: `true`
|
||||||
|
|
||||||
*nvim-tree.log*
|
*nvim-tree.log*
|
||||||
Configuration for diagnostic logging.
|
Configuration for diagnostic logging.
|
||||||
|
|
||||||
|
|||||||
@ -698,7 +698,6 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
|||||||
},
|
},
|
||||||
trash = {
|
trash = {
|
||||||
cmd = "gio trash",
|
cmd = "gio trash",
|
||||||
require_confirm = true,
|
|
||||||
},
|
},
|
||||||
live_filter = {
|
live_filter = {
|
||||||
prefix = "[FILTER]: ",
|
prefix = "[FILTER]: ",
|
||||||
@ -714,6 +713,12 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
|||||||
notify = {
|
notify = {
|
||||||
threshold = vim.log.levels.INFO,
|
threshold = vim.log.levels.INFO,
|
||||||
},
|
},
|
||||||
|
ui = {
|
||||||
|
confirm = {
|
||||||
|
remove = true,
|
||||||
|
trash = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
log = {
|
log = {
|
||||||
enable = false,
|
enable = false,
|
||||||
truncate = false,
|
truncate = false,
|
||||||
|
|||||||
@ -73,34 +73,45 @@ function M.fn(node)
|
|||||||
if node.name == ".." then
|
if node.name == ".." then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local prompt_select = "Remove " .. node.name .. " ?"
|
|
||||||
local prompt_input = prompt_select .. " y/n: "
|
local function do_remove()
|
||||||
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
|
if node.nodes ~= nil and not node.link_to then
|
||||||
utils.clear_prompt()
|
local success = remove_dir(node.absolute_path)
|
||||||
if item_short == "y" then
|
if not success then
|
||||||
if node.nodes ~= nil and not node.link_to then
|
return notify.error("Could not remove " .. node.name)
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
notify.info(node.absolute_path .. " was properly removed.")
|
events._dispatch_folder_removed(node.absolute_path)
|
||||||
if M.enable_reload then
|
else
|
||||||
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
|
local success = vim.loop.fs_unlink(node.absolute_path)
|
||||||
|
if not success then
|
||||||
|
return notify.error("Could not remove " .. node.name)
|
||||||
end
|
end
|
||||||
|
events._dispatch_file_removed(node.absolute_path)
|
||||||
|
clear_buffer(node.absolute_path)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
|
M.config = {}
|
||||||
|
M.config.ui = opts.ui or {}
|
||||||
M.enable_reload = not opts.filesystem_watchers.enable
|
M.enable_reload = not opts.filesystem_watchers.enable
|
||||||
M.close_window = opts.actions.remove_file.close_window
|
M.close_window = opts.actions.remove_file.close_window
|
||||||
end
|
end
|
||||||
|
|||||||
@ -32,8 +32,8 @@ function M.fn(node)
|
|||||||
if M.config.trash.cmd == nil then
|
if M.config.trash.cmd == nil then
|
||||||
M.config.trash.cmd = "trash"
|
M.config.trash.cmd = "trash"
|
||||||
end
|
end
|
||||||
if M.config.trash.require_confirm == nil then
|
if M.config.ui.confirm.trash == nil then
|
||||||
M.config.trash.require_confirm = true
|
M.config.ui.confirm.trash = true
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
notify.warn "Trash is currently a UNIX only feature!"
|
notify.warn "Trash is currently a UNIX only feature!"
|
||||||
@ -87,7 +87,7 @@ function M.fn(node)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if M.config.trash.require_confirm then
|
if M.config.ui.confirm.trash then
|
||||||
local prompt_select = "Trash " .. node.name .. " ?"
|
local prompt_select = "Trash " .. node.name .. " ?"
|
||||||
local prompt_input = prompt_select .. " y/n: "
|
local prompt_input = prompt_select .. " y/n: "
|
||||||
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
|
lib.prompt(prompt_input, prompt_select, { "y", "n" }, { "Yes", "No" }, function(item_short)
|
||||||
@ -103,6 +103,7 @@ end
|
|||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.config = {}
|
M.config = {}
|
||||||
|
M.config.ui = opts.ui or {}
|
||||||
M.config.trash = opts.trash or {}
|
M.config.trash = opts.trash or {}
|
||||||
M.enable_reload = not opts.filesystem_watchers.enable
|
M.enable_reload = not opts.filesystem_watchers.enable
|
||||||
end
|
end
|
||||||
|
|||||||
@ -27,6 +27,9 @@ local function refactored(opts)
|
|||||||
|
|
||||||
-- 2023/01/01
|
-- 2023/01/01
|
||||||
utils.move_missing_val(opts, "update_focused_file", "debounce_delay", opts, "view", "debounce_delay", true)
|
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
|
end
|
||||||
|
|
||||||
local function removed(opts)
|
local function removed(opts)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user