PageBrowser: toggle page bookmark with long-press on thumbnail

reviewable/pr10227/r1
poire-z 1 year ago
parent 4f76a208b0
commit 3006348585

@ -844,7 +844,7 @@ function ReaderBookmark:isBookmarkMatch(item, pn_or_xp)
if self.ui.paging then
return item.page == pn_or_xp
else
return self.ui.document:isXPointerInCurrentPage(item.page)
return self.ui.document:getPageFromXPointer(item.page) == self.ui.document:getPageFromXPointer(pn_or_xp)
end
end
@ -1190,8 +1190,17 @@ function ReaderBookmark:doesBookmarkMatchTable(item, match_table)
end
end
function ReaderBookmark:toggleBookmark()
local pn_or_xp = self:getCurrentPageNumber()
function ReaderBookmark:toggleBookmark(pageno)
local pn_or_xp
if pageno then
if self.ui.rolling then
pn_or_xp = self.ui.document:getPageXPointer(pageno)
else
pn_or_xp = pageno
end
else
pn_or_xp = self:getCurrentPageNumber()
end
local index = self:getDogearBookmarkIndex(pn_or_xp)
if index then
self.ui:handleEvent(Event:new("BookmarkRemoved", self.bookmarks[index]))

@ -831,6 +831,10 @@ function CreDocument:getXPointer()
return self._document:getXPointer()
end
function CreDocument:getPageXPointer(page)
return self._document:getPageXPointer(page)
end
function CreDocument:isXPointerInDocument(xp)
return self._document:isXPointerInDocument(xp)
end

@ -984,6 +984,32 @@ function PageBrowserWidget:onHold(arg, ges)
end
return true
end
-- Hold on title: do nothing
if ges.pos.y < self.title_bar_h then
return true
end
-- If hold on a thumbnail, toggle bookmark on that page
for idx=1, self.nb_grid_items do
if ges.pos:intersectWith(self.grid[idx].dimen) then
local page = self.grid[idx].page_idx
if page and self.grid[idx][1][1].is_page_thumbnail then
-- Only allow hold on fully displayed thumbnails.
-- Also, a thumbnail might be smaller than the original grid
-- item dimension. Be sure the hold is on it (otherwise, it's
-- a hold in the inter thumbnail margin, that we'd rather not
-- handle)
local thumb_frame = self.grid[idx][1][1]
if ges.pos:intersectWith(thumb_frame.dimen) then
self.ui.bookmark:toggleBookmark(page)
-- Update our cached bookmarks info and ensure the bottom ribbon is redrawn
self.bookmarked_pages = self.ui.bookmark:getBookmarkedPages()
self:updateLayout()
return true
end
end
break
end
end
return true
end

Loading…
Cancel
Save