FileManager: add overwrite check for Rename (#7833)

Checks for existing destination file/folder for Rename operation
and asks to overwrite.
pull/7907/head
hius07 3 years ago committed by GitHub
parent 5e2d83965b
commit eb41ad3bda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -321,7 +321,6 @@ function FileManager:setupLayout()
callback = function()
if fileManager.rename_dialog:getInputText() ~= "" then
renameFile(file)
self:refreshPath()
UIManager:close(fileManager.rename_dialog)
end
end,
@ -1016,8 +1015,10 @@ function FileManager:deleteFile(file)
end
function FileManager:renameFile(file)
if BaseUtil.basename(file) ~= self.rename_dialog:getInputText() then
local dest = BaseUtil.joinPath(BaseUtil.dirname(file), self.rename_dialog:getInputText())
local basename = self.rename_dialog:getInputText()
if BaseUtil.basename(file) ~= basename then
local dest = BaseUtil.joinPath(BaseUtil.dirname(file), basename)
local function doRenameFile()
if self:moveFile(file, dest) then
require("readhistory"):updateItemByPath(file, dest) -- (will update "lastfile" if needed)
ReadCollection:updateItemByPath(file, dest)
@ -1057,6 +1058,43 @@ function FileManager:renameFile(file)
})
end
end
local mode_dest = lfs.attributes(dest, "mode")
local mode_file = lfs.attributes(file, "mode")
if mode_dest then
local text, ok_text
if mode_dest ~= mode_file then
if mode_file == "file" then
text = T(_("Folder already exists:\n%1\nFile cannot be renamed."), BD.directory(basename))
else
text = T(_("File already exists:\n%1\nFolder cannot be renamed."), BD.filename(basename))
end
UIManager:show(InfoMessage:new {
text = text,
icon = "notice-warning",
})
else
if mode_file == "file" then
text = T(_("File already exists:\n%1\nOverwrite file?"), BD.filename(basename))
ok_text = _("Overwrite")
else
text = T(_("Folder already exists:\n%1\nMove the folder inside it?"), BD.directory(basename))
ok_text = _("Move")
end
UIManager:show(ConfirmBox:new {
text = text,
ok_text = ok_text,
ok_callback = function()
doRenameFile()
self:onRefresh()
end,
})
end
else
doRenameFile()
self:onRefresh()
end
end
end
function FileManager:getSortingMenuTable()

Loading…
Cancel
Save