2019-12-06 21:55:39 +00:00
|
|
|
local BD = require("ui/bidi")
|
2017-04-29 08:38:09 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2017-09-30 16:17:48 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Event = require("ui/event")
|
2014-06-10 13:32:49 +00:00
|
|
|
local Font = require("ui/font")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2017-09-30 16:17:48 +00:00
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Menu = require("ui/widget/menu")
|
2017-07-31 17:21:38 +00:00
|
|
|
local TextViewer = require("ui/widget/textviewer")
|
2017-04-29 08:38:09 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2016-12-29 08:10:38 +00:00
|
|
|
local logger = require("logger")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Screen = require("device").screen
|
2017-09-30 16:17:48 +00:00
|
|
|
local T = require("ffi/util").template
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
local ReaderBookmark = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
bm_menu_title = _("Bookmarks"),
|
2017-09-23 16:25:22 +00:00
|
|
|
bbm_menu_title = _("Bookmark browsing mode"),
|
2021-02-04 16:43:52 +00:00
|
|
|
bookmarks_items_per_page_default = 14,
|
2014-03-13 13:52:43 +00:00
|
|
|
bookmarks = nil,
|
2013-01-01 19:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderBookmark:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
if Device:hasKeyboard() then
|
|
|
|
self.key_events = {
|
|
|
|
ShowBookmark = {
|
|
|
|
{ "B" },
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "show bookmarks" },
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
end
|
2021-02-04 16:43:52 +00:00
|
|
|
|
2021-03-06 21:44:18 +00:00
|
|
|
if G_reader_settings:hasNot("bookmarks_items_per_page") then
|
2021-02-04 16:43:52 +00:00
|
|
|
-- The Bookmarks items per page and items' font size can now be
|
|
|
|
-- configured. Previously, the ones set for the file browser
|
|
|
|
-- were used. Initialize them from these ones.
|
|
|
|
local items_per_page = G_reader_settings:readSetting("items_per_page")
|
2021-03-06 21:44:18 +00:00
|
|
|
or self.bookmarks_items_per_page_default
|
2021-02-04 16:43:52 +00:00
|
|
|
G_reader_settings:saveSetting("bookmarks_items_per_page", items_per_page)
|
|
|
|
local items_font_size = G_reader_settings:readSetting("items_font_size")
|
|
|
|
if items_font_size and items_font_size ~= Menu.getItemFontSize(items_per_page) then
|
|
|
|
-- Keep the user items font size if it's not the default for items_per_page
|
|
|
|
G_reader_settings:saveSetting("bookmarks_items_font_size", items_font_size)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2013-01-01 19:38:29 +00:00
|
|
|
end
|
|
|
|
|
2017-03-04 13:46:38 +00:00
|
|
|
function ReaderBookmark:addToMainMenu(menu_items)
|
2014-11-27 13:59:27 +00:00
|
|
|
-- insert table to main reader menu
|
2017-03-04 13:46:38 +00:00
|
|
|
menu_items.bookmarks = {
|
2014-11-27 13:59:27 +00:00
|
|
|
text = self.bm_menu_title,
|
|
|
|
callback = function()
|
|
|
|
self:onShowBookmark()
|
|
|
|
end,
|
2017-02-28 21:46:32 +00:00
|
|
|
}
|
2018-10-16 19:05:58 +00:00
|
|
|
if not Device:isTouchDevice() then
|
|
|
|
menu_items.toggle_bookmark = {
|
|
|
|
text_func = function() return self:isCurrentPageBookmarked() and _("Remove bookmark for current page") or _("Bookmark current page") end,
|
|
|
|
callback = function()
|
|
|
|
self:onToggleBookmark()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end
|
2017-09-23 16:25:22 +00:00
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
menu_items.bookmark_browsing_mode = {
|
|
|
|
text = self.bbm_menu_title,
|
2019-08-27 12:07:14 +00:00
|
|
|
checked_func = function() return self.ui.paging.bookmark_flipping_mode end,
|
2017-09-23 16:25:22 +00:00
|
|
|
callback = function(touchmenu_instance)
|
|
|
|
self:enableBookmarkBrowsingMode()
|
|
|
|
touchmenu_instance:closeMenu()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end
|
2021-02-04 16:43:52 +00:00
|
|
|
menu_items.bookmarks_items_per_page = {
|
|
|
|
text = _("Bookmarks per page"),
|
|
|
|
keep_menu_open = true,
|
|
|
|
callback = function()
|
|
|
|
local SpinWidget = require("ui/widget/spinwidget")
|
|
|
|
local curr_perpage = G_reader_settings:readSetting("bookmarks_items_per_page") or self.bookmarks_items_per_page_default
|
|
|
|
local items = SpinWidget:new{
|
|
|
|
width = math.floor(Screen:getWidth() * 0.6),
|
|
|
|
value = curr_perpage,
|
|
|
|
value_min = 6,
|
|
|
|
value_max = 24,
|
|
|
|
default_value = self.bookmarks_items_per_page_default,
|
|
|
|
title_text = _("Bookmarks per page"),
|
|
|
|
callback = function(spin)
|
|
|
|
G_reader_settings:saveSetting("bookmarks_items_per_page", spin.value)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
UIManager:show(items)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
menu_items.bookmarks_items_font_size = {
|
|
|
|
text = _("Bookmark font size"),
|
|
|
|
keep_menu_open = true,
|
|
|
|
callback = function()
|
|
|
|
local SpinWidget = require("ui/widget/spinwidget")
|
|
|
|
local curr_perpage = G_reader_settings:readSetting("bookmarks_items_per_page") or self.bookmarks_items_per_page_default
|
|
|
|
local default_font_size = Menu.getItemFontSize(curr_perpage)
|
|
|
|
local curr_font_size = G_reader_settings:readSetting("bookmarks_items_font_size") or default_font_size
|
|
|
|
local items_font = SpinWidget:new{
|
|
|
|
width = math.floor(Screen:getWidth() * 0.6),
|
|
|
|
value = curr_font_size,
|
|
|
|
value_min = 10,
|
|
|
|
value_max = 72,
|
|
|
|
default_value = default_font_size,
|
|
|
|
title_text = _("Bookmark font size"),
|
|
|
|
callback = function(spin)
|
|
|
|
G_reader_settings:saveSetting("bookmarks_items_font_size", spin.value)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
UIManager:show(items_font)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
menu_items.bookmarks_items_show_more_text = {
|
|
|
|
text = _("Shrink bookmark font size to fit more text"),
|
|
|
|
keep_menu_open = true,
|
|
|
|
checked_func = function()
|
|
|
|
return G_reader_settings:isTrue("bookmarks_items_multilines_show_more_text")
|
|
|
|
end,
|
|
|
|
callback = function()
|
|
|
|
G_reader_settings:flipNilOrFalse("bookmarks_items_multilines_show_more_text")
|
|
|
|
end
|
|
|
|
}
|
2017-09-23 16:25:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:enableBookmarkBrowsingMode()
|
|
|
|
self.ui:handleEvent(Event:new("ToggleBookmarkFlipping"))
|
2014-11-27 13:59:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:isBookmarkInTimeOrder(a, b)
|
|
|
|
return a.datetime > b.datetime
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:isBookmarkInPageOrder(a, b)
|
|
|
|
if self.ui.document.info.has_pages then
|
2020-02-27 21:03:04 +00:00
|
|
|
if a.page == b.page then -- have bookmarks before highlights
|
|
|
|
return a.highlighted
|
|
|
|
end
|
2014-11-27 13:59:27 +00:00
|
|
|
return a.page > b.page
|
|
|
|
else
|
2020-02-27 21:03:04 +00:00
|
|
|
local a_page = self.ui.document:getPageFromXPointer(a.page)
|
|
|
|
local b_page = self.ui.document:getPageFromXPointer(b.page)
|
|
|
|
if a_page == b_page then -- have bookmarks before highlights
|
|
|
|
return a.highlighted
|
|
|
|
end
|
|
|
|
return a_page > b_page
|
2014-11-27 13:59:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:isBookmarkInReversePageOrder(a, b)
|
2020-02-27 21:03:04 +00:00
|
|
|
-- The way this is used (by getNextBookmarkedPage(), iterating bookmarks
|
|
|
|
-- in reverse order), we want to skip highlights, but also the current
|
|
|
|
-- page: so we do not do any "a.page == b.page" check (not even with
|
|
|
|
-- a reverse logic than the one from above function).
|
2014-11-27 13:59:27 +00:00
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
return a.page < b.page
|
|
|
|
else
|
2020-02-27 21:03:04 +00:00
|
|
|
local a_page = self.ui.document:getPageFromXPointer(a.page)
|
|
|
|
local b_page = self.ui.document:getPageFromXPointer(b.page)
|
|
|
|
return a_page < b_page
|
2014-11-27 13:59:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-22 11:09:49 +00:00
|
|
|
function ReaderBookmark:isBookmarkPageInPageOrder(a, b)
|
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
return a > b.page
|
|
|
|
else
|
|
|
|
return a > self.ui.document:getPageFromXPointer(b.page)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:isBookmarkPageInReversePageOrder(a, b)
|
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
return a < b.page
|
|
|
|
else
|
|
|
|
return a < self.ui.document:getPageFromXPointer(b.page)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-27 13:59:27 +00:00
|
|
|
function ReaderBookmark:fixBookmarkSort(config)
|
|
|
|
-- for backward compatibility, since previously bookmarks for credocuments
|
|
|
|
-- are not well sorted. We need to do a whole sorting for at least once.
|
2021-03-06 21:44:18 +00:00
|
|
|
if config:hasNot("bookmarks_sorted") then
|
2014-11-27 13:59:27 +00:00
|
|
|
table.sort(self.bookmarks, function(a, b)
|
|
|
|
return self:isBookmarkInPageOrder(a, b)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:importSavedHighlight(config)
|
|
|
|
local textmarks = config:readSetting("highlight") or {}
|
|
|
|
-- import saved highlight once, because from now on highlight are added to
|
|
|
|
-- bookmarks when they are created.
|
2021-03-06 21:44:18 +00:00
|
|
|
if config:hasNot("highlights_imported") then
|
2014-11-27 13:59:27 +00:00
|
|
|
for page, marks in pairs(textmarks) do
|
|
|
|
for _, mark in ipairs(marks) do
|
2016-02-16 07:10:07 +00:00
|
|
|
page = self.ui.document.info.has_pages and page or mark.pos0
|
2014-12-04 01:13:41 +00:00
|
|
|
-- highlights saved by some old versions don't have pos0 field
|
|
|
|
-- we just ignore those highlights
|
|
|
|
if page then
|
|
|
|
self:addBookmark({
|
|
|
|
page = page,
|
|
|
|
datetime = mark.datetime,
|
|
|
|
notes = mark.text,
|
|
|
|
highlighted = true,
|
|
|
|
})
|
|
|
|
end
|
2014-11-27 13:59:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-01 19:38:29 +00:00
|
|
|
function ReaderBookmark:onReadSettings(config)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.bookmarks = config:readSetting("bookmarks") or {}
|
2014-11-27 13:59:27 +00:00
|
|
|
-- need to do this after initialization because checking xpointer
|
|
|
|
-- may cause segfaults before credocuments are inited.
|
|
|
|
self.ui:registerPostInitCallback(function()
|
|
|
|
self:fixBookmarkSort(config)
|
|
|
|
self:importSavedHighlight(config)
|
|
|
|
end)
|
2013-01-01 19:38:29 +00:00
|
|
|
end
|
|
|
|
|
2013-12-27 15:18:16 +00:00
|
|
|
function ReaderBookmark:onSaveSettings()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui.doc_settings:saveSetting("bookmarks", self.bookmarks)
|
2021-03-06 21:44:18 +00:00
|
|
|
self.ui.doc_settings:makeTrue("bookmarks_sorted")
|
|
|
|
self.ui.doc_settings:makeTrue("highlights_imported")
|
2013-01-01 19:38:29 +00:00
|
|
|
end
|
|
|
|
|
2018-10-16 19:05:58 +00:00
|
|
|
function ReaderBookmark:isCurrentPageBookmarked()
|
|
|
|
local pn_or_xp
|
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
pn_or_xp = self.view.state.page
|
|
|
|
else
|
|
|
|
pn_or_xp = self.ui.document:getXPointer()
|
|
|
|
end
|
|
|
|
return self:getDogearBookmarkIndex(pn_or_xp) and true or false
|
|
|
|
end
|
|
|
|
|
2013-02-24 11:49:23 +00:00
|
|
|
function ReaderBookmark:onToggleBookmark()
|
2016-02-16 07:10:07 +00:00
|
|
|
local pn_or_xp
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
pn_or_xp = self.view.state.page
|
|
|
|
else
|
|
|
|
pn_or_xp = self.ui.document:getXPointer()
|
|
|
|
end
|
|
|
|
self:toggleBookmark(pn_or_xp)
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.view.footer:onUpdateFooter(self.view.footer_visible)
|
2016-04-19 06:50:36 +00:00
|
|
|
self.ui:handleEvent(Event:new("SetDogearVisibility",
|
|
|
|
not self.view.dogear_visible))
|
2015-04-26 18:07:17 +00:00
|
|
|
UIManager:setDirty(self.view.dialog, "ui")
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-02-24 11:49:23 +00:00
|
|
|
end
|
2013-01-01 22:27:10 +00:00
|
|
|
|
2013-02-24 11:49:23 +00:00
|
|
|
function ReaderBookmark:setDogearVisibility(pn_or_xp)
|
2014-11-27 13:59:27 +00:00
|
|
|
if self:getDogearBookmarkIndex(pn_or_xp) then
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui:handleEvent(Event:new("SetDogearVisibility", true))
|
|
|
|
else
|
|
|
|
self.ui:handleEvent(Event:new("SetDogearVisibility", false))
|
|
|
|
end
|
2013-01-01 19:38:29 +00:00
|
|
|
end
|
|
|
|
|
2013-02-24 11:49:23 +00:00
|
|
|
function ReaderBookmark:onPageUpdate(pageno)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
self:setDogearVisibility(pageno)
|
|
|
|
else
|
2014-11-27 13:59:27 +00:00
|
|
|
self:setDogearVisibility(self.ui.document:getXPointer())
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-02-24 11:49:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:onPosUpdate(pos)
|
2014-11-27 13:59:27 +00:00
|
|
|
self:setDogearVisibility(self.ui.document:getXPointer())
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:02:05 +00:00
|
|
|
function ReaderBookmark:gotoBookmark(pn_or_xp, marker_xp)
|
2020-03-16 15:52:09 +00:00
|
|
|
if pn_or_xp then
|
|
|
|
local event = self.ui.document.info.has_pages and "GotoPage" or "GotoXPointer"
|
2021-01-29 00:02:05 +00:00
|
|
|
self.ui:handleEvent(Event:new(event, pn_or_xp, marker_xp))
|
2020-03-16 15:52:09 +00:00
|
|
|
end
|
2013-02-24 11:49:23 +00:00
|
|
|
end
|
|
|
|
|
2020-06-17 21:51:02 +00:00
|
|
|
-- This function adds "chapter" property to highlights already saved in the document
|
|
|
|
function ReaderBookmark:updateHighlightsIfNeeded()
|
|
|
|
local version = self.ui.doc_settings:readSetting("bookmarks_version") or 0
|
|
|
|
if version >= 20200615 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
for page, highlights in pairs(self.view.highlight.saved) do
|
|
|
|
for _, highlight in pairs(highlights) do
|
|
|
|
local pg_or_xp = self.ui.document.info.has_pages and
|
|
|
|
page or highlight.pos0
|
|
|
|
local chapter_name = self.ui.toc:getTocTitleByPage(pg_or_xp)
|
|
|
|
highlight.chapter = chapter_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, bookmark in ipairs(self.bookmarks) do
|
|
|
|
if bookmark.pos0 then
|
|
|
|
local pg_or_xp = self.ui.document.info.has_pages and
|
|
|
|
bookmark.page or bookmark.pos0
|
|
|
|
local chapter_name = self.ui.toc:getTocTitleByPage(pg_or_xp)
|
|
|
|
bookmark.chapter = chapter_name
|
|
|
|
elseif bookmark.page then -- dogear bookmark
|
|
|
|
local chapter_name = self.ui.toc:getTocTitleByPage(bookmark.page)
|
|
|
|
bookmark.chapter = chapter_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.ui.doc_settings:saveSetting("bookmarks_version", 20200615)
|
|
|
|
end
|
|
|
|
|
2013-01-01 19:38:29 +00:00
|
|
|
function ReaderBookmark:onShowBookmark()
|
2020-06-17 21:51:02 +00:00
|
|
|
self:updateHighlightsIfNeeded()
|
2014-03-13 13:52:43 +00:00
|
|
|
-- build up item_table
|
2014-10-26 07:05:17 +00:00
|
|
|
for k, v in ipairs(self.bookmarks) do
|
2014-03-13 13:52:43 +00:00
|
|
|
local page = v.page
|
|
|
|
-- for CREngine, bookmark page is xpointer
|
2014-11-27 13:59:27 +00:00
|
|
|
if not self.ui.document.info.has_pages then
|
2020-03-26 13:04:59 +00:00
|
|
|
if self.ui.pagemap and self.ui.pagemap:wantsPageLabels() then
|
|
|
|
page = self.ui.pagemap:getXPointerPageLabel(page, true)
|
|
|
|
else
|
|
|
|
page = self.ui.document:getPageFromXPointer(page)
|
2020-10-31 09:40:36 +00:00
|
|
|
if self.ui.document:hasHiddenFlows() then
|
|
|
|
local flow = self.ui.document:getPageFlow(page)
|
|
|
|
page = self.ui.document:getPageNumberInFlow(page)
|
|
|
|
if flow > 0 then
|
|
|
|
page = T("[%1]%2", page, flow)
|
|
|
|
end
|
|
|
|
end
|
2020-03-26 13:04:59 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2017-09-30 16:17:48 +00:00
|
|
|
if v.text == nil or v.text == "" then
|
|
|
|
v.text = T(_("Page %1 %2 @ %3"), page, v.notes, v.datetime)
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
|
2021-02-04 16:43:52 +00:00
|
|
|
local items_per_page = G_reader_settings:readSetting("bookmarks_items_per_page") or self.bookmarks_items_per_page_default
|
|
|
|
local items_font_size = G_reader_settings:readSetting("bookmarks_items_font_size") or Menu.getItemFontSize(items_per_page)
|
|
|
|
local multilines_show_more_text = G_reader_settings:isTrue("bookmarks_items_multilines_show_more_text")
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
local bm_menu = Menu:new{
|
2014-08-14 11:37:06 +00:00
|
|
|
title = _("Bookmarks"),
|
2014-03-13 13:52:43 +00:00
|
|
|
item_table = self.bookmarks,
|
2014-06-10 13:32:49 +00:00
|
|
|
is_borderless = true,
|
2014-11-27 13:59:27 +00:00
|
|
|
is_popout = false,
|
2014-04-04 15:37:50 +00:00
|
|
|
width = Screen:getWidth(),
|
|
|
|
height = Screen:getHeight(),
|
2017-04-29 08:38:09 +00:00
|
|
|
cface = Font:getFace("x_smallinfofont"),
|
2021-02-04 16:43:52 +00:00
|
|
|
items_per_page = items_per_page,
|
|
|
|
items_font_size = items_font_size,
|
|
|
|
multilines_show_more_text = multilines_show_more_text,
|
2018-01-13 22:38:53 +00:00
|
|
|
line_color = require("ffi/blitbuffer").COLOR_WHITE,
|
2014-06-10 13:13:21 +00:00
|
|
|
on_close_ges = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "two_finger_swipe",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
},
|
2019-12-06 21:55:39 +00:00
|
|
|
direction = BD.flipDirectionIfMirroredUILayout("east")
|
2014-06-10 13:13:21 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-04 15:37:50 +00:00
|
|
|
}
|
|
|
|
|
2014-11-27 13:59:27 +00:00
|
|
|
self.bookmark_menu = CenterContainer:new{
|
2014-04-04 15:37:50 +00:00
|
|
|
dimen = Screen:getSize(),
|
2018-03-17 22:02:32 +00:00
|
|
|
covers_fullscreen = true, -- hint for UIManager:_repaint()
|
2014-04-04 15:37:50 +00:00
|
|
|
bm_menu,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2014-04-04 15:37:50 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
-- buid up menu widget method as closure
|
2014-11-27 13:59:27 +00:00
|
|
|
local bookmark = self
|
2014-03-13 13:52:43 +00:00
|
|
|
function bm_menu:onMenuChoice(item)
|
2018-01-31 12:18:37 +00:00
|
|
|
bookmark.ui.link:addCurrentLocationToStack()
|
2021-01-29 00:02:05 +00:00
|
|
|
bookmark:gotoBookmark(item.page, item.pos0)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
|
2015-02-01 13:37:22 +00:00
|
|
|
function bm_menu:onMenuHold(item)
|
2017-07-31 17:21:38 +00:00
|
|
|
self.textviewer = TextViewer:new{
|
|
|
|
title = _("Bookmark details"),
|
|
|
|
text = item.notes,
|
|
|
|
width = self.textviewer_width,
|
|
|
|
height = self.textviewer_height,
|
|
|
|
buttons_table = {
|
2015-02-01 13:37:22 +00:00
|
|
|
{
|
2017-07-31 17:21:38 +00:00
|
|
|
{
|
2017-09-30 16:17:48 +00:00
|
|
|
text = _("Rename this bookmark"),
|
2017-07-31 17:21:38 +00:00
|
|
|
callback = function()
|
2017-09-30 16:17:48 +00:00
|
|
|
bookmark:renameBookmark(item)
|
2017-07-31 17:21:38 +00:00
|
|
|
UIManager:close(self.textviewer)
|
|
|
|
end,
|
|
|
|
},
|
2015-02-01 13:37:22 +00:00
|
|
|
{
|
|
|
|
text = _("Remove this bookmark"),
|
|
|
|
callback = function()
|
2017-09-30 16:17:48 +00:00
|
|
|
UIManager:show(ConfirmBox:new{
|
2020-12-27 13:10:43 +00:00
|
|
|
text = _("Remove this bookmark?"),
|
2017-09-30 16:17:48 +00:00
|
|
|
cancel_text = _("Cancel"),
|
|
|
|
cancel_callback = function()
|
|
|
|
return
|
|
|
|
end,
|
|
|
|
ok_text = _("Remove"),
|
|
|
|
ok_callback = function()
|
2017-10-18 15:19:06 +00:00
|
|
|
bookmark:removeHighlight(item)
|
2017-09-30 16:17:48 +00:00
|
|
|
bm_menu:switchItemTable(nil, bookmark.bookmarks, -1)
|
|
|
|
UIManager:close(self.textviewer)
|
|
|
|
end,
|
|
|
|
})
|
2015-02-01 13:37:22 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
2017-09-30 16:17:48 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Close"),
|
|
|
|
is_enter_default = true,
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(self.textviewer)
|
|
|
|
end,
|
|
|
|
},
|
Revamp flash_ui handling, once more, with feeling ;) (#7262)
* Simplify flash_ui handling (by handling the unhighlight pre-callback, c.f., #7262 for more details).
* UIManager: Handle translucent window-level widgets (and those wrapped in a translucent MovableContainer) properly in setDirty directly, making sure what's *underneath* them gets repainted to avoid alpha layering glitches. (This was previously handled via localized hacks).
* Update UIManager's documentation, and format it properly for ldoc parsing, making the HTML docs more useful.
* ReaderView: Reinitialize the various page areas when opening a new document, to prevent poisoning from the previous document.
* Event: Handle nils in an event's arguments.
* CheckButton/RadioButton: Switch to simple inversion to handle highlighting
* CheckButton: Make the highlight span the inner frame's width, instead of just the text's width, if possible.
* AlphaContainer: Fix & simplify, given the UIManager alpha handling.
* MovableContainer: When translucent, cache the canvas bb used for composition.
* Avoid spurious refreshes in a few widgets using various dummy *TextWidgets in order to first compute a text height.
* KeyValuePage: Avoid floats in size computations.
2021-02-20 17:22:48 +00:00
|
|
|
},
|
|
|
|
}
|
2015-02-01 13:37:22 +00:00
|
|
|
}
|
2017-07-31 17:21:38 +00:00
|
|
|
UIManager:show(self.textviewer)
|
2015-02-01 13:37:22 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
bm_menu.close_callback = function()
|
2014-11-27 13:59:27 +00:00
|
|
|
UIManager:close(self.bookmark_menu)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
|
2014-11-27 13:59:27 +00:00
|
|
|
bm_menu.show_parent = self.bookmark_menu
|
2017-09-30 16:17:48 +00:00
|
|
|
self.refresh = function()
|
|
|
|
bm_menu:updateItems()
|
|
|
|
self:onSaveSettings()
|
|
|
|
end
|
2014-06-10 13:13:21 +00:00
|
|
|
|
2014-11-27 13:59:27 +00:00
|
|
|
UIManager:show(self.bookmark_menu)
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-01-01 19:38:29 +00:00
|
|
|
end
|
|
|
|
|
2014-11-27 13:59:27 +00:00
|
|
|
function ReaderBookmark:isBookmarkMatch(item, pn_or_xp)
|
2016-12-04 14:18:33 +00:00
|
|
|
-- this is not correct, but previous commit temporarily
|
|
|
|
-- reverted, see #2395 & #2394
|
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
return item.page == pn_or_xp
|
|
|
|
else
|
|
|
|
return self.ui.document:isXPointerInCurrentPage(item.page)
|
|
|
|
end
|
2013-01-01 19:38:29 +00:00
|
|
|
end
|
|
|
|
|
2014-11-27 13:59:27 +00:00
|
|
|
function ReaderBookmark:getDogearBookmarkIndex(pn_or_xp)
|
2016-04-03 04:52:30 +00:00
|
|
|
local _middle
|
|
|
|
local _start, _end = 1, #self.bookmarks
|
2014-11-27 13:59:27 +00:00
|
|
|
while _start <= _end do
|
|
|
|
_middle = math.floor((_start + _end)/2)
|
|
|
|
local v = self.bookmarks[_middle]
|
2020-02-27 21:03:04 +00:00
|
|
|
if not v.highlighted and self:isBookmarkMatch(v, pn_or_xp) then
|
|
|
|
return _middle
|
2014-11-27 13:59:27 +00:00
|
|
|
elseif self:isBookmarkInPageOrder({page = pn_or_xp}, v) then
|
|
|
|
_end = _middle - 1
|
|
|
|
else
|
|
|
|
_start = _middle + 1
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
end
|
2013-02-24 11:49:23 +00:00
|
|
|
end
|
|
|
|
|
2015-02-01 16:09:07 +00:00
|
|
|
function ReaderBookmark:isBookmarkSame(item1, item2)
|
2015-04-27 00:49:27 +00:00
|
|
|
if item1.notes ~= item2.notes then return false end
|
2015-02-01 16:09:07 +00:00
|
|
|
if self.ui.document.info.has_pages then
|
2020-08-26 18:44:54 +00:00
|
|
|
return item1.pos0 and item1.pos1 and item2.pos0 and item2.pos1
|
|
|
|
and item1.pos0.page == item2.pos0.page
|
2015-02-01 16:09:07 +00:00
|
|
|
and item1.pos0.x == item2.pos0.x and item1.pos0.y == item2.pos0.y
|
|
|
|
and item1.pos1.x == item2.pos1.x and item1.pos1.y == item2.pos1.y
|
|
|
|
else
|
|
|
|
return item1.page == item2.page
|
|
|
|
and item1.pos0 == item2.pos0 and item1.pos1 == item2.pos1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-27 13:59:27 +00:00
|
|
|
-- binary insert of sorted bookmarks
|
|
|
|
function ReaderBookmark:addBookmark(item)
|
|
|
|
local _start, _middle, _end, direction = 1, 1, #self.bookmarks, 0
|
|
|
|
while _start <= _end do
|
|
|
|
_middle = math.floor((_start + _end)/2)
|
2015-02-01 13:37:22 +00:00
|
|
|
-- won't add duplicated bookmarks
|
2015-02-01 16:09:07 +00:00
|
|
|
if self:isBookmarkSame(item, self.bookmarks[_middle]) then
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.warn("skip adding duplicated bookmark")
|
2015-02-01 16:09:07 +00:00
|
|
|
return
|
|
|
|
end
|
2014-11-27 13:59:27 +00:00
|
|
|
if self:isBookmarkInPageOrder(item, self.bookmarks[_middle]) then
|
|
|
|
_end, direction = _middle - 1, 0
|
|
|
|
else
|
|
|
|
_start, direction = _middle + 1, 1
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-11-27 13:59:27 +00:00
|
|
|
table.insert(self.bookmarks, _middle + direction, item)
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.view.footer:onUpdateFooter(self.view.footer_visible)
|
2013-03-12 17:18:53 +00:00
|
|
|
end
|
2013-01-01 19:38:29 +00:00
|
|
|
|
2015-03-12 10:50:57 +00:00
|
|
|
-- binary search of sorted bookmarks
|
|
|
|
function ReaderBookmark:isBookmarkAdded(item)
|
2016-04-03 04:52:30 +00:00
|
|
|
local _middle
|
|
|
|
local _start, _end = 1, #self.bookmarks
|
2015-03-12 10:50:57 +00:00
|
|
|
while _start <= _end do
|
|
|
|
_middle = math.floor((_start + _end)/2)
|
|
|
|
if self:isBookmarkSame(item, self.bookmarks[_middle]) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
if self:isBookmarkInPageOrder(item, self.bookmarks[_middle]) then
|
2016-02-16 07:10:07 +00:00
|
|
|
_end = _middle - 1
|
2015-03-12 10:50:57 +00:00
|
|
|
else
|
2016-02-16 07:10:07 +00:00
|
|
|
_start = _middle + 1
|
2015-03-12 10:50:57 +00:00
|
|
|
end
|
|
|
|
end
|
2015-04-27 00:49:27 +00:00
|
|
|
return false
|
2015-03-12 10:50:57 +00:00
|
|
|
end
|
|
|
|
|
2017-10-18 15:19:06 +00:00
|
|
|
function ReaderBookmark:removeHighlight(item)
|
2017-07-28 20:39:54 +00:00
|
|
|
if item.pos0 then
|
|
|
|
self.ui:handleEvent(Event:new("Unhighlight", item))
|
|
|
|
else
|
|
|
|
self:removeBookmark(item)
|
2020-01-23 16:41:17 +00:00
|
|
|
-- Update dogear in case we removed a bookmark for current page
|
|
|
|
if self.ui.document.info.has_pages then
|
|
|
|
self:setDogearVisibility(self.view.state.page)
|
|
|
|
else
|
|
|
|
self:setDogearVisibility(self.ui.document:getXPointer())
|
|
|
|
end
|
2017-07-28 20:39:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-27 13:59:27 +00:00
|
|
|
-- binary search to remove bookmark
|
|
|
|
function ReaderBookmark:removeBookmark(item)
|
2016-04-03 04:52:30 +00:00
|
|
|
local _middle
|
|
|
|
local _start, _end = 1, #self.bookmarks
|
2014-11-27 13:59:27 +00:00
|
|
|
while _start <= _end do
|
|
|
|
_middle = math.floor((_start + _end)/2)
|
|
|
|
local v = self.bookmarks[_middle]
|
|
|
|
if item.datetime == v.datetime and item.page == v.page then
|
2020-11-13 12:04:27 +00:00
|
|
|
table.remove(self.bookmarks, _middle)
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.view.footer:onUpdateFooter(self.view.footer_visible)
|
2020-11-13 12:04:27 +00:00
|
|
|
return
|
2014-11-27 13:59:27 +00:00
|
|
|
elseif self:isBookmarkInPageOrder(item, v) then
|
|
|
|
_end = _middle - 1
|
|
|
|
else
|
|
|
|
_start = _middle + 1
|
|
|
|
end
|
|
|
|
end
|
2017-10-18 15:19:06 +00:00
|
|
|
-- If we haven't found item, it may be because there are multiple
|
|
|
|
-- bookmarks on the same page, and the above binary search decided to
|
|
|
|
-- not search on one side of one it found on page, where item could be.
|
|
|
|
-- Fallback to do a full scan.
|
|
|
|
logger.dbg("removeBookmark: binary search didn't find bookmark, doing full scan")
|
|
|
|
for i=1, #self.bookmarks do
|
|
|
|
local v = self.bookmarks[i]
|
|
|
|
if item.datetime == v.datetime and item.page == v.page then
|
2020-11-13 12:04:27 +00:00
|
|
|
table.remove(self.bookmarks, i)
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
self.view.footer:onUpdateFooter(self.view.footer_visible)
|
2020-11-13 12:04:27 +00:00
|
|
|
return
|
2017-10-18 15:19:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
logger.warn("removeBookmark: full scan search didn't find bookmark")
|
2013-01-01 19:38:29 +00:00
|
|
|
end
|
|
|
|
|
2019-02-15 23:42:27 +00:00
|
|
|
function ReaderBookmark:updateBookmark(item)
|
|
|
|
for i=1, #self.bookmarks do
|
|
|
|
if item.datetime == self.bookmarks[i].datetime and item.page == self.bookmarks[i].page then
|
|
|
|
local page = self.ui.document:getPageFromXPointer(item.updated_highlight.pos0)
|
2020-10-31 09:40:36 +00:00
|
|
|
if self.ui.document:hasHiddenFlows() then
|
|
|
|
local flow = self.ui.document:getPageFlow(page)
|
|
|
|
page = self.ui.document:getPageNumberInFlow(page)
|
|
|
|
if flow > 0 then
|
|
|
|
page = T("[%1]%2", page, flow)
|
|
|
|
end
|
|
|
|
end
|
2019-02-15 23:42:27 +00:00
|
|
|
local new_text = item.updated_highlight.text
|
|
|
|
self.bookmarks[i].page = item.updated_highlight.pos0
|
|
|
|
self.bookmarks[i].pos0 = item.updated_highlight.pos0
|
|
|
|
self.bookmarks[i].pos1 = item.updated_highlight.pos1
|
|
|
|
self.bookmarks[i].notes = item.updated_highlight.text
|
|
|
|
self.bookmarks[i].text = T(_("Page %1 %2 @ %3"), page,
|
|
|
|
new_text,
|
|
|
|
item.updated_highlight.datetime)
|
|
|
|
self.bookmarks[i].datetime = item.updated_highlight.datetime
|
2020-06-17 21:51:02 +00:00
|
|
|
self.bookmarks[i].chapter = item.updated_highlight.chapter
|
2019-02-15 23:42:27 +00:00
|
|
|
self:onSaveSettings()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-18 15:19:06 +00:00
|
|
|
function ReaderBookmark:renameBookmark(item, from_highlight)
|
2021-04-09 17:00:25 +00:00
|
|
|
local bookmark
|
2017-10-18 15:19:06 +00:00
|
|
|
if from_highlight then
|
|
|
|
-- Called by ReaderHighlight:editHighlight, we need to find the bookmark
|
2021-03-23 09:31:52 +00:00
|
|
|
local pboxes = item.pboxes
|
2021-04-09 17:00:25 +00:00
|
|
|
for __, bm in ipairs(self.bookmarks) do
|
|
|
|
if item.datetime == bm.datetime and item.page == bm.page then
|
|
|
|
bookmark = bm
|
|
|
|
bookmark.pboxes = pboxes
|
|
|
|
if bookmark.text == nil or bookmark.text == "" then
|
2017-10-18 15:19:06 +00:00
|
|
|
-- Make up bookmark text as done in onShowBookmark
|
2021-04-09 17:00:25 +00:00
|
|
|
local page = bookmark.page
|
2017-10-18 15:19:06 +00:00
|
|
|
if not self.ui.document.info.has_pages then
|
|
|
|
page = self.ui.document:getPageFromXPointer(page)
|
2020-10-31 09:40:36 +00:00
|
|
|
if self.ui.document:hasHiddenFlows() then
|
|
|
|
local flow = self.ui.document:getPageFlow(page)
|
|
|
|
page = self.ui.document:getPageNumberInFlow(page)
|
|
|
|
if flow > 0 then
|
|
|
|
page = T("[%1]%2", page, flow)
|
|
|
|
end
|
|
|
|
end
|
2017-10-18 15:19:06 +00:00
|
|
|
end
|
2021-04-09 17:00:25 +00:00
|
|
|
bookmark.text = T(_("Page %1 %2 @ %3"), page, bookmark.notes, bookmark.datetime)
|
2017-10-18 15:19:06 +00:00
|
|
|
end
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2021-04-09 17:00:25 +00:00
|
|
|
if bookmark.text == nil then -- bookmark not found
|
2017-10-18 15:19:06 +00:00
|
|
|
return
|
|
|
|
end
|
2021-04-09 17:00:25 +00:00
|
|
|
else
|
|
|
|
bookmark = item
|
2017-10-18 15:19:06 +00:00
|
|
|
end
|
2017-09-30 16:17:48 +00:00
|
|
|
self.input = InputDialog:new{
|
|
|
|
title = _("Rename bookmark"),
|
2021-04-09 17:00:25 +00:00
|
|
|
input = bookmark.text,
|
2017-09-30 16:17:48 +00:00
|
|
|
input_type = "text",
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
allow_newline = true,
|
|
|
|
cursor_at_end = false,
|
|
|
|
add_scroll_buttons = true,
|
2017-09-30 16:17:48 +00:00
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
|
|
|
is_enter_default = true,
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(self.input)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Rename"),
|
|
|
|
callback = function()
|
|
|
|
local value = self.input:getInputValue()
|
|
|
|
if value ~= "" then
|
2021-04-09 17:00:25 +00:00
|
|
|
for __, bm in ipairs(self.bookmarks) do
|
|
|
|
if bookmark.text == bm.text and bookmark.pos0 == bm.pos0 and
|
|
|
|
bookmark.pos1 == bm.pos1 and bookmark.page == bm.page then
|
|
|
|
bm.text = value
|
|
|
|
-- A bookmark isn't necessarily a highlight (it doesn't have pboxes)
|
|
|
|
if bookmark.pboxes then
|
|
|
|
local setting = G_reader_settings:readSetting("save_document")
|
|
|
|
if setting ~= "disable" then
|
|
|
|
self.ui.document:updateHighlightContents(bookmark.page, bookmark, value)
|
|
|
|
end
|
2021-03-23 09:31:52 +00:00
|
|
|
end
|
2017-09-30 16:17:48 +00:00
|
|
|
UIManager:close(self.input)
|
2017-10-18 15:19:06 +00:00
|
|
|
if not from_highlight then
|
|
|
|
self.refresh()
|
|
|
|
end
|
2017-09-30 16:17:48 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
UIManager:close(self.input)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
UIManager:show(self.input)
|
2018-03-30 10:46:36 +00:00
|
|
|
self.input:onShowKeyboard()
|
2017-09-30 16:17:48 +00:00
|
|
|
end
|
|
|
|
|
2013-02-24 11:49:23 +00:00
|
|
|
function ReaderBookmark:toggleBookmark(pn_or_xp)
|
2014-11-27 13:59:27 +00:00
|
|
|
local index = self:getDogearBookmarkIndex(pn_or_xp)
|
|
|
|
if index then
|
|
|
|
table.remove(self.bookmarks, index)
|
|
|
|
else
|
|
|
|
-- build notes from TOC
|
|
|
|
local notes = self.ui.toc:getTocTitleByPage(pn_or_xp)
|
2020-06-17 21:51:02 +00:00
|
|
|
local chapter_name = notes
|
2014-11-27 13:59:27 +00:00
|
|
|
if notes ~= "" then
|
2020-07-25 13:26:26 +00:00
|
|
|
-- @translators In which chapter title (%1) a note is found.
|
|
|
|
notes = T(_("in %1"), notes)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-11-27 13:59:27 +00:00
|
|
|
self:addBookmark({
|
|
|
|
page = pn_or_xp,
|
|
|
|
datetime = os.date("%Y-%m-%d %H:%M:%S"),
|
|
|
|
notes = notes,
|
2020-06-17 21:51:02 +00:00
|
|
|
chapter = chapter_name
|
2014-11-27 13:59:27 +00:00
|
|
|
})
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-02-24 11:49:23 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2014-01-03 19:14:24 +00:00
|
|
|
function ReaderBookmark:getPreviousBookmarkedPage(pn_or_xp)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("go to next bookmark from", pn_or_xp)
|
2014-11-27 13:59:27 +00:00
|
|
|
for i = 1, #self.bookmarks do
|
|
|
|
if self:isBookmarkInPageOrder({page = pn_or_xp}, self.bookmarks[i]) then
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.bookmarks[i].page
|
|
|
|
end
|
|
|
|
end
|
2014-01-03 19:14:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:getNextBookmarkedPage(pn_or_xp)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("go to next bookmark from", pn_or_xp)
|
2014-11-27 13:59:27 +00:00
|
|
|
for i = #self.bookmarks, 1, -1 do
|
|
|
|
if self:isBookmarkInReversePageOrder({page = pn_or_xp}, self.bookmarks[i]) then
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.bookmarks[i].page
|
|
|
|
end
|
|
|
|
end
|
2014-01-03 19:14:24 +00:00
|
|
|
end
|
|
|
|
|
2017-10-22 11:09:49 +00:00
|
|
|
function ReaderBookmark:getPreviousBookmarkedPageFromPage(pn_or_xp)
|
|
|
|
logger.dbg("go to next bookmark from", pn_or_xp)
|
|
|
|
for i = 1, #self.bookmarks do
|
|
|
|
if self:isBookmarkPageInPageOrder(pn_or_xp, self.bookmarks[i]) then
|
|
|
|
return self.bookmarks[i].page
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:getNextBookmarkedPageFromPage(pn_or_xp)
|
|
|
|
logger.dbg("go to next bookmark from", pn_or_xp)
|
|
|
|
for i = #self.bookmarks, 1, -1 do
|
|
|
|
if self:isBookmarkPageInReversePageOrder(pn_or_xp, self.bookmarks[i]) then
|
|
|
|
return self.bookmarks[i].page
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-09 12:00:57 +00:00
|
|
|
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
|
|
|
|
|
2014-01-03 19:14:24 +00:00
|
|
|
function ReaderBookmark:onGotoPreviousBookmark(pn_or_xp)
|
2014-11-27 13:59:27 +00:00
|
|
|
self:gotoBookmark(self:getPreviousBookmarkedPage(pn_or_xp))
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2014-01-03 19:14:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:onGotoNextBookmark(pn_or_xp)
|
2014-11-27 13:59:27 +00:00
|
|
|
self:gotoBookmark(self:getNextBookmarkedPage(pn_or_xp))
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2014-01-03 19:14:24 +00:00
|
|
|
end
|
|
|
|
|
2020-06-25 19:19:50 +00:00
|
|
|
function ReaderBookmark:onGotoNextBookmarkFromPage(add_current_location_to_stack)
|
|
|
|
if add_current_location_to_stack ~= false then -- nil or true
|
|
|
|
self.ui.link:addCurrentLocationToStack()
|
|
|
|
end
|
2020-03-16 15:52:09 +00:00
|
|
|
self:gotoBookmark(self:getNextBookmarkedPageFromPage(self.ui:getCurrentPage()))
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2020-06-25 19:19:50 +00:00
|
|
|
function ReaderBookmark:onGotoPreviousBookmarkFromPage(add_current_location_to_stack)
|
|
|
|
if add_current_location_to_stack ~= false then -- nil or true
|
|
|
|
self.ui.link:addCurrentLocationToStack()
|
|
|
|
end
|
2020-03-16 15:52:09 +00:00
|
|
|
self:gotoBookmark(self:getPreviousBookmarkedPageFromPage(self.ui:getCurrentPage()))
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-09-11 20:56:15 +00:00
|
|
|
function ReaderBookmark:getLatestBookmark()
|
|
|
|
local latest_bookmark = nil
|
|
|
|
local latest_bookmark_datetime = "0"
|
|
|
|
for i = 1, #self.bookmarks do
|
|
|
|
if self.bookmarks[i].datetime > latest_bookmark_datetime then
|
|
|
|
latest_bookmark_datetime = self.bookmarks[i].datetime
|
|
|
|
latest_bookmark = self.bookmarks[i]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return latest_bookmark
|
|
|
|
end
|
|
|
|
|
2019-07-14 20:13:05 +00:00
|
|
|
function ReaderBookmark:hasBookmarks()
|
|
|
|
return self.bookmarks and #self.bookmarks > 0
|
|
|
|
end
|
|
|
|
|
2020-09-05 12:54:53 +00:00
|
|
|
function ReaderBookmark:getNumberOfBookmarks()
|
|
|
|
return self.bookmarks and #self.bookmarks or 0
|
|
|
|
end
|
|
|
|
|
2020-05-20 19:40:49 +00:00
|
|
|
function ReaderBookmark:getNumberOfHighlightsAndNotes()
|
|
|
|
local highlights = 0
|
|
|
|
local notes = 0
|
|
|
|
for i = 1, #self.bookmarks do
|
|
|
|
if self.bookmarks[i].highlighted then
|
|
|
|
highlights = highlights + 1
|
|
|
|
-- No real way currently to know which highlights
|
|
|
|
-- have been edited and became "notes". Editing them
|
|
|
|
-- adds this 'text' field, but just showing bookmarks
|
|
|
|
-- do that as well...
|
|
|
|
if self.bookmarks[i].text then
|
|
|
|
notes = notes + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return highlights, notes
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return ReaderBookmark
|