mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
File manager: added 'Go to letter' (#3664)
When Hold on page number, allows for inputing letters to go to file starting with them (and not only numbers to go to page number).
This commit is contained in:
@@ -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"),
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user