100行代码实现简单目录浏览器制作

给大家分享使用Lae软件开发工具开发小应用程序的过程,希望大家喜欢!

 

界面部分我们lae软件开发工具实现,无需写代码,业务逻辑部分使用Lae软件开发平台自带的LuaIDE编辑器,使用100lua代码完成简单目录浏览器的制作




 

lae软件下载地址:

https://github.com/ouloba/laetool.git

lae软件下载地址(国内):https://pan.baidu.com/s/1ckMy0Q

相关视频:

http://www.tudou.com/listplay/aly7NDWz_sQ/AaqZ81jIt-k.html

教程:

lae界面开发工具入门介绍之一<新建工程篇>

lae界面开发工具入门之介绍二--<渲染组件篇>

lae界面开发工具入门之介绍三--<布局篇>

lae界面开发工具入门之介绍四-- <秘籍篇-拷贝粘贴>

lae界面开发工具入门之介绍五--<秘籍篇-杂项>

lae界面开发工具入门之介绍六--<秘籍篇-状态篇>

关于lae工具问题单独介绍!

--lua代码

lua编辑器 csdn下载

github下载地址,csdn没有更新版本功能,这里改为git,可实时获得最新的版本下载地址:

--目录浏览器下载地址

https://github.com/ouloba/folder-explorer.git

--辅助接口

LXZDoFile("LXZHelper.lua");

LXZDoFile("serial.lua");

--每帧调用,root窗口statusIsActive设置为true,即可触发OnUpdate事件。local function OnUpdate(window, msg, sender)

UpdateWindow();end

--更新目录子目录或者文件列表local function UpdateDirectry(dir)

local root = HelperGetRoot();

--set current dir.

lfs.chdir(dir);

HelperSetWindowText(root:GetLXZWindow("directry"), dir);

--

local items = root:GetLXZWindow("folders:area:items"); --目录文件容器

local item = root:GetLXZWindow("folders:item"); --目录文件项

local path = lfs.currentdir();

--清除容器中内容

items:ClearChilds();

--遍历该目录下的子目录文件

local cnt = 0;

for file in lfs.dir(lfs.currentdir()) do

local wnd = item:Clone(); --克隆一个目录文件项"folders:item"

wnd:Show(); --显示

HelperSetWindowText(wnd:GetChild("text"), file); --设置目录或者文件名

items:AddChild(wnd); --加入items容器中

local f = path.."\\"..file;

local attr = lfs.attributes(f);

if attr and attr.mode=="directory" then

wnd:GetChild("icon"):SetState(0); --通过0状态设置目录图标

else

wnd:GetChild("icon"):SetState(1);--通过1状态设置文件名图标

end

cnt=cnt+1;

end

--如果无法访问该目录,则添加"."".."

if cnt==0 then

local wnd = item:Clone();

wnd:Show();

HelperSetWindowText(wnd:GetChild("text"), ".");

items:AddChild(wnd);

local wnd = item:Clone();

wnd:Show();

HelperSetWindowText(wnd:GetChild("text"), "..");

items:AddChild(wnd);

end

--垂直滚动条适应内容大小。

local msg = CLXZMessage:new_local();

local wnd = root:GetLXZWindow("folders:vertical slider");

wnd:ProcMessage("OnReset", msg, wnd);

end

--点击目录或者文件项local function OnClickItem(window, msg, sender)

local file=HelperGetWindowText(sender:GetChild("text"));

local path = lfs.currentdir();

local f = path.."\\"..file;

local attr,err = lfs.attributes (f)

if attr== nil then

LXZMessageBox("error:"..err);

return;

end

-- LXZMessageBox("type(attr)"..type(attr).."f:"..f)

assert (type(attr) == "table");

if attr.mode == "directory" then --如果是目录

UpdateDirectry(f);

end

end

--ui加载时触发该事件local function OnLoad(window, msg, sender)

local root = HelperGetRoot();

--set default.

local default_dir = "c:\\";

HelperSetWindowText(root:GetLXZWindow("directry"), default_dir);

--set folder list.

UpdateDirectry(default_dir);end

--事件与接口绑定local event_callback = {}

event_callback ["OnUpdate"] = OnUpdate;

event_callback ["OnLoad"] = OnLoad;

event_callback ["OnClickItem"] = OnClickItem;

--事件分发器function main_dispacher(window, cmd, msg, sender)--- LXZAPI_OutputDebugStr("cmd 1:"..cmd);

if(event_callback[cmd] ~= nil) then-- LXZAPI_OutputDebugStr("cmd 2:"..cmd);

event_callback[cmd](window, msg, sender);

endend



 

增加权限、创建时间、修改时间等

--增加lua代码

if attr then

HelperSetWindowText(wnd:GetChild("access time"), os.date("%c", attr.access) );

HelperSetWindowText(wnd:GetChild("modify time"), os.date("%c", attr.modification));

HelperSetWindowText(wnd:GetChild("change time"), os.date("%c", attr.change));

HelperSetWindowText(wnd:GetChild("permissions"), attr.permissions);

end

--界面修改如下


--增加浏览图片的功能


--修改lua代码,增加事件

--获取扩展名 function getextension(filename)

return filename:match(".+%.(%w+)$") end

--鼠标进入local function OnMouseEnterItem(window, msg, sender)

local file=HelperGetWindowText(sender:GetChild("text"));

local path = lfs.currentdir();

local f = path.."\\"..file;

local attr,err = lfs.attributes (f)

if attr== nil then

LXZMessageBox("error:"..err);

return;

end

local root = HelperGetRoot();

assert (type(attr) == "table");

local ext = getextension(file);

LXZAPI_OutputDebugStr("OnMouseEnterItem:"..f.." mode:"..attr.mode);

if attr.mode == "file" and (ext=="png" or ext=="PNG") then --如果是图片文件

LXZAPI_OutputDebugStr("OnMouseEnterItem:"..f.." ext:"..ext.." mode:"..attr.mode);

local wnd = root:GetLXZWindow ("folders:show picture");

HelperSetWindowPictureFile(wnd,f);

wnd:Show();

HelperCoroutine(function(thread)

AddWndUpdateFunc(wnd, EffectFaceOut, {from=255, End=200,step=3, old=255, hide=true}, thread);

coroutine.yield();

local texture = ILXZTexture:GetTexture(f);

if texture then

texture:RemoveTexture();

end

end);

endend

表现如下



 

<!--EndFragment-->
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值