From f637555d93a16d77b78140f3c18a16a2bcdb6d13 Mon Sep 17 00:00:00 2001 From: Galunid Date: Thu, 14 Mar 2019 15:33:04 +0100 Subject: [PATCH] [UX] Gesture manager: add action - cycle default highlight action (#4791) Cf. https://github.com/koreader/koreader/issues/4727 --- .../apps/reader/modules/readergesture.lua | 6 +++-- .../apps/reader/modules/readerhighlight.lua | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/frontend/apps/reader/modules/readergesture.lua b/frontend/apps/reader/modules/readergesture.lua index bef028797..85300c705 100644 --- a/frontend/apps/reader/modules/readergesture.lua +++ b/frontend/apps/reader/modules/readergesture.lua @@ -76,7 +76,7 @@ local action_strings = { folder_up = _("Folder up"), folder_shortcuts = _("Folder shortcuts"), - + toggle_highlight_action = _("Toggle highlight action"), wallabag_download = _("Wallabag retrieval"), } @@ -358,7 +358,7 @@ function ReaderGesture:buildMenu(ges, default) {"zoom_column", not self.is_docless}, {"zoom_content", not self.is_docless}, {"zoom_page", not self.is_docless, true}, - + {"toggle_highlight_action", not self.is_docless}, {"wallabag_download", self.ui.wallabag ~= nil}, } local return_menu = {} @@ -796,6 +796,8 @@ function ReaderGesture:gestureAction(action, ges) self.ui:handleEvent(Event:new("SetZoomMode", "page")) elseif action == "wallabag_download" then self.ui:handleEvent(Event:new("SynchronizeWallabag")) + elseif action == "toggle_highlight_action" then + self.ui:handleEvent(Event:new("CycleHighlightAction")) end return true end diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 487319f3d..0e14a6973 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -3,6 +3,7 @@ local ConfirmBox = require("ui/widget/confirmbox") local Device = require("device") local Event = require("ui/event") local InfoMessage = require("ui/widget/infomessage") +local Notification = require("ui/widget/notification") local InputContainer = require("ui/widget/container/inputcontainer") local TimeVal = require("ui/timeval") local Translator = require("ui/translator") @@ -843,6 +844,29 @@ function ReaderHighlight:onHoldRelease() return true end +function ReaderHighlight:onCycleHighlightAction() + local next_actions = { + highlight = "translate", + translate = "wikipedia", + wikipedia = nil + } + local current_action = G_reader_settings:readSetting("default_highlight_action") + if not current_action then + G_reader_settings:saveSetting("default_highlight_action", "highlight") + UIManager:show(Notification:new{ + text = _("Default highlight action changed to 'highlight'."), + timeout = 1, + }) + else + 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")), + timeout = 1, + }) + end +end + function ReaderHighlight:highlightFromHoldPos() if self.hold_pos then if not self.selected_text then