diff --git a/frontend/apps/filemanager/filemanagermenu.lua b/frontend/apps/filemanager/filemanagermenu.lua index 1d2f75ddf..86195779f 100644 --- a/frontend/apps/filemanager/filemanagermenu.lua +++ b/frontend/apps/filemanager/filemanagermenu.lua @@ -136,12 +136,6 @@ function FileManagerMenu:onOpenLastDoc() end function FileManagerMenu:setUpdateItemTable() - for _, widget in pairs(self.registered_widgets) do - local ok, err = pcall(widget.addToMainMenu, widget, self.menu_items) - if not ok then - logger.err("failed to register widget", widget.name, err) - end - end -- setting tab self.menu_items.filebrowser_settings = { @@ -159,131 +153,186 @@ function FileManagerMenu:setUpdateItemTable() separator = true, }, { - text = _("Items per page"), - help_text = _([[This sets the number of items per page in: + text = _("Classic mode settings"), + sub_item_table = { + { + text = _("Items per page"), + help_text = _([[This sets the number of items per page in: - File browser, history and favorites in 'classic' display mode - Search results and folder shortcuts -- File and directory selection +- File and folder selection - Calibre and OPDS browsers/search results]]), - keep_menu_open = true, - callback = function() - local SpinWidget = require("ui/widget/spinwidget") - local Menu = require("ui/widget/menu") - local default_perpage = Menu.items_per_page_default - local curr_perpage = G_reader_settings:readSetting("items_per_page") or default_perpage - local items = SpinWidget:new{ - width = math.floor(Screen:getWidth() * 0.6), - value = curr_perpage, - value_min = 6, - value_max = 24, - default_value = default_perpage, - title_text = _("Items per page"), - keep_shown_on_apply = true, - callback = function(spin) - G_reader_settings:saveSetting("items_per_page", spin.value) + callback = function() + local SpinWidget = require("ui/widget/spinwidget") + local Menu = require("ui/widget/menu") + local default_perpage = Menu.items_per_page_default + local curr_perpage = G_reader_settings:readSetting("items_per_page") or default_perpage + local items = SpinWidget:new{ + width = math.floor(Screen:getWidth() * 0.6), + value = curr_perpage, + value_min = 6, + value_max = 24, + default_value = default_perpage, + title_text = _("Items per page"), + keep_shown_on_apply = true, + callback = function(spin) + G_reader_settings:saveSetting("items_per_page", spin.value) + self.ui:onRefresh() + end + } + UIManager:show(items) + end, + }, + { + text = _("Item font size"), + callback = function() + local SpinWidget = require("ui/widget/spinwidget") + local Menu = require("ui/widget/menu") + local curr_perpage = G_reader_settings:readSetting("items_per_page") or Menu.items_per_page_default + local default_font_size = Menu.getItemFontSize(curr_perpage) + local curr_font_size = G_reader_settings:readSetting("items_font_size") or default_font_size + local items_font = SpinWidget:new{ + width = math.floor(Screen:getWidth() * 0.6), + value = curr_font_size, + value_min = 10, + value_max = 72, + default_value = default_font_size, + keep_shown_on_apply = true, + title_text = _("Item font size"), + callback = function(spin) + if spin.value == default_font_size then + -- We can't know if the user has set a size or hit "Use default", but + -- assume that if it is the default font size, he will prefer to have + -- our default font size if he later updates per-page + G_reader_settings:delSetting("items_font_size") + else + G_reader_settings:saveSetting("items_font_size", spin.value) + end + self.ui:onRefresh() + end + } + UIManager:show(items_font) + end, + }, + { + text = _("Shrink item font size to fit more text"), + checked_func = function() + return G_reader_settings:isTrue("items_multilines_show_more_text") + end, + callback = function() + G_reader_settings:flipNilOrFalse("items_multilines_show_more_text") self.ui:onRefresh() - end - } - UIManager:show(items) - end, - }, - { - text = _("Item font size"), - keep_menu_open = true, - callback = function() - local SpinWidget = require("ui/widget/spinwidget") - local Menu = require("ui/widget/menu") - local curr_perpage = G_reader_settings:readSetting("items_per_page") or Menu.items_per_page_default - local default_font_size = Menu.getItemFontSize(curr_perpage) - local curr_font_size = G_reader_settings:readSetting("items_font_size") or default_font_size - local items_font = SpinWidget:new{ - width = math.floor(Screen:getWidth() * 0.6), - value = curr_font_size, - value_min = 10, - value_max = 72, - default_value = default_font_size, - keep_shown_on_apply = true, - title_text = _("Item font size"), - callback = function(spin) - if spin.value == default_font_size then - -- We can't know if the user has set a size or hit "Use default", but - -- assume that if it is the default font size, he will prefer to have - -- our default font size if he later updates per-page - G_reader_settings:delSetting("items_font_size") + end, + separator = true, + }, + { + text = _("Show opened files in bold"), + checked_func = function() + return G_reader_settings:readSetting("show_file_in_bold") == "opened" + end, + callback = function() + if G_reader_settings:readSetting("show_file_in_bold") == "opened" then + G_reader_settings:saveSetting("show_file_in_bold", false) else - G_reader_settings:saveSetting("items_font_size", spin.value) + G_reader_settings:saveSetting("show_file_in_bold", "opened") end self.ui:onRefresh() - end - } - UIManager:show(items_font) - end, - }, - { - text = _("Shrink item font size to fit more text"), - keep_menu_open = true, - checked_func = function() - return G_reader_settings:isTrue("items_multilines_show_more_text") - end, - callback = function() - G_reader_settings:flipNilOrFalse("items_multilines_show_more_text") - self.ui:onRefresh() - end, + end, + }, + { + text = _("Show new (not yet opened) files in bold"), + checked_func = function() + return G_reader_settings:hasNot("show_file_in_bold") + end, + callback = function() + if G_reader_settings:hasNot("show_file_in_bold") then + G_reader_settings:saveSetting("show_file_in_bold", false) + else + G_reader_settings:delSetting("show_file_in_bold") + end + self.ui:onRefresh() + end, + }, + }, }, { - text_func = function() - local current_state = _("Show new files in bold") - if G_reader_settings:readSetting("show_file_in_bold") == "opened" then - current_state = _("Show opened files in bold") - elseif G_reader_settings:isFalse("show_file_in_bold") then - current_state = _("Show files in bold") -- with checkmark unchecked - end - -- Inform that this settings applies only to classic file chooser - current_state = T(_("(Classic file browser) %1"), current_state) - return current_state - end, - checked_func = function() return not G_reader_settings:isFalse("show_file_in_bold") end, + text = _("History settings"), sub_item_table = { { - text = _("Don't show files in bold"), - checked_func = function() return G_reader_settings:isFalse("show_file_in_bold") end, + text = _("Clear history of deleted files"), callback = function() - G_reader_settings:saveSetting("show_file_in_bold", false) - self.ui:onRefresh() + UIManager:show(ConfirmBox:new{ + text = _("Clear history of deleted files?"), + ok_text = _("Clear"), + ok_callback = function() + require("readhistory"):clearMissing() + end, + }) end, }, { - text = _("Show opened files in bold"), - checked_func = function() return G_reader_settings:readSetting("show_file_in_bold") == "opened" end, + text = _("Auto-remove deleted or purged items from history"), + checked_func = function() + return G_reader_settings:isTrue("autoremove_deleted_items_from_history") + end, callback = function() - G_reader_settings:saveSetting("show_file_in_bold", "opened") - self.ui:onRefresh() + G_reader_settings:flipNilOrFalse("autoremove_deleted_items_from_history") end, + separator = true, }, { - text = _("Show new (not yet opened) files in bold"), + text = _("Show filename in Open last/previous menu items"), checked_func = function() - return not G_reader_settings:isFalse("show_file_in_bold") and G_reader_settings:readSetting("show_file_in_bold") ~= "opened" + return G_reader_settings:isTrue("open_last_menu_show_filename") end, callback = function() - G_reader_settings:delSetting("show_file_in_bold") - self.ui:onRefresh() + G_reader_settings:flipNilOrFalse("open_last_menu_show_filename") end, }, }, - separator = true, }, { - text = _("Shorten home folder"), - checked_func = function() - return G_reader_settings:nilOrTrue("shorten_home_dir") - end, - callback = function() - G_reader_settings:flipNilOrTrue("shorten_home_dir") - local FileManager = require("apps/filemanager/filemanager") - if FileManager.instance then FileManager.instance:reinit() end - end, - help_text = _([[ + text = _("Home folder settings"), + sub_item_table = { + { + text = _("Set home folder"), + callback = function() + local text + local home_dir = G_reader_settings:readSetting("home_dir") + if home_dir then + text = T(_("Home folder is set to:\n%1"), home_dir) + else + text = _("Home folder is not set.") + home_dir = Device.home_dir + end + UIManager:show(ConfirmBox:new{ + text = text .. "\nChoose new folder to set as home?", + ok_text = _("Choose folder"), + ok_callback = function() + local path_chooser = require("ui/widget/pathchooser"):new{ + select_file = false, + show_files = false, + path = home_dir, + onConfirm = function(new_path) + G_reader_settings:saveSetting("home_dir", new_path) + end + } + UIManager:show(path_chooser) + end, + }) + end, + }, + { + text = _("Shorten home folder"), + checked_func = function() + return G_reader_settings:nilOrTrue("shorten_home_dir") + end, + callback = function() + G_reader_settings:flipNilOrTrue("shorten_home_dir") + local FileManager = require("apps/filemanager/filemanager") + if FileManager.instance then FileManager.instance:reinit() end + end, + help_text = _([[ "Shorten home folder" will display the home folder itself as "Home" instead of its full path. Assuming the home folder is: @@ -292,16 +341,21 @@ A subfolder will be shortened from: `/mnt/onboard/.books/Manga/Cells at Work` To: `Manga/Cells at Work`.]]), - }, - { - text = _("Show filename in Open last/previous menu items"), - checked_func = function() return G_reader_settings:isTrue("open_last_menu_show_filename") end, - callback = function() G_reader_settings:flipNilOrFalse("open_last_menu_show_filename") end, - }, - { - text = _("Auto-remove deleted or purged items from history"), - checked_func = function() return G_reader_settings:isTrue("autoremove_deleted_items_from_history") end, - callback = function() G_reader_settings:flipNilOrFalse("autoremove_deleted_items_from_history") end, + }, + { + text = _("Lock home folder"), + enabled_func = function() + return G_reader_settings:has("home_dir") + end, + checked_func = function() + return G_reader_settings:isTrue("lock_home_folder") + end, + callback = function() + G_reader_settings:flipNilOrFalse("lock_home_folder") + self.ui:onRefresh() + end, + }, + }, separator = true, }, { @@ -340,6 +394,14 @@ To: }, } } + + for _, widget in pairs(self.registered_widgets) do + local ok, err = pcall(widget.addToMainMenu, widget, self.menu_items) + if not ok then + logger.err("failed to register widget", widget.name, err) + end + end + self.menu_items.sort_by = self.ui:getSortingMenuTable() self.menu_items.reverse_sorting = { text = _("Reverse sorting"), diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index 36d529b0d..d5541dade 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -264,7 +264,10 @@ function FileChooser:genItemTableFromPath(path) table.sort(dirs, sorting) table.sort(files, sorting) end - if path ~= "/" then table.insert(dirs, 1, {name = ".."}) end + if path ~= "/" and not (G_reader_settings:isTrue("lock_home_folder") and + path == G_reader_settings:readSetting("home_dir")) then + table.insert(dirs, 1, {name = ".."}) + end if self.show_current_dir_for_hold then table.insert(dirs, 1, {name = "."}) end local item_table = {} @@ -394,7 +397,10 @@ function FileChooser:changeToPath(path, focused_path) end function FileChooser:onFolderUp() - self:changeToPath(string.format("%s/..", self.path), self.path) + if not (G_reader_settings:isTrue("lock_home_folder") and + self.path == G_reader_settings:readSetting("home_dir")) then + self:changeToPath(string.format("%s/..", self.path), self.path) + end end function FileChooser:changePageToPath(path) diff --git a/plugins/coverbrowser.koplugin/main.lua b/plugins/coverbrowser.koplugin/main.lua index d5c9e2ddb..e091197de 100644 --- a/plugins/coverbrowser.koplugin/main.lua +++ b/plugins/coverbrowser.koplugin/main.lua @@ -178,7 +178,6 @@ function CoverBrowser:addToMainMenu(menu_items) callback = function() self:setupHistoryDisplayMode("list_image_filename") end, - separator = true, }, }, }, @@ -226,152 +225,155 @@ function CoverBrowser:addToMainMenu(menu_items) callback = function() self:setupCollectionDisplayMode("list_image_filename") end, - separator = true, }, }, - separator = true, }, - -- Misc settings + }, + } + + -- add Mosaic / Detailed list mode settings to File browser Settings submenu + -- next to Classic mode settings + if menu_items.filebrowser_settings == nil then return end + table.insert (menu_items.filebrowser_settings.sub_item_table, 4, { + text = _("Mosaic and detailed list settings"), + separator = true, + sub_item_table = { { - text = _("Mosaic and detailed list settings"), + text = _("Items per page"), + help_text = _([[This sets the number of files and folders per page in display modes other than classic.]]), + -- Best to not "keep_menu_open = true", to see how this apply on the full view + callback = function() + local SpinWidget = require("ui/widget/spinwidget") + -- "files_per_page" should have been saved with an adequate value + -- the first time Detailed list was shown. Fallback to a start + -- value of 10 if it hasn't. + local curr_items = BookInfoManager:getSetting("files_per_page") or 10 + local items = SpinWidget:new{ + width = math.floor(Screen:getWidth() * 0.6), + value = curr_items, + value_min = 4, + value_max = 20, + default_value = 10, + keep_shown_on_apply = true, + title_text = _("Items per page"), + callback = function(spin) + BookInfoManager:saveSetting("files_per_page", spin.value) + self.ui:onRefresh() + end + } + UIManager:show(items) + end, + }, + { + text = _("Display hints"), sub_item_table = { { - text = _("Display hints"), - sub_item_table = { - { - text = _("Show hint for books with description"), - checked_func = function() return not BookInfoManager:getSetting("no_hint_description") end, - callback = function() - if BookInfoManager:getSetting("no_hint_description") then - BookInfoManager:saveSetting("no_hint_description", false) - else - BookInfoManager:saveSetting("no_hint_description", true) - end - self:refreshFileManagerInstance() - end, - }, - { - text = _("Show hint for opened books in history"), - checked_func = function() return BookInfoManager:getSetting("history_hint_opened") end, - callback = function() - if BookInfoManager:getSetting("history_hint_opened") then - BookInfoManager:saveSetting("history_hint_opened", false) - else - BookInfoManager:saveSetting("history_hint_opened", true) - end - self:refreshFileManagerInstance() - end, - }, - { - text = _("Show hint for opened books in favorites"), - checked_func = function() return BookInfoManager:getSetting("collections_hint_opened") end, - callback = function() - if BookInfoManager:getSetting("collections_hint_opened") then - BookInfoManager:saveSetting("collections_hint_opened", false) - else - BookInfoManager:saveSetting("collections_hint_opened", true) - end - self:refreshFileManagerInstance() - end, - } - } + text = _("Show hint for books with description"), + checked_func = function() return not BookInfoManager:getSetting("no_hint_description") end, + callback = function() + if BookInfoManager:getSetting("no_hint_description") then + BookInfoManager:saveSetting("no_hint_description", false) + else + BookInfoManager:saveSetting("no_hint_description", true) + end + self:refreshFileManagerInstance() + end, }, { - text = _("Series"), - sub_item_table = { - { - text = _("Append series metadata to authors"), - checked_func = function() return series_mode == "append_series_to_authors" end, - callback = function() - if series_mode == "append_series_to_authors" then - series_mode = nil - else - series_mode = "append_series_to_authors" - end - BookInfoManager:saveSetting("series_mode", series_mode) - self:refreshFileManagerInstance() - end, - }, - { - text = _("Append series metadata to title"), - checked_func = function() return series_mode == "append_series_to_title" end, - callback = function() - if series_mode == "append_series_to_title" then - series_mode = nil - else - series_mode = "append_series_to_title" - end - BookInfoManager:saveSetting("series_mode", series_mode) - self:refreshFileManagerInstance() - end, - }, - { - text = _("Show series metadata in separate line"), - checked_func = function() return series_mode == "series_in_separate_line" end, - callback = function() - if series_mode == "series_in_separate_line" then - series_mode = nil - else - series_mode = "series_in_separate_line" - end - BookInfoManager:saveSetting("series_mode", series_mode) - self:refreshFileManagerInstance() - end, - }, - }, - separator = true + text = _("Show hint for opened books in history"), + checked_func = function() return BookInfoManager:getSetting("history_hint_opened") end, + callback = function() + if BookInfoManager:getSetting("history_hint_opened") then + BookInfoManager:saveSetting("history_hint_opened", false) + else + BookInfoManager:saveSetting("history_hint_opened", true) + end + self:refreshFileManagerInstance() + end, }, { - text = _("(Detailed list) Files per page"), - help_text = _([[This sets the number of files and directories per page in non-'classic' display modes.]]), - -- Best to not "keep_menu_open = true", to see how this apply on the full view + text = _("Show hint for opened books in favorites"), + checked_func = function() return BookInfoManager:getSetting("collections_hint_opened") end, callback = function() - local SpinWidget = require("ui/widget/spinwidget") - -- "files_per_page" should have been saved with an adequate value - -- the first time Detailed list was shown. Fallback to a start - -- value of 10 if it hasn't. - local curr_items = BookInfoManager:getSetting("files_per_page") or 10 - local items = SpinWidget:new{ - width = math.floor(Screen:getWidth() * 0.6), - value = curr_items, - value_min = 4, - value_max = 20, - keep_shown_on_apply = true, - title_text = _("Files per page"), - callback = function(spin) - BookInfoManager:saveSetting("files_per_page", spin.value) - self.ui:onRefresh() - end - } - UIManager:show(items) + if BookInfoManager:getSetting("collections_hint_opened") then + BookInfoManager:saveSetting("collections_hint_opened", false) + else + BookInfoManager:saveSetting("collections_hint_opened", true) + end + self:refreshFileManagerInstance() + end, + } + } + }, + { + text = _("Series"), + sub_item_table = { + { + text = _("Append series metadata to authors"), + checked_func = function() return series_mode == "append_series_to_authors" end, + callback = function() + if series_mode == "append_series_to_authors" then + series_mode = nil + else + series_mode = "append_series_to_authors" + end + BookInfoManager:saveSetting("series_mode", series_mode) + self:refreshFileManagerInstance() end, }, { - text = _("Show number of pages read instead of progress %"), - checked_func = function() return BookInfoManager:getSetting("show_pages_read_as_progress") end, + text = _("Append series metadata to title"), + checked_func = function() return series_mode == "append_series_to_title" end, callback = function() - if BookInfoManager:getSetting("show_pages_read_as_progress") then - BookInfoManager:saveSetting("show_pages_read_as_progress", false) + if series_mode == "append_series_to_title" then + series_mode = nil else - BookInfoManager:saveSetting("show_pages_read_as_progress", true) + series_mode = "append_series_to_title" end + BookInfoManager:saveSetting("series_mode", series_mode) self:refreshFileManagerInstance() end, }, { - text = _("Show number of pages left to read"), - checked_func = function() return BookInfoManager:getSetting("show_pages_left_in_progress") end, + text = _("Show series metadata in separate line"), + checked_func = function() return series_mode == "series_in_separate_line" end, callback = function() - if BookInfoManager:getSetting("show_pages_left_in_progress") then - BookInfoManager:saveSetting("show_pages_left_in_progress", false) + if series_mode == "series_in_separate_line" then + series_mode = nil else - BookInfoManager:saveSetting("show_pages_left_in_progress", true) + series_mode = "series_in_separate_line" end + BookInfoManager:saveSetting("series_mode", series_mode) self:refreshFileManagerInstance() end, - separator = true }, }, + separator = true + }, + { + text = _("Show number of pages read instead of progress %"), + checked_func = function() return BookInfoManager:getSetting("show_pages_read_as_progress") end, + callback = function() + if BookInfoManager:getSetting("show_pages_read_as_progress") then + BookInfoManager:saveSetting("show_pages_read_as_progress", false) + else + BookInfoManager:saveSetting("show_pages_read_as_progress", true) + end + self:refreshFileManagerInstance() + end, + }, + { + text = _("Show number of pages left to read"), + checked_func = function() return BookInfoManager:getSetting("show_pages_left_in_progress") end, + callback = function() + if BookInfoManager:getSetting("show_pages_left_in_progress") then + BookInfoManager:saveSetting("show_pages_left_in_progress", false) + else + BookInfoManager:saveSetting("show_pages_left_in_progress", true) + end + self:refreshFileManagerInstance() + end, + separator = true, }, { text = _("Book info cache management"), @@ -447,7 +449,7 @@ function CoverBrowser:addToMainMenu(menu_items) }, }, }, - } + }) end function CoverBrowser:refreshFileManagerInstance(cleanup, post_init)