mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Highlights popup dialog: add "Color" and "Details" buttons (#12461)
This commit is contained in:
@@ -318,7 +318,7 @@ function ReaderBookmark:onToggleBookmark()
|
||||
end)
|
||||
-- And ask for a footer refresh, in case we have bookmark_count enabled.
|
||||
-- Assuming the footer is visible, it'll request a refresh regardless, but the EPDC should optimize it out if no content actually changed.
|
||||
self.view.footer:onUpdateFooter(self.view.footer_visible)
|
||||
self.view.footer:maybeUpdateFooter()
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -402,9 +402,9 @@ end
|
||||
|
||||
-- remove, update bookmark
|
||||
|
||||
function ReaderBookmark:removeItem(item)
|
||||
local index = self.ui.annotation:getItemIndex(item)
|
||||
if item.pos0 then
|
||||
function ReaderBookmark:removeItem(item, item_idx)
|
||||
local index = item_idx or self:getBookmarkItemIndex(item)
|
||||
if item.drawer then
|
||||
self.ui.highlight:deleteHighlight(index) -- will call ReaderBookmark:removeItemByIndex()
|
||||
else -- dogear bookmark, update it in case we removed a bookmark for current page
|
||||
self:removeItemByIndex(index)
|
||||
@@ -421,11 +421,11 @@ function ReaderBookmark:removeItemByIndex(index)
|
||||
self.ui:handleEvent(Event:new("AnnotationsModified", { item, nb_notes_added = -1 }))
|
||||
end
|
||||
table.remove(self.ui.annotation.annotations, index)
|
||||
self.view.footer:onUpdateFooter(self.view.footer_visible)
|
||||
self.view.footer:maybeUpdateFooter()
|
||||
end
|
||||
|
||||
function ReaderBookmark:deleteItemNote(item)
|
||||
local index = self.ui.annotation:getItemIndex(item)
|
||||
local index = self:getBookmarkItemIndex(item)
|
||||
self.ui.annotation.annotations[index].note = nil
|
||||
self.ui:handleEvent(Event:new("AnnotationsModified", { item, nb_highlights_added = 1, nb_notes_added = -1 }))
|
||||
end
|
||||
@@ -1026,7 +1026,7 @@ function ReaderBookmark:updateBookmarkList(item_table, item_number)
|
||||
end
|
||||
|
||||
function ReaderBookmark:getBookmarkItemIndex(item)
|
||||
if self.match_table or self.show_edited_only or self.show_drawer_only -- filtered
|
||||
if not item.idx or self.match_table or self.show_edited_only or self.show_drawer_only -- filtered
|
||||
or self.sorting_mode ~= "page" then -- or item_table order does not match with annotations
|
||||
return self.ui.annotation:getItemIndex(item)
|
||||
end
|
||||
@@ -1068,142 +1068,169 @@ function ReaderBookmark:_getDialogHeader(bookmark)
|
||||
return T(_("Page: %1"), page_str) .. " " .. T(_("Time: %1"), bookmark.datetime)
|
||||
end
|
||||
|
||||
function ReaderBookmark:showBookmarkDetails(item)
|
||||
local bm_menu = self.bookmark_menu[1]
|
||||
local item_table = bm_menu.item_table
|
||||
function ReaderBookmark:showBookmarkDetails(item_or_index)
|
||||
local item_table, item, item_idx, item_type
|
||||
local bm_menu = self.bookmark_menu and self.bookmark_menu[1]
|
||||
if bm_menu then -- called from Bookmark list, got item
|
||||
item_table = bm_menu.item_table
|
||||
item = item_or_index
|
||||
item_idx = item.idx
|
||||
item_type = item.type
|
||||
else -- called from Reader, got index
|
||||
item_table = self.ui.annotation.annotations
|
||||
item_idx = item_or_index
|
||||
item = item_table[item_idx]
|
||||
item_type = self.getBookmarkType(item)
|
||||
end
|
||||
local items_nb = #item_table
|
||||
local text = self:_getDialogHeader(item) .. "\n\n"
|
||||
local prefix = item.type == "bookmark" and self.display_prefix["bookmark"] or self.display_prefix["highlight"]
|
||||
text = text .. prefix .. item.text_orig
|
||||
local prefix = item_type == "bookmark" and self.display_prefix["bookmark"] or self.display_prefix["highlight"]
|
||||
text = text .. prefix .. (item.text_orig or item.text)
|
||||
if item.note then
|
||||
text = text .. "\n\n" .. self.display_prefix["note"] .. item.note
|
||||
end
|
||||
local not_select_mode = not bm_menu.select_count and not self.ui.highlight.select_mode
|
||||
local not_select_mode = not (bm_menu and bm_menu.select_count) and not self.ui.highlight.select_mode
|
||||
|
||||
local textviewer
|
||||
local edit_details_callback = function()
|
||||
local function _goToBookmark()
|
||||
UIManager:close(textviewer)
|
||||
self.ui.link:addCurrentLocationToStack()
|
||||
self:gotoBookmark(item.page, item.pos0)
|
||||
end
|
||||
local function _showBookmarkDetails(idx)
|
||||
UIManager:close(textviewer)
|
||||
if bm_menu then
|
||||
self:updateBookmarkList(nil, idx)
|
||||
self:showBookmarkDetails(item_table[idx])
|
||||
else
|
||||
self:showBookmarkDetails(idx)
|
||||
end
|
||||
end
|
||||
local function edit_details_callback()
|
||||
self.details_updated = true
|
||||
UIManager:close(textviewer)
|
||||
self:showBookmarkDetails(item_table[item.idx])
|
||||
self:showBookmarkDetails(item_or_index)
|
||||
end
|
||||
local _showBookmarkDetails = function(idx)
|
||||
UIManager:close(textviewer)
|
||||
self:updateBookmarkList(nil, idx)
|
||||
self:showBookmarkDetails(item_table[idx])
|
||||
end
|
||||
-- Refresh the bookmark list whenever details may have been edited
|
||||
local _updateBookmarkList = function()
|
||||
local function close_callback()
|
||||
if self.details_updated then
|
||||
self.details_updated = nil
|
||||
if self.show_edited_only then
|
||||
for i = #item_table, 1, -1 do
|
||||
if not item_table[i].text_edited then
|
||||
table.remove(item_table, i)
|
||||
if bm_menu then
|
||||
if self.show_edited_only then
|
||||
for i = items_nb, 1, -1 do
|
||||
if not item_table[i].text_edited then
|
||||
table.remove(item_table, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
self:updateBookmarkList(item_table, -1)
|
||||
else
|
||||
if self.view.highlight.note_mark then -- refresh note marker
|
||||
UIManager:setDirty(self.dialog, "ui")
|
||||
end
|
||||
end
|
||||
self:updateBookmarkList(item_table, -1)
|
||||
end
|
||||
end
|
||||
|
||||
local buttons_table = {
|
||||
{
|
||||
{
|
||||
text = _("Reset text"),
|
||||
enabled = item.text_edited and not_select_mode or false,
|
||||
callback = function()
|
||||
self:setHighlightedText(item_or_index, nil, edit_details_callback)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Edit text"),
|
||||
enabled = item.drawer and not_select_mode or false,
|
||||
callback = function()
|
||||
self:editHighlightedText(item_or_index, edit_details_callback)
|
||||
end,
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
text = _("Remove bookmark"),
|
||||
enabled = not_select_mode,
|
||||
callback = function()
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("Remove this bookmark?"),
|
||||
ok_text = _("Remove"),
|
||||
ok_callback = function()
|
||||
UIManager:close(textviewer)
|
||||
self:removeItem(item, not bm_menu and item_idx)
|
||||
if bm_menu then
|
||||
table.remove(item_table, item_idx)
|
||||
self:updateBookmarkList(item_table, -1)
|
||||
end
|
||||
end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = item.note and _("Edit note") or _("Add note"),
|
||||
enabled = not_select_mode,
|
||||
callback = function()
|
||||
self:setBookmarkNote(item_or_index, nil, nil, edit_details_callback)
|
||||
end,
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
text = _("Close"),
|
||||
callback = function()
|
||||
textviewer:onClose()
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Go to bookmark"),
|
||||
enabled = not (bm_menu and bm_menu.select_count),
|
||||
callback = function()
|
||||
_goToBookmark()
|
||||
if bm_menu then
|
||||
bm_menu.close_callback()
|
||||
end
|
||||
end,
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
text = "▕◁",
|
||||
enabled = item_idx > 1,
|
||||
callback = function()
|
||||
_showBookmarkDetails(1)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = "◁",
|
||||
enabled = item_idx > 1,
|
||||
callback = function()
|
||||
_showBookmarkDetails(item_idx - 1)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = "▷",
|
||||
enabled = item_idx < items_nb,
|
||||
callback = function()
|
||||
_showBookmarkDetails(item_idx + 1)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = "▷▏",
|
||||
enabled = item_idx < items_nb,
|
||||
callback = function()
|
||||
_showBookmarkDetails(items_nb)
|
||||
end,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
textviewer = TextViewer:new{
|
||||
title = T(_("Bookmark details (%1/%2)"), item.idx, #item_table),
|
||||
title = T(_("Bookmark details (%1/%2)"), item_idx, items_nb),
|
||||
text = text,
|
||||
text_type = "bookmark",
|
||||
close_callback = function()
|
||||
_updateBookmarkList()
|
||||
end,
|
||||
buttons_table = {
|
||||
{
|
||||
{
|
||||
text = _("Reset text"),
|
||||
enabled = item.drawer and not_select_mode and item.text_edited or false,
|
||||
callback = function()
|
||||
self:setHighlightedText(item, nil, edit_details_callback)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Edit text"),
|
||||
enabled = item.drawer and not_select_mode or false,
|
||||
callback = function()
|
||||
self:editHighlightedText(item, edit_details_callback)
|
||||
end,
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
text = _("Remove bookmark"),
|
||||
enabled = not_select_mode,
|
||||
callback = function()
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("Remove this bookmark?"),
|
||||
ok_text = _("Remove"),
|
||||
ok_callback = function()
|
||||
self:removeItem(item)
|
||||
table.remove(item_table, item.idx)
|
||||
self:updateBookmarkList(item_table, -1)
|
||||
UIManager:close(textviewer)
|
||||
end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = item.note and _("Edit note") or _("Add note"),
|
||||
enabled = not bm_menu.select_count,
|
||||
callback = function()
|
||||
self:setBookmarkNote(item, nil, nil, edit_details_callback)
|
||||
end,
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
text = _("Close"),
|
||||
callback = function()
|
||||
_updateBookmarkList()
|
||||
UIManager:close(textviewer)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Go to bookmark"),
|
||||
enabled = not bm_menu.select_count,
|
||||
callback = function()
|
||||
UIManager:close(textviewer)
|
||||
self.ui.link:addCurrentLocationToStack()
|
||||
self:gotoBookmark(item.page, item.pos0)
|
||||
bm_menu.close_callback()
|
||||
end,
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
text = "▕◁",
|
||||
enabled = item.idx > 1,
|
||||
callback = function()
|
||||
_showBookmarkDetails(1)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = "◁",
|
||||
enabled = item.idx > 1,
|
||||
callback = function()
|
||||
_showBookmarkDetails(item.idx - 1)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = "▷",
|
||||
enabled = item.idx < #item_table,
|
||||
callback = function()
|
||||
_showBookmarkDetails(item.idx + 1)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = "▷▏",
|
||||
enabled = item.idx < #item_table,
|
||||
callback = function()
|
||||
_showBookmarkDetails(#item_table)
|
||||
end,
|
||||
},
|
||||
},
|
||||
}
|
||||
buttons_table = buttons_table,
|
||||
close_callback = close_callback,
|
||||
}
|
||||
UIManager:show(textviewer)
|
||||
return true
|
||||
@@ -1264,6 +1291,7 @@ function ReaderBookmark:setBookmarkNote(item_or_index, is_new_note, new_note, ca
|
||||
value = nil
|
||||
end
|
||||
annotation.note = value
|
||||
self.ui.highlight:writePdfAnnotation("content", annotation, value)
|
||||
local type_after = self.getBookmarkType(annotation)
|
||||
if type_before ~= type_after then
|
||||
if type_before == "highlight" then
|
||||
@@ -1290,12 +1318,18 @@ function ReaderBookmark:setBookmarkNote(item_or_index, is_new_note, new_note, ca
|
||||
input_dialog:onShowKeyboard()
|
||||
end
|
||||
|
||||
function ReaderBookmark:editHighlightedText(item, caller_callback)
|
||||
function ReaderBookmark:editHighlightedText(item_or_index, caller_callback)
|
||||
local item
|
||||
if self.bookmark_menu then
|
||||
item = item_or_index -- in item_table
|
||||
else -- from Highlight
|
||||
item = self.ui.annotation.annotations[item_or_index]
|
||||
end
|
||||
local input_dialog
|
||||
input_dialog = InputDialog:new{
|
||||
title = _("Edit highlighted text"),
|
||||
description = " " .. self:_getDialogHeader(item),
|
||||
input = item.text_orig,
|
||||
input = item.text_orig or item.text,
|
||||
allow_newline = true,
|
||||
add_scroll_buttons = true,
|
||||
use_available_height = true,
|
||||
@@ -1312,7 +1346,7 @@ function ReaderBookmark:editHighlightedText(item, caller_callback)
|
||||
text = _("Save"),
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
self:setHighlightedText(item, input_dialog:getInputText(), caller_callback)
|
||||
self:setHighlightedText(item_or_index, input_dialog:getInputText(), caller_callback)
|
||||
UIManager:close(input_dialog)
|
||||
end,
|
||||
},
|
||||
@@ -1323,23 +1357,32 @@ function ReaderBookmark:editHighlightedText(item, caller_callback)
|
||||
input_dialog:onShowKeyboard()
|
||||
end
|
||||
|
||||
function ReaderBookmark:setHighlightedText(item, text, caller_callback)
|
||||
function ReaderBookmark:setHighlightedText(item_or_index, text, caller_callback)
|
||||
local item, index
|
||||
if self.bookmark_menu then
|
||||
item = item_or_index -- in item_table
|
||||
index = self:getBookmarkItemIndex(item)
|
||||
else -- from Highlight
|
||||
index = item_or_index
|
||||
end
|
||||
local annotation = self.ui.annotation.annotations[index]
|
||||
local edited
|
||||
if text then
|
||||
edited = true
|
||||
else -- reset to selected text
|
||||
if self.ui.rolling then
|
||||
text = self.ui.document:getTextFromXPointers(item.pos0, item.pos1)
|
||||
text = self.ui.document:getTextFromXPointers(annotation.pos0, annotation.pos1)
|
||||
else
|
||||
text = self.ui.document:getTextFromPositions(item.pos0, item.pos1).text
|
||||
text = self.ui.document:getTextFromPositions(annotation.pos0, annotation.pos1).text
|
||||
end
|
||||
end
|
||||
local index = self:getBookmarkItemIndex(item)
|
||||
self.ui.annotation.annotations[index].text = text
|
||||
self.ui.annotation.annotations[index].text_edited = edited
|
||||
item.text_orig = text
|
||||
item.text = self:getBookmarkItemText(item)
|
||||
item.text_edited = edited
|
||||
annotation.text = text
|
||||
annotation.text_edited = edited
|
||||
if item then
|
||||
item.text_orig = text
|
||||
item.text = self:getBookmarkItemText(item)
|
||||
item.text_edited = edited
|
||||
end
|
||||
caller_callback()
|
||||
end
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local Notification = require("ui/widget/notification")
|
||||
local RadioButtonWidget = require("ui/widget/radiobuttonwidget")
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local TextViewer = require("ui/widget/textviewer")
|
||||
local Translator = require("ui/translator")
|
||||
local UIManager = require("ui/uimanager")
|
||||
@@ -36,7 +37,7 @@ local ReaderHighlight = InputContainer:extend{
|
||||
{_("Blue"), "blue"},
|
||||
{_("Purple"), "purple"},
|
||||
{_("Gray"), "gray"},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
local function inside_box(pos, box)
|
||||
@@ -58,8 +59,8 @@ function ReaderHighlight:init()
|
||||
self._current_indicator_pos = nil
|
||||
self._previous_indicator_pos = nil
|
||||
self._last_indicator_move_args = {dx = 0, dy = 0, distance = 0, time = time:now()}
|
||||
-- NOTE: Unfortunately, yellow tends to look like absolute ass on Kaleido panels...
|
||||
self._fallback_color = Screen:isColorEnabled() and "yellow" or "gray"
|
||||
self._fallback_drawer = self.view.highlight.saved_drawer -- "lighten"
|
||||
self._fallback_color = self.view.highlight.saved_color -- "yellow" or "gray"
|
||||
|
||||
self:registerKeyEvents()
|
||||
|
||||
@@ -396,7 +397,7 @@ function ReaderHighlight:addToMainMenu(menu_items)
|
||||
table.insert(menu_items.highlight_options.sub_item_table, {
|
||||
text_func = function()
|
||||
local text = v[1]
|
||||
if v[2] == G_reader_settings:readSetting("highlight_drawing_style") then
|
||||
if v[2] == (G_reader_settings:readSetting("highlight_drawing_style") or self._fallback_drawer) then
|
||||
text = text .. " ★"
|
||||
end
|
||||
return text
|
||||
@@ -417,53 +418,35 @@ function ReaderHighlight:addToMainMenu(menu_items)
|
||||
end
|
||||
table.insert(menu_items.highlight_options.sub_item_table, {
|
||||
text_func = function()
|
||||
local saved_color = self.view.highlight.saved_color or self._fallback_color
|
||||
for __, v in ipairs(self.highlight_colors) do
|
||||
local saved_color = self.view.highlight.saved_color
|
||||
local text
|
||||
for _, v in ipairs(self.highlight_colors) do
|
||||
if v[2] == saved_color then
|
||||
return T(_("Highlight color: %1"), string.lower(v[1]))
|
||||
text = v[1]:lower()
|
||||
break
|
||||
end
|
||||
end
|
||||
return T(_("Highlight color: %1"), saved_color)
|
||||
text = text or saved_color -- nonstandard color
|
||||
local default_color = G_reader_settings:readSetting("highlight_color") or self._fallback_color
|
||||
if saved_color == default_color then
|
||||
text = text .. " ★"
|
||||
end
|
||||
return T(_("Highlight color: %1"), text)
|
||||
end,
|
||||
enabled_func = function()
|
||||
return self.view.highlight.saved_drawer ~= "invert"
|
||||
end,
|
||||
callback = function(touchmenu_instance)
|
||||
local default_color = G_reader_settings:readSetting("highlight_color", self._fallback_color)
|
||||
local saved_color = self.view.highlight.saved_color or self._fallback_color
|
||||
local radio_buttons = {}
|
||||
for _, v in ipairs(self.highlight_colors) do
|
||||
table.insert(radio_buttons, {
|
||||
{
|
||||
text = v[1],
|
||||
checked = v[2] == saved_color,
|
||||
bgcolor = BlitBuffer.colorFromName(v[2]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)),
|
||||
provider = v[2],
|
||||
},
|
||||
})
|
||||
keep_menu_open = true,
|
||||
callback = function(touchmenu_instance) -- set color for new highlights in this book
|
||||
local function apply_color(color)
|
||||
self.view.highlight.saved_color = color
|
||||
touchmenu_instance:updateItems()
|
||||
end
|
||||
UIManager:show(RadioButtonWidget:new{
|
||||
title_text = _("Highlight color"),
|
||||
width_factor = 0.5,
|
||||
keep_shown_on_apply = false,
|
||||
radio_buttons = radio_buttons,
|
||||
default_provider = default_color,
|
||||
callback = function(radio)
|
||||
self.view.highlight.saved_color = radio.provider
|
||||
UIManager:setDirty(self.dialog, "ui")
|
||||
if touchmenu_instance then touchmenu_instance:updateItems() end
|
||||
end,
|
||||
-- This ensures the waveform mode will be upgraded to a Kaleido wfm on compatible devices
|
||||
colorful = true,
|
||||
dithered = true,
|
||||
})
|
||||
self:showHighlightColorDialog(apply_color)
|
||||
end,
|
||||
hold_callback = function(touchmenu_instance)
|
||||
hold_callback = function(touchmenu_instance) -- set color for new highlights in new books
|
||||
G_reader_settings:saveSetting("highlight_color", self.view.highlight.saved_color)
|
||||
UIManager:show(Notification:new{
|
||||
text = T(_("Default highlight color changed to '%1'."), self.view.highlight.saved_color),
|
||||
})
|
||||
if touchmenu_instance then touchmenu_instance:updateItems() end
|
||||
touchmenu_instance:updateItems()
|
||||
end,
|
||||
})
|
||||
table.insert(menu_items.highlight_options.sub_item_table, {
|
||||
@@ -474,8 +457,7 @@ function ReaderHighlight:addToMainMenu(menu_items)
|
||||
return self.view.highlight.saved_drawer == "lighten"
|
||||
end,
|
||||
callback = function(touchmenu_instance)
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local curr_val = G_reader_settings:readSetting("highlight_lighten_factor", 0.2)
|
||||
local curr_val = G_reader_settings:readSetting("highlight_lighten_factor")
|
||||
local spin_widget = SpinWidget:new{
|
||||
value = curr_val,
|
||||
value_min = 0,
|
||||
@@ -537,10 +519,11 @@ function ReaderHighlight:addToMainMenu(menu_items)
|
||||
end,
|
||||
})
|
||||
end,
|
||||
separator = true,
|
||||
})
|
||||
table.insert(menu_items.highlight_options.sub_item_table, {
|
||||
text = _("Apply default style to all highlights"),
|
||||
callback = function(touchmenu_instance)
|
||||
text = _("Apply current style and color to all highlights"),
|
||||
callback = function()
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("Are you sure you want to update all highlights?"),
|
||||
icon = "texture-box",
|
||||
@@ -556,11 +539,11 @@ function ReaderHighlight:addToMainMenu(menu_items)
|
||||
if count > 0 then
|
||||
UIManager:setDirty(self.dialog, "ui")
|
||||
UIManager:show(Notification:new{
|
||||
text = T(N_("Applied default style to 1 highlight",
|
||||
"Applied default style to %1 highlights", count), count),
|
||||
text = T(N_("Applied style and color to 1 highlight",
|
||||
"Applied style and color to %1 highlights", count), count),
|
||||
})
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
end,
|
||||
})
|
||||
@@ -636,7 +619,6 @@ function ReaderHighlight:addToMainMenu(menu_items)
|
||||
end,
|
||||
keep_menu_open = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local items = SpinWidget:new{
|
||||
title_text = _("Highlight very-long-press interval"),
|
||||
info_text = _("If a long-press is not released in this interval, it is considered a very-long-press. On document text, single word selection will not be triggered."),
|
||||
@@ -686,7 +668,6 @@ Except when in two columns mode, where this is limited to showing only the previ
|
||||
return T(_("Rate of movement in content selection: %1"), G_reader_settings:readSetting("highlight_non_touch_factor") or 4)
|
||||
end,
|
||||
callback = function(touchmenu_instance)
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local curr_val = G_reader_settings:readSetting("highlight_non_touch_factor") or 4
|
||||
local spin_widget = SpinWidget:new{
|
||||
value = curr_val,
|
||||
@@ -726,7 +707,6 @@ Except when in two columns mode, where this is limited to showing only the previ
|
||||
return not self.view.highlight.disabled and G_reader_settings:nilOrTrue("highlight_non_touch_spedup")
|
||||
end,
|
||||
callback = function(touchmenu_instance)
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local curr_val = G_reader_settings:readSetting("highlight_non_touch_interval") or 1
|
||||
local spin_widget = SpinWidget:new{
|
||||
value = curr_val,
|
||||
@@ -1134,13 +1114,30 @@ function ReaderHighlight:onShowHighlightDialog(index)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = item.note and _("Edit note") or _("Add note"),
|
||||
text = C_("Highlight", "Color"),
|
||||
enabled = item.drawer ~= "invert",
|
||||
callback = function()
|
||||
self:editHighlightColor(index)
|
||||
UIManager:close(self.edit_highlight_dialog)
|
||||
self.edit_highlight_dialog = nil
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Note"),
|
||||
callback = function()
|
||||
self:editHighlight(index)
|
||||
UIManager:close(self.edit_highlight_dialog)
|
||||
self.edit_highlight_dialog = nil
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Details"),
|
||||
callback = function()
|
||||
self.ui.bookmark:showBookmarkDetails(index)
|
||||
UIManager:close(self.edit_highlight_dialog)
|
||||
self.edit_highlight_dialog = nil
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = "…",
|
||||
callback = function()
|
||||
@@ -1174,7 +1171,7 @@ function ReaderHighlight:onShowHighlightDialog(index)
|
||||
hold_callback = function()
|
||||
self:updateHighlight(index, 0, -1, true)
|
||||
return true
|
||||
end
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = start_next,
|
||||
@@ -1185,7 +1182,7 @@ function ReaderHighlight:onShowHighlightDialog(index)
|
||||
hold_callback = function()
|
||||
self:updateHighlight(index, 0, 1, true)
|
||||
return true
|
||||
end
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = end_prev,
|
||||
@@ -1195,7 +1192,7 @@ function ReaderHighlight:onShowHighlightDialog(index)
|
||||
end,
|
||||
hold_callback = function()
|
||||
self:updateHighlight(index, 1, -1, true)
|
||||
end
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = end_next,
|
||||
@@ -1205,11 +1202,11 @@ function ReaderHighlight:onShowHighlightDialog(index)
|
||||
end,
|
||||
hold_callback = function()
|
||||
self:updateHighlight(index, 1, 1, true)
|
||||
end
|
||||
end,
|
||||
}
|
||||
})
|
||||
end
|
||||
self.edit_highlight_dialog = ButtonDialog:new{
|
||||
self.edit_highlight_dialog = ButtonDialog:new{ -- in self for unit tests
|
||||
buttons = buttons,
|
||||
}
|
||||
UIManager:show(self.edit_highlight_dialog)
|
||||
@@ -1934,7 +1931,7 @@ function ReaderHighlight:saveHighlight(extend_to_sentence)
|
||||
self:writePdfAnnotation("save", item)
|
||||
end
|
||||
local index = self.ui.annotation:addItem(item)
|
||||
self.view.footer:onUpdateFooter(self.view.footer_visible)
|
||||
self.view.footer:maybeUpdateFooter()
|
||||
self.ui:handleEvent(Event:new("AnnotationsModified", { item, nb_highlights_added = 1 }))
|
||||
return index
|
||||
end
|
||||
@@ -2021,14 +2018,10 @@ function ReaderHighlight:addNote(text)
|
||||
self:clear()
|
||||
end
|
||||
self:editHighlight(index, true, text)
|
||||
UIManager:close(self.edit_highlight_dialog)
|
||||
self.edit_highlight_dialog = nil
|
||||
end
|
||||
|
||||
function ReaderHighlight:editHighlight(index, is_new_note, text)
|
||||
local note_updated_callback = function()
|
||||
local item = self.ui.annotation.annotations[index]
|
||||
self:writePdfAnnotation("content", item, item.note)
|
||||
if self.view.highlight.note_mark then -- refresh note marker
|
||||
UIManager:setDirty(self.dialog, "ui")
|
||||
end
|
||||
@@ -2067,14 +2060,13 @@ function ReaderHighlight:editHighlightColor(index)
|
||||
UIManager:setDirty(self.dialog, "ui")
|
||||
self.ui:handleEvent(Event:new("AnnotationsModified", { item }))
|
||||
end
|
||||
self:showHighlightColorDialog(apply_color, item.color)
|
||||
self:showHighlightColorDialog(apply_color, item)
|
||||
end
|
||||
|
||||
function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer, index)
|
||||
function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer)
|
||||
local default_drawer, keep_shown_on_apply
|
||||
if item_drawer then -- called from ReaderHighlight:editHighlightStyle()
|
||||
default_drawer = self.view.highlight.saved_drawer or
|
||||
G_reader_settings:readSetting("highlight_drawing_style", "lighten")
|
||||
default_drawer = self.view.highlight.saved_drawer
|
||||
keep_shown_on_apply = true
|
||||
end
|
||||
local radio_buttons = {}
|
||||
@@ -2087,7 +2079,7 @@ function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer,
|
||||
},
|
||||
})
|
||||
end
|
||||
local ctor = {
|
||||
UIManager:show(RadioButtonWidget:new{
|
||||
title_text = _("Highlight style"),
|
||||
width_factor = 0.5,
|
||||
keep_shown_on_apply = keep_shown_on_apply,
|
||||
@@ -2096,38 +2088,27 @@ function ReaderHighlight:showHighlightStyleDialog(caller_callback, item_drawer,
|
||||
callback = function(radio)
|
||||
caller_callback(radio.provider)
|
||||
end,
|
||||
}
|
||||
if index then
|
||||
-- called from editHighlightStyle
|
||||
ctor.extra_text = _("Highlight color")
|
||||
ctor.extra_callback = function(this)
|
||||
local item = self.ui.annotation.annotations[index]
|
||||
if item.drawer == "invert" then
|
||||
UIManager:show(InfoMessage:new{ text = _("Colors unavailable when highlight style is set to 'Invert'") })
|
||||
else
|
||||
-- Close the style dialog before showing the color dialog
|
||||
this:onClose()
|
||||
self:editHighlightColor(index)
|
||||
end
|
||||
end
|
||||
end
|
||||
UIManager:show(RadioButtonWidget:new(ctor))
|
||||
})
|
||||
end
|
||||
|
||||
function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color)
|
||||
local default_color, keep_shown_on_apply
|
||||
if item_color then -- called from editHighlightColor
|
||||
default_color = self.view.highlight.saved_color or
|
||||
G_reader_settings:readSetting("highlight_color", self._fallback_color)
|
||||
function ReaderHighlight:showHighlightColorDialog(caller_callback, item)
|
||||
local default_color, curr_color, keep_shown_on_apply
|
||||
if item then -- called from ReaderHighlight:editHighlightColor()
|
||||
default_color = self.view.highlight.saved_color
|
||||
curr_color = item.color or default_color
|
||||
keep_shown_on_apply = true
|
||||
else
|
||||
default_color = G_reader_settings:readSetting("highlight_color") or self._fallback_color
|
||||
curr_color = self.view.highlight.saved_color
|
||||
end
|
||||
local radio_buttons = {}
|
||||
for _, v in ipairs(self.highlight_colors) do
|
||||
table.insert(radio_buttons, {
|
||||
{
|
||||
text = v[1],
|
||||
checked = item_color == v[2],
|
||||
bgcolor = BlitBuffer.colorFromName(v[2]) or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)),
|
||||
checked = curr_color == v[2],
|
||||
bgcolor = BlitBuffer.colorFromName(v[2])
|
||||
or BlitBuffer.Color8(bit.bxor(0xFF * self.view.highlight.lighten_factor, 0xFF)),
|
||||
provider = v[2],
|
||||
},
|
||||
})
|
||||
@@ -2141,6 +2122,7 @@ function ReaderHighlight:showHighlightColorDialog(caller_callback, item_color)
|
||||
callback = function(radio)
|
||||
caller_callback(radio.provider)
|
||||
end,
|
||||
-- This ensures the waveform mode will be upgraded to a Kaleido wfm on compatible devices
|
||||
colorful = true,
|
||||
dithered = true,
|
||||
})
|
||||
|
||||
@@ -95,6 +95,7 @@ function ReaderView:init()
|
||||
temp_drawer = "invert",
|
||||
temp = {},
|
||||
saved_drawer = "lighten",
|
||||
-- NOTE: Unfortunately, yellow tends to look like absolute ass on Kaleido panels...
|
||||
saved_color = Screen:isColorEnabled() and "yellow" or "gray",
|
||||
indicator = nil, -- geom: non-touch highlight position indicator: {x = 50, y=50}
|
||||
}
|
||||
@@ -547,7 +548,7 @@ function ReaderView:drawPageSavedHighlight(bb, x, y)
|
||||
local boxes = self.document:getPageBoxesFromPositions(page, item.pos0, item.pos1)
|
||||
if boxes then
|
||||
local color = item.color and Blitbuffer.colorFromName(item.color)
|
||||
if color and not Blitbuffer.isColor8(color) then
|
||||
if not colorful and color and not Blitbuffer.isColor8(color) then
|
||||
colorful = true
|
||||
end
|
||||
local draw_note_mark = item.note and self.highlight.note_mark
|
||||
@@ -593,7 +594,7 @@ function ReaderView:drawXPointerSavedHighlight(bb, x, y)
|
||||
local boxes = self.document:getScreenBoxesFromPositions(item.pos0, item.pos1, true) -- get_segments=true
|
||||
if boxes then
|
||||
local color = item.color and Blitbuffer.colorFromName(item.color)
|
||||
if color and not Blitbuffer.isColor8(color) then
|
||||
if not colorful and color and not Blitbuffer.isColor8(color) then
|
||||
colorful = true
|
||||
end
|
||||
local draw_note_mark = item.note and self.highlight.note_mark
|
||||
|
||||
Reference in New Issue
Block a user