Reader: re-enable File search, Folder shortcuts (#11028)

reviewable/pr11030/r1
hius07 7 months ago committed by GitHub
parent f3520effd6
commit 3b2fc7a551
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,7 +30,6 @@ function FileSearcher:init()
end end
function FileSearcher:onShowFileSearch(search_string) function FileSearcher:onShowFileSearch(search_string)
if not self.ui.file_chooser then return end -- FM only
local search_dialog local search_dialog
local check_button_case, check_button_subfolders, check_button_metadata local check_button_case, check_button_subfolders, check_button_metadata
search_dialog = InputDialog:new{ search_dialog = InputDialog:new{
@ -57,13 +56,13 @@ function FileSearcher:onShowFileSearch(search_string)
end, end,
}, },
{ {
text = _("Current folder"), text = self.ui.file_chooser and _("Current folder") or _("Book folder"),
is_enter_default = true, is_enter_default = true,
callback = function() callback = function()
self.search_value = search_dialog:getInputText() self.search_value = search_dialog:getInputText()
if self.search_value == "" then return end if self.search_value == "" then return end
UIManager:close(search_dialog) UIManager:close(search_dialog)
self.path = self.ui.file_chooser.path or self.ui:getLastDirFile() self.path = self.ui.file_chooser and self.ui.file_chooser.path or self.ui:getLastDirFile()
self:doSearch() self:doSearch()
end, end,
}, },
@ -104,8 +103,14 @@ function FileSearcher:onShowFileSearch(search_string)
end end
function FileSearcher:doSearch() function FileSearcher:doSearch()
local results
local dirs, files = self:getList() local dirs, files = self:getList()
local results = self.ui.file_chooser:genItemTable(dirs, files) -- If we have a FileChooser instance, use it, to be able to make use of its natsort cache
if self.ui.file_chooser then
results = self.ui.file_chooser:genItemTable(dirs, files)
else
results = FileChooser:genItemTable(dirs, files)
end
if #results > 0 then if #results > 0 then
self:showSearchResults(results) self:showSearchResults(results)
else else
@ -239,18 +244,21 @@ function FileSearcher:showSearchResults(results)
dimen = Screen:getSize(), dimen = Screen:getSize(),
} }
self.search_menu = Menu:new{ self.search_menu = Menu:new{
ui = self.ui,
covers_fullscreen = true, -- hint for UIManager:_repaint()
is_borderless = true, is_borderless = true,
is_popout = false, is_popout = false,
show_parent = menu_container, show_parent = menu_container,
onMenuSelect = self.onMenuSelect, onMenuSelect = self.onMenuSelect,
onMenuHold = self.onMenuHold, onMenuHold = self.onMenuHold,
handle_hold_on_hold_release = true, handle_hold_on_hold_release = true,
_manager = self,
} }
table.insert(menu_container, self.search_menu) table.insert(menu_container, self.search_menu)
self.search_menu.close_callback = function() self.search_menu.close_callback = function()
UIManager:close(menu_container) UIManager:close(menu_container)
self.ui.file_chooser:refreshPath() if self.ui.file_chooser then
self.ui.file_chooser:refreshPath()
end
end end
self.search_menu:switchItemTable(T(_("Search results (%1)"), #results), results) self.search_menu:switchItemTable(T(_("Search results (%1)"), #results), results)
UIManager:show(menu_container) UIManager:show(menu_container)
@ -272,18 +280,21 @@ function FileSearcher:onMenuSelect(item)
end end
local buttons = {} local buttons = {}
if item.is_file then if item.is_file then
local is_currently_opened = self.ui.document and self.ui.document.file == file
has_provider = DocumentRegistry:hasProvider(file) has_provider = DocumentRegistry:hasProvider(file)
if has_provider or DocSettings:hasSidecarFile(file) then if has_provider or DocSettings:hasSidecarFile(file) then
table.insert(buttons, filemanagerutil.genStatusButtonsRow(file, close_dialog_callback)) 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))
table.insert(buttons, {}) -- separator table.insert(buttons, {}) -- separator
table.insert(buttons, { table.insert(buttons, {
filemanagerutil.genResetSettingsButton(file, close_dialog_callback), filemanagerutil.genResetSettingsButton(file, close_dialog_callback, is_currently_opened),
filemanagerutil.genAddRemoveFavoritesButton(file, close_dialog_callback), filemanagerutil.genAddRemoveFavoritesButton(file, close_dialog_callback),
}) })
end end
table.insert(buttons, { table.insert(buttons, {
{ {
text = _("Delete"), text = _("Delete"),
enabled = not is_currently_opened,
callback = function() callback = function()
local function post_delete_callback() local function post_delete_callback()
UIManager:close(dialog) UIManager:close(dialog)
@ -295,7 +306,8 @@ function FileSearcher:onMenuSelect(item)
self:switchItemTable(T(_("Search results (%1)"), #self.item_table), self.item_table) self:switchItemTable(T(_("Search results (%1)"), #self.item_table), self.item_table)
end end
end end
self._manager.ui:showDeleteFileDialog(file, post_delete_callback) local FileManager = require("apps/filemanager/filemanager")
FileManager:showDeleteFileDialog(file, post_delete_callback)
end, end,
}, },
filemanagerutil.genBookInformationButton(file, close_dialog_callback), filemanagerutil.genBookInformationButton(file, close_dialog_callback),
@ -329,8 +341,13 @@ function FileSearcher:onMenuHold(item)
end end
else else
self.close_callback() self.close_callback()
local pathname = util.splitFilePathName(item.path) if self.ui.file_chooser then
self._manager.ui.file_chooser:changeToPath(pathname, item.path) 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
end end
return true return true
end end

@ -1021,13 +1021,12 @@ end
function Dispatcher:isActionEnabled(action) function Dispatcher:isActionEnabled(action)
local disabled = true local disabled = true
if action and (action.condition == nil or action.condition == true) then if action and (action.condition == nil or action.condition == true) then
local for_fm_only = action["filemanager"] and not action["reader"]
local ui = require("apps/reader/readerui").instance local ui = require("apps/reader/readerui").instance
local context = ui and (ui.paging and "paging" or "rolling") local context = ui and (ui.paging and "paging" or "rolling")
if context == "paging" then if context == "paging" then
disabled = action["rolling"] or for_fm_only disabled = action["rolling"]
elseif context == "rolling" then elseif context == "rolling" then
disabled = action["paging"] or for_fm_only disabled = action["paging"]
else -- FM else -- FM
disabled = (action["reader"] or action["rolling"] or action["paging"]) and not action["filemanager"] disabled = (action["reader"] or action["rolling"] or action["paging"]) and not action["filemanager"]
end end

Loading…
Cancel
Save