diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index 505ba248a..cdd2a0939 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -28,6 +28,7 @@ local FileChooser = Menu:extend{ strcoll = strcoll, collate = "strcoll", -- or collate = "access", reverse_collate = false, + path_pages = {}, -- store last browsed location(page) for each path } function FileChooser:init() @@ -148,8 +149,14 @@ function FileChooser:genItemTableFromPath(path) return item_table end +function FileChooser:updateItems(select_number) + Menu.updateItems(self, select_number) -- call parent's updateItems() + self.path_pages[self.path] = self.page +end + function FileChooser:refreshPath() - self:swithItemTable(nil, self:genItemTableFromPath(self.path)) + self.page = self.path_pages[self.path] or 1 + self:swithItemTable(nil, self:genItemTableFromPath(self.path), -1) end function FileChooser:changeToPath(path) diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index 273600ee6..d8db38ded 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -675,6 +675,12 @@ function Menu:swithItemTable(new_title, new_item_table, itemnumber) self.page = math.ceil(itemnumber / self.perpage) end + -- make sure current page is in right page range + local max_pages = math.ceil(#new_item_table / self.perpage) + if self.page > max_pages then + self.page = max_pages + end + self.item_table = new_item_table self:updateItems(1) end