From 56b277f72e200f1f2ef06194e0fbc22225b99725 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Sat, 19 Feb 2022 11:44:10 +0200 Subject: [PATCH] filemanager: free home button, text viewer --- frontend/apps/filemanager/filemanager.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index c7e69cf73..9593fbbb7 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -113,7 +113,7 @@ function FileManager:setupLayout() left_icon = "home", left_icon_size_ratio = 1, left_icon_tap_callback = function() self:goHome() end, - left_icon_hold_callback = function() self:setHome() end, + left_icon_hold_callback = false, -- propagate long-press to dispatcher right_icon = "plus", right_icon_size_ratio = 1, right_icon_tap_callback = function() self:onShowPlusMenu() end, @@ -331,6 +331,12 @@ function FileManager:setupLayout() callback = function() UIManager:close(self.file_dialog) local one_time_providers = {} + table.insert(one_time_providers, { + provider_name = _("Text viewer"), + callback = function() + file_manager:openTextViewer(file) + end, + }) if file_manager.texteditor then table.insert(one_time_providers, { provider_name = _("Text editor"), @@ -1279,6 +1285,18 @@ function FileManager:showFiles(path, focused_file) UIManager:show(file_manager) end +function FileManager:openTextViewer(file_path) + local file = io.open(file_path, "rb") + if not file then return end + local file_content = file:read("*all") + file:close() + UIManager:show(require("ui/widget/textviewer"):new{ + title = file_path, + title_multilines = true, + text = file_content, + }) +end + --- A shortcut to execute mv. -- @treturn boolean result of mv command function FileManager:moveFile(from, to)