skimto: add beginning and end as hold callback (#5820)

* first/last bookmark
pull/5836/head
yparitcher 4 years ago committed by GitHub
parent 73659b6bd6
commit f6b23adb2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -571,6 +571,24 @@ function ReaderBookmark:getNextBookmarkedPageFromPage(pn_or_xp)
end
end
function ReaderBookmark:getFirstBookmarkedPageFromPage(pn_or_xp)
if #self.bookmarks > 0 then
local first = #self.bookmarks
if self:isBookmarkPageInPageOrder(pn_or_xp, self.bookmarks[first]) then
return self.bookmarks[first].page
end
end
end
function ReaderBookmark:getLastBookmarkedPageFromPage(pn_or_xp)
if #self.bookmarks > 0 then
local last = 1
if self:isBookmarkPageInReversePageOrder(pn_or_xp, self.bookmarks[last]) then
return self.bookmarks[last].page
end
end
end
function ReaderBookmark:onGotoPreviousBookmark(pn_or_xp)
self:gotoBookmark(self:getPreviousBookmarkedPage(pn_or_xp))
return true

@ -134,10 +134,7 @@ function SkimToWidget:init()
width = self.button_width,
show_parent = self,
callback = function()
self.curr_page = self.curr_page - 1
self:update()
self:addOriginToLocationStack()
self.ui:handleEvent(Event:new("GotoPage", self.curr_page))
self:goToPage(self.curr_page - 1)
end,
}
local button_minus_ten = Button:new{
@ -149,10 +146,7 @@ function SkimToWidget:init()
width = self.button_width,
show_parent = self,
callback = function()
self.curr_page = self.curr_page - 10
self:update()
self:addOriginToLocationStack()
self.ui:handleEvent(Event:new("GotoPage", self.curr_page))
self:goToPage(self.curr_page - 10)
end,
}
local button_plus = Button:new{
@ -164,10 +158,7 @@ function SkimToWidget:init()
width = self.button_width,
show_parent = self,
callback = function()
self.curr_page = self.curr_page + 1
self:update()
self:addOriginToLocationStack()
self.ui:handleEvent(Event:new("GotoPage", self.curr_page))
self:goToPage(self.curr_page + 1)
end,
}
local button_plus_ten = Button:new{
@ -179,10 +170,7 @@ function SkimToWidget:init()
width = self.button_width,
show_parent = self,
callback = function()
self.curr_page = self.curr_page + 10
self:update()
self:addOriginToLocationStack()
self.ui:handleEvent(Event:new("GotoPage", self.curr_page))
self:goToPage(self.curr_page + 10)
end,
}
self.current_page_text = Button:new{
@ -218,12 +206,12 @@ function SkimToWidget:init()
callback = function()
local page = self:getNextChapter(self.curr_page)
if page and page >=1 and page <= self.page_count then
self.curr_page = page
self:addOriginToLocationStack()
self.ui:handleEvent(Event:new("GotoPage", self.curr_page))
self:update()
self:goToPage(page)
end
end,
hold_callback = function()
self:goToPage(self.page_count)
end,
}
local button_chapter_prev = Button:new{
@ -237,12 +225,12 @@ function SkimToWidget:init()
callback = function()
local page = self:getPrevChapter(self.curr_page)
if page and page >=1 and page <= self.page_count then
self.curr_page = page
self:addOriginToLocationStack()
self.ui:handleEvent(Event:new("GotoPage", self.curr_page))
self:update()
self:goToPage(page)
end
end,
hold_callback = function()
self:goToPage(1)
end,
}
local button_bookmark_next = Button:new{
@ -260,16 +248,16 @@ function SkimToWidget:init()
else
page = self.ui.bookmark:getNextBookmarkedPageFromPage(self.curr_page)
end
if page then
self:addOriginToLocationStack()
self.ui.bookmark:gotoBookmark(page)
if self.document.info.has_pages then
self.curr_page = self.ui.paging.current_page
else
self.curr_page = self.document:getCurrentPage()
end
self:update()
self:goToBookmark(page)
end,
hold_callback = function()
local page
if self.document.info.has_pages then
page = self.ui.bookmark:getLastBookmarkedPageFromPage(self.ui.paging.current_page)
else
page = self.ui.bookmark:getLastBookmarkedPageFromPage(self.curr_page)
end
self:goToBookmark(page)
end,
}
@ -288,16 +276,16 @@ function SkimToWidget:init()
else
page = self.ui.bookmark:getPreviousBookmarkedPageFromPage(self.curr_page)
end
if page then
self:addOriginToLocationStack()
self.ui.bookmark:gotoBookmark(page)
if self.document.info.has_pages then
self.curr_page = self.ui.paging.current_page
else
self.curr_page = self.document:getCurrentPage()
end
self:update()
self:goToBookmark(page)
end,
hold_callback = function()
local page
if self.document.info.has_pages then
page = self.ui.bookmark:getFirstBookmarkedPageFromPage(self.ui.paging.current_page)
else
page = self.ui.bookmark:getFirstBookmarkedPageFromPage(self.curr_page)
end
self:goToBookmark(page)
end,
}
@ -422,6 +410,26 @@ function SkimToWidget:onShow()
return true
end
function SkimToWidget:goToPage(page)
self.curr_page = page
self:addOriginToLocationStack()
self.ui:handleEvent(Event:new("GotoPage", self.curr_page))
self:update()
end
function SkimToWidget:goToBookmark(page)
if page then
self:addOriginToLocationStack()
self.ui.bookmark:gotoBookmark(page)
if self.document.info.has_pages then
self.curr_page = self.ui.paging.current_page
else
self.curr_page = self.document:getCurrentPage()
end
self:update()
end
end
function SkimToWidget:onAnyKeyPressed()
UIManager:close(self)
return true

Loading…
Cancel
Save