Skip to content

Commit

Permalink
feature: enable to rename in copy and move
Browse files Browse the repository at this point in the history
  • Loading branch information
amedama41 committed Aug 11, 2023
1 parent 118d5bb commit e0971c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lua/vfiler/clipboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ local vim = require('vfiler/libs/vim')

local current_functor = nil

local function input_new_name(name, destdir_path)
while true do
local new_name = cmdline.input('New name - ' .. name, name, 'file')
if #new_name == 0 then
return ''
end
local destpath = core.path.join(destdir_path, new_name)
if not core.path.exists(destpath) then
return destpath
end
core.message.info('"%s" already exists', new_name)
end
end

local PasteFunctor = {}
PasteFunctor.__index = PasteFunctor

Expand All @@ -20,7 +34,15 @@ function PasteFunctor:paste(destdir)
local skipped = false
local destpath = core.path.join(destdir.path, item.name)
if core.path.exists(destpath) then
if cmdline.util.confirm_overwrite(item.name) ~= cmdline.choice.YES then
local choice = cmdline.util.confirm_overwrite_or_rename(item.name)
if choice == cmdline.choice.RENAME then
local new_destpath = input_new_name(item.name, destdir.path)
if #new_destpath ~= 0 then
destpath = new_destpath
else
skipped = true
end
elseif choice ~= cmdline.choice.YES then
skipped = true
end
end
Expand Down
9 changes: 9 additions & 0 deletions lua/vfiler/libs/cmdline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ M.choice = {
YES = '&Yes',
NO = '&No',
CANCEL = '&Cancel',
RENAME = '&Rename',
}

function M.clear_prompt()
Expand Down Expand Up @@ -86,4 +87,12 @@ function M.util.confirm_overwrite(name)
)
end

function M.util.confirm_overwrite_or_rename(name)
return M.confirm(
('"%s" already exists. Overwrite?'):format(name),
{ M.choice.YES, M.choice.NO, M.choice.RENAME },
1
)
end

return M

0 comments on commit e0971c4

Please sign in to comment.