From 69e6b6b9cbf0a0ad06f5cef5ffedabe6da93947a Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 12 Mar 2015 16:29:15 +0800 Subject: [PATCH] hold on directory in filemanager can set the it as HOME directory and this "HOME" directory will override the command line option passed to koreader. This patch implements #1434. --- frontend/apps/filemanager/filemanager.lua | 93 +++++++++++++---------- reader.lua | 3 +- 2 files changed, 55 insertions(+), 41 deletions(-) diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index 52cb23bea..6ba1e128b 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -75,52 +75,65 @@ function FileManager:init() function file_chooser:onFileHold(file) --DEBUG("hold file", file) - self.file_dialog = ButtonDialog:new{ - buttons = { + local buttons = { + { + { + text = _("Copy"), + callback = function() + copyFile(file) + UIManager:close(self.file_dialog) + end, + }, + { + text = _("Paste"), + enabled = fileManager.clipboard and true or false, + callback = function() + pasteHere(file) + self:refreshPath() + UIManager:close(self.file_dialog) + end, + }, + }, + { { - { - text = _("Copy"), - callback = function() - copyFile(file) - UIManager:close(self.file_dialog) - end, - }, - { - text = _("Paste"), - enabled = fileManager.clipboard and true or false, - callback = function() - pasteHere(file) - self:refreshPath() - UIManager:close(self.file_dialog) - end, - }, + text = _("Cut"), + callback = function() + cutFile(file) + UIManager:close(self.file_dialog) + end, }, { - { - text = _("Cut"), - callback = function() - cutFile(file) - UIManager:close(self.file_dialog) - end, - }, - { - text = _("Delete"), - callback = function() - local path = util.realpath(file) - local ConfirmBox = require("ui/widget/confirmbox") - UIManager:close(self.file_dialog) - UIManager:show(ConfirmBox:new{ - text = _("Are you sure that you want to delete this file?\n") .. file .. ("\n") .. _("If you delete a file, it is permanently lost."), - ok_callback = function() - deleteFile(file) - self:refreshPath() - end, - }) - end, - }, + text = _("Delete"), + callback = function() + local path = util.realpath(file) + local ConfirmBox = require("ui/widget/confirmbox") + UIManager:close(self.file_dialog) + UIManager:show(ConfirmBox:new{ + text = _("Are you sure that you want to delete this file?\n") .. file .. ("\n") .. _("If you delete a file, it is permanently lost."), + ok_callback = function() + deleteFile(file) + self:refreshPath() + end, + }) + end, }, }, } + if lfs.attributes(file, "mode") == "directory" then + local realpath = util.realpath(file) + table.insert(buttons, { + { + text = _("Set as HOME directory"), + callback = function() + G_reader_settings:saveSetting("home_dir", realpath) + UIManager:close(self.file_dialog) + end + } + }) + end + self.file_dialog = ButtonDialog:new{ + buttons = buttons, + } UIManager:show(self.file_dialog) return true end diff --git a/reader.lua b/reader.lua index 81484714d..fff81b540 100755 --- a/reader.lua +++ b/reader.lua @@ -138,7 +138,8 @@ if ARGV[argidx] and ARGV[argidx] ~= "" then -- the filemanger will show the files in that path else local FileManager = require("apps/filemanager/filemanager") - FileManager:showFiles(ARGV[argidx]) + local home_dir = G_reader_settings:readSetting("home_dir") or ARGV[argidx] + FileManager:showFiles(home_dir) end UIManager:run() elseif last_file then