2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00
koreader/frontend/apps/filemanager/filemanagerhistory.lua

151 lines
5.6 KiB
Lua
Raw Normal View History

local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
local DocSettings = require("docsettings")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local InputContainer = require("ui/widget/container/inputcontainer")
2014-08-14 11:49:42 +00:00
local Menu = require("ui/widget/menu")
local UIManager = require("ui/uimanager")
local Screen = require("device").screen
local filemanagerutil = require("apps/filemanager/filemanagerutil")
local util = require("ffi/util")
2013-10-18 20:38:07 +00:00
local _ = require("gettext")
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
function FileManagerHistory:addToMainMenu(menu_items)
-- insert table to main tab of filemanager menu
menu_items.history = {
2016-02-17 07:10:23 +00:00
text = self.hist_menu_title,
callback = function()
self:onShowHist()
end,
}
2016-02-17 07:10:23 +00:00
end
function FileManagerHistory:updateItemTable()
-- 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,
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
function FileManagerHistory:onMenuHold(item)
local readerui_instance = require("apps/reader/readerui"):_getRunningInstance()
local currently_opened_file = readerui_instance and readerui_instance.document.file
self.histfile_dialog = nil
local buttons = {
{
2014-03-13 13:52:43 +00:00
{
text = _("Purge .sdr"),
enabled = item.file ~= currently_opened_file and DocSettings:hasSidecarFile(util.realpath(item.file)),
callback = function()
local ConfirmBox = require("ui/widget/confirmbox")
UIManager:show(ConfirmBox:new{
text = util.template(_("Purge .sdr to reset settings for this document?\n\n%1"), item.text),
ok_text = _("Purge"),
ok_callback = function()
filemanagerutil.purgeSettings(item.file)
filemanagerutil.removeFileFromHistoryIfWanted(item.file)
self._manager:updateItemTable()
UIManager:close(self.histfile_dialog)
end,
})
end,
2014-03-13 13:52:43 +00:00
},
{
text = _("Remove from history"),
callback = function()
require("readhistory"):removeItem(item)
self._manager:updateItemTable()
UIManager:close(self.histfile_dialog)
end,
},
},
{
{
text = _("Delete"),
enabled = (item.file ~= currently_opened_file and lfs.attributes(item.file, "mode")) and true or false,
callback = function()
local ConfirmBox = require("ui/widget/confirmbox")
UIManager:show(ConfirmBox:new{
text = _("Are you sure that you want to delete this file?\n") .. item.file .. ("\n") .. _("If you delete a file, it is permanently lost."),
ok_text = _("Delete"),
ok_callback = function()
local FileManager = require("apps/filemanager/filemanager")
FileManager:deleteFile(item.file)
filemanagerutil.removeFileFromHistoryIfWanted(item.file)
require("readhistory"):setDeleted(item)
self._manager:updateItemTable()
UIManager:close(self.histfile_dialog)
end,
})
end,
},
{
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
},
}
self.histfile_dialog = ButtonDialogTitle:new{
title = item.text:match("([^/]+)$"),
title_align = "center",
buttons = buttons,
}
2014-03-13 13:52:43 +00:00
UIManager:show(self.histfile_dialog)
return true
end
2013-08-14 09:29:05 +00:00
function FileManagerHistory:onShowHist()
2014-03-13 13:52:43 +00:00
self.hist_menu = Menu:new{
ui = self.ui,
width = Screen:getWidth(),
height = Screen:getHeight(),
covers_fullscreen = true, -- hint for UIManager:_repaint()
is_borderless = true,
is_popout = false,
2014-03-13 13:52:43 +00:00
onMenuHold = self.onMenuHold,
_manager = self,
}
self:updateItemTable()
self.hist_menu.close_callback = function()
-- 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
UIManager:show(self.hist_menu)
2014-03-13 13:52:43 +00:00
return true
2013-08-14 09:29:05 +00:00
end
return FileManagerHistory