From 89f7f5ac2d7c279a1ae0d243a564b520ac86cac1 Mon Sep 17 00:00:00 2001 From: Artjoms Rizihs Date: Wed, 23 Apr 2025 16:07:13 +0300 Subject: [PATCH] Change random document to open any random document, long-press for any unopened document (#13160) --- frontend/apps/filemanager/filemanager.lua | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index ddfbff6a2..9b4ce2c52 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -705,7 +705,13 @@ function FileManager:tapPlus() text = _("Open random document"), callback = function() UIManager:close(plus_dialog) - self:openRandomFile(self.file_chooser.path) + -- any random document + self:openRandomFile(self.file_chooser.path, false) + end, + hold_callback = function() + UIManager:close(plus_dialog) + -- only previously unopened + self:openRandomFile(self.file_chooser.path, true) end }, }, @@ -863,9 +869,13 @@ function FileManager:setHome(path) return true end -function FileManager:openRandomFile(dir) - local match_func = function(file) -- documents, not yet opened - return DocumentRegistry:hasProvider(file) and not BookList.hasBookBeenOpened(file) +function FileManager:openRandomFile(dir, unopened_only) + local match_func = function(file) + if unopened_only then + return DocumentRegistry:hasProvider(file) and not BookList.hasBookBeenOpened(file) + else + return DocumentRegistry:hasProvider(file) + end end local random_file = filemanagerutil.getRandomFile(dir, match_func) if random_file then @@ -879,7 +889,7 @@ function FileManager:openRandomFile(dir) -- @translators Another file. This is a button on the open random file dialog. It presents a file with the choices Open/Another. choice2_text = _("Another"), choice2_callback = function() - self:openRandomFile(dir) + self:openRandomFile(dir, unopened_only) end, }) else