2020-01-04 00:18:51 +00:00
|
|
|
local BD = require("ui/bidi")
|
2017-09-22 16:24:38 +00:00
|
|
|
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
|
|
|
|
local DocSettings = require("docsettings")
|
2017-07-01 10:11:44 +00:00
|
|
|
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
|
2017-04-25 16:49:39 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2014-08-14 11:49:42 +00:00
|
|
|
local Menu = require("ui/widget/menu")
|
2017-04-25 16:49:39 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Screen = require("device").screen
|
2017-09-22 16:24:38 +00:00
|
|
|
local filemanagerutil = require("apps/filemanager/filemanagerutil")
|
|
|
|
local util = require("ffi/util")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
2017-04-25 16:49:39 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local FileManagerHistory = InputContainer:extend{
|
2014-03-13 13:52:43 +00:00
|
|
|
hist_menu_title = _("History"),
|
2013-08-14 09:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function FileManagerHistory:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2013-08-14 09:29:05 +00:00
|
|
|
end
|
|
|
|
|
2017-03-04 13:46:38 +00:00
|
|
|
function FileManagerHistory:addToMainMenu(menu_items)
|
2017-02-25 10:58:39 +00:00
|
|
|
-- insert table to main tab of filemanager menu
|
2017-03-04 13:46:38 +00:00
|
|
|
menu_items.history = {
|
2016-02-17 07:10:23 +00:00
|
|
|
text = self.hist_menu_title,
|
|
|
|
callback = function()
|
|
|
|
self:onShowHist()
|
|
|
|
end,
|
2017-02-28 21:46:32 +00:00
|
|
|
}
|
2016-02-17 07:10:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:updateItemTable()
|
2017-09-22 16:24:38 +00:00
|
|
|
-- try to stay on current page
|
|
|
|
local select_number = nil
|
|
|
|
if self.hist_menu.page and self.hist_menu.perpage then
|
|
|
|
select_number = (self.hist_menu.page - 1) * self.hist_menu.perpage + 1
|
|
|
|
end
|
2017-02-01 14:24:21 +00:00
|
|
|
self.hist_menu:switchItemTable(self.hist_menu_title,
|
2017-09-22 16:24:38 +00:00
|
|
|
require("readhistory").hist, select_number)
|
2016-02-17 07:10:23 +00:00
|
|
|
end
|
|
|
|
|
2013-08-14 09:29:05 +00:00
|
|
|
function FileManagerHistory:onSetDimensions(dimen)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dimen = dimen
|
2013-08-14 09:29:05 +00:00
|
|
|
end
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
function FileManagerHistory:onMenuHold(item)
|
2017-11-19 08:12:53 +00:00
|
|
|
local readerui_instance = require("apps/reader/readerui"):_getRunningInstance()
|
|
|
|
local currently_opened_file = readerui_instance and readerui_instance.document.file
|
2017-09-22 16:24:38 +00:00
|
|
|
self.histfile_dialog = nil
|
|
|
|
local buttons = {
|
|
|
|
{
|
2014-03-13 13:52:43 +00:00
|
|
|
{
|
2017-09-22 16:24:38 +00:00
|
|
|
text = _("Purge .sdr"),
|
2017-11-19 08:12:53 +00:00
|
|
|
enabled = item.file ~= currently_opened_file and DocSettings:hasSidecarFile(util.realpath(item.file)),
|
2017-09-22 16:24:38 +00:00
|
|
|
callback = function()
|
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2020-01-04 00:18:51 +00:00
|
|
|
text = util.template(_("Purge .sdr to reset settings for this document?\n\n%1"), BD.filename(item.text)),
|
2017-09-22 16:24:38 +00:00
|
|
|
ok_text = _("Purge"),
|
|
|
|
ok_callback = function()
|
|
|
|
filemanagerutil.purgeSettings(item.file)
|
2020-05-06 19:11:34 +00:00
|
|
|
require("readhistory"):fileSettingsPurged(item.file)
|
2017-09-22 16:24:38 +00:00
|
|
|
self._manager:updateItemTable()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2016-10-30 22:24:50 +00:00
|
|
|
{
|
2017-09-22 16:24:38 +00:00
|
|
|
text = _("Remove from history"),
|
|
|
|
callback = function()
|
|
|
|
require("readhistory"):removeItem(item)
|
|
|
|
self._manager:updateItemTable()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
2016-10-30 22:24:50 +00:00
|
|
|
},
|
2017-09-22 16:24:38 +00:00
|
|
|
},
|
|
|
|
{
|
2017-02-25 18:22:04 +00:00
|
|
|
{
|
2017-09-22 16:24:38 +00:00
|
|
|
text = _("Delete"),
|
2017-11-19 08:12:53 +00:00
|
|
|
enabled = (item.file ~= currently_opened_file and lfs.attributes(item.file, "mode")) and true or false,
|
2017-09-22 16:24:38 +00:00
|
|
|
callback = function()
|
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2020-01-04 00:18:51 +00:00
|
|
|
text = _("Are you sure that you want to delete this file?\n") .. BD.filepath(item.file) .. ("\n") .. _("If you delete a file, it is permanently lost."),
|
2017-09-22 16:24:38 +00:00
|
|
|
ok_text = _("Delete"),
|
|
|
|
ok_callback = function()
|
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
|
|
|
FileManager:deleteFile(item.file)
|
2020-05-06 19:11:34 +00:00
|
|
|
require("readhistory"):fileDeleted(item.file) -- (will update "lastfile" if needed)
|
2017-09-22 16:24:38 +00:00
|
|
|
self._manager:updateItemTable()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end,
|
2017-02-25 18:22:04 +00:00
|
|
|
},
|
2017-09-22 16:24:38 +00:00
|
|
|
{
|
|
|
|
text = _("Book information"),
|
|
|
|
enabled = FileManagerBookInfo:isSupported(item.file),
|
|
|
|
callback = function()
|
|
|
|
FileManagerBookInfo:show(item.file)
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Clear history of deleted files"),
|
|
|
|
callback = function()
|
|
|
|
require("readhistory"):clearMissing()
|
|
|
|
self._manager:updateItemTable()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
}
|
2017-09-22 16:24:38 +00:00
|
|
|
self.histfile_dialog = ButtonDialogTitle:new{
|
2020-01-04 00:18:51 +00:00
|
|
|
title = BD.filename(item.text:match("([^/]+)$")),
|
2017-09-22 16:24:38 +00:00
|
|
|
title_align = "center",
|
|
|
|
buttons = buttons,
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:show(self.histfile_dialog)
|
|
|
|
return true
|
2014-01-22 18:03:44 +00:00
|
|
|
end
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
function FileManagerHistory:onShowHist()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.hist_menu = Menu:new{
|
|
|
|
ui = self.ui,
|
2017-08-14 11:15:12 +00:00
|
|
|
width = Screen:getWidth(),
|
|
|
|
height = Screen:getHeight(),
|
2018-03-17 22:02:32 +00:00
|
|
|
covers_fullscreen = true, -- hint for UIManager:_repaint()
|
2017-08-14 11:15:12 +00:00
|
|
|
is_borderless = true,
|
2017-09-24 12:46:50 +00:00
|
|
|
is_popout = false,
|
2014-03-13 13:52:43 +00:00
|
|
|
onMenuHold = self.onMenuHold,
|
|
|
|
_manager = self,
|
|
|
|
}
|
|
|
|
self:updateItemTable()
|
|
|
|
self.hist_menu.close_callback = function()
|
2017-08-18 08:02:11 +00:00
|
|
|
-- Close it at next tick so it stays displayed
|
|
|
|
-- while a book is opening (avoids a transient
|
|
|
|
-- display of the underlying File Browser)
|
|
|
|
UIManager:nextTick(function()
|
|
|
|
UIManager:close(self.hist_menu)
|
|
|
|
end)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2017-08-18 08:02:11 +00:00
|
|
|
UIManager:show(self.hist_menu)
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-08-14 09:29:05 +00:00
|
|
|
end
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
return FileManagerHistory
|