add option to display file size in filemanager

file size is not shown by default
pull/401/head
chrox 11 years ago
parent 5b31076025
commit 42c5ae2ac0

@ -38,6 +38,10 @@ DSHOWOVERLAP = false
-- default to false -- default to false
DSHOWHIDDENFILES = false DSHOWHIDDENFILES = false
-- show file size in filemanager
-- default to false
DSHOWFILESIZE = false
-- customizable tap zones(rectangles) -- customizable tap zones(rectangles)
-- x: x coordinate of top left corner in proportion of screen width -- x: x coordinate of top left corner in proportion of screen width
-- y: y coordinate of top left corner in proportion of screen height -- y: y coordinate of top left corner in proportion of screen height

@ -10,6 +10,7 @@ local FileChooser = Menu:extend{
path = lfs.currentdir(), path = lfs.currentdir(),
parent = nil, parent = nil,
show_hidden = DSHOWHIDDENFILES, show_hidden = DSHOWHIDDENFILES,
show_filesize = DSHOWFILESIZE,
filter = function(filename) return true end, filter = function(filename) return true end,
} }
@ -46,7 +47,13 @@ function FileChooser:genItemTableFromPath(path)
table.insert(item_table, { text = dir.."/", path = self.path.."/"..dir }) table.insert(item_table, { text = dir.."/", path = self.path.."/"..dir })
end end
for _, file in ipairs(files) do for _, file in ipairs(files) do
table.insert(item_table, { text = file, path = self.path.."/"..file }) local full_path = self.path.."/"..file
if self.show_filesize then
local sstr = string.format("%4.1fM",lfs.attributes(full_path, "size")/1024/1024)
table.insert(item_table, { text = file, mandatory = sstr, path = full_path })
else
table.insert(item_table, { text = file, path = full_path })
end
end end
return item_table return item_table

@ -1,5 +1,7 @@
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local WidgetContainer = require("ui/widget/container/widgetcontainer") local WidgetContainer = require("ui/widget/container/widgetcontainer")
local LeftContainer = require("ui/widget/container/leftcontainer")
local RightContainer = require("ui/widget/container/rightcontainer")
local FrameContainer = require("ui/widget/container/framecontainer") local FrameContainer = require("ui/widget/container/framecontainer")
local CenterContainer = require("ui/widget/container/centercontainer") local CenterContainer = require("ui/widget/container/centercontainer")
local BottomContainer = require("ui/widget/container/bottomcontainer") local BottomContainer = require("ui/widget/container/bottomcontainer")
@ -8,6 +10,7 @@ local HorizontalSpan = require("ui/widget/horizontalspan")
local FocusManager = require("ui/widget/focusmanager") local FocusManager = require("ui/widget/focusmanager")
local TextWidget = require("ui/widget/textwidget") local TextWidget = require("ui/widget/textwidget")
local OverlapGroup = require("ui/widget/overlapgroup") local OverlapGroup = require("ui/widget/overlapgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local VerticalGroup = require("ui/widget/verticalgroup") local VerticalGroup = require("ui/widget/verticalgroup")
local HorizontalGroup = require("ui/widget/horizontalgroup") local HorizontalGroup = require("ui/widget/horizontalgroup")
local Button = require("ui/widget/button") local Button = require("ui/widget/button")
@ -111,7 +114,8 @@ local MenuItem = InputContainer:new{
text = nil, text = nil,
show_parent = nil, show_parent = nil,
detail = nil, detail = nil,
face = Font:getFace("cfont", 22), face = Font:getFace("cfont", 30),
info_face = Font:getFace("infont", 15),
dimen = nil, dimen = nil,
shortcut = nil, shortcut = nil,
shortcut_style = "square", shortcut_style = "square",
@ -147,32 +151,51 @@ function MenuItem:init()
} }
end end
local mandatory = self.mandatory and ""..self.mandatory.." " or ""
local mandatory_w = RenderText:sizeUtf8Text(0, self.dimen.w, self.info_face, ""..mandatory, true).x
w = RenderText:sizeUtf8Text(0, self.dimen.w, self.face, self.text, true).x w = RenderText:sizeUtf8Text(0, self.dimen.w, self.face, self.text, true).x
if w >= self.content_width then if w + mandatory_w >= self.content_width then
if Device:isTouchDevice() then if Device:isTouchDevice() then
else else
self.active_key_events.ShowItemDetail = { self.active_key_events.ShowItemDetail = {
{"Right"}, doc = "show item detail" {"Right"}, doc = "show item detail"
} }
end end
indicator = " >>" local indicator = " >> "
indicator_w = RenderText:sizeUtf8Text(0, self.dimen.w, self.face, indicator, true).x local indicator_w = RenderText:sizeUtf8Text(0, self.dimen.w, self.face, indicator, true).x
self.text = RenderText:getSubTextByWidth(self.text, self.face, self.text = RenderText:getSubTextByWidth(self.text, self.face,
self.content_width - indicator_w, true) .. indicator self.content_width - indicator_w - mandatory_w, true) .. indicator
end end
local text_container = LeftContainer:new{
dimen = Geom:new{w = self.content_width},
TextWidget:new{
text = self.text,
face = self.face,
}
}
local mandatory_container = RightContainer:new{
dimen = Geom:new{w = self.content_width},
TextWidget:new{
text = mandatory,
face = self.info_face,
}
}
self._underline_container = UnderlineContainer:new{ self._underline_container = UnderlineContainer:new{
dimen = Geom:new{ dimen = Geom:new{
w = self.content_width, w = self.content_width,
h = self.dimen.h h = self.dimen.h
}, },
HorizontalGroup:new { HorizontalGroup:new{
align = "center", align = "center",
TextWidget:new{ OverlapGroup:new{
text = self.text, text_container,
face = self.face, mandatory_container,
}, },
}, }
} }
self[1] = FrameContainer:new{ self[1] = FrameContainer:new{
@ -458,6 +481,7 @@ function Menu:updateItems(select_number)
local item_tmp = MenuItem:new{ local item_tmp = MenuItem:new{
show_parent = self.show_parent, show_parent = self.show_parent,
text = self.item_table[i].text, text = self.item_table[i].text,
mandatory = self.item_table[i].mandatory,
face = self.cface, face = self.cface,
dimen = self.item_dimen:new(), dimen = self.item_dimen:new(),
shortcut = item_shortcut, shortcut = item_shortcut,

Loading…
Cancel
Save