Bookmarks: start Add note with empty text, add some buttons (#8738)

- New button Go to bookmark in Bookmark details dialog.
- New button Latest bookmark in the popup menu.
- Empty input box for new note, new button Paste to
  paste highlighted text (auto-text).
- Allow duplicated bookmarks to avoid orphaned highlights.
- TextBoxWidget: fix enabled up-arrow on empty box in InputDialog.
reviewable/pr8747/r1
hius07 2 years ago committed by GitHub
parent 978aa2006a
commit 1c863f76aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -589,6 +589,16 @@ function ReaderBookmark:onShowBookmark(match_table)
UIManager:close(self.textviewer)
end,
},
{
text = _("Go to bookmark"),
enabled = not self.select_mode,
callback = function()
UIManager:close(self.textviewer)
UIManager:close(bookmark.bookmark_menu)
bookmark.ui.link:addCurrentLocationToStack()
bookmark:gotoBookmark(item.page, item.pos0)
end,
},
},
}
}
@ -783,29 +793,40 @@ function ReaderBookmark:onShowBookmark(match_table)
table.insert(buttons, {})
table.insert(buttons, {
{
text = _("Select bookmarks"),
enabled = actions_enabled,
text = _("Book current page"),
enabled = curr_page_bm_idx ~= nil,
callback = function()
UIManager:close(bm_dialog)
bm_menu:toggleSelectMode()
bm_menu:switchItemTable(nil, item_table, curr_page_bm_idx)
end,
},
{
text = _("Search bookmarks"),
text = _("Latest bookmark"),
enabled = actions_enabled,
callback = function()
UIManager:close(bm_dialog)
bookmark:onSearchBookmark(bm_menu)
local _, idx = bookmark:getLatestBookmark()
idx = is_reverse_sorting and idx or #item_table - idx + 1
bm_menu:switchItemTable(nil, item_table, idx)
bm_menu:onMenuHold(item_table[idx])
end,
},
})
table.insert(buttons, {
{
text = _("Show book current page bookmarks"),
enabled = curr_page_bm_idx ~= nil,
text = _("Select bookmarks"),
enabled = actions_enabled,
callback = function()
UIManager:close(bm_dialog)
bm_menu:switchItemTable(nil, item_table, curr_page_bm_idx)
bm_menu:toggleSelectMode()
end,
},
{
text = _("Search bookmarks"),
enabled = actions_enabled,
callback = function()
UIManager:close(bm_dialog)
bookmark:onSearchBookmark(bm_menu)
end,
},
})
@ -880,11 +901,6 @@ function ReaderBookmark:addBookmark(item)
local _start, _middle, _end, direction = 1, 1, #self.bookmarks, 0
while _start <= _end do
_middle = math.floor((_start + _end)/2)
-- won't add duplicated bookmarks
if self:isBookmarkSame(item, self.bookmarks[_middle]) then
logger.warn("skip adding duplicated bookmark")
return
end
if self:isBookmarkInPositionOrder(item, self.bookmarks[_middle]) then
_end, direction = _middle - 1, 0
else
@ -1020,12 +1036,12 @@ function ReaderBookmark:renameBookmark(item, from_highlight, is_new_note, new_te
else
bookmark = item
end
local input_text = bookmark.text_orig
local input_text = self:getBookmarkNote(bookmark) and bookmark.text_orig or nil
if new_text then
if self:isBookmarkAutoText(bookmark) then
input_text = new_text
else
if input_text then
input_text = input_text .. "\n\n" .. new_text
else
input_text = new_text
end
end
self.input = InputDialog:new{
@ -1051,6 +1067,12 @@ function ReaderBookmark:renameBookmark(item, from_highlight, is_new_note, new_te
end
end,
},
{
text = _("Paste"), -- insert highlighted text (auto-text)
callback = function()
self.input._input_widget:addChars(bookmark.text_orig)
end,
},
{
text = _("Save"),
is_enter_default = true,
@ -1298,15 +1320,16 @@ function ReaderBookmark:onGotoPreviousBookmarkFromPage(add_current_location_to_s
end
function ReaderBookmark:getLatestBookmark()
local latest_bookmark = nil
local latest_bookmark, latest_bookmark_idx
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]
latest_bookmark_idx = i
end
end
return latest_bookmark
return latest_bookmark, latest_bookmark_idx
end
function ReaderBookmark:hasBookmarks()

@ -1069,6 +1069,9 @@ function TextBoxWidget:getBaseline()
end
function TextBoxWidget:getVisibleHeightRatios()
if #self.vertical_string_list == 0 then
return 0, 1
end
local low = (self.virtual_line_num - 1) / #self.vertical_string_list
local high = (self.virtual_line_num - 1 + self.lines_per_page) / #self.vertical_string_list
return low, high

Loading…
Cancel
Save