2014-01-18 15:15:44 +00:00
|
|
|
local FileManagerHistory = require("apps/filemanager/filemanagerhistory")
|
2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
2014-01-18 15:15:44 +00:00
|
|
|
local FileManagerMenu = require("apps/filemanager/filemanagermenu")
|
|
|
|
local DocumentRegistry = require("document/documentregistry")
|
2013-10-18 20:38:07 +00:00
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
|
|
|
local FileChooser = require("ui/widget/filechooser")
|
2013-12-19 15:21:41 +00:00
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
2013-10-18 20:38:07 +00:00
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
2014-01-22 18:03:44 +00:00
|
|
|
local ButtonDialog = require("ui/widget/buttondialog")
|
2014-01-18 15:15:44 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Font = require("ui/font")
|
|
|
|
local Screen = require("ui/screen")
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Event = require("ui/event")
|
2014-01-18 15:15:44 +00:00
|
|
|
local DEBUG = require("dbg")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local FileManager = InputContainer:extend{
|
2013-08-14 09:29:05 +00:00
|
|
|
title = _("FileManager"),
|
|
|
|
width = Screen:getWidth(),
|
|
|
|
height = Screen:getHeight(),
|
2013-08-15 22:50:33 +00:00
|
|
|
root_path = lfs.currentdir(),
|
2013-08-14 09:29:05 +00:00
|
|
|
-- our own size
|
|
|
|
dimen = Geom:new{ w = 400, h = 600 },
|
|
|
|
onExit = function() end,
|
|
|
|
}
|
|
|
|
|
|
|
|
function FileManager:init()
|
|
|
|
local exclude_dirs = {"%.sdr$"}
|
|
|
|
|
|
|
|
self.show_parent = self.show_parent or self
|
|
|
|
|
2013-12-19 15:21:41 +00:00
|
|
|
self.banner = VerticalGroup:new{
|
2013-08-15 00:28:18 +00:00
|
|
|
TextWidget:new{
|
|
|
|
face = Font:getFace("tfont", 24),
|
|
|
|
text = self.title,
|
2013-12-19 15:21:41 +00:00
|
|
|
},
|
|
|
|
VerticalSpan:new{ width = Screen:scaleByDPI(10) }
|
2013-08-15 00:28:18 +00:00
|
|
|
}
|
2013-12-28 09:49:39 +00:00
|
|
|
|
|
|
|
local g_show_hidden = G_reader_settings:readSetting("show_hidden")
|
|
|
|
local show_hidden = g_show_hidden == nil and DSHOWHIDDENFILES or g_show_hidden
|
2013-08-14 09:29:05 +00:00
|
|
|
local file_chooser = FileChooser:new{
|
2013-08-15 00:28:18 +00:00
|
|
|
-- remeber to adjust the height when new item is added to the group
|
2013-08-15 21:53:22 +00:00
|
|
|
path = self.root_path,
|
2013-12-25 22:18:38 +00:00
|
|
|
show_parent = self.show_parent,
|
2013-12-28 09:49:39 +00:00
|
|
|
show_hidden = show_hidden,
|
2013-08-15 00:28:18 +00:00
|
|
|
height = Screen:getHeight() - self.banner:getSize().h,
|
2013-08-14 09:29:05 +00:00
|
|
|
is_popout = false,
|
|
|
|
is_borderless = true,
|
|
|
|
has_close_button = true,
|
|
|
|
dir_filter = function(dirname)
|
|
|
|
for _, pattern in ipairs(exclude_dirs) do
|
|
|
|
if dirname:match(pattern) then return end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
file_filter = function(filename)
|
|
|
|
if DocumentRegistry:getProvider(filename) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
2013-08-25 04:00:06 +00:00
|
|
|
self.file_chooser = file_chooser
|
2013-08-14 09:29:05 +00:00
|
|
|
|
|
|
|
function file_chooser:onFileSelect(file)
|
|
|
|
showReaderUI(file)
|
|
|
|
return true
|
|
|
|
end
|
2014-01-18 15:15:44 +00:00
|
|
|
|
|
|
|
local copyFile = function(file) self:copyFile(file) end
|
|
|
|
local pasteHere = function(file) self:pasteHere(file) end
|
|
|
|
local cutFile = function(file) self:cutFile(file) end
|
|
|
|
local deleteFile = function(file) self:deleteFile(file) end
|
|
|
|
local fileManager = self
|
|
|
|
|
|
|
|
function file_chooser:onFileHold(file)
|
|
|
|
--DEBUG("hold file", file)
|
2014-01-22 18:03:44 +00:00
|
|
|
self.file_dialog = ButtonDialog:new{
|
2014-01-18 15:15:44 +00:00
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Copy"),
|
|
|
|
callback = function()
|
|
|
|
copyFile(file)
|
|
|
|
UIManager:close(self.file_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Paste"),
|
|
|
|
enabled = fileManager.clipboard and true or false,
|
|
|
|
callback = function()
|
|
|
|
pasteHere(file)
|
|
|
|
self:changeToPath(util.realpath(file):match("(.*/)"))
|
|
|
|
UIManager:close(self.file_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Cut"),
|
|
|
|
callback = function()
|
|
|
|
cutFile(file)
|
|
|
|
UIManager:close(self.file_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Delete"),
|
|
|
|
callback = function()
|
|
|
|
local path = util.realpath(file)
|
|
|
|
deleteFile(file)
|
|
|
|
self:changeToPath(path:match("(.*/)"))
|
|
|
|
UIManager:close(self.file_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
UIManager:show(self.file_dialog)
|
|
|
|
return true
|
|
|
|
end
|
2013-08-14 09:29:05 +00:00
|
|
|
|
|
|
|
self.layout = VerticalGroup:new{
|
|
|
|
self.banner,
|
|
|
|
file_chooser,
|
|
|
|
}
|
|
|
|
|
|
|
|
local fm_ui = FrameContainer:new{
|
|
|
|
padding = 0,
|
|
|
|
bordersize = 0,
|
|
|
|
background = 0,
|
|
|
|
self.layout,
|
|
|
|
}
|
|
|
|
|
|
|
|
self[1] = fm_ui
|
|
|
|
|
|
|
|
self.menu = FileManagerMenu:new{
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, self.menu)
|
|
|
|
table.insert(self, FileManagerHistory:new{
|
|
|
|
ui = self,
|
|
|
|
menu = self.menu
|
|
|
|
})
|
|
|
|
|
|
|
|
self:handleEvent(Event:new("SetDimensions", self.dimen))
|
|
|
|
end
|
|
|
|
|
2013-08-25 04:00:06 +00:00
|
|
|
function FileManager:toggleHiddenFiles()
|
|
|
|
self.file_chooser:toggleHiddenFiles()
|
2013-12-28 09:49:39 +00:00
|
|
|
G_reader_settings:saveSetting("show_hidden", self.file_chooser.show_hidden)
|
2013-08-25 04:00:06 +00:00
|
|
|
end
|
2013-08-14 09:29:05 +00:00
|
|
|
|
|
|
|
function FileManager:onClose()
|
|
|
|
UIManager:close(self)
|
|
|
|
if self.onExit then
|
|
|
|
self:onExit()
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2014-01-18 15:15:44 +00:00
|
|
|
function FileManager:copyFile(file)
|
|
|
|
self.cutfile = false
|
|
|
|
self.clipboard = file
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManager:cutFile(file)
|
|
|
|
self.cutfile = true
|
|
|
|
self.clipboard = file
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManager:pasteHere(file)
|
|
|
|
if self.clipboard then
|
2014-01-22 18:08:24 +00:00
|
|
|
file = util.realpath(file)
|
2014-01-18 19:54:23 +00:00
|
|
|
local orig = util.realpath(self.clipboard)
|
2014-01-22 18:08:24 +00:00
|
|
|
local dest = lfs.attributes(file, "mode") == "directory" and
|
|
|
|
file or file:match("(.*/)")
|
2014-01-18 19:54:23 +00:00
|
|
|
if self.cutfile then
|
|
|
|
util.execute("/bin/mv", orig, dest)
|
|
|
|
else
|
|
|
|
util.execute("/bin/cp", "-r", orig, dest)
|
|
|
|
end
|
2014-01-18 15:15:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManager:deleteFile(file)
|
2014-01-18 19:54:23 +00:00
|
|
|
util.execute("/bin/rm", "-r", util.realpath(file))
|
2014-01-18 15:15:44 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return FileManager
|