From cad8ddec92687fcd845ffe8acf474d18e4ef3f59 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 22 Aug 2013 11:39:35 +0800 Subject: [PATCH 1/2] disable path compress on relative path --- frontend/ui/widget/filechooser.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index fc17fd1fd..fe72d891c 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -16,6 +16,11 @@ function FileChooser:init() end function FileChooser:compressPath(item_path) + if (item_path:sub(1, 1) == ".") then + -- ignore relative path + return item_path + end + -- compress paths like "test/pdf/../epub" into "test/epub" local path = item_path while path:match("/[^/]+[/][\\.][\\.]") do From c951eacc35806411831072ca0a7ea4ccd04db10c Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 22 Aug 2013 12:01:00 +0800 Subject: [PATCH 2/2] fix: reset current page on item_table switch for menu widget --- frontend/ui/widget/filechooser.lua | 21 +++++++++++---------- frontend/ui/widget/menu.lua | 5 ++++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index fe72d891c..d52f0c686 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -11,7 +11,7 @@ FileChooser = Menu:extend{ } function FileChooser:init() - self:updateItemTableFromPath(self.path) + self.item_table = self:genItemTableFromPath(self.path) Menu.init(self) -- call parent's init() end @@ -29,11 +29,9 @@ function FileChooser:compressPath(item_path) return path end -function FileChooser:updateItemTableFromPath(path) - path = self:compressPath(path) +function FileChooser:genItemTableFromPath(path) local dirs = {} local files = {} - self.path = path for f in lfs.dir(self.path) do if self.show_hidden or not string.match(f, "^%.[^.]") then @@ -51,21 +49,24 @@ function FileChooser:updateItemTableFromPath(path) end end table.sort(dirs) - if self.path ~= "/" then table.insert(dirs, 1, "..") end + if path ~= "/" then table.insert(dirs, 1, "..") end table.sort(files) - self.item_table = {} + local item_table = {} for _, dir in ipairs(dirs) do - table.insert(self.item_table, { text = dir.."/", path = self.path.."/"..dir }) + table.insert(item_table, { text = dir.."/", path = self.path.."/"..dir }) end for _, file in ipairs(files) do - table.insert(self.item_table, { text = file, path = self.path.."/"..file }) + table.insert(item_table, { text = file, path = self.path.."/"..file }) end + + return item_table end function FileChooser:changeToPath(path) - self:updateItemTableFromPath(path) - self:updateItems(1) + path = self:compressPath(path) + self.path = path + self:swithItemTable(nil, self:genItemTableFromPath(path)) end function FileChooser:onMenuSelect(item) diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index 41649daed..410aaeea8 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -477,7 +477,10 @@ function Menu:updateItems(select_number) end function Menu:swithItemTable(new_title, new_item_table) - self.menu_title.text = new_title + if self.menu_title then + self.menu_title.text = new_title + end + self.page = 1 self.item_table = new_item_table self:updateItems(1) end