diff --git a/frontend/ui/widget/container/inputcontainer.lua b/frontend/ui/widget/container/inputcontainer.lua index bfa5b6740..fc40a371d 100644 --- a/frontend/ui/widget/container/inputcontainer.lua +++ b/frontend/ui/widget/container/inputcontainer.lua @@ -217,7 +217,7 @@ function InputContainer:onInput(input) input = input.input, input_hint = input.hint_func and input.hint_func() or input.hint or "", input_type = input.type or "number", - buttons = { + buttons = input.buttons or { { { text = input.cancel_text or _("Cancel"), diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index d4757ebac..334bb1dbe 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -35,6 +35,7 @@ local FileChooser = Menu:extend{ reverse_collate = false, path_items = {}, -- store last browsed location(item index) for each path perpage = G_reader_settings:readSetting("items_per_page"), + goto_letter = true, } function FileChooser:init() diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index c3b7444e5..e593c06cd 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -593,20 +593,67 @@ function Menu:init() self.page_info_first_chev:hide() self.page_info_last_chev:hide() + local title_goto, type_goto, hint_func + local buttons = { + { + { + text = _("Cancel"), + callback = function() + self.page_info_text:closeInputDialog() + end, + }, + { + text = _("Go to page"), + is_enter_default = true, + callback = function() + local page = tonumber(self.page_info_text.input_dialog:getInputText()) + if page and page >= 1 and page <= self.page_num then + self:onGotoPage(page) + end + self.page_info_text:closeInputDialog() + end, + }, + }, + } + + if self.goto_letter then + title_goto = _("Input page number or letter") + type_goto = "string" + hint_func = function() + return string.format("(1 - %s) or (a - z)", self.page_num) + end + table.insert(buttons[1], { + text = _("Go to letter"), + is_enter_default = true, + callback = function() + for k, v in ipairs(self.item_table) do + --TODO support utf8 lowercase + local filename = util.basename(v.path):lower() + local search_string = self.page_info_text.input_dialog:getInputText():lower() + local i, _ = filename:find(search_string) + if i == 1 and not v.is_go_up then + self:onGotoPage(math.ceil(k / self.perpage)) + break + end + end + self.page_info_text:closeInputDialog() + end, + }) + else + title_goto = _("Input page number") + type_goto = "number" + hint_func = function() + return string.format("(1 - %s)", self.page_num) + end + end + self.page_info_text = Button:new{ text = "", hold_input = { - title = _("Input page number"), - type = "number", - hint_func = function() - return "(" .. "1 - " .. self.page_num .. ")" - end, - callback = function(input) - local page = tonumber(input) - if page and page >= 1 and page <= self.page_num then - self:onGotoPage(page) - end - end, + title = title_goto , + type = type_goto, + hint_func = hint_func, + buttons = buttons, }, bordersize = 0, text_font_face = "cfont",