[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.
This commit is contained in:
poire-z
2019-03-02 22:55:09 +01:00
committed by Frans de Jonge
parent 5b30ea1920
commit 93422d05f4
2 changed files with 26 additions and 6 deletions

View File

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