File manager: some broken actions for parent folder (#7475)

For parent folder (..):
disabled `Copy`, `Cut`, `Delete`, `Rename`.
enabled `Paste`, `Set as HOME folder`.
pull/7480/head
hius07 3 years ago committed by GitHub
parent de543b3484
commit 91262f9647
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -227,10 +227,14 @@ function FileManager:setupLayout()
local fileManager = self local fileManager = self
function file_chooser:onFileHold(file) -- luacheck: ignore function file_chooser:onFileHold(file) -- luacheck: ignore
local is_file = lfs.attributes(file, "mode") == "file"
local is_folder = lfs.attributes(file, "mode") == "directory"
local is_not_parent_folder = BaseUtil.basename(file) ~= ".."
local buttons = { local buttons = {
{ {
{ {
text = C_("File", "Copy"), text = C_("File", "Copy"),
enabled = is_not_parent_folder,
callback = function() callback = function()
copyFile(file) copyFile(file)
UIManager:close(self.file_dialog) UIManager:close(self.file_dialog)
@ -264,6 +268,7 @@ function FileManager:setupLayout()
{ {
{ {
text = _("Cut"), text = _("Cut"),
enabled = is_not_parent_folder,
callback = function() callback = function()
cutFile(file) cutFile(file)
UIManager:close(self.file_dialog) UIManager:close(self.file_dialog)
@ -271,6 +276,7 @@ function FileManager:setupLayout()
}, },
{ {
text = _("Delete"), text = _("Delete"),
enabled = is_not_parent_folder,
callback = function() callback = function()
UIManager:show(ConfirmBox:new{ UIManager:show(ConfirmBox:new{
text = _("Are you sure that you want to delete this file?\n") .. BD.filepath(file) .. ("\n") .. _("If you delete a file, it is permanently lost."), text = _("Are you sure that you want to delete this file?\n") .. BD.filepath(file) .. ("\n") .. _("If you delete a file, it is permanently lost."),
@ -286,6 +292,7 @@ function FileManager:setupLayout()
}, },
{ {
text = _("Rename"), text = _("Rename"),
enabled = is_not_parent_folder,
callback = function() callback = function()
UIManager:close(self.file_dialog) UIManager:close(self.file_dialog)
fileManager.rename_dialog = InputDialog:new{ fileManager.rename_dialog = InputDialog:new{
@ -320,7 +327,7 @@ function FileManager:setupLayout()
}, },
} }
if lfs.attributes(file, "mode") == "file" and Device:canExecuteScript(file) then if is_file and Device:canExecuteScript(file) then
-- NOTE: We populate the empty separator, in order not to mess with the button reordering code in CoverMenu -- NOTE: We populate the empty separator, in order not to mess with the button reordering code in CoverMenu
table.insert(buttons[3], table.insert(buttons[3],
{ {
@ -361,7 +368,7 @@ function FileManager:setupLayout()
) )
end end
if lfs.attributes(file, "mode") == "file" then if is_file then
table.insert(buttons, { table.insert(buttons, {
{ {
text = _("Open with…"), text = _("Open with…"),
@ -422,7 +429,7 @@ function FileManager:setupLayout()
}) })
end end
end end
if lfs.attributes(file, "mode") == "directory" then if is_folder then
local realpath = BaseUtil.realpath(file) local realpath = BaseUtil.realpath(file)
table.insert(buttons, { table.insert(buttons, {
{ {
@ -436,7 +443,7 @@ function FileManager:setupLayout()
end end
local title local title
if lfs.attributes(file, "mode") == "directory" then if is_folder then
title = BD.directory(file:match("([^/]+)$")) title = BD.directory(file:match("([^/]+)$"))
else else
title = BD.filename(file:match("([^/]+)$")) title = BD.filename(file:match("([^/]+)$"))
@ -888,7 +895,7 @@ function FileManager:pasteHere(file)
if mode == "file" then if mode == "file" then
text = T(_("The file %1 already exists. Do you want to overwrite it?"), BD.filename(basename)) text = T(_("The file %1 already exists. Do you want to overwrite it?"), BD.filename(basename))
else else
text = T(_("The directory %1 already exists. Do you want to overwrite it?"), BD.directory(basename)) text = T(_("The folder %1 already exists. Overwrite folder?"), BD.directory(basename))
end end
UIManager:show(ConfirmBox:new { UIManager:show(ConfirmBox:new {

Loading…
Cancel
Save