FileBrowser: change page to show last file or previous subdir (#3351)

When going from reader to filemanager, we are in the directory
containing the last_file. With this, we will also be on the page
showing this file.
When in filemanager and going up (".."), we will also be on the
page containing the directory we came from.
pull/3357/head
poire-z 7 years ago committed by Frans de Jonge
parent 532c850cbd
commit 29707bd664

@ -317,7 +317,7 @@ function FileManager:init()
self:handleEvent(Event:new("SetDimensions", self.dimen)) self:handleEvent(Event:new("SetDimensions", self.dimen))
end end
function FileManager:reinit(path) function FileManager:reinit(path, focused_file)
self.dimen = Screen:getSize() self.dimen = Screen:getSize()
-- backup the root path and path items -- backup the root path and path items
self.root_path = path or self.file_chooser.path self.root_path = path or self.file_chooser.path
@ -329,6 +329,9 @@ function FileManager:reinit(path)
self:init() self:init()
self.file_chooser.path_items = path_items_backup self.file_chooser.path_items = path_items_backup
self:onRefresh() self:onRefresh()
if focused_file then
self.file_chooser:changePageToPath(focused_file)
end
end end
function FileManager:toggleHiddenFiles() function FileManager:toggleHiddenFiles()
@ -547,7 +550,7 @@ function FileManager:getStartWithMenuTable()
} }
end end
function FileManager:showFiles(path) function FileManager:showFiles(path, focused_file)
path = path or G_reader_settings:readSetting("lastdir") or filemanagerutil.getDefaultDir() path = path or G_reader_settings:readSetting("lastdir") or filemanagerutil.getDefaultDir()
G_reader_settings:saveSetting("lastdir", path) G_reader_settings:saveSetting("lastdir", path)
restoreScreenMode() restoreScreenMode()
@ -558,6 +561,9 @@ function FileManager:showFiles(path)
self.instance = nil self.instance = nil
end end
} }
if focused_file then
file_manager.file_chooser:changePageToPath(focused_file)
end
UIManager:show(file_manager) UIManager:show(file_manager)
self.instance = file_manager self.instance = file_manager
end end

@ -365,16 +365,16 @@ end
function ReaderUI:showFileManager() function ReaderUI:showFileManager()
local FileManager = require("apps/filemanager/filemanager") local FileManager = require("apps/filemanager/filemanager")
local QuickStart = require("ui/quickstart") local QuickStart = require("ui/quickstart")
local lastdir local last_dir
local last_file = G_reader_settings:readSetting("lastfile") local last_file = G_reader_settings:readSetting("lastfile")
-- ignore quickstart guide as last_file so we can go back to home dir -- ignore quickstart guide as last_file so we can go back to home dir
if last_file and last_file ~= QuickStart.quickstart_filename then if last_file and last_file ~= QuickStart.quickstart_filename then
lastdir = last_file:match("(.*)/") last_dir = last_file:match("(.*)/")
end end
if FileManager.instance then if FileManager.instance then
FileManager.instance:reinit(lastdir) FileManager.instance:reinit(last_dir, last_file)
else else
FileManager:showFiles(lastdir) FileManager:showFiles(last_dir, last_file)
end end
end end

@ -175,7 +175,8 @@ function FileChooser:genItemTableFromPath(path)
table.insert(item_table, { table.insert(item_table, {
text = dir.name == ".." and "⬆ ../" or dir.name.."/", text = dir.name == ".." and "⬆ ../" or dir.name.."/",
mandatory = istr, mandatory = istr,
path = subdir_path path = subdir_path,
is_go_up = dir.name == ".."
}) })
end end
@ -230,13 +231,29 @@ function FileChooser:refreshPath()
self:switchItemTable(nil, self:genItemTableFromPath(self.path), self.path_items[self.path]) self:switchItemTable(nil, self:genItemTableFromPath(self.path), self.path_items[self.path])
end end
function FileChooser:changeToPath(path) function FileChooser:changeToPath(path, focused_path)
path = util.realpath(path) path = util.realpath(path)
self.path = path self.path = path
self:refreshPath() self:refreshPath()
if focused_path then
self:changePageToPath(focused_path)
end
self:onPathChanged(path) self:onPathChanged(path)
end end
function FileChooser:changePageToPath(path)
if not path then return end
for num, item in ipairs(self.item_table) do
if item.path == path then
local page = math.floor((num-1) / self.perpage) + 1
if page ~= self.page then
self:onGotoPage(page)
end
break
end
end
end
function FileChooser:toggleHiddenFiles() function FileChooser:toggleHiddenFiles()
self.show_hidden = not self.show_hidden self.show_hidden = not self.show_hidden
self:refreshPath() self:refreshPath()
@ -258,7 +275,7 @@ function FileChooser:onMenuSelect(item)
if lfs.attributes(item.path, "mode") == "file" then if lfs.attributes(item.path, "mode") == "file" then
self:onFileSelect(item.path) self:onFileSelect(item.path)
else else
self:changeToPath(item.path) self:changeToPath(item.path, item.is_go_up and self.path)
end end
return true return true
end end

Loading…
Cancel
Save