您的位置:首页 > 职场人生

100行代码实现简单目录浏览器制作(程序员)

2016-09-04 22:53 387 查看
给大家分享使用Lae软件开发工具开发小应用程序的过程,希望大家喜欢!

 

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


 



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界面开发工具入门介绍之一<<spanse-mark="1">新建工程篇>

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

lae界面开发工具入门之介绍三--<<spanse-mark="1">布局篇>

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

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

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

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

--lua代码

lua编辑器 csdn下载

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

--目录浏览器下载地址
https://github.com/ouloba/folder-explorer.git
--辅助接口

LXZDoFile("LXZHelper.lua");

LXZDoFile("serial.lua");

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

UpdateWindow();end

--更新目录子目录或者文件列表localfunction 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

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

localfile=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加载时触发该事件localfunction 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

--事件与接口绑定localevent_callback = {}

event_callback ["OnUpdate"] =OnUpdate;

event_callback ["OnLoad"] = OnLoad;

event_callback ["OnClickItem"] =OnClickItem;

--事件分发器functionmain_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("accesstime"), os.date("%c", attr.access) );

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

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

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

end

--界面修改如下​



--增加浏览图片的功能​



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

--获取扩展名 functiongetextension(filename)

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

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

localfile=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" orext=="PNG") then --如果是图片文件

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

local wnd = root:GetLXZWindow ("folders:showpicture");

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

表现如下

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息