Readerhighlight: manage actions (#8199)

Discussion in #6409.

Highlight action renamed to Long-press on text and moved from Gear - Document to Gear - Taps and gestures.

Added action Do nothing.
Removed menu item Typeset - Highlighting - Allow highlighting.

Fixed untranslated strings in the Cycle highlight action notification.

Long-press on images always opens ImageViewer. Closes #6409.
pull/8207/head
hius07 3 years ago committed by GitHub
parent 9e55e4da3d
commit f6020a7260
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,7 +4,6 @@ local Device = require("device")
local Event = require("ui/event") local Event = require("ui/event")
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
local Notification = require("ui/widget/notification") local Notification = require("ui/widget/notification")
local TimeVal = require("ui/timeval") local TimeVal = require("ui/timeval")
local Translator = require("ui/translator") local Translator = require("ui/translator")
@ -260,10 +259,20 @@ function ReaderHighlight:onReaderReady()
self:setupTouchZones() self:setupTouchZones()
end end
local long_press_action = {
{_("Ask with popup dialog"), "ask"},
{_("Do nothing"), "nothing"},
{_("Highlight"), "highlight"},
{_("Translate"), "translate"},
{_("Wikipedia"), "wikipedia"},
{_("Dictionary"), "dictionary"},
{_("Fulltext search"), "search"},
}
function ReaderHighlight:addToMainMenu(menu_items) function ReaderHighlight:addToMainMenu(menu_items)
-- insert table to main reader menu -- insert table to main reader menu
menu_items.highlight_options = { menu_items.highlight_options = {
text = _("Highlighting"), text = _("Highlight style"),
sub_item_table = self:genHighlightDrawerMenu(), sub_item_table = self:genHighlightDrawerMenu(),
} }
if self.document.info.has_pages then if self.document.info.has_pages then
@ -273,6 +282,36 @@ function ReaderHighlight:addToMainMenu(menu_items)
} }
end end
menu_items.translation_settings = Translator:genSettingsMenu() menu_items.translation_settings = Translator:genSettingsMenu()
menu_items.long_press = {
text = _("Long-press on text"),
sub_item_table = {
{
text = _("Dictionary on single word selection"),
checked_func = function()
return not self.view.highlight.disabled and G_reader_settings:nilOrFalse("highlight_action_on_single_word")
end,
enabled_func = function()
return not self.view.highlight.disabled
end,
callback = function()
G_reader_settings:flipNilOrFalse("highlight_action_on_single_word")
end,
separator = true,
},
},
}
for _, v in ipairs(long_press_action) do
table.insert(menu_items.long_press.sub_item_table, {
text = v[1],
checked_func = function()
return G_reader_settings:readSetting("default_highlight_action", "ask") == v[2]
end,
callback = function()
G_reader_settings:saveSetting("default_highlight_action", v[2])
self.view.highlight.disabled = v[2] == "nothing"
end,
})
end
end end
local highlight_style = { local highlight_style = {
@ -328,9 +367,6 @@ function ReaderHighlight:genHighlightDrawerMenu()
checked_func = function() checked_func = function()
return self.view.highlight.saved_drawer == style return self.view.highlight.saved_drawer == style
end, end,
enabled_func = function()
return not self.view.highlight.disabled
end,
callback = function() callback = function()
self.view.highlight.saved_drawer = style self.view.highlight.saved_drawer = style
end, end,
@ -341,19 +377,6 @@ function ReaderHighlight:genHighlightDrawerMenu()
} }
end end
return { return {
{
text = _("Allow highlighting"),
checked_func = function()
return not self.view.highlight.disabled
end,
callback = function()
self.view.highlight.disabled = not self.view.highlight.disabled
end,
hold_callback = function()
self:toggleDefault()
end,
separator = true,
},
get_highlight_style("lighten"), get_highlight_style("lighten"),
get_highlight_style("underscore"), get_highlight_style("underscore"),
get_highlight_style("invert"), get_highlight_style("invert"),
@ -362,13 +385,12 @@ function ReaderHighlight:genHighlightDrawerMenu()
return T(_("Highlight opacity: %1"), G_reader_settings:readSetting("highlight_lighten_factor", 0.2)) return T(_("Highlight opacity: %1"), G_reader_settings:readSetting("highlight_lighten_factor", 0.2))
end, end,
enabled_func = function() enabled_func = function()
return not self.view.highlight.disabled and self.view.highlight.saved_drawer == "lighten" return self.view.highlight.saved_drawer == "lighten"
end, end,
callback = function() callback = function()
local SpinWidget = require("ui/widget/spinwidget") 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", 0.2)
local items = SpinWidget:new{ local items = SpinWidget:new{
width = math.floor(Screen:getWidth() * 0.6),
value = curr_val, value = curr_val,
value_min = 0, value_min = 0,
value_max = 1, value_max = 1,
@ -784,8 +806,6 @@ function ReaderHighlight:onHold(arg, ges)
end end
end end
-- disable hold gesture if highlighting is disabled
if self.view.highlight.disabled then return false end
self:clear() -- clear previous highlight (delayed clear may not have done it yet) self:clear() -- clear previous highlight (delayed clear may not have done it yet)
self.hold_ges_pos = ges.pos -- remember hold original gesture position self.hold_ges_pos = ges.pos -- remember hold original gesture position
self.hold_pos = self.view:screenToPageTransform(ges.pos) self.hold_pos = self.view:screenToPageTransform(ges.pos)
@ -814,6 +834,7 @@ function ReaderHighlight:onHold(arg, ges)
end end
-- otherwise, we must be holding on text -- otherwise, we must be holding on text
if self.view.highlight.disabled then return false end -- Long-press action "Do nothing" checked
local ok, word = pcall(self.ui.document.getWordFromPosition, self.ui.document, self.hold_pos) local ok, word = pcall(self.ui.document.getWordFromPosition, self.ui.document, self.hold_pos)
if ok and word then if ok and word then
logger.dbg("selected word:", word) logger.dbg("selected word:", word)
@ -1209,8 +1230,8 @@ function ReaderHighlight:onHoldRelease()
end end
if self.selected_text then if self.selected_text then
local default_highlight_action = G_reader_settings:readSetting("default_highlight_action") local default_highlight_action = G_reader_settings:readSetting("default_highlight_action", "ask")
if long_final_hold or not default_highlight_action then if long_final_hold or default_highlight_action == "ask" then
-- bypass default action and show popup if long final hold -- bypass default action and show popup if long final hold
self:onShowHighlightMenu() self:onShowHighlightMenu()
elseif default_highlight_action == "highlight" then elseif default_highlight_action == "highlight" then
@ -1238,26 +1259,21 @@ function ReaderHighlight:onHoldRelease()
end end
function ReaderHighlight:onCycleHighlightAction() function ReaderHighlight:onCycleHighlightAction()
local next_actions = { local current_action = G_reader_settings:readSetting("default_highlight_action", "ask")
highlight = "translate", local next_action_num
translate = "wikipedia", for i, v in ipairs(long_press_action) do
wikipedia = "dictionary", if v[2] == current_action then
dictionary = "search", next_action_num = i + 1
search = nil, break
} end
if G_reader_settings:hasNot("default_highlight_action") then end
G_reader_settings:saveSetting("default_highlight_action", "highlight") if next_action_num > #long_press_action then
UIManager:show(Notification:new{ next_action_num = 1
text = _("Default highlight action changed to 'highlight'."),
})
else
local current_action = G_reader_settings:readSetting("default_highlight_action")
local next_action = next_actions[current_action]
G_reader_settings:saveSetting("default_highlight_action", next_action)
UIManager:show(Notification:new{
text = T(_("Default highlight action changed to '%1'."), (next_action or "default")),
})
end end
G_reader_settings:saveSetting("default_highlight_action", long_press_action[next_action_num][2])
UIManager:show(Notification:new{
text = T(_("Default highlight action changed to '%1'."), long_press_action[next_action_num][1]),
})
return true return true
end end
@ -1533,11 +1549,8 @@ end
function ReaderHighlight:onReadSettings(config) function ReaderHighlight:onReadSettings(config)
self.view.highlight.saved_drawer = config:readSetting("highlight_drawer") self.view.highlight.saved_drawer = config:readSetting("highlight_drawer")
or G_reader_settings:readSetting("highlight_drawing_style") or self.view.highlight.saved_drawer or G_reader_settings:readSetting("highlight_drawing_style") or self.view.highlight.saved_drawer
if config:has("highlight_disabled") then self.view.highlight.disabled = G_reader_settings:has("default_highlight_action")
self.view.highlight.disabled = config:isTrue("highlight_disabled") and G_reader_settings:readSetting("default_highlight_action") == "nothing"
else
self.view.highlight.disabled = G_reader_settings:isTrue("highlight_disabled")
end
-- panel zoom settings isn't supported in EPUB -- panel zoom settings isn't supported in EPUB
if self.document.info.has_pages then if self.document.info.has_pages then
@ -1563,7 +1576,6 @@ end
function ReaderHighlight:onSaveSettings() function ReaderHighlight:onSaveSettings()
self.ui.doc_settings:saveSetting("highlight_drawer", self.view.highlight.saved_drawer) self.ui.doc_settings:saveSetting("highlight_drawer", self.view.highlight.saved_drawer)
self.ui.doc_settings:saveSetting("highlight_disabled", self.view.highlight.disabled)
self.ui.doc_settings:saveSetting("panel_zoom_enabled", self.panel_zoom_enabled) self.ui.doc_settings:saveSetting("panel_zoom_enabled", self.panel_zoom_enabled)
end end
@ -1574,24 +1586,4 @@ function ReaderHighlight:onClose()
self:clear() self:clear()
end end
function ReaderHighlight:toggleDefault()
local highlight_disabled = G_reader_settings:isTrue("highlight_disabled")
UIManager:show(MultiConfirmBox:new{
text = highlight_disabled and _("Would you like to enable or disable highlighting by default?\n\nThe current default (★) is disabled.")
or _("Would you like to enable or disable highlighting by default?\n\nThe current default (★) is enabled."),
choice1_text_func = function()
return highlight_disabled and _("Disable (★)") or _("Disable")
end,
choice1_callback = function()
G_reader_settings:makeTrue("highlight_disabled")
end,
choice2_text_func = function()
return highlight_disabled and _("Enable") or _("Enable (★)")
end,
choice2_callback = function()
G_reader_settings:makeFalse("highlight_disabled")
end,
})
end
return ReaderHighlight return ReaderHighlight

@ -87,7 +87,8 @@ common_settings.time = {
{ {
text_func = function () text_func = function ()
local duration_format = G_reader_settings:readSetting("duration_format", "classic") local duration_format = G_reader_settings:readSetting("duration_format", "classic")
return T(_("Duration format (%1)"), duration_format) local text = duration_format == "classic" and _("Classic") or _("Modern")
return T(_("Duration format: %1"), text)
end, end,
sub_item_table = { sub_item_table = {
{ {
@ -588,7 +589,7 @@ common_settings.document = {
separator = true, separator = true,
}, },
{ {
text = _("Ask with pop-up dialog"), text = _("Ask with popup dialog"),
checked_func = function() checked_func = function()
local setting = G_reader_settings:readSetting("end_document_action") local setting = G_reader_settings:readSetting("end_document_action")
return setting == "pop-up" or setting == nil return setting == "pop-up" or setting == nil
@ -674,75 +675,6 @@ common_settings.document = {
}, },
} }
}, },
{
text = _("Highlight action"),
sub_item_table = {
{
text = _("Enable on single word selection"),
checked_func = function()
return G_reader_settings:isTrue("highlight_action_on_single_word")
end,
callback = function()
G_reader_settings:flipNilOrFalse("highlight_action_on_single_word")
end,
separator = true,
},
{
text = _("Ask with popup dialog"),
checked_func = function()
return G_reader_settings:nilOrFalse("default_highlight_action")
end,
callback = function()
G_reader_settings:saveSetting("default_highlight_action", nil)
end,
},
{
text = _("Highlight"),
checked_func = function()
return G_reader_settings:readSetting("default_highlight_action") == "highlight"
end,
callback = function()
G_reader_settings:saveSetting("default_highlight_action", "highlight")
end,
},
{
text = _("Translate"),
checked_func = function()
return G_reader_settings:readSetting("default_highlight_action") == "translate"
end,
callback = function()
G_reader_settings:saveSetting("default_highlight_action", "translate")
end,
},
{
text = _("Wikipedia"),
checked_func = function()
return G_reader_settings:readSetting("default_highlight_action") == "wikipedia"
end,
callback = function()
G_reader_settings:saveSetting("default_highlight_action", "wikipedia")
end,
},
{
text = _("Dictionary"),
checked_func = function()
return G_reader_settings:readSetting("default_highlight_action") == "dictionary"
end,
callback = function()
G_reader_settings:saveSetting("default_highlight_action", "dictionary")
end,
},
{
text = _("Fulltext search"),
checked_func = function()
return G_reader_settings:readSetting("default_highlight_action") == "search"
end,
callback = function()
G_reader_settings:saveSetting("default_highlight_action", "search")
end,
},
}
},
}, },
} }
common_settings.language = Language:getLangMenuTable() common_settings.language = Language:getLangMenuTable()

@ -59,7 +59,6 @@ local order = {
"android_haptic_feedback", "android_haptic_feedback",
"android_back_button", "android_back_button",
"----------------------------", "----------------------------",
"invert_page_turn_buttons",
"opening_page_location_stack", "opening_page_location_stack",
}, },
network = { network = {
@ -92,9 +91,10 @@ local order = {
"gesture_manager", "gesture_manager",
"gesture_intervals", "gesture_intervals",
"----------------------------", "----------------------------",
"menu_activate",
"ignore_hold_corners", "ignore_hold_corners",
"screen_disable_double_tab", "screen_disable_double_tab",
"----------------------------",
"menu_activate",
}, },
tools = { tools = {
"calibre", "calibre",

@ -53,7 +53,8 @@ local order = {
"speed_reading_module_perception_expander", "speed_reading_module_perception_expander",
"----------------------------", "----------------------------",
"highlight_options", "highlight_options",
"panel_zoom_options" "panel_zoom_options",
"djvu_render_mode",
}, },
setting = { setting = {
-- common settings -- common settings
@ -71,7 +72,6 @@ local order = {
"language", "language",
"device", "device",
"----------------------------", "----------------------------",
"djvu_render_mode",
"status_bar", "status_bar",
}, },
device = { device = {
@ -98,8 +98,6 @@ local order = {
"android_haptic_feedback", "android_haptic_feedback",
"android_back_button", "android_back_button",
"----------------------------", "----------------------------",
"invert_page_turn_gestures",
"invert_page_turn_buttons",
"opening_page_location_stack", "opening_page_location_stack",
}, },
network = { network = {
@ -133,13 +131,15 @@ local order = {
"gesture_manager", "gesture_manager",
"gesture_intervals", "gesture_intervals",
"----------------------------", "----------------------------",
"ignore_hold_corners",
"screen_disable_double_tab",
"----------------------------",
"follow_links", "follow_links",
"----------------------------", "----------------------------",
"menu_activate", "menu_activate",
"page_turns", "page_turns",
"scrolling", "scrolling",
"ignore_hold_corners", "long_press",
"screen_disable_double_tab",
}, },
tools = { tools = {
"read_timer", "read_timer",

Loading…
Cancel
Save