Merge pull request #322 from chrox/master

add gotoLocation for credocument
pull/325/head
{Qingping, Dave} Hou 11 years ago
commit 2275e437e6

@ -326,8 +326,6 @@ local function grok_string(self, text, start, etc)
elseif text:match('^\\t', i) then
VALUE = VALUE .. "\t"
i = i + 2
elseif text:match('^\\\\', i) then
i = i + 1
else
local hex = text:match('^\\u([0123456789aAbBcCdDeEfF][0123456789aAbBcCdDeEfF][0123456789aAbBcCdDeEfF][0123456789aAbBcCdDeEfF])', i)
if hex then

@ -119,6 +119,10 @@ function CreDocument:close()
Document.close(self)
end
function CreDocument:getPageCount()
return self._document:getPages()
end
function CreDocument:drawCurrentView(target, x, y, rect, pos)
tile_bb = Blitbuffer.new(rect.w, rect.h)
self._document:drawCurrentPage(tile_bb)

@ -126,6 +126,10 @@ function Document:_readMetadata()
return true
end
function Document:getPageCount()
return self.info.number_of_pages
end
-- calculates page dimensions
function Document:getPageDimensions(pageno, zoom, rotation)
local native_dimen = self:getNativePageDimensions(pageno):copy()

@ -19,7 +19,7 @@ function ReaderDictionary:stardictLookup(word)
word = string.gsub(word, "%p+$", '')
DEBUG("stripped word:", word)
-- escape quotes and other funny characters in word
local std_out = io.popen("./sdcv -nj "..("%q"):format(word), "r")
local std_out = io.popen("./sdcv --utf8-input --utf8-output -nj "..("%q"):format(word), "r")
local results_str = std_out:read("*all")
if results_str then
--DEBUG("result str:", word, results_str)

@ -25,7 +25,7 @@ function ReaderGoto:onShowGotoDialog()
DEBUG("show goto dialog")
self.goto_dialog = InputDialog:new{
title = self.goto_dialog_title,
input_hint = "(1 - "..self.document.info.number_of_pages..")",
input_hint = "(1 - "..self.document:getPageCount()..")",
buttons = {
{
{
@ -52,6 +52,9 @@ function ReaderGoto:onShowGotoDialog()
},
},
input_type = "number",
enter_callback = self.document.info.has_pages
and function() self:gotoPage() end
or function() self:gotoLocation() end,
width = Screen:getWidth() * 0.8,
height = Screen:getHeight() * 0.2,
}
@ -74,6 +77,10 @@ function ReaderGoto:gotoPage()
end
function ReaderGoto:gotoLocation()
-- TODO: implement go to location
local number = tonumber(self.goto_dialog:getInputText())
if number then
self.ui:handleEvent(Event:new("GotoPage", number))
end
self:close()
return true
end

@ -325,4 +325,7 @@ function ReaderRolling:gotoPercent(new_percent)
self:gotoPos(new_percent * self.doc_height / 10000)
end
function ReaderRolling:onGotoPage(number)
self:gotoPage(number)
return true
end

@ -7,6 +7,7 @@ InputDialog = InputContainer:new{
input_hint = "",
buttons = nil,
input_type = nil,
enter_callback = nil,
width = nil,
height = nil,
@ -38,6 +39,7 @@ function InputDialog:init()
face = self.input_face,
width = self.width * 0.9,
input_type = self.input_type,
enter_callback = self.enter_callback,
scroll = false,
parent = self,
}

@ -94,6 +94,10 @@ function InputText:getKeyboardDimen()
end
function InputText:addChar(char)
if self.enter_callback and char == '\n' then
UIManager:scheduleIn(0.1, function() self.enter_callback() end)
return
end
table.insert(self.charlist, self.charpos, char)
self.charpos = self.charpos + 1
self.text = self:CharlistToString()

Loading…
Cancel
Save