2023-08-30 04:53:59 +00:00
|
|
|
local ButtonDialog = require("ui/widget/buttondialog")
|
2021-07-15 10:53:28 +00:00
|
|
|
local CheckButton = require("ui/widget/checkbutton")
|
2023-10-12 05:58:52 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
local DocSettings = require("docsettings")
|
2014-11-16 11:57:56 +00:00
|
|
|
local DocumentRegistry = require("document/documentregistry")
|
2021-07-18 18:21:39 +00:00
|
|
|
local FileChooser = require("ui/widget/filechooser")
|
2023-10-12 05:58:52 +00:00
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
2018-07-24 19:11:25 +00:00
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
2014-11-16 11:57:56 +00:00
|
|
|
local Menu = require("ui/widget/menu")
|
2017-04-29 08:38:09 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2021-07-15 10:53:28 +00:00
|
|
|
local Utf8Proc = require("ffi/utf8proc")
|
2023-10-12 05:58:52 +00:00
|
|
|
local filemanagerutil = require("apps/filemanager/filemanagerutil")
|
2017-04-29 08:38:09 +00:00
|
|
|
local lfs = require("libs/libkoreader-lfs")
|
2020-02-05 02:14:21 +00:00
|
|
|
local util = require("util")
|
2014-11-16 11:57:56 +00:00
|
|
|
local _ = require("gettext")
|
2023-03-28 13:16:53 +00:00
|
|
|
local N_ = _.ngettext
|
2023-10-12 05:58:52 +00:00
|
|
|
local T = require("ffi/util").template
|
2014-11-16 11:57:56 +00:00
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local FileSearcher = WidgetContainer:extend{
|
2022-03-12 10:24:07 +00:00
|
|
|
case_sensitive = false,
|
|
|
|
include_subfolders = true,
|
2023-03-28 13:16:53 +00:00
|
|
|
include_metadata = false,
|
2014-11-16 11:57:56 +00:00
|
|
|
}
|
|
|
|
|
2021-08-14 15:53:39 +00:00
|
|
|
function FileSearcher:onShowFileSearch(search_string)
|
2023-03-28 13:16:53 +00:00
|
|
|
local search_dialog
|
|
|
|
local check_button_case, check_button_subfolders, check_button_metadata
|
|
|
|
search_dialog = InputDialog:new{
|
|
|
|
title = _("Enter text to search for in filename"),
|
2023-11-09 05:34:56 +00:00
|
|
|
input = search_string or self.search_string,
|
2014-11-16 11:57:56 +00:00
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
2022-03-04 20:20:00 +00:00
|
|
|
id = "close",
|
2014-11-16 11:57:56 +00:00
|
|
|
callback = function()
|
2023-03-28 13:16:53 +00:00
|
|
|
UIManager:close(search_dialog)
|
2014-11-16 11:57:56 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
2021-04-04 15:27:17 +00:00
|
|
|
text = _("Home folder"),
|
|
|
|
enabled = G_reader_settings:has("home_dir"),
|
2014-11-16 11:57:56 +00:00
|
|
|
callback = function()
|
2023-11-09 05:34:56 +00:00
|
|
|
self.search_string = search_dialog:getInputText()
|
|
|
|
if self.search_string == "" then return end
|
2023-03-28 13:16:53 +00:00
|
|
|
UIManager:close(search_dialog)
|
2021-04-04 15:27:17 +00:00
|
|
|
self.path = G_reader_settings:readSetting("home_dir")
|
2023-03-28 13:16:53 +00:00
|
|
|
self:doSearch()
|
2018-07-24 19:11:25 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
2023-10-20 09:16:26 +00:00
|
|
|
text = self.ui.file_chooser and _("Current folder") or _("Book folder"),
|
2021-04-04 15:27:17 +00:00
|
|
|
is_enter_default = true,
|
2018-07-24 19:11:25 +00:00
|
|
|
callback = function()
|
2023-11-09 05:34:56 +00:00
|
|
|
self.search_string = search_dialog:getInputText()
|
|
|
|
if self.search_string == "" then return end
|
2023-03-28 13:16:53 +00:00
|
|
|
UIManager:close(search_dialog)
|
2023-10-20 09:16:26 +00:00
|
|
|
self.path = self.ui.file_chooser and self.ui.file_chooser.path or self.ui:getLastDirFile()
|
2023-03-28 13:16:53 +00:00
|
|
|
self:doSearch()
|
2014-11-16 11:57:56 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-03-28 13:16:53 +00:00
|
|
|
check_button_case = CheckButton:new{
|
2021-07-15 10:53:28 +00:00
|
|
|
text = _("Case sensitive"),
|
|
|
|
checked = self.case_sensitive,
|
2023-03-28 13:16:53 +00:00
|
|
|
parent = search_dialog,
|
2021-07-15 10:53:28 +00:00
|
|
|
callback = function()
|
2023-03-28 13:16:53 +00:00
|
|
|
self.case_sensitive = check_button_case.checked
|
2021-07-15 10:53:28 +00:00
|
|
|
end,
|
|
|
|
}
|
2023-03-28 13:16:53 +00:00
|
|
|
search_dialog:addWidget(check_button_case)
|
|
|
|
check_button_subfolders = CheckButton:new{
|
2022-03-12 10:24:07 +00:00
|
|
|
text = _("Include subfolders"),
|
|
|
|
checked = self.include_subfolders,
|
2023-03-28 13:16:53 +00:00
|
|
|
parent = search_dialog,
|
2022-03-12 10:24:07 +00:00
|
|
|
callback = function()
|
2023-03-28 13:16:53 +00:00
|
|
|
self.include_subfolders = check_button_subfolders.checked
|
2022-03-12 10:24:07 +00:00
|
|
|
end,
|
|
|
|
}
|
2023-03-28 13:16:53 +00:00
|
|
|
search_dialog:addWidget(check_button_subfolders)
|
|
|
|
if self.ui.coverbrowser then
|
|
|
|
check_button_metadata = CheckButton:new{
|
|
|
|
text = _("Also search in book metadata"),
|
|
|
|
checked = self.include_metadata,
|
|
|
|
parent = search_dialog,
|
|
|
|
callback = function()
|
|
|
|
self.include_metadata = check_button_metadata.checked
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
search_dialog:addWidget(check_button_metadata)
|
|
|
|
end
|
|
|
|
UIManager:show(search_dialog)
|
|
|
|
search_dialog:onShowKeyboard()
|
2014-11-16 11:57:56 +00:00
|
|
|
end
|
|
|
|
|
2023-03-28 13:16:53 +00:00
|
|
|
function FileSearcher:doSearch()
|
|
|
|
local dirs, files = self:getList()
|
2023-10-20 09:16:26 +00:00
|
|
|
-- If we have a FileChooser instance, use it, to be able to make use of its natsort cache
|
2024-06-06 08:44:03 +00:00
|
|
|
local results = (self.ui.file_chooser or FileChooser):genItemTable(dirs, files)
|
2023-03-28 13:16:53 +00:00
|
|
|
if #results > 0 then
|
|
|
|
self:showSearchResults(results)
|
|
|
|
else
|
|
|
|
self:showSearchResultsMessage(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileSearcher:getList()
|
|
|
|
self.no_metadata_count = 0
|
|
|
|
local sys_folders = { -- do not search in sys_folders
|
|
|
|
["/dev"] = true,
|
|
|
|
["/proc"] = true,
|
|
|
|
["/sys"] = true,
|
|
|
|
}
|
2023-11-23 13:48:33 +00:00
|
|
|
local collate = FileChooser:getCollate()
|
2023-11-09 05:34:56 +00:00
|
|
|
local search_string = self.search_string
|
|
|
|
if search_string ~= "*" then -- one * to show all files
|
2023-03-28 13:16:53 +00:00
|
|
|
if not self.case_sensitive then
|
2023-11-09 05:34:56 +00:00
|
|
|
search_string = Utf8Proc.lowercase(util.fixUtf8(search_string, "?"))
|
2023-03-28 13:16:53 +00:00
|
|
|
end
|
|
|
|
-- replace '.' with '%.'
|
2023-11-09 05:34:56 +00:00
|
|
|
search_string = search_string:gsub("%.","%%%.")
|
2023-03-28 13:16:53 +00:00
|
|
|
-- replace '*' with '.*'
|
2023-11-09 05:34:56 +00:00
|
|
|
search_string = search_string:gsub("%*","%.%*")
|
2023-03-28 13:16:53 +00:00
|
|
|
-- replace '?' with '.'
|
2023-11-09 05:34:56 +00:00
|
|
|
search_string = search_string:gsub("%?","%.")
|
2023-03-28 13:16:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local dirs, files = {}, {}
|
|
|
|
local scan_dirs = {self.path}
|
|
|
|
while #scan_dirs ~= 0 do
|
|
|
|
local new_dirs = {}
|
|
|
|
-- handle each dir
|
|
|
|
for _, d in ipairs(scan_dirs) do
|
|
|
|
-- handle files in d
|
|
|
|
local ok, iter, dir_obj = pcall(lfs.dir, d)
|
|
|
|
if ok then
|
|
|
|
for f in iter, dir_obj do
|
|
|
|
local fullpath = "/" .. f
|
|
|
|
if d ~= "/" then
|
|
|
|
fullpath = d .. fullpath
|
|
|
|
end
|
|
|
|
local attributes = lfs.attributes(fullpath) or {}
|
|
|
|
-- Don't traverse hidden folders if we're not showing them
|
|
|
|
if attributes.mode == "directory" and f ~= "." and f ~= ".."
|
2023-10-12 05:58:52 +00:00
|
|
|
and (FileChooser.show_hidden or not util.stringStartsWith(f, "."))
|
2023-03-28 13:16:53 +00:00
|
|
|
and FileChooser:show_dir(f) then
|
|
|
|
if self.include_subfolders and not sys_folders[fullpath] then
|
|
|
|
table.insert(new_dirs, fullpath)
|
|
|
|
end
|
2023-11-09 05:34:56 +00:00
|
|
|
if self:isFileMatch(f, fullpath, search_string) then
|
2023-11-27 08:34:12 +00:00
|
|
|
table.insert(dirs, FileChooser:getListItem(nil, f, fullpath, attributes, collate))
|
2023-03-28 13:16:53 +00:00
|
|
|
end
|
|
|
|
-- Always ignore macOS resource forks, too.
|
|
|
|
elseif attributes.mode == "file" and not util.stringStartsWith(f, "._")
|
2023-10-12 05:58:52 +00:00
|
|
|
and (FileChooser.show_unsupported or DocumentRegistry:hasProvider(fullpath))
|
2023-03-28 13:16:53 +00:00
|
|
|
and FileChooser:show_file(f) then
|
2023-11-09 05:34:56 +00:00
|
|
|
if self:isFileMatch(f, fullpath, search_string, true) then
|
2023-11-26 13:54:02 +00:00
|
|
|
table.insert(files, FileChooser:getListItem(nil, f, fullpath, attributes, collate))
|
2023-03-28 13:16:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
scan_dirs = new_dirs
|
|
|
|
end
|
|
|
|
return dirs, files
|
|
|
|
end
|
|
|
|
|
2023-11-09 05:34:56 +00:00
|
|
|
function FileSearcher:isFileMatch(filename, fullpath, search_string, is_file)
|
|
|
|
if search_string == "*" then
|
2023-03-28 13:16:53 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
if not self.case_sensitive then
|
|
|
|
filename = Utf8Proc.lowercase(util.fixUtf8(filename, "?"))
|
|
|
|
end
|
2023-11-09 05:34:56 +00:00
|
|
|
if string.find(filename, search_string) then
|
2023-03-28 13:16:53 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
if self.include_metadata and is_file and DocumentRegistry:hasProvider(fullpath) then
|
|
|
|
local book_props = self.ui.coverbrowser:getBookInfo(fullpath) or
|
2023-11-09 05:34:56 +00:00
|
|
|
self.ui.bookinfo.getDocProps(fullpath, nil, true) -- do not open the document
|
2023-03-28 13:16:53 +00:00
|
|
|
if next(book_props) ~= nil then
|
2023-11-09 05:34:56 +00:00
|
|
|
if self.ui.bookinfo:findInProps(book_props, search_string, self.case_sensitive) then
|
|
|
|
return true
|
2023-03-28 13:16:53 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
self.no_metadata_count = self.no_metadata_count + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileSearcher:showSearchResultsMessage(no_results)
|
2023-11-09 05:34:56 +00:00
|
|
|
local text = no_results and T(_("No results for '%1'."), self.search_string)
|
2023-03-28 13:16:53 +00:00
|
|
|
if self.no_metadata_count == 0 then
|
|
|
|
UIManager:show(InfoMessage:new{ text = text })
|
|
|
|
else
|
|
|
|
local txt = T(N_("1 book has been skipped.", "%1 books have been skipped.",
|
|
|
|
self.no_metadata_count), self.no_metadata_count) .. "\n" ..
|
|
|
|
_("Not all books metadata extracted yet.\nExtract metadata now?")
|
|
|
|
text = no_results and text .. "\n\n" .. txt or txt
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
text = text,
|
|
|
|
ok_text = _("Extract"),
|
|
|
|
ok_callback = function()
|
|
|
|
if not no_results then
|
|
|
|
self.search_menu.close_callback()
|
|
|
|
end
|
|
|
|
self.ui.coverbrowser:extractBooksInDirectory(self.path)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileSearcher:showSearchResults(results)
|
2014-11-16 11:57:56 +00:00
|
|
|
self.search_menu = Menu:new{
|
2024-01-26 21:01:45 +00:00
|
|
|
subtitle = T(_("Query: %1"), self.search_string),
|
2023-10-20 09:16:26 +00:00
|
|
|
covers_fullscreen = true, -- hint for UIManager:_repaint()
|
2023-03-28 13:16:53 +00:00
|
|
|
is_borderless = true,
|
|
|
|
is_popout = false,
|
2024-01-26 21:01:45 +00:00
|
|
|
title_bar_fm_style = true,
|
2024-06-06 08:44:03 +00:00
|
|
|
title_bar_left_icon = "appbar.menu",
|
|
|
|
onLeftButtonTap = function() self:setSelectMode() end,
|
2023-03-28 13:16:53 +00:00
|
|
|
onMenuSelect = self.onMenuSelect,
|
2014-11-16 11:57:56 +00:00
|
|
|
onMenuHold = self.onMenuHold,
|
2023-03-28 13:16:53 +00:00
|
|
|
handle_hold_on_hold_release = true,
|
2024-06-06 08:44:03 +00:00
|
|
|
ui = self.ui,
|
|
|
|
_manager = self,
|
2014-11-16 11:57:56 +00:00
|
|
|
}
|
|
|
|
self.search_menu.close_callback = function()
|
2024-06-06 08:44:03 +00:00
|
|
|
self.selected_files = nil
|
2024-01-26 21:01:45 +00:00
|
|
|
UIManager:close(self.search_menu)
|
2023-10-20 09:16:26 +00:00
|
|
|
if self.ui.file_chooser then
|
|
|
|
self.ui.file_chooser:refreshPath()
|
|
|
|
end
|
2014-11-16 11:57:56 +00:00
|
|
|
end
|
2024-06-06 08:44:03 +00:00
|
|
|
self:updateMenu(results)
|
2024-01-26 21:01:45 +00:00
|
|
|
UIManager:show(self.search_menu)
|
2023-03-28 13:16:53 +00:00
|
|
|
if self.no_metadata_count ~= 0 then
|
|
|
|
self:showSearchResultsMessage()
|
|
|
|
end
|
2014-11-16 11:57:56 +00:00
|
|
|
end
|
|
|
|
|
2024-06-06 08:44:03 +00:00
|
|
|
function FileSearcher:updateMenu(item_table)
|
|
|
|
item_table = item_table or self.search_menu.item_table
|
|
|
|
self.search_menu:switchItemTable(T(_("Search results (%1)"), #item_table), item_table, -1)
|
|
|
|
end
|
|
|
|
|
2023-03-28 13:16:53 +00:00
|
|
|
function FileSearcher:onMenuSelect(item)
|
2024-06-06 08:44:03 +00:00
|
|
|
if self._manager.selected_files then
|
|
|
|
if item.is_file then
|
|
|
|
item.dim = not item.dim and true or nil
|
|
|
|
self._manager.selected_files[item.path] = item.dim
|
|
|
|
self._manager:updateMenu()
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self._manager:showFileDialog(item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileSearcher:showFileDialog(item)
|
2023-10-12 05:58:52 +00:00
|
|
|
local file = item.path
|
2024-01-26 21:01:45 +00:00
|
|
|
local bookinfo, dialog
|
2023-10-12 05:58:52 +00:00
|
|
|
local function close_dialog_callback()
|
|
|
|
UIManager:close(dialog)
|
|
|
|
end
|
|
|
|
local function close_dialog_menu_callback()
|
|
|
|
UIManager:close(dialog)
|
2024-06-06 08:44:03 +00:00
|
|
|
self.search_menu.close_callback()
|
|
|
|
end
|
|
|
|
local function update_item_callback()
|
|
|
|
item.mandatory = FileChooser:getMenuItemMandatory(item, FileChooser:getCollate())
|
|
|
|
self:updateMenu()
|
2023-10-12 05:58:52 +00:00
|
|
|
end
|
2023-03-28 13:16:53 +00:00
|
|
|
local buttons = {}
|
|
|
|
if item.is_file then
|
2023-10-20 09:16:26 +00:00
|
|
|
local is_currently_opened = self.ui.document and self.ui.document.file == file
|
2023-11-05 05:24:18 +00:00
|
|
|
if DocumentRegistry:hasProvider(file) or DocSettings:hasSidecarFile(file) then
|
2024-01-26 21:01:45 +00:00
|
|
|
bookinfo = self.ui.coverbrowser and self.ui.coverbrowser:getBookInfo(file)
|
2023-10-20 09:16:26 +00:00
|
|
|
local doc_settings_or_file = is_currently_opened and self.ui.doc_settings or file
|
|
|
|
table.insert(buttons, filemanagerutil.genStatusButtonsRow(doc_settings_or_file, close_dialog_callback))
|
2023-10-12 05:58:52 +00:00
|
|
|
table.insert(buttons, {}) -- separator
|
|
|
|
table.insert(buttons, {
|
2023-10-20 09:16:26 +00:00
|
|
|
filemanagerutil.genResetSettingsButton(file, close_dialog_callback, is_currently_opened),
|
2024-06-06 08:44:03 +00:00
|
|
|
self.ui.collections:genAddToCollectionButton(file, close_dialog_callback, update_item_callback),
|
2023-10-12 05:58:52 +00:00
|
|
|
})
|
|
|
|
end
|
2023-03-28 13:16:53 +00:00
|
|
|
table.insert(buttons, {
|
2021-08-18 14:17:27 +00:00
|
|
|
{
|
2023-10-12 05:58:52 +00:00
|
|
|
text = _("Delete"),
|
2023-10-20 09:16:26 +00:00
|
|
|
enabled = not is_currently_opened,
|
2021-08-18 14:17:27 +00:00
|
|
|
callback = function()
|
2023-10-12 05:58:52 +00:00
|
|
|
local function post_delete_callback()
|
|
|
|
UIManager:close(dialog)
|
2024-06-06 08:44:03 +00:00
|
|
|
table.remove(self.search_menu.item_table, item.idx)
|
|
|
|
self:updateMenu()
|
2023-10-12 05:58:52 +00:00
|
|
|
end
|
2023-10-20 09:16:26 +00:00
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
|
|
|
FileManager:showDeleteFileDialog(file, post_delete_callback)
|
2021-08-18 14:17:27 +00:00
|
|
|
end,
|
|
|
|
},
|
2024-01-26 21:01:45 +00:00
|
|
|
filemanagerutil.genBookInformationButton(file, bookinfo, close_dialog_callback),
|
2023-03-28 13:16:53 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
table.insert(buttons, {
|
2023-10-12 05:58:52 +00:00
|
|
|
filemanagerutil.genShowFolderButton(file, close_dialog_menu_callback),
|
2023-03-28 13:16:53 +00:00
|
|
|
{
|
2023-10-12 05:58:52 +00:00
|
|
|
text = _("Open"),
|
2023-11-05 05:24:18 +00:00
|
|
|
enabled = DocumentRegistry:hasProvider(file, nil, true), -- allow auxiliary providers
|
2021-08-18 14:17:27 +00:00
|
|
|
callback = function()
|
2024-06-06 08:44:03 +00:00
|
|
|
close_dialog_menu_callback()
|
2023-11-05 05:24:18 +00:00
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
2024-06-06 08:44:03 +00:00
|
|
|
FileManager.openFile(self.ui, file)
|
2021-08-18 14:17:27 +00:00
|
|
|
end,
|
2023-03-28 13:16:53 +00:00
|
|
|
},
|
|
|
|
})
|
2024-01-26 21:01:45 +00:00
|
|
|
local title = file
|
|
|
|
if bookinfo then
|
|
|
|
if bookinfo.title then
|
|
|
|
title = title .. "\n\n" .. T(_("Title: %1"), bookinfo.title)
|
|
|
|
end
|
|
|
|
if bookinfo.authors then
|
|
|
|
title = title .. "\n" .. T(_("Authors: %1"), bookinfo.authors:gsub("[\n\t]", "|"))
|
|
|
|
end
|
|
|
|
end
|
2023-08-30 04:53:59 +00:00
|
|
|
dialog = ButtonDialog:new{
|
2024-01-26 21:01:45 +00:00
|
|
|
title = title .. "\n",
|
2021-08-18 14:17:27 +00:00
|
|
|
buttons = buttons,
|
|
|
|
}
|
2023-03-28 13:16:53 +00:00
|
|
|
UIManager:show(dialog)
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileSearcher:onMenuHold(item)
|
2024-06-06 08:44:03 +00:00
|
|
|
if self._manager.selected_files then return true end
|
2023-03-28 13:16:53 +00:00
|
|
|
if item.is_file then
|
2023-11-05 05:24:18 +00:00
|
|
|
if DocumentRegistry:hasProvider(item.path, nil, true) then
|
2024-06-06 08:44:03 +00:00
|
|
|
self.close_callback()
|
2023-11-05 05:24:18 +00:00
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
2024-06-06 08:44:03 +00:00
|
|
|
FileManager.openFile(self.ui, item.path)
|
2023-03-28 13:16:53 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
self.close_callback()
|
2023-10-20 09:16:26 +00:00
|
|
|
if self.ui.file_chooser then
|
|
|
|
local pathname = util.splitFilePathName(item.path)
|
|
|
|
self.ui.file_chooser:changeToPath(pathname, item.path)
|
|
|
|
else -- called from Reader
|
|
|
|
self.ui:onClose()
|
|
|
|
self.ui:showFileManager(item.path)
|
|
|
|
end
|
2023-03-28 13:16:53 +00:00
|
|
|
end
|
2021-08-18 14:17:27 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2024-06-06 08:44:03 +00:00
|
|
|
function FileSearcher:setSelectMode()
|
|
|
|
if self.selected_files then
|
|
|
|
self:showSelectModeDialog()
|
|
|
|
else
|
|
|
|
self.selected_files = {}
|
|
|
|
self.search_menu:setTitleBarLeftIcon("check")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileSearcher:showSelectModeDialog()
|
|
|
|
local item_table = self.search_menu.item_table
|
|
|
|
local select_count = util.tableSize(self.selected_files)
|
|
|
|
local actions_enabled = select_count > 0
|
|
|
|
local title = actions_enabled and T(N_("1 file selected", "%1 files selected", select_count), select_count)
|
|
|
|
or _("No files selected")
|
|
|
|
local select_dialog
|
|
|
|
local buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Deselect all"),
|
|
|
|
enabled = actions_enabled,
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(select_dialog)
|
|
|
|
for file in pairs (self.selected_files) do
|
|
|
|
self.selected_files[file] = nil
|
|
|
|
end
|
|
|
|
for _, item in ipairs(item_table) do
|
|
|
|
item.dim = nil
|
|
|
|
end
|
|
|
|
self:updateMenu()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Select all"),
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(select_dialog)
|
|
|
|
for _, item in ipairs(item_table) do
|
|
|
|
if item.is_file then
|
|
|
|
item.dim = true
|
|
|
|
self.selected_files[item.path] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self:updateMenu()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Exit select mode"),
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(select_dialog)
|
|
|
|
self.selected_files = nil
|
|
|
|
self.search_menu:setTitleBarLeftIcon("appbar.menu")
|
|
|
|
if actions_enabled then
|
|
|
|
for _, item in ipairs(item_table) do
|
|
|
|
item.dim = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self:updateMenu()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Select in file browser"),
|
|
|
|
enabled = actions_enabled,
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(select_dialog)
|
|
|
|
local selected_files = self.selected_files
|
|
|
|
self.search_menu.close_callback()
|
|
|
|
if self.ui.file_chooser then
|
|
|
|
self.ui.selected_files = selected_files
|
|
|
|
self.ui.title_bar:setRightIcon("check")
|
|
|
|
self.ui.file_chooser:refreshPath()
|
|
|
|
else -- called from Reader
|
|
|
|
self.ui:onClose()
|
|
|
|
self.ui:showFileManager(self.path .. "/", selected_files)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
select_dialog = ButtonDialog:new{
|
|
|
|
title = title,
|
|
|
|
title_align = "center",
|
|
|
|
buttons = buttons,
|
|
|
|
}
|
|
|
|
UIManager:show(select_dialog)
|
|
|
|
end
|
|
|
|
|
2014-11-16 11:57:56 +00:00
|
|
|
return FileSearcher
|