From 9b6b91b743ccad589ac8c19dd853f934d9c973d4 Mon Sep 17 00:00:00 2001 From: poire-z Date: Fri, 25 May 2018 20:56:37 +0200 Subject: [PATCH] TouchMenu: added hook to show help text on long-press (#3980) When Hold and there is no hold callback attached to a menu item, a help_text attribute, when present, is shown in an InfoMessage. --- frontend/apps/reader/modules/readerlink.lua | 7 +++++++ frontend/ui/widget/touchmenu.lua | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readerlink.lua b/frontend/apps/reader/modules/readerlink.lua index 682e0d8d5..907146fbe 100644 --- a/frontend/apps/reader/modules/readerlink.lua +++ b/frontend/apps/reader/modules/readerlink.lua @@ -95,6 +95,7 @@ function ReaderLink:addToMainMenu(menu_items) not isTapToFollowLinksOn()) end, separator = true, + help_text = _([[Tap on links to follow them.]]), }, { @@ -104,6 +105,7 @@ function ReaderLink:addToMainMenu(menu_items) G_reader_settings:saveSetting("swipe_to_go_back", not isSwipeToGoBackEnabled()) end, + help_text = _([[Swipe to the right to go back to the previous location after you have followed a link. When the location stack is empty, swiping to the right takes you to the previous page.]]), }, { text = _("Swipe to follow first link on page"), @@ -115,6 +117,7 @@ function ReaderLink:addToMainMenu(menu_items) G_reader_settings:delSetting("swipe_to_follow_nearest_link") -- can't have both end end, + help_text = _([[Swipe to the left to follow the first link in the current page.]]), }, { text = _("Swipe to follow nearest link"), @@ -126,6 +129,7 @@ function ReaderLink:addToMainMenu(menu_items) G_reader_settings:delSetting("swipe_to_follow_first_link") -- can't have both end end, + help_text = _([[Swipe to the left to follow the link nearest to where you started the swipe. This is useful when a small font is used and tapping on small links is tedious.]]), separator = true, }, { @@ -135,6 +139,9 @@ function ReaderLink:addToMainMenu(menu_items) G_reader_settings:saveSetting("swipe_to_jump_to_latest_bookmark", not isSwipeToJumpToLatestBookmarkEnabled()) end, + help_text = _([[Swipe to the left to go the most recently bookmarked page. +This can be useful to quickly swipe back and forth between what you are reading and some reference page (for example notes, a map or a characters list). +If any of the other Swipe to follow link options is enabled, this will work only when the current page contains no link.]]), }, } } diff --git a/frontend/ui/widget/touchmenu.lua b/frontend/ui/widget/touchmenu.lua index 07f9aea15..2b090d402 100644 --- a/frontend/ui/widget/touchmenu.lua +++ b/frontend/ui/widget/touchmenu.lua @@ -15,6 +15,7 @@ local GestureRange = require("ui/gesturerange") local HorizontalGroup = require("ui/widget/horizontalgroup") local HorizontalSpan = require("ui/widget/horizontalspan") local IconButton = require("ui/widget/iconbutton") +local InfoMessage = require("ui/widget/infomessage") local InputContainer = require("ui/widget/container/inputcontainer") local LeftContainer = require("ui/widget/container/leftcontainer") local LineWidget = require("ui/widget/linewidget") @@ -719,7 +720,7 @@ function TouchMenu:onMenuHold(item) else self:onInput(item.hold_input_func()) end - else + elseif item.hold_callback or type(item.hold_callback_func) == "function" then local callback = item.hold_callback if item.hold_callback_func then callback = item.hold_callback_func() @@ -734,6 +735,14 @@ function TouchMenu:onMenuHold(item) end end) end + elseif item.help_text or type(item.help_text_func) == "function" then + local help_text = item.help_text + if item.help_text_func then + help_text = item.help_text_func() + end + if help_text then + UIManager:show(InfoMessage:new{ text = help_text, }) + end end return true end