[UX] Gesture manager: add action - clear location history (#4716)

Also show notification when previous_location can't go
back because the location stack is empty.
pull/4718/head
poire-z 5 years ago committed by Frans de Jonge
parent 5b30ea1920
commit 93422d05f4

@ -31,6 +31,7 @@ local action_strings = {
previous_location = _("Back to previous location"), previous_location = _("Back to previous location"),
latest_bookmark = _("Go to latest bookmark"), latest_bookmark = _("Go to latest bookmark"),
follow_nearest_link = _("Follow nearest link"), follow_nearest_link = _("Follow nearest link"),
clear_location_history = _("Clear location history"),
toc = _("Table of contents"), toc = _("Table of contents"),
bookmarks = _("Bookmarks"), bookmarks = _("Bookmarks"),
@ -269,7 +270,8 @@ function ReaderGesture:buildMenu(ges, default)
{"back", true}, {"back", true},
{"previous_location", not self.is_docless}, {"previous_location", not self.is_docless},
{"latest_bookmark", not self.is_docless}, {"latest_bookmark", not self.is_docless},
{"follow_nearest_link", not self.is_docless, true}, {"follow_nearest_link", not self.is_docless},
{"clear_location_history", not self.is_docless, true},
{"folder_up", self.is_docless, true}, {"folder_up", self.is_docless, true},
@ -547,11 +549,13 @@ function ReaderGesture:gestureAction(action, ges)
elseif action == "back" then elseif action == "back" then
self.ui:handleEvent(Event:new("Back")) self.ui:handleEvent(Event:new("Back"))
elseif action == "previous_location" then elseif action == "previous_location" then
self.ui:handleEvent(Event:new("GoBackLink")) self.ui:handleEvent(Event:new("GoBackLink", true)) -- show_notification_if_empty
elseif action == "latest_bookmark" then elseif action == "latest_bookmark" then
self.ui.link:onGoToLatestBookmark() self.ui:handleEvent(Event:new("GoToLatestBookmark"))
elseif action == "follow_nearest_link" then elseif action == "follow_nearest_link" then
self.ui:handleEvent(Event:new("GoToPageLink", ges, false, G_reader_settings:isTrue("footnote_link_in_popup"))) self.ui:handleEvent(Event:new("GoToPageLink", ges, false, G_reader_settings:isTrue("footnote_link_in_popup")))
elseif action == "clear_location_history" then
self.ui:handleEvent(Event:new("ClearLocationStack", true)) -- show_notification
elseif action == "filemanager" then elseif action == "filemanager" then
self.ui:onClose() self.ui:onClose()
self.ui:showFileManager() self.ui:showFileManager()

@ -278,7 +278,7 @@ This allows you to specify how much smaller or larger it should be relative to t
text = _("Clear location history?"), text = _("Clear location history?"),
ok_text = _("Clear"), ok_text = _("Clear"),
ok_callback = function() ok_callback = function()
self.location_stack = {} self:onClearLocationStack()
touchmenu_instance:closeMenu() touchmenu_instance:closeMenu()
end, end,
}) })
@ -440,6 +440,17 @@ function ReaderLink:addCurrentLocationToStack()
end end
end end
function ReaderLink:onClearLocationStack(show_notification)
self.location_stack = {}
if show_notification then
UIManager:show(Notification:new{
text = _("Location history cleared."),
timeout = 2,
})
end
return true
end
--- Goes to link. --- Goes to link.
-- (This is called by other modules (highlight, search) to jump to a xpointer, -- (This is called by other modules (highlight, search) to jump to a xpointer,
-- they should not provide allow_footnote_popup=true) -- they should not provide allow_footnote_popup=true)
@ -613,12 +624,17 @@ function ReaderLink:onGotoLink(link, neglect_current_location, allow_footnote_po
end end
--- Goes back to previous location. --- Goes back to previous location.
function ReaderLink:onGoBackLink() function ReaderLink:onGoBackLink(show_notification_if_empty)
local saved_location = table.remove(self.location_stack) local saved_location = table.remove(self.location_stack)
if saved_location then if saved_location then
logger.dbg("GoBack: restoring:", saved_location) logger.dbg("GoBack: restoring:", saved_location)
self.ui:handleEvent(Event:new('RestoreBookLocation', saved_location)) self.ui:handleEvent(Event:new('RestoreBookLocation', saved_location))
return true return true
elseif show_notification_if_empty then
UIManager:show(Notification:new{
text = _("Location history is empty."),
timeout = 2,
})
end end
end end
@ -637,7 +653,7 @@ function ReaderLink:onSwipe(arg, ges)
-- Make that gesture don't do anything, and show a Notification -- Make that gesture don't do anything, and show a Notification
-- so the user knows why -- so the user knows why
UIManager:show(Notification:new{ UIManager:show(Notification:new{
text = _("Location history is empty"), text = _("Location history is empty."),
timeout = 2, timeout = 2,
}) })
return true return true

Loading…
Cancel
Save