2017-09-11 08:32:12 +00:00
|
|
|
local Event = require("ui/event")
|
2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
2017-04-14 18:12:21 +00:00
|
|
|
local SkimToWidget = require("apps/reader/skimtowidget")
|
2017-09-11 08:32:12 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
2020-03-26 13:04:59 +00:00
|
|
|
local T = require("ffi/util").template
|
2013-07-30 15:09:08 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local ReaderGoto = InputContainer:new{
|
2014-11-12 11:29:38 +00:00
|
|
|
goto_menu_title = _("Go to"),
|
2018-09-18 19:37:13 +00:00
|
|
|
skim_menu_title = _("Skim document"),
|
2013-07-30 15:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderGoto:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2013-07-31 05:51:01 +00:00
|
|
|
end
|
|
|
|
|
2017-03-04 13:46:38 +00:00
|
|
|
function ReaderGoto:addToMainMenu(menu_items)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- insert goto command to main reader menu
|
2017-03-04 13:46:38 +00:00
|
|
|
menu_items.go_to = {
|
2014-03-13 13:52:43 +00:00
|
|
|
text = self.goto_menu_title,
|
|
|
|
callback = function()
|
|
|
|
self:onShowGotoDialog()
|
|
|
|
end,
|
2017-02-28 21:46:32 +00:00
|
|
|
}
|
2017-03-04 13:46:38 +00:00
|
|
|
menu_items.skim_to = {
|
2016-12-29 07:27:48 +00:00
|
|
|
text = self.skim_menu_title,
|
|
|
|
callback = function()
|
|
|
|
self:onShowSkimtoDialog()
|
|
|
|
end,
|
2017-02-28 21:46:32 +00:00
|
|
|
}
|
2013-07-31 05:51:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderGoto:onShowGotoDialog()
|
2016-02-26 08:04:21 +00:00
|
|
|
local dialog_title, goto_btn, curr_page
|
2016-02-26 07:50:12 +00:00
|
|
|
if self.document.info.has_pages then
|
|
|
|
dialog_title = _("Go to Page")
|
|
|
|
goto_btn = {
|
2016-05-26 06:09:49 +00:00
|
|
|
is_enter_default = true,
|
2016-02-26 07:50:12 +00:00
|
|
|
text = _("Page"),
|
|
|
|
callback = function() self:gotoPage() end,
|
|
|
|
}
|
2016-02-26 08:04:21 +00:00
|
|
|
curr_page = self.ui.paging.current_page
|
2016-02-26 07:50:12 +00:00
|
|
|
else
|
|
|
|
dialog_title = _("Go to Location")
|
|
|
|
goto_btn = {
|
2016-05-26 06:09:49 +00:00
|
|
|
is_enter_default = true,
|
2016-02-26 07:50:12 +00:00
|
|
|
text = _("Location"),
|
|
|
|
callback = function() self:gotoPage() end,
|
|
|
|
}
|
2016-02-26 08:04:21 +00:00
|
|
|
-- only CreDocument has this method
|
|
|
|
curr_page = self.document:getCurrentPage()
|
2016-02-26 07:50:12 +00:00
|
|
|
end
|
2020-03-26 13:04:59 +00:00
|
|
|
local input_hint
|
|
|
|
if self.ui.pagemap and self.ui.pagemap:wantsPageLabels() then
|
|
|
|
input_hint = T("@%1 (%2 - %3)", self.ui.pagemap:getCurrentPageLabel(true),
|
|
|
|
self.ui.pagemap:getFirstPageLabel(true),
|
|
|
|
self.ui.pagemap:getLastPageLabel(true))
|
|
|
|
else
|
|
|
|
input_hint = T("@%1 (1 - %2)", curr_page, self.document:getPageCount())
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
self.goto_dialog = InputDialog:new{
|
2016-02-26 07:50:12 +00:00
|
|
|
title = dialog_title,
|
2020-03-26 13:04:59 +00:00
|
|
|
input_hint = input_hint,
|
2014-03-13 13:52:43 +00:00
|
|
|
buttons = {
|
2015-03-12 07:45:58 +00:00
|
|
|
{
|
2014-03-13 13:52:43 +00:00
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
|
|
|
enabled = true,
|
|
|
|
callback = function()
|
|
|
|
self:close()
|
|
|
|
end,
|
|
|
|
},
|
2016-12-29 07:27:48 +00:00
|
|
|
{
|
|
|
|
text = _("Skim mode"),
|
|
|
|
enabled = true,
|
|
|
|
callback = function()
|
|
|
|
self:close()
|
|
|
|
self.skimto = SkimToWidget:new{
|
|
|
|
document = self.document,
|
|
|
|
ui = self.ui,
|
|
|
|
callback_switch_to_goto = function()
|
|
|
|
UIManager:close(self.skimto)
|
|
|
|
self:onShowGotoDialog()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
UIManager:show(self.skimto)
|
|
|
|
|
|
|
|
end,
|
|
|
|
},
|
2017-09-11 08:32:12 +00:00
|
|
|
goto_btn,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
input_type = "number",
|
|
|
|
}
|
|
|
|
UIManager:show(self.goto_dialog)
|
2018-03-30 10:46:36 +00:00
|
|
|
self.goto_dialog:onShowKeyboard()
|
2013-07-30 15:09:08 +00:00
|
|
|
end
|
|
|
|
|
2016-12-29 07:27:48 +00:00
|
|
|
function ReaderGoto:onShowSkimtoDialog()
|
|
|
|
self.skimto = SkimToWidget:new{
|
|
|
|
document = self.document,
|
|
|
|
ui = self.ui,
|
|
|
|
callback_switch_to_goto = function()
|
|
|
|
UIManager:close(self.skimto)
|
|
|
|
self:onShowGotoDialog()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
UIManager:show(self.skimto)
|
|
|
|
end
|
|
|
|
|
2013-07-30 15:37:51 +00:00
|
|
|
function ReaderGoto:close()
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:close(self.goto_dialog)
|
2013-07-30 15:09:08 +00:00
|
|
|
end
|
|
|
|
|
2013-07-30 15:37:51 +00:00
|
|
|
function ReaderGoto:gotoPage()
|
2015-03-12 07:45:58 +00:00
|
|
|
local page_number = self.goto_dialog:getInputText()
|
|
|
|
local relative_sign = page_number:sub(1, 1)
|
|
|
|
local number = tonumber(page_number)
|
2014-03-13 13:52:43 +00:00
|
|
|
if number then
|
2018-08-15 13:22:55 +00:00
|
|
|
self.ui.link:addCurrentLocationToStack()
|
2015-03-12 07:45:58 +00:00
|
|
|
if relative_sign == "+" or relative_sign == "-" then
|
|
|
|
self.ui:handleEvent(Event:new("GotoRelativePage", number))
|
|
|
|
else
|
2020-03-26 13:04:59 +00:00
|
|
|
if self.ui.pagemap and self.ui.pagemap:wantsPageLabels() then
|
|
|
|
number = self.ui.pagemap:getRenderedPageNumber(page_number, true)
|
|
|
|
if number then -- found
|
|
|
|
self.ui:handleEvent(Event:new("GotoPage", number))
|
|
|
|
else
|
|
|
|
return -- avoid self:close()
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.ui:handleEvent(Event:new("GotoPage", number))
|
|
|
|
end
|
2015-03-12 07:45:58 +00:00
|
|
|
end
|
|
|
|
self:close()
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-07-30 15:09:08 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2020-02-05 07:19:35 +00:00
|
|
|
function ReaderGoto:onGoToBeginning()
|
|
|
|
self.ui.link:addCurrentLocationToStack()
|
|
|
|
self.ui:handleEvent(Event:new("GotoPage", 1))
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderGoto:onGoToEnd()
|
|
|
|
local endpage = self.document:getPageCount()
|
|
|
|
if endpage then
|
|
|
|
self.ui.link:addCurrentLocationToStack()
|
|
|
|
self.ui:handleEvent(Event:new("GotoPage", endpage))
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return ReaderGoto
|