mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
ReaderHighlight: add abort select mode (#9786)
This commit is contained in:
@@ -10,14 +10,21 @@ local ReaderFlipping = WidgetContainer:extend{
|
||||
|
||||
function ReaderFlipping:init()
|
||||
local icon_size = Screen:scaleBySize(32)
|
||||
local widget = IconWidget:new{
|
||||
self.flipping_widget = IconWidget:new{
|
||||
icon = "book.opened",
|
||||
width = icon_size,
|
||||
height = icon_size,
|
||||
}
|
||||
-- Re-use this widget to show an indicator when we are in select mode
|
||||
self.select_mode_widget = IconWidget:new{
|
||||
icon = "format-quote-close",
|
||||
width = icon_size,
|
||||
height = icon_size,
|
||||
alpha = true,
|
||||
}
|
||||
self[1] = LeftContainer:new{
|
||||
dimen = Geom:new{w = Screen:getWidth(), h = widget:getSize().h},
|
||||
widget,
|
||||
dimen = Geom:new{w = Screen:getWidth(), h = self.flipping_widget:getSize().h},
|
||||
self.flipping_widget,
|
||||
}
|
||||
self:resetLayout()
|
||||
end
|
||||
@@ -30,4 +37,17 @@ function ReaderFlipping:resetLayout()
|
||||
self[1].dimen.w = new_screen_width
|
||||
end
|
||||
|
||||
function ReaderFlipping:paintTo(bb, x, y)
|
||||
if self.ui.highlight.select_mode then
|
||||
if self[1][1] ~= self.select_mode_widget then
|
||||
self[1][1] = self.select_mode_widget
|
||||
end
|
||||
else
|
||||
if self[1][1] ~= self.flipping_widget then
|
||||
self[1][1] = self.flipping_widget
|
||||
end
|
||||
end
|
||||
WidgetContainer.paintTo(self, bb, x, y)
|
||||
end
|
||||
|
||||
return ReaderFlipping
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
local BD = require("ui/bidi")
|
||||
local ButtonDialog = require("ui/widget/buttondialog")
|
||||
local ConfirmBox = require("ui/widget/confirmbox")
|
||||
local Device = require("device")
|
||||
local Event = require("ui/event")
|
||||
local Geom = require("ui/geometry")
|
||||
@@ -249,7 +250,25 @@ function ReaderHighlight:setupTouchZones()
|
||||
if not hold_pan_rate then
|
||||
hold_pan_rate = Screen.low_pan_rate and 5.0 or 30.0
|
||||
end
|
||||
local DTAP_ZONE_TOP_LEFT = G_defaults:readSetting("DTAP_ZONE_TOP_LEFT")
|
||||
self.ui:registerTouchZones({
|
||||
{
|
||||
id = "readerhighlight_tap_select_mode",
|
||||
ges = "tap",
|
||||
screen_zone = {
|
||||
ratio_x = DTAP_ZONE_TOP_LEFT.x, ratio_y = DTAP_ZONE_TOP_LEFT.y,
|
||||
ratio_w = DTAP_ZONE_TOP_LEFT.w, ratio_h = DTAP_ZONE_TOP_LEFT.h,
|
||||
},
|
||||
overrides = {
|
||||
"readerhighlight_tap",
|
||||
"tap_top_left_corner",
|
||||
"readermenu_ext_tap",
|
||||
"readermenu_tap",
|
||||
"tap_forward",
|
||||
"tap_backward",
|
||||
},
|
||||
handler = function(ges) return self:onTapSelectModeIcon() end
|
||||
},
|
||||
{
|
||||
id = "readerhighlight_tap",
|
||||
ges = "tap",
|
||||
@@ -452,37 +471,6 @@ function ReaderHighlight:addToMainMenu(menu_items)
|
||||
menu_items.long_press = {
|
||||
text = _("Long-press on text"),
|
||||
sub_item_table = {
|
||||
{
|
||||
text_func = function()
|
||||
return T(_("Highlight long-press interval: %1 s"),
|
||||
G_reader_settings:readSetting("highlight_long_hold_threshold_s", 3))
|
||||
end,
|
||||
keep_menu_open = true,
|
||||
callback = function(touchmenu_instance)
|
||||
local SpinWidget = require("ui/widget/spinwidget")
|
||||
local items = SpinWidget:new{
|
||||
title_text = _("Highlight long-press interval"),
|
||||
info_text = _([[
|
||||
If a touch is not released in this interval, it is considered a long-press. On document text, single word selection will not be triggered.
|
||||
|
||||
The interval value is in seconds and can range from 3 to 20 seconds.]]),
|
||||
width = math.floor(Screen:getWidth() * 0.75),
|
||||
value = G_reader_settings:readSetting("highlight_long_hold_threshold_s", 3),
|
||||
value_min = 3,
|
||||
value_max = 20,
|
||||
value_step = 1,
|
||||
value_hold_step = 5,
|
||||
unit = C_("Time", "s"),
|
||||
ok_text = _("Set interval"),
|
||||
default_value = 3,
|
||||
callback = function(spin)
|
||||
G_reader_settings:saveSetting("highlight_long_hold_threshold_s", spin.value)
|
||||
if touchmenu_instance then touchmenu_instance:updateItems() end
|
||||
end
|
||||
}
|
||||
UIManager:show(items)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Dictionary on single word selection"),
|
||||
checked_func = function()
|
||||
@@ -510,6 +498,35 @@ The interval value is in seconds and can range from 3 to 20 seconds.]]),
|
||||
end,
|
||||
})
|
||||
end
|
||||
table.insert(menu_items.long_press.sub_item_table, {
|
||||
text_func = function()
|
||||
return T(_("Highlight very-long-press interval: %1 s"),
|
||||
G_reader_settings:readSetting("highlight_long_hold_threshold_s", 3))
|
||||
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."),
|
||||
width = math.floor(Screen:getWidth() * 0.75),
|
||||
value = G_reader_settings:readSetting("highlight_long_hold_threshold_s", 3),
|
||||
value_min = 2.5,
|
||||
value_max = 20,
|
||||
value_step = 0.1,
|
||||
value_hold_step = 0.5,
|
||||
unit = C_("Time", "s"),
|
||||
precision = "%0.1f",
|
||||
ok_text = _("Set interval"),
|
||||
default_value = 3,
|
||||
callback = function(spin)
|
||||
G_reader_settings:saveSetting("highlight_long_hold_threshold_s", spin.value)
|
||||
if touchmenu_instance then touchmenu_instance:updateItems() end
|
||||
end
|
||||
}
|
||||
UIManager:show(items)
|
||||
end,
|
||||
})
|
||||
-- long_press menu is under taps_and_gestures menu which is not available for non touch device
|
||||
-- Clone long_press menu and change label making much meaning for non touch devices
|
||||
if not Device:isTouchDevice() and Device:hasDPad() then
|
||||
@@ -597,6 +614,20 @@ function ReaderHighlight:onClearHighlight()
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderHighlight:onTapSelectModeIcon()
|
||||
if not self.select_mode then return end
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = _("You are currently in SELECT mode.\nTo finish highlighting, long press where the highlight should end and press the HIGHLIGHT button.\nYou can also exit select mode by tapping on the start of the highlight."),
|
||||
ok_text = _("Exit select mode"),
|
||||
cancel_text = _("Close"),
|
||||
ok_callback = function()
|
||||
self.select_mode = false
|
||||
self:deleteHighlight(self.highlight_page, self.highlight_idx)
|
||||
end
|
||||
})
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderHighlight:onTap(_, ges)
|
||||
-- We only actually need to clear if we have something to clear in the first place.
|
||||
-- (We mainly want to avoid CRe's clearSelection,
|
||||
@@ -604,7 +635,7 @@ function ReaderHighlight:onTap(_, ges)
|
||||
-- ReaderHighlight:clear can only return true if self.hold_pos was set anyway.
|
||||
local cleared = self.hold_pos and self:clear()
|
||||
-- We only care about potential taps on existing highlights, not on taps that closed a highlight menu.
|
||||
if not cleared and ges and not self.select_mode then
|
||||
if not cleared and ges then
|
||||
if self.ui.document.info.has_pages then
|
||||
return self:onTapPageSavedHighlight(ges)
|
||||
else
|
||||
@@ -776,6 +807,13 @@ function ReaderHighlight:updateHighlight(page, index, side, direction, move_by_c
|
||||
end
|
||||
|
||||
function ReaderHighlight:onShowHighlightNoteOrDialog(page, index)
|
||||
if self.select_mode then
|
||||
if page ~= self.highlight_page or index ~= self.highlight_idx then return end
|
||||
-- tap on the first fragment: abort select mode, clear highlight
|
||||
self.select_mode = false
|
||||
self:deleteHighlight(page, index)
|
||||
return true
|
||||
end
|
||||
local item = self.view.highlight.saved[page][index]
|
||||
local bookmark_note = self.ui.bookmark:getBookmarkNote({
|
||||
page = self.ui.document.info.has_pages and item.pos0.page or item.pos0,
|
||||
@@ -1870,9 +1908,6 @@ end
|
||||
function ReaderHighlight:startSelection()
|
||||
self.highlight_page, self.highlight_idx = self:saveHighlight()
|
||||
self.select_mode = true
|
||||
UIManager:show(Notification:new{
|
||||
text = _("Select ending fragment"),
|
||||
})
|
||||
end
|
||||
|
||||
function ReaderHighlight:extendSelection()
|
||||
|
||||
@@ -225,8 +225,8 @@ function ReaderView:paintTo(bb, x, y)
|
||||
if self.footer_visible then
|
||||
self.footer:paintTo(bb, x, y)
|
||||
end
|
||||
-- paint flipping
|
||||
if self.flipping_visible then
|
||||
-- paint flipping or select mode sign
|
||||
if self.flipping_visible or self.ui.highlight.select_mode then
|
||||
self.flipping:paintTo(bb, x, y)
|
||||
end
|
||||
for _, m in pairs(self.view_modules) do
|
||||
|
||||
5
resources/icons/mdlight/format-quote-close.svg
Normal file
5
resources/icons/mdlight/format-quote-close.svg
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full" width="24" height="24" viewBox="2 4 26.00 28.00" enable-background="new 0 0 24.00 24.00" xml:space="preserve">
|
||||
<path fill="#000000" fill-opacity="1" stroke-width="0.2" stroke-linejoin="round" d="M 18,6L 18,14L 16.0491,18L 11.8487,18L 13.7996,14L 12,14L 12,6L 18,6 Z M 17,13.7691L 17,7.00001L 13,7.00001L 13,13L 15.3999,13L 13.449,17L 15.4242,17L 17,13.7691 Z M 11,6L 11,14L 9.04907,18L 4.84866,18L 6.79959,14L 5,14L 5,6L 11,6 Z M 10,13.7691L 9.99999,7.00001L 5.99999,7.00001L 5.99999,13L 8.39992,13L 6.449,17L 8.4242,17L 10,13.7691 Z "/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 805 B |
Reference in New Issue
Block a user