File search, FileChooser and others (#10994)

reviewable/pr10999/r1
hius07 7 months ago committed by GitHub
parent 16e96969c5
commit e577c79d95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,10 +36,6 @@ DCREREADER_VIEW_MODE = "page",
-- default to false
DSHOWOVERLAP = false,
-- show hidden files in filemanager
-- default to false
DSHOWHIDDENFILES = false,
-- landscape clockwise rotation
-- default to true, set to false for counterclockwise rotation
DLANDSCAPE_CLOCKWISE_ROTATION = true,

@ -128,9 +128,6 @@ function FileManager:setupLayout()
right_icon_hold_callback = false, -- propagate long-press to dispatcher
}
local show_finished = G_reader_settings:nilOrTrue("show_finished")
local show_hidden = G_reader_settings:isTrue("show_hidden") or G_defaults:readSetting("DSHOWHIDDENFILES")
local show_unsupported = G_reader_settings:isTrue("show_unsupported")
local file_chooser = FileChooser:new{
-- remember to adjust the height when new item is added to the group
path = self.root_path,
@ -139,14 +136,7 @@ function FileManager:setupLayout()
height = Screen:getHeight() - self.title_bar:getHeight(),
is_popout = false,
is_borderless = true,
show_finished = show_finished,
show_hidden = show_hidden,
show_unsupported = show_unsupported,
file_filter = function(filename)
if DocumentRegistry:hasProvider(filename) then
return true
end
end,
file_filter = function(filename) return DocumentRegistry:hasProvider(filename) end,
close_callback = function() return self:onClose() end,
-- allow left bottom tap gesture, otherwise it is eaten by hidden return button
return_arrow_propagation = true,
@ -262,15 +252,15 @@ function FileManager:setupLayout()
UIManager:close(self.file_dialog)
self:refreshPath() -- sidecar folder may be created/deleted
end
local has_provider = DocumentRegistry:getProviders(file) ~= nil
local has_provider = DocumentRegistry:hasProvider(file)
if has_provider or DocSettings:hasSidecarFile(file) then
table.insert(buttons, filemanagerutil.genStatusButtonsRow(file, status_button_callback))
table.insert(buttons, {}) -- separator
table.insert(buttons, {
filemanagerutil.genResetSettingsButton(file, status_button_callback),
filemanagerutil.genAddRemoveFavoritesButton(file, close_dialog_callback),
})
end
table.insert(buttons, {
filemanagerutil.genResetSettingsButton(file, status_button_callback),
filemanagerutil.genAddRemoveFavoritesButton(file, close_dialog_callback, not has_provider),
})
table.insert(buttons, {
{
text = _("Open with…"),
@ -317,10 +307,12 @@ function FileManager:setupLayout()
},
filemanagerutil.genBookInformationButton(file, close_dialog_callback),
})
table.insert(buttons, {
filemanagerutil.genBookCoverButton(file, close_dialog_callback),
filemanagerutil.genBookDescriptionButton(file, close_dialog_callback),
})
if has_provider then
table.insert(buttons, {
filemanagerutil.genBookCoverButton(file, close_dialog_callback),
filemanagerutil.genBookDescriptionButton(file, close_dialog_callback),
})
end
if Device:canExecuteScript(file) then
table.insert(buttons, {
filemanagerutil.genExecuteScriptButton(file, close_dialog_callback),
@ -782,21 +774,6 @@ function FileManager:getCurrentDir()
return FileManager.instance and FileManager.instance.file_chooser.path
end
function FileManager:toggleFinishedBooks()
self.file_chooser:toggleFinishedBooks()
G_reader_settings:saveSetting("show_finished", self.file_chooser.show_finished)
end
function FileManager:toggleHiddenFiles()
self.file_chooser:toggleHiddenFiles()
G_reader_settings:saveSetting("show_hidden", self.file_chooser.show_hidden)
end
function FileManager:toggleUnsupportedFiles()
self.file_chooser:toggleUnsupportedFiles()
G_reader_settings:saveSetting("show_unsupported", self.file_chooser.show_unsupported)
end
function FileManager:onClose()
logger.dbg("close filemanager")
PluginLoader:finalize()

@ -1,21 +1,24 @@
local ButtonDialog = require("ui/widget/buttondialog")
local CheckButton = require("ui/widget/checkbutton")
local CenterContainer = require("ui/widget/container/centercontainer")
local ConfirmBox = require("ui/widget/confirmbox")
local DocSettings = require("docsettings")
local DocumentRegistry = require("document/documentregistry")
local FileChooser = require("ui/widget/filechooser")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local InfoMessage = require("ui/widget/infomessage")
local InputDialog = require("ui/widget/inputdialog")
local Menu = require("ui/widget/menu")
local UIManager = require("ui/uimanager")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local BaseUtil = require("ffi/util")
local Utf8Proc = require("ffi/utf8proc")
local filemanagerutil = require("apps/filemanager/filemanagerutil")
local lfs = require("libs/libkoreader-lfs")
local util = require("util")
local _ = require("gettext")
local N_ = _.ngettext
local Screen = require("device").screen
local T = BaseUtil.template
local T = require("ffi/util").template
local FileSearcher = WidgetContainer:extend{
case_sensitive = false,
@ -27,6 +30,7 @@ function FileSearcher:init()
end
function FileSearcher:onShowFileSearch(search_string)
if not self.ui.file_chooser then return end -- FM only
local search_dialog
local check_button_case, check_button_subfolders, check_button_metadata
search_dialog = InputDialog:new{
@ -53,20 +57,19 @@ function FileSearcher:onShowFileSearch(search_string)
end,
},
{
text = self.ui.file_chooser and _("Current folder") or _("Book folder"),
text = _("Current folder"),
is_enter_default = true,
callback = function()
self.search_value = search_dialog:getInputText()
if self.search_value == "" then return end
UIManager:close(search_dialog)
self.path = self.ui.file_chooser and self.ui.file_chooser.path or self.ui:getLastDirFile()
self.path = self.ui.file_chooser.path or self.ui:getLastDirFile()
self:doSearch()
end,
},
},
},
}
check_button_case = CheckButton:new{
text = _("Case sensitive"),
checked = self.case_sensitive,
@ -96,20 +99,13 @@ function FileSearcher:onShowFileSearch(search_string)
}
search_dialog:addWidget(check_button_metadata)
end
UIManager:show(search_dialog)
search_dialog:onShowKeyboard()
end
function FileSearcher:doSearch()
local results
local dirs, files = self:getList()
-- 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
local results = self.ui.file_chooser:genItemTable(dirs, files)
if #results > 0 then
self:showSearchResults(results)
else
@ -124,8 +120,6 @@ function FileSearcher:getList()
["/proc"] = true,
["/sys"] = true,
}
local show_hidden = G_reader_settings:isTrue("show_hidden")
local show_unsupported = G_reader_settings:isTrue("show_unsupported")
local collate = G_reader_settings:readSetting("collate")
local keywords = self.search_value
if keywords ~= "*" then -- one * to show all files
@ -157,20 +151,20 @@ function FileSearcher:getList()
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 ~= ".."
and (show_hidden or not util.stringStartsWith(f, "."))
and (FileChooser.show_hidden or not util.stringStartsWith(f, "."))
and FileChooser:show_dir(f) then
if self.include_subfolders and not sys_folders[fullpath] then
table.insert(new_dirs, fullpath)
end
if self:isFileMatch(f, fullpath, keywords) then
table.insert(dirs, FileChooser:getListItem(f, fullpath, attributes))
table.insert(dirs, FileChooser.getListItem(f, fullpath, attributes))
end
-- Always ignore macOS resource forks, too.
elseif attributes.mode == "file" and not util.stringStartsWith(f, "._")
and (show_unsupported or DocumentRegistry:hasProvider(fullpath))
and (FileChooser.show_unsupported or DocumentRegistry:hasProvider(fullpath))
and FileChooser:show_file(f) then
if self:isFileMatch(f, fullpath, keywords, true) then
table.insert(files, FileChooser:getListItem(f, fullpath, attributes, collate))
table.insert(files, FileChooser.getListItem(f, fullpath, attributes, collate))
end
end
end
@ -221,14 +215,12 @@ end
function FileSearcher:showSearchResultsMessage(no_results)
local text = no_results and T(_("No results for '%1'."), self.search_value)
if self.no_metadata_count == 0 then
local InfoMessage = require("ui/widget/infomessage")
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
local ConfirmBox = require("ui/widget/confirmbox")
UIManager:show(ConfirmBox:new{
text = text,
ok_text = _("Extract"),
@ -258,6 +250,7 @@ function FileSearcher:showSearchResults(results)
table.insert(menu_container, self.search_menu)
self.search_menu.close_callback = function()
UIManager:close(menu_container)
self.ui.file_chooser:refreshPath()
end
self.search_menu:switchItemTable(T(_("Search results (%1)"), #results), results)
UIManager:show(menu_container)
@ -267,46 +260,61 @@ function FileSearcher:showSearchResults(results)
end
function FileSearcher:onMenuSelect(item)
local file = item.path
local has_provider = false
local dialog
local function close_dialog_callback()
UIManager:close(dialog)
end
local function close_dialog_menu_callback()
UIManager:close(dialog)
self.close_callback()
end
local buttons = {}
if item.is_file then
has_provider = DocumentRegistry:hasProvider(file)
if has_provider or DocSettings:hasSidecarFile(file) then
table.insert(buttons, filemanagerutil.genStatusButtonsRow(file, close_dialog_callback))
table.insert(buttons, {}) -- separator
table.insert(buttons, {
filemanagerutil.genResetSettingsButton(file, close_dialog_callback),
filemanagerutil.genAddRemoveFavoritesButton(file, close_dialog_callback),
})
end
table.insert(buttons, {
{
text = _("Book information"),
text = _("Delete"),
callback = function()
UIManager:close(dialog)
FileManagerBookInfo:show(item.path)
end,
},
{
text = _("Open"),
enabled = DocumentRegistry:hasProvider(item.path),
callback = function()
UIManager:close(dialog)
self.close_callback()
require("apps/reader/readerui"):showReader(item.path)
local function post_delete_callback()
UIManager:close(dialog)
for i, menu_item in ipairs(self.item_table) do
if menu_item.path == file then
table.remove(self.item_table, i)
break
end
self:switchItemTable(T(_("Search results (%1)"), #self.item_table), self.item_table)
end
end
self._manager.ui:showDeleteFileDialog(file, post_delete_callback)
end,
},
filemanagerutil.genBookInformationButton(file, close_dialog_callback),
})
end
table.insert(buttons, {
filemanagerutil.genShowFolderButton(file, close_dialog_menu_callback),
{
text = _("Cancel"),
callback = function()
UIManager:close(dialog)
end,
},
{
text = _("Show folder"),
text = _("Open"),
enabled = has_provider,
callback = function()
UIManager:close(dialog)
self.close_callback()
self._manager:showFolder(item.path)
close_dialog_menu_callback()
local ReaderUI = require("apps/reader/readerui")
ReaderUI:showReader(file)
end,
},
})
dialog = ButtonDialog:new{
title = item.path,
title = file,
buttons = buttons,
}
UIManager:show(dialog)
@ -316,23 +324,15 @@ function FileSearcher:onMenuHold(item)
if item.is_file then
if DocumentRegistry:hasProvider(item.path) then
self.close_callback()
require("apps/reader/readerui"):showReader(item.path)
local ReaderUI = require("apps/reader/readerui")
ReaderUI:showReader(item.path)
end
else
self.close_callback()
self._manager:showFolder(item.path)
local pathname = util.splitFilePathName(item.path)
self._manager.ui.file_chooser:changeToPath(pathname, item.path)
end
return true
end
function FileSearcher:showFolder(path)
if self.ui.file_chooser then
local pathname = util.splitFilePathName(path)
self.ui.file_chooser:changeToPath(pathname, path)
else -- called from Reader
self.ui:onClose()
self.ui:showFileManager(path)
end
end
return FileSearcher

@ -65,6 +65,9 @@ function FileManagerHistory:updateItemTable()
local item_table = {}
for _, v in ipairs(require("readhistory").hist) do
if self.filter == "all" or v.status == self.filter then
if self.is_frozen and v.status == "complete" then
v.mandatory_dim = true
end
table.insert(item_table, v)
end
if self.statuses_fetched then
@ -190,7 +193,8 @@ function FileManagerHistory:onShowHist()
}
self.filter = G_reader_settings:readSetting("history_filter", "all")
if self.filter ~= "all" then
self.is_frozen = G_reader_settings:isTrue("history_freeze_finished_books")
if self.filter ~= "all" or self.is_frozen then
self:fetchStatuses(false)
end
self:updateItemTable()

@ -143,6 +143,7 @@ function FileManagerMenu:onOpenLastDoc()
end
function FileManagerMenu:setUpdateItemTable()
local FileChooser = self.ui.file_chooser
-- setting tab
self.menu_items.filebrowser_settings = {
@ -150,18 +151,18 @@ function FileManagerMenu:setUpdateItemTable()
sub_item_table = {
{
text = _("Show finished books"),
checked_func = function() return self.ui.file_chooser.show_finished end,
callback = function() self.ui:toggleFinishedBooks() end,
checked_func = function() return FileChooser.show_finished end,
callback = function() FileChooser:toggleShowFilesMode("show_finished") end,
},
{
text = _("Show hidden files"),
checked_func = function() return self.ui.file_chooser.show_hidden end,
callback = function() self.ui:toggleHiddenFiles() end,
checked_func = function() return FileChooser.show_hidden end,
callback = function() FileChooser:toggleShowFilesMode("show_hidden") end,
},
{
text = _("Show unsupported files"),
checked_func = function() return self.ui.file_chooser.show_unsupported end,
callback = function() self.ui:toggleUnsupportedFiles() end,
checked_func = function() return FileChooser.show_unsupported end,
callback = function() FileChooser:toggleShowFilesMode("show_unsupported") end,
separator = true,
},
{
@ -439,7 +440,7 @@ To:
end,
callback = function()
G_reader_settings:flipNilOrFalse("reverse_collate")
self.ui.file_chooser:refreshPath()
FileChooser:refreshPath()
end,
}
self.menu_items.sort_mixed = {
@ -461,7 +462,7 @@ To:
end,
callback = function()
G_reader_settings:flipNilOrFalse("collate_mixed")
self.ui.file_chooser:refreshPath()
FileChooser:refreshPath()
end,
}
self.menu_items.start_with = self:getStartWithMenuTable()

@ -54,43 +54,45 @@ local settingsList = {
history = {category="none", event="ShowHist", title=_("History"), general=true},
favorites = {category="none", event="ShowColl", arg="favorites", title=_("Favorites"), general=true},
filemanager = {category="none", event="Home", title=_("File browser"), general=true, separator=true},
----
dictionary_lookup = {category="none", event="ShowDictionaryLookup", title=_("Dictionary lookup"), general=true},
wikipedia_lookup = {category="none", event="ShowWikipediaLookup", title=_("Wikipedia lookup"), general=true},
fulltext_search = {category="none", event="ShowFulltextSearchInput", title=_("Fulltext search"), general=true},
file_search = {category="none", event="ShowFileSearch", title=_("File search"), general=true, separator=true},
wikipedia_lookup = {category="none", event="ShowWikipediaLookup", title=_("Wikipedia lookup"), general=true, separator=true},
----
show_menu = {category="none", event="ShowMenu", title=_("Show menu"), general=true},
menu_search = {category="none", event="MenuSearch", title=_("Menu search"), general=true},
screenshot = {category="none", event="Screenshot", title=_("Screenshot"), general=true, separator=true},
----
-- Device settings
-- Device
exit_screensaver = {category="none", event="ExitScreensaver", title=_("Exit screensaver"), device=true},
suspend = {category="none", event="RequestSuspend", title=_("Suspend"), device=true, condition=Device:canSuspend()},
exit = {category="none", event="Exit", title=_("Exit KOReader"), device=true},
restart = {category="none", event="Restart", title=_("Restart KOReader"), device=true, condition=Device:canRestart()},
reboot = {category="none", event="RequestReboot", title=_("Reboot the device"), device=true, condition=Device:canReboot()},
poweroff = {category="none", event="RequestPowerOff", title=_("Power off"), device=true, condition=Device:canPowerOff(), separator=true},
poweroff = {category="none", event="RequestPowerOff", title=_("Power off"), device=true, condition=Device:canPowerOff()},
exit = {category="none", event="Exit", title=_("Exit KOReader"), device=true, separator=true},
----
toggle_hold_corners = {category="none", event="IgnoreHoldCorners", title=_("Toggle hold corners"), device=true},
touch_input_on = {category="none", event="IgnoreTouchInput", arg=false, title=_("Enable touch input"), device=true},
touch_input_off = {category="none", event="IgnoreTouchInput", arg=true, title=_("Disable touch input"), device=true},
toggle_touch_input = {category="none", event="IgnoreTouchInput", title=_("Toggle touch input"), device=true, separator=true},
----
swap_page_turn_buttons = {category="none", event="SwapPageTurnButtons", title=_("Invert page turn buttons"), device=true, condition=Device:hasKeys(), separator=true},
----
toggle_key_repeat = {category="none", event="ToggleKeyRepeat", title=_("Toggle key repeat"), device=true, condition=Device:hasKeys() and Device:canKeyRepeat(), separator=true},
toggle_gsensor = {category="none", event="ToggleGSensor", title=_("Toggle accelerometer"), device=true, condition=Device:hasGSensor()},
toggle_rotation = {category="none", event="SwapRotation", title=_("Toggle orientation"), device=true},
invert_rotation = {category="none", event="InvertRotation", title=_("Invert rotation"), device=true},
iterate_rotation = {category="none", event="IterateRotation", title=_("Rotate by 90° CW"), device=true},
iterate_rotation_ccw = {category="none", event="IterateRotation", arg=true, title=_("Rotate by 90° CCW"), device=true, separator=true},
----
wifi_on = {category="none", event="InfoWifiOn", title=_("Turn on Wi-Fi"), device=true, condition=Device:hasWifiToggle()},
wifi_off = {category="none", event="InfoWifiOff", title=_("Turn off Wi-Fi"), device=true, condition=Device:hasWifiToggle()},
toggle_wifi = {category="none", event="ToggleWifi", title=_("Toggle Wi-Fi"), device=true, condition=Device:hasWifiToggle()},
toggle_fullscreen = {category="none", event="ToggleFullscreen", title=_("Toggle Fullscreen"), device=true, condition=not Device:isAlwaysFullscreen()},
show_network_info = {category="none", event="ShowNetworkInfo", title=_("Show network info"), device=true, separator=true},
----
-- Screen & Lights
-- Screen and lights
show_frontlight_dialog = {category="none", event="ShowFlDialog", title=_("Show frontlight dialog"), screen=true, condition=Device:hasFrontlight()},
toggle_frontlight = {category="none", event="ToggleFrontlight", title=_("Toggle frontlight"), screen=true, condition=Device:hasFrontlight()},
set_frontlight = {category="absolutenumber", event="SetFlIntensity", min=0, max=Device:getPowerDevice().fl_max, title=_("Set frontlight brightness"), screen=true, condition=Device:hasFrontlight()},
@ -99,9 +101,9 @@ local settingsList = {
set_frontlight_warmth = {category="absolutenumber", event="SetFlWarmth", min=0, max=100, title=_("Set frontlight warmth"), screen=true, condition=Device:hasNaturalLight()},
increase_frontlight_warmth = {category="incrementalnumber", event="IncreaseFlWarmth", min=1, max=Device:getPowerDevice().fl_warmth_max, title=_("Increase frontlight warmth"), screen=true, condition=Device:hasNaturalLight()},
decrease_frontlight_warmth = {category="incrementalnumber", event="DecreaseFlWarmth", min=1, max=Device:getPowerDevice().fl_warmth_max, title=_("Decrease frontlight warmth"), screen=true, condition=Device:hasNaturalLight(), separator=true},
night_mode = {category="none", event="ToggleNightMode", title=_("Toggle night mode"), screen=true},
set_night_mode = {category="string", event="SetNightMode", title=_("Set night mode"), screen=true, args={true, false}, toggle={_("on"), _("off")}, separator=true},
----
full_refresh = {category="none", event="FullRefresh", title=_("Full screen refresh"), screen=true},
set_refresh_rate = {category="absolutenumber", event="SetBothRefreshRates", min=-1, max=200, title=_("Full refresh rate (always)"), screen=true, condition=Device:hasEinkScreen()},
set_day_refresh_rate = {category="absolutenumber", event="SetDayRefreshRate", min=-1, max=200, title=_("Full refresh rate (not in night mode)"), screen=true, condition=Device:hasEinkScreen()},
@ -109,23 +111,28 @@ local settingsList = {
set_flash_on_chapter_boundaries = {category="string", event="SetFlashOnChapterBoundaries", title=_("Always flash on chapter boundaries"), screen=true, condition=Device:hasEinkScreen(), args={true, false}, toggle={_("on"), _("off")}},
toggle_flash_on_chapter_boundaries = {category="none", event="ToggleFlashOnChapterBoundaries", title=_("Toggle flashing on chapter boundaries"), screen=true, condition=Device:hasEinkScreen()},
set_no_flash_on_second_chapter_page = {category="string", event="SetNoFlashOnSecondChapterPage", title=_("Never flash on chapter's 2nd page"), screen=true, condition=Device:hasEinkScreen(), args={true, false}, toggle={_("on"), _("off")}},
toggle_no_flash_on_second_chapter_page = {category="none", event="ToggleNoFlashOnSecondChapterPage", title=_("Toggle flashing on chapter's 2nd page"), screen=true, condition=Device:hasEinkScreen(), separator=true},
toggle_no_flash_on_second_chapter_page = {category="none", event="ToggleNoFlashOnSecondChapterPage", title=_("Toggle flashing on chapter's 2nd page"), screen=true, condition=Device:hasEinkScreen()},
set_flash_on_pages_with_images = {category="string", event="SetFlashOnPagesWithImages", title=_("Always flash on pages with images"), screen=true, condition=Device:hasEinkScreen(), args={true, false}, toggle={_("on"), _("off")}},
toggle_flash_on_pages_with_images = {category="none", event="ToggleFlashOnPagesWithImages", title=_("Toggle flashing on pages with images"), screen=true, condition=Device:hasEinkScreen()},
toggle_flash_on_pages_with_images = {category="none", event="ToggleFlashOnPagesWithImages", title=_("Toggle flashing on pages with images"), screen=true, condition=Device:hasEinkScreen(), separator=true},
----
-- filemanager settings
-- File browser
folder_up = {category="none", event="FolderUp", title=_("Folder up"), filemanager=true},
show_plus_menu = {category="none", event="ShowPlusMenu", title=_("Show plus menu"), filemanager=true},
toggle_select_mode = {category="none", event="ToggleSelectMode", title=_("Toggle select mode"), filemanager=true},
refresh_content = {category="none", event="RefreshContent", title=_("Refresh content"), filemanager=true},
folder_shortcuts = {category="none", event="ShowFolderShortcutsDialog", title=_("Folder shortcuts"), filemanager=true, separator=true},
folder_shortcuts = {category="none", event="ShowFolderShortcutsDialog", title=_("Folder shortcuts"), filemanager=true},
file_search = {category="none", event="ShowFileSearch", title=_("File search"), filemanager=true, separator=true},
----
-- go_to
-- back
-- reader settings
-- Reader
open_next_document_in_folder = {category="none", event="OpenNextDocumentInFolder", title=_("Open next document in folder"), reader=true, separator=true},
----
show_config_menu = {category="none", event="ShowConfigMenu", title=_("Show bottom menu"), reader=true},
toggle_status_bar = {category="none", event="ToggleFooterMode", title=_("Toggle status bar"), reader=true, separator=true},
----
prev_chapter = {category="none", event="GotoPrevChapter", title=_("Previous chapter"), reader=true},
next_chapter = {category="none", event="GotoNextChapter", title=_("Next chapter"), reader=true},
first_page = {category="none", event="GoToBeginning", title=_("First page"), reader=true},
@ -138,6 +145,7 @@ local settingsList = {
first_bookmark = {category="none", event="GotoFirstBookmark", title=_("First bookmark"), reader=true},
last_bookmark = {category="none", event="GotoLastBookmark", title=_("Last bookmark"), reader=true},
latest_bookmark = {category="none", event="GoToLatestBookmark", title=_("Latest bookmark"), reader=true, separator=true},
----
back = {category="none", event="Back", title=_("Back"), filemanager=true, reader=true},
previous_location = {category="none", event="GoBackLink", arg=true, title=_("Back to previous location"), reader=true},
next_location = {category="none", event="GoForwardLink", arg=true, title=_("Forward to next location"), reader=true},
@ -145,72 +153,77 @@ local settingsList = {
follow_nearest_internal_link = {category="arg", event="GoToInternalPageLink", arg={pos={x=0,y=0}}, title=_("Follow nearest internal link"), reader=true},
add_location_to_history = {category="none", event="AddCurrentLocationToStack", arg=true, title=_("Add current location to history"), reader=true},
clear_location_history = {category="none", event="ClearLocationStack", arg=true, title=_("Clear location history"), reader=true, separator=true},
----
fulltext_search = {category="none", event="ShowFulltextSearchInput", title=_("Fulltext search"), reader=true},
toc = {category="none", event="ShowToc", title=_("Table of contents"), reader=true},
book_map = {category="none", event="ShowBookMap", title=_("Book map"), reader=true, condition=Device:isTouchDevice()},
book_map_overview = {category="none", event="ShowBookMap", arg=true, title=_("Book map (overview)"), reader=true, condition=Device:isTouchDevice()},
page_browser = {category="none", event="ShowPageBrowser", title=_("Page browser"), reader=true, condition=Device:isTouchDevice()},
bookmarks = {category="none", event="ShowBookmark", title=_("Bookmarks"), reader=true},
bookmark_search = {category="none", event="SearchBookmark", title=_("Bookmark search"), reader=true, separator=true},
bookmark_search = {category="none", event="SearchBookmark", title=_("Bookmark search"), reader=true},
toggle_bookmark = {category="none", event="ToggleBookmark", title=_("Toggle bookmark"), reader=true, separator=true},
----
book_status = {category="none", event="ShowBookStatus", title=_("Book status"), reader=true},
book_info = {category="none", event="ShowBookInfo", title=_("Book information"), reader=true},
book_description = {category="none", event="ShowBookDescription", title=_("Book description"), reader=true},
book_cover = {category="none", event="ShowBookCover", title=_("Book cover"), reader=true, separator=true},
----
translate_page = {category="none", event="TranslateCurrentPage", title=_("Translate current page"), reader=true, separator=true},
----
toggle_page_change_animation = {category="none", event="TogglePageChangeAnimation", title=_("Toggle page turn animations"), reader=true, condition=Device:canDoSwipeAnimation()},
toggle_inverse_reading_order = {category="none", event="ToggleReadingOrder", title=_("Toggle page turn direction"), reader=true},
toggle_handmade_toc = {category="none", event="ToggleHandmadeToc", title=_("Toggle custom TOC"), reader=true},
toggle_handmade_flows = {category="none", event="ToggleHandmadeFlows", title=_("Toggle custom hidden flows"), reader=true, separator=true},
----
set_highlight_action = {category="string", event="SetHighlightAction", title=_("Set highlight action"), args_func=ReaderHighlight.getHighlightActions, reader=true},
cycle_highlight_action = {category="none", event="CycleHighlightAction", title=_("Cycle highlight action"), reader=true},
cycle_highlight_style = {category="none", event="CycleHighlightStyle", title=_("Cycle highlight style"), reader=true, separator=true},
----
flush_settings = {category="none", event="FlushSettings", arg=true, title=_("Save book metadata"), reader=true, separator=true},
----
-- rolling reader settings
-- Reflowable documents
set_font = {category="string", event="SetFont", title=_("Set font"), rolling=true, args_func=require("fontlist").getFontArgFunc,},
increase_font = {category="incrementalnumber", event="IncreaseFontSize", min=0.5, max=255, step=0.5, title=_("Increase font size"), rolling=true},
decrease_font = {category="incrementalnumber", event="DecreaseFontSize", min=0.5, max=255, step=0.5, title=_("Decrease font size"), rolling=true},
--
toggle_bookmark = {category="none", event="ToggleBookmark", title=_("Toggle bookmark"), reader=true},
toggle_page_change_animation = {category="none", event="TogglePageChangeAnimation", title=_("Toggle page turn animations"), reader=true, condition=Device:canDoSwipeAnimation()},
-- paging reader settings
-- Page layout documents
toggle_page_flipping = {category="none", event="TogglePageFlipping", title=_("Toggle page flipping"), paging=true},
toggle_bookmark_flipping = {category="none", event="ToggleBookmarkFlipping", title=_("Toggle bookmark flipping"), paging=true},
toggle_reflow = {category="none", event="ToggleReflow", title=_("Toggle reflow"), paging=true},
zoom = {category="string", event="SetZoomMode", title=_("Zoom mode"), args_func=ReaderZooming.getZoomModeActions, paging=true},
zoom_factor_change = {category="none", event="ZoomFactorChange", title=_("Change zoom factor"), paging=true, separator=true},
--
toggle_inverse_reading_order = {category="none", event="ToggleReadingOrder", title=_("Toggle page turn direction"), reader=true},
toggle_handmade_toc = {category="none", event="ToggleHandmadeToc", title=_("Toggle custom TOC"), reader=true},
toggle_handmade_flows = {category="none", event="ToggleHandmadeFlows", title=_("Toggle custom hidden flows"), reader=true, separator=true},
set_highlight_action = {category="string", event="SetHighlightAction", title=_("Set highlight action"), args_func=ReaderHighlight.getHighlightActions, reader=true},
cycle_highlight_action = {category="none", event="CycleHighlightAction", title=_("Cycle highlight action"), reader=true},
cycle_highlight_style = {category="none", event="CycleHighlightStyle", title=_("Cycle highlight style"), reader=true, separator=true},
flush_settings = {category="none", event="FlushSettings", arg=true, title=_("Save book metadata"), reader=true, separator=true},
----
panel_zoom_toggle = {category="none", event="TogglePanelZoomSetting", title=_("Toggle panel zoom"), paging=true, separator=true},
----
-- parsed from CreOptions
-- the rest of the table elements are built from their counterparts in CreOptions
rotation_mode = {category="string", device=true},
font_size = {category="absolutenumber", title=_("Set font size"), rolling=true, step=0.5},
word_spacing = {category="string", rolling=true},
word_expansion = {category="string", rolling=true},
font_gamma = {category="string", rolling=true},
font_base_weight = {category="string", rolling=true},
font_hinting = {category="string", rolling=true},
font_kerning = {category="string", rolling=true, separator=true},
----
visible_pages = {category="string", rolling=true, separator=true},
----
h_page_margins = {category="string", rolling=true},
sync_t_b_page_margins = {category="string", rolling=true},
t_page_margin = {category="absolutenumber", rolling=true},
b_page_margin = {category="absolutenumber", rolling=true, separator=true},
----
view_mode = {category="string", rolling=true},
block_rendering_mode = {category="string", rolling=true},
render_dpi = {category="string", title=_("Zoom"), rolling=true},
line_spacing = {category="absolutenumber", rolling=true, separator=true},
font_size = {category="absolutenumber", title=_("Set font size"), rolling=true, step=0.5},
font_base_weight = {category="string", rolling=true},
word_spacing = {category="string", rolling=true},
word_expansion = {category="string", rolling=true},
font_gamma = {category="string", rolling=true},
font_hinting = {category="string", rolling=true},
font_kerning = {category="string", rolling=true, separator=true},
----
status_line = {category="string", rolling=true},
embedded_css = {category="string", rolling=true},
embedded_fonts = {category="string", rolling=true},
smooth_scaling = {category="string", rolling=true},
nightmode_images = {category="string", rolling=true, separator=true},
nightmode_images = {category="string", rolling=true},
-- parsed from KoptOptions
kopt_trim_page = {category="string", paging=true},
@ -218,7 +231,7 @@ local settingsList = {
kopt_zoom_overlap_h = {category="absolutenumber", paging=true},
kopt_zoom_overlap_v = {category="absolutenumber", paging=true},
kopt_zoom_mode_type = {category="string", paging=true},
kopt_zoom_range_number = {category="string", paging=true},
-- kopt_zoom_range_number = {category="string", paging=true},
kopt_zoom_factor = {category="string", paging=true},
kopt_zoom_mode_genus = {category="string", paging=true},
kopt_zoom_direction = {category="string", paging=true},
@ -249,34 +262,36 @@ local settingsList = {
-- array for item order in menu
local dispatcher_menu_order = {
-- device
-- General
"reading_progress",
"open_previous_document",
"history",
"favorites",
"filemanager",
----
"dictionary_lookup",
"wikipedia_lookup",
"fulltext_search",
"file_search",
----
"show_menu",
"menu_search",
"screenshot",
----
-- Device
"exit_screensaver",
"suspend",
"exit",
"restart",
"reboot",
"poweroff",
"exit",
----
"toggle_hold_corners",
"touch_input_on",
"touch_input_off",
"toggle_touch_input",
----
"swap_page_turn_buttons",
----
"toggle_key_repeat",
"toggle_gsensor",
"rotation_mode",
@ -284,13 +299,15 @@ local dispatcher_menu_order = {
"invert_rotation",
"iterate_rotation",
"iterate_rotation_ccw",
----
"wifi_on",
"wifi_off",
"toggle_wifi",
"toggle_fullscreen",
"show_network_info",
----
-- Screen and lights
"show_frontlight_dialog",
"toggle_frontlight",
"set_frontlight",
@ -299,10 +316,9 @@ local dispatcher_menu_order = {
"set_frontlight_warmth",
"increase_frontlight_warmth",
"decrease_frontlight_warmth",
"night_mode",
"set_night_mode",
----
"full_refresh",
"set_refresh_rate",
"set_day_refresh_rate",
@ -313,20 +329,25 @@ local dispatcher_menu_order = {
"toggle_no_flash_on_second_chapter_page",
"set_flash_on_pages_with_images",
"toggle_flash_on_pages_with_images",
----
-- filemanager
-- File browser
"folder_up",
"show_plus_menu",
"toggle_select_mode",
"refresh_content",
"folder_shortcuts",
"file_search",
----
-- "go_to"
-- "back"
-- reader
-- Reader
"open_next_document_in_folder",
----
"show_config_menu",
"toggle_status_bar",
----
"prev_chapter",
"next_chapter",
"first_page",
@ -339,6 +360,7 @@ local dispatcher_menu_order = {
"first_bookmark",
"last_bookmark",
"latest_bookmark",
----
"back",
"previous_location",
"next_location",
@ -346,21 +368,36 @@ local dispatcher_menu_order = {
"follow_nearest_internal_link",
"add_location_to_history",
"clear_location_history",
----
"fulltext_search",
"toc",
"book_map",
"book_map_overview",
"page_browser",
"bookmarks",
"bookmark_search",
"toggle_bookmark",
----
"book_status",
"book_info",
"book_description",
"book_cover",
----
"translate_page",
----
"toggle_page_change_animation",
"toggle_inverse_reading_order",
"toggle_handmade_toc",
"toggle_handmade_flows",
----
"set_highlight_action",
"cycle_highlight_action",
"cycle_highlight_style",
----
"flush_settings",
----
-- Reflowable documents
"set_font",
"increase_font",
"decrease_font",
@ -371,44 +408,36 @@ local dispatcher_menu_order = {
"font_base_weight",
"font_hinting",
"font_kerning",
"toggle_bookmark",
"toggle_page_change_animation",
"toggle_page_flipping",
"toggle_bookmark_flipping",
"toggle_reflow",
"toggle_inverse_reading_order",
"toggle_handmade_toc",
"toggle_handmade_flows",
"zoom",
"zoom_factor_change",
"set_highlight_action",
"cycle_highlight_action",
"cycle_highlight_style",
"flush_settings",
"panel_zoom_toggle",
----
"visible_pages",
----
"h_page_margins",
"sync_t_b_page_margins",
"t_page_margin",
"b_page_margin",
----
"view_mode",
"block_rendering_mode",
"render_dpi",
"line_spacing",
----
"status_line",
"embedded_css",
"embedded_fonts",
"smooth_scaling",
"nightmode_images",
-- Fixed layout documents
"toggle_page_flipping",
"toggle_bookmark_flipping",
"toggle_reflow",
"zoom",
"zoom_factor_change",
----
"panel_zoom_toggle",
----
"kopt_trim_page",
"kopt_page_margin",
"kopt_zoom_overlap_h",
"kopt_zoom_overlap_v",
"kopt_zoom_mode_type",
@ -416,24 +445,20 @@ local dispatcher_menu_order = {
"kopt_zoom_factor",
"kopt_zoom_mode_genus",
"kopt_zoom_direction",
"kopt_page_scroll",
"kopt_page_gap_height",
"kopt_full_screen",
"kopt_line_spacing",
"kopt_justification",
"kopt_font_size",
"kopt_font_fine_tune",
"kopt_word_spacing",
"kopt_text_wrap",
"kopt_contrast",
"kopt_page_opt",
"kopt_hw_dithering",
"kopt_sw_dithering",
"kopt_quality",
"kopt_doc_language",
"kopt_forced_ocr",
"kopt_writing_direction",
@ -996,12 +1021,13 @@ end
function Dispatcher:isActionEnabled(action)
local disabled = true
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 context = ui and (ui.paging and "paging" or "rolling")
if context == "paging" then
disabled = action["rolling"]
disabled = action["rolling"] or for_fm_only
elseif context == "rolling" then
disabled = action["paging"]
disabled = action["paging"] or for_fm_only
else -- FM
disabled = (action["reader"] or action["rolling"] or action["paging"]) and not action["filemanager"]
end

@ -22,10 +22,10 @@ local FileChooser = Menu:extend{
path = lfs.currentdir(),
show_path = true,
parent = nil,
show_hidden = false, -- set to true to show folders/files starting with "."
show_finished = G_reader_settings:readSetting("show_finished", true), -- books marked as finished
show_hidden = G_reader_settings:readSetting("show_hidden", false), -- folders/files starting with "."
show_unsupported = G_reader_settings:readSetting("show_unsupported", false), -- set to true to ignore file_filter
file_filter = nil, -- function defined in the caller, returns true for files to be shown
show_unsupported = false, -- set to true to ignore file_filter
show_finished = true, -- show all books
-- NOTE: Input is *always* a relative entry name
exclude_dirs = { -- const
-- KOReader / Kindle
@ -101,7 +101,6 @@ end
function FileChooser:init()
self.path_items = {}
self.width = Screen:getWidth()
self.item_table = self:genItemTableFromPath(self.path)
Menu.init(self) -- call parent's init()
end
@ -121,7 +120,7 @@ function FileChooser:getList(path, collate)
if attributes.mode == "directory" and f ~= "." and f ~= ".." then
if self:show_dir(f) then
if collate then -- when collate == nil count only to display in folder mandatory
item = self:getListItem(f, filename, attributes)
item = FileChooser.getListItem(f, filename, attributes)
end
table.insert(dirs, item)
end
@ -129,7 +128,7 @@ function FileChooser:getList(path, collate)
elseif attributes.mode == "file" and not util.stringStartsWith(f, "._") then
if self:show_file(f, filename) then
if collate then -- when collate == nil count only to display in folder mandatory
item = self:getListItem(f, filename, attributes, collate)
item = FileChooser.getListItem(f, filename, attributes, collate)
end
table.insert(files, item)
end
@ -140,7 +139,7 @@ function FileChooser:getList(path, collate)
else -- error, probably "permission denied"
if unreadable_dir_content[path] then
-- Add this dummy item that will be replaced with a message by genItemTable()
table.insert(dirs, self:getListItem("./.", path, lfs.attributes(path)))
table.insert(dirs, FileChooser.getListItem("./.", path, lfs.attributes(path)))
-- If we knew about some content (if we had come up from them
-- to this directory), have them shown
for k, v in pairs(unreadable_dir_content[path]) do
@ -155,7 +154,7 @@ function FileChooser:getList(path, collate)
return dirs, files
end
function FileChooser:getListItem(f, filename, attributes, collate)
function FileChooser.getListItem(f, filename, attributes, collate)
local item = {
text = f,
fullpath = filename,
@ -454,18 +453,10 @@ function FileChooser:changePageToPath(path)
end
end
function FileChooser:toggleFinishedBooks()
self.show_finished = not self.show_finished
self:refreshPath()
end
function FileChooser:toggleHiddenFiles()
self.show_hidden = not self.show_hidden
self:refreshPath()
end
function FileChooser:toggleUnsupportedFiles()
self.show_unsupported = not self.show_unsupported
function FileChooser:toggleShowFilesMode(mode)
-- modes: "show_finished", "show_hidden", "show_unsupported"
FileChooser[mode] = not FileChooser[mode]
G_reader_settings:saveSetting(mode, FileChooser[mode])
self:refreshPath()
end

@ -1,6 +1,5 @@
local BD = require("ui/bidi")
local ButtonDialog = require("ui/widget/buttondialog")
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
local Device = require("device")
local Event = require("ui/event")
local FileChooser = require("ui/widget/filechooser")
@ -36,10 +35,12 @@ function PathChooser:init()
self.title = _("Long-press to choose")
end
end
self.show_hidden = G_reader_settings:isTrue("show_hidden")
if not self.show_files then
self.file_filter = function() return false end -- filter out regular files
end
if self.file_filter then
self.show_unsupported = false -- honour file_filter
end
if self.select_directory then
-- Let FileChooser display "Long-press to choose current folder"
self.show_current_dir_for_hold = true
@ -127,7 +128,7 @@ function PathChooser:onMenuHold(item)
title = T(_("Choose this path?\n\n%1"), BD.path(path))
end
local onConfirm = self.onConfirm
self.button_dialog = ButtonDialogTitle:new{
self.button_dialog = ButtonDialog:new{
title = title,
buttons = {
{

@ -316,12 +316,14 @@ function CoverMenu:updateItems(select_number)
-- Fudge the "Reset settings" button callback to also trash the cover_info_cache
local button = self.file_dialog:getButtonById("reset")
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
self:updateCache(file)
-- And then purge the sidecar folder as expected
orig_purge_callback()
if button then
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
self:updateCache(file)
-- And then purge the sidecar folder as expected
orig_purge_callback()
end
end
-- Fudge the status change button callbacks to also update the cover_info_cache
@ -345,18 +347,20 @@ function CoverMenu:updateItems(select_number)
end
button = self.file_dialog:getButtonById("book_cover")
if not bookinfo.has_cover then
if button and not bookinfo.has_cover then
button:disable()
end
button = self.file_dialog:getButtonById("book_description")
if bookinfo.description then
button.callback = function()
UIManager:close(self.file_dialog)
FileManagerBookInfo:onShowBookDescription(bookinfo.description)
if button then
if bookinfo.description then
button.callback = function()
UIManager:close(self.file_dialog)
FileManagerBookInfo:onShowBookDescription(bookinfo.description)
end
else
button:disable()
end
else
button:disable()
end
UIManager:show(self.file_dialog)
@ -443,12 +447,14 @@ function CoverMenu:onHistoryMenuHold(item)
-- Fudge the "Reset settings" button callback to also trash the cover_info_cache
local button = self.histfile_dialog:getButtonById("reset")
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
self:updateCache(file)
-- And then purge the sidecar folder as expected
orig_purge_callback()
if button then
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
self:updateCache(file)
-- And then purge the sidecar folder as expected
orig_purge_callback()
end
end
-- Fudge the status change button callbacks to also update the cover_info_cache
@ -472,18 +478,20 @@ function CoverMenu:onHistoryMenuHold(item)
end
button = self.histfile_dialog:getButtonById("book_cover")
if not bookinfo.has_cover then
if button and not bookinfo.has_cover then
button:disable()
end
button = self.histfile_dialog:getButtonById("book_description")
if bookinfo.description then
button.callback = function()
UIManager:close(self.histfile_dialog)
FileManagerBookInfo:onShowBookDescription(bookinfo.description)
if button then
if bookinfo.description then
button.callback = function()
UIManager:close(self.histfile_dialog)
FileManagerBookInfo:onShowBookDescription(bookinfo.description)
end
else
button:disable()
end
else
button:disable()
end
UIManager:show(self.histfile_dialog)
@ -563,12 +571,14 @@ function CoverMenu:onCollectionsMenuHold(item)
-- Fudge the "Reset settings" button callback to also trash the cover_info_cache
local button = self.collfile_dialog:getButtonById("reset")
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
self:updateCache(file)
-- And then purge the sidecar folder as expected
orig_purge_callback()
if button then
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
self:updateCache(file)
-- And then purge the sidecar folder as expected
orig_purge_callback()
end
end
-- Fudge the status change button callbacks to also update the cover_info_cache
@ -592,18 +602,20 @@ function CoverMenu:onCollectionsMenuHold(item)
end
button = self.collfile_dialog:getButtonById("book_cover")
if not bookinfo.has_cover then
if button and not bookinfo.has_cover then
button:disable()
end
button = self.collfile_dialog:getButtonById("book_description")
if bookinfo.description then
button.callback = function()
UIManager:close(self.collfile_dialog)
FileManagerBookInfo:onShowBookDescription(bookinfo.description)
if button then
if bookinfo.description then
button.callback = function()
UIManager:close(self.collfile_dialog)
FileManagerBookInfo:onShowBookDescription(bookinfo.description)
end
else
button:disable()
end
else
button:disable()
end
UIManager:show(self.collfile_dialog)

Loading…
Cancel
Save