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
DSHOWHIDDENFILES = false
-- show file size in filemanager
-- default to false
DSHOWFILESIZE = false
-- customizable tap zones(rectangles)
-- x: x coordinate of top left corner in proportion of screen width
-- y: y coordinate of top left corner in proportion of screen height

@ -10,6 +10,7 @@ local FileChooser = Menu:extend{
path = lfs.currentdir(),
parent = nil,
show_hidden = DSHOWHIDDENFILES,
show_filesize = DSHOWFILESIZE,
filter = function(filename) return true end,
}
@ -46,7 +47,13 @@ function FileChooser:genItemTableFromPath(path)
table.insert(item_table, { text = dir.."/", path = self.path.."/"..dir })
end
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
return item_table

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

Loading…
Cancel
Save