Finally I got some code to work that takes me from page search to file search in Koreader.
I now have these buttons in readergoto.lua
buttons = {
{
{
text = _("Skim"),
callback = function()
self:close()
self.skimto = SkimToWidget:new{
document = self.document,
ui = self.ui,
callback_switch_to_goto = function()
UIManager:close(self.skimto)
self:onShowGotoDialog()
end,
}
UIManager:show(self.skimto)
end,
},
{
text = _("Go to page"),
is_enter_default = true,
callback = function()
self:gotoPage()
end,
}
},
{
{
text = _("Bookmarks"),
callback = function()
self:close()
UIManager:broadcastEvent(Event:new("ShowBookmark"))
end,
},
{
text = _("Go to %"),
callback = function()
self:gotoPercent()
end,
}
},
{
{
text = _("Table of Contents"),
callback = function()
self:close()
UIManager:broadcastEvent(Event:new("ShowToc"))
end,
},
{
text = _("Book map"),
callback = function()
self:close()
UIManager:broadcastEvent(Event:new("ShowBookMap"))
end,
}
},
{
{
text = _("File search"),
callback = function()
self:close()
self.ui:showFileManager()
self.ui:handleEvent(Event:new("ShowFileSearch"))
end,
},
{
text = _("Open previous file"),
callback = function()
self:close()
UIManager:broadcastEvent(Event:new("OpenLastDoc"))
end,
}
},
{
{
text = _("History"),
callback = function()
self:close()
UIManager:broadcastEvent(Event:new("ShowHist"))
end,
},
{
text = _("Cancel"),
callback = function()
self:close()
end,
}
},
The File search button took me months to get right, but it's working now.
The only issue is that, after switching to the File search dialog, you have to press Cancel twice to dismiss the File search dialog. For some reason a single press of Cancel won't work. But this is an ignorable little problem, not too frustrating.
Edit: Hah, and I found what fixes it. In the above code, I replaced UIManager:broadcastEvent(Event:new("ShowFileSearch")) with self.ui:handleEvent(Event:new("ShowFileSearch")) and now the File search dialog does not require two-times Cancel to cancel.
As a result, also my changes of filemanagerfilesearcher.lua started working (i.e. I added buttons for "Open previous file" and "History"):
buttons = {
{
{
text = _("Cancel"),
callback = function()
UIManager:close(self.search_dialog)
end,
},
{
text = _("Home folder"),
enabled = G_reader_settings:has("home_dir"),
callback = function()
self.search_value = self.search_dialog:getInputText()
if self.search_value == "" then return end
self.path = G_reader_settings:readSetting("home_dir")
self:close()
end,
},
{
text = _("Current folder"),
is_enter_default = true,
callback = function()
self.search_value = self.search_dialog:getInputText()
if self.search_value == "" then return end
self.path = self.ui.file_chooser and self.ui.file_chooser.path or self.ui:getLastDirFile()
self:close()
end,
},
},
{
{
text = _("Open previous file"),
callback = function()
UIManager:close(self.search_dialog)
UIManager:broadcastEvent(Event:new("OpenLastDoc"))
end,
},
{
text = _("History"),
callback = function()
UIManager:close(self.search_dialog)
UIManager:broadcastEvent(Event:new("ShowHist"))
end,
},
},
},
This latter file also needs to have this line at the top: local Event = require("ui/event").
I still really don't like Lua. I do not like any programming language that requires curly braces and on top of that more sets of braces. Also all languages that are ultra-touchy on commas have certainly been created for the purpose of maximising the torment of souls.