2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
|
|
|
local UIManager = require("ui/uimanager")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Screen = require("device").screen
|
2013-10-18 20:38:07 +00:00
|
|
|
local Event = require("ui/event")
|
2013-10-22 18:51:29 +00:00
|
|
|
local DEBUG = require("dbg")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
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"),
|
2014-03-13 13:52:43 +00:00
|
|
|
goto_dialog_title = _("Go to Page or Location"),
|
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
|
|
|
|
|
|
|
|
function ReaderGoto:addToMainMenu(tab_item_table)
|
2014-03-13 13:52:43 +00:00
|
|
|
-- insert goto command to main reader menu
|
|
|
|
table.insert(tab_item_table.navi, {
|
|
|
|
text = self.goto_menu_title,
|
|
|
|
callback = function()
|
|
|
|
self:onShowGotoDialog()
|
|
|
|
end,
|
|
|
|
})
|
2013-07-31 05:51:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderGoto:onShowGotoDialog()
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("show goto dialog")
|
|
|
|
self.goto_dialog = InputDialog:new{
|
|
|
|
title = self.goto_dialog_title,
|
|
|
|
input_hint = "(1 - "..self.document:getPageCount()..")",
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Page"),
|
|
|
|
enabled = self.document.info.has_pages,
|
|
|
|
callback = function()
|
|
|
|
self:gotoPage()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Location"),
|
|
|
|
enabled = not self.document.info.has_pages,
|
|
|
|
callback = function()
|
2015-03-12 07:45:58 +00:00
|
|
|
self:gotoPage()
|
2014-03-13 13:52:43 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input_type = "number",
|
2015-03-12 07:45:58 +00:00
|
|
|
enter_callback = function() self:gotoPage() end,
|
2014-03-13 13:52:43 +00:00
|
|
|
width = Screen:getWidth() * 0.8,
|
|
|
|
height = Screen:getHeight() * 0.2,
|
|
|
|
}
|
|
|
|
self.goto_dialog:onShowKeyboard()
|
|
|
|
UIManager:show(self.goto_dialog)
|
2013-07-30 15:09:08 +00:00
|
|
|
end
|
|
|
|
|
2013-07-30 15:37:51 +00:00
|
|
|
function ReaderGoto:close()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.goto_dialog:onClose()
|
|
|
|
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
|
2015-03-12 07:45:58 +00:00
|
|
|
if relative_sign == "+" or relative_sign == "-" then
|
|
|
|
self.ui:handleEvent(Event:new("GotoRelativePage", number))
|
|
|
|
else
|
|
|
|
self.ui:handleEvent(Event:new("GotoPage", number))
|
|
|
|
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
|
|
|
|
|
|
|
return ReaderGoto
|