---++!! !CommonCtrl.FileExplorerCtrl %TOC{title="Contents:"}% %STARTINCLUDE% ---++ a control that displaying folder/files using a treeview control | *Title* | a control that displaying folder/files using a treeview control | | *Author(s)* | LiXizhi | | *Date* | 2008/4/24 | | *File* | script/ide/FileExplorerCtrl.lua | ---+++ Description %T% __Sample Code__ <verbatim> NPL.load("(gl)script/ide/FileExplorerCtrl.lua"); local ctl = CommonCtrl.FileExplorerCtrl:new{ name = "FileExplorerCtrl1", alignment = "_lt",left=0, top=0,width = 256,height = 300, parent = _parent, rootfolder = "temp", filter = "*.png;*.jpg", AllowFolderSelection = true, OnSelect = function(filepath) _guihelper.MessageBox(filepath); end, OnDoubleClick = nil, }; ctl:Show(true); -- alternatively one can open multiple folders by setting rootfolder to nil and add child nodes as below. local ctl = CommonCtrl.FileExplorerCtrl:new{ name = "FileExplorerCtrl1", alignment = "_lt",left=0, top=0,width = 256,height = 300, parent = _parent, rootfolder = nil, filter = "*.*", OnSelect = function(filepath) _guihelper.MessageBox(filepath); end, }; -- node.rootfolder property should contain the rootfolder path, you can even add owner draw to these nodes ctl.RootNode:AddChild(CommonCtrl.TreeNode:new({Text = "My documents", rootfolder = "temp"})); ctl.RootNode:AddChild(CommonCtrl.TreeNode:new({Text = "My worlds", rootfolder = "worlds/", Expanded = false,})); ctl:Show(true); </verbatim> ---+++ Member Functions ---++++ !FileExplorerCtrl:Destroy <verbatim> common control library NPL.load("(gl)script/ide/Encoding.lua"); NPL.load("(gl)script/ide/common_control.lua"); NPL.load("(gl)script/ide/TreeView.lua"); local FileExplorerCtrl = commonlib.inherit(CommonCtrl.TreeView, { name = "FileExplorerCtrl1", -- appearance alignment = "_lt", left = 0, top = 0, width = 500, height = 500, parent = nil, container_bg = "Texture/3DMapSystem/common/ThemeLightBlue/container_bg.png: 4 4 4 4", -- default item height DefaultNodeHeight = 22, DefaultIndentation = 16, FolderOpenIcon = "Texture/3DMapSystem/common/Folder_open.png", FolderIcon = "Texture/3DMapSystem/common/Folder.png", -- Icon for display file extensions Icons = { -- file without extension ["none"]="Texture/3DMapSystem/common/Folder.png", -- unknown file without extension ["unknown"]="Texture/3DMapSystem/common/page_white.png", -- media files ["wav"]="Texture/3DMapSystem/common/music.png", ["dds"]="Texture/3DMapSystem/common/image.png", ["jpg"]="Texture/3DMapSystem/common/image.png", ["bmp"]="Texture/3DMapSystem/common/image.png", ["png"]="Texture/3DMapSystem/common/image.png", ["tga"]="Texture/3DMapSystem/common/image.png", ["avi"]="Texture/3DMapSystem/common/film.png", ["flv"]="Texture/3DMapSystem/common/film.png", ["swf"]="Texture/3DMapSystem/common/film.png", ["x"]="Texture/3DMapSystem/common/file_parax.png", -- modules ["db"]="Texture/3DMapSystem/common/page_white_database.png", ["config"]="Texture/3DMapSystem/common/page_white_gear.png", ["max"]="Texture/3DMapSystem/common/plugin.png", ["dll"]="Texture/3DMapSystem/common/script_gear.png", ["exe"]="Texture/3DMapSystem/common/application_xp.png", ["zip"]="Texture/3DMapSystem/common/page_white_zip.png", ["pkg"]="Texture/3DMapSystem/common/page_white_zip.png", -- script files ["lua"]="Texture/3DMapSystem/common/script_code_red.png", ["txt"]="Texture/3DMapSystem/common/page_white_text.png", ["xml"]="Texture/3DMapSystem/common/page_code.png", ["html"]="Texture/3DMapSystem/common/page_code.png", ["c"]="Texture/3DMapSystem/common/page_white_c.png", ["cpp"]="Texture/3DMapSystem/common/page_white_c.png", ["h"]="Texture/3DMapSystem/common/page_white_h.png", -- open world file ["worldconfig.txt"]="Texture/3DMapSystem/common/page_world.png", ["world.zip"]="Texture/3DMapSystem/common/page_world.png", ["world.pkg"]="Texture/3DMapSystem/common/page_world.png", }, -- only used when CheckBoxes is true, checked_bg = "Texture/3DMapSystem/common/ThemeLightBlue/checkbox.png", -- only used when CheckBoxes is true, unchecked_bg = "Texture/3DMapSystem/common/ThemeLightBlue/uncheckbox.png", -- only used when CheckBoxes is true, checkmixed_bg = "Texture/3DMapSystem/common/ThemeLightBlue/checkbox_mixed.png", -- default is FileExplorerCtrl.DrawNormalNodeHandler DrawNodeHandler = nil, -- parameters -- -- initial root folder name, such as "temp", "script/test", -- if this is nil, the first level children of rootNode will be expanded as child node. -- The childNode.Name should contain the rootfolder instead. One can also implement owner draw function -- for the first level root, such as in the open file dialog. rootfolder = nil, -- the files to be displayed, such as ".*", ".jpg;*.x". if nil, only folder will be displayed. filter = nil, -- boolean: whether allow folder selection. if true, a folder node can be selected and select event is fired AllowFolderSelection = nil, -- boolean: if true, folder can not be expanded, otherwise it can. DisableFolderExpand = nil, -- boolean: if true, folder will be hidden. However if self.filter contains folder, they will be displayed anyway. HideFolder = nil, -- max number of items per folder MaxItemPerFolder = 300, -- currently selected folder path SelectedPath = nil, -- boolean: Gets or sets a value indicating whether check boxes are displayed next to the tree nodes in the tree view control -- A check box is displayed to the left of both the tree node label and tree node Icon, if any. Check boxes allow the user to select more than one tree node at a time CheckBoxes=nil, -- event -- -- called when user click on a folder or file item. it is a string or a function(filepath) end OnSelect = nil, -- called when user double clicked on an file item. it is a string or a function(filepath) end OnDoubleClick = nil, -- called when user checks or unchecks a folder or file item. it is a function(treeNode, filepath, Checked) end OnCheck = nil, -- called when a new folder or file node is added. it is a function(treeNode, filepath) end -- usually one can alter the Text, Icon, TextColor property of the created treeNode according to treeNode.Name OnCreateNode = nil, -- private selectedNodePath = nil, treeViewName = nil, --璁板綍鎵€鏈夎閫変腑鐨勭洰褰? CheckedPathList = {}, --宸茬粡瀛樺湪鐨勪竴涓矾寰勫垪琛? fromTxtPathList = {}, filterList = {"*.x","*.png","*.dds","*.lua","*.htm","*.html","*.xml","*.jpg","*.jpeg","*.gif","*.swf","*.avi","*.mp3"} }</verbatim>) CommonCtrl.FileExplorerCtrl = FileExplorerCtrl; Destroy the UI control __syntax__ <verbatim>function FileExplorerCtrl:Destroy ()</verbatim> ---++++ !FileExplorerCtrl:Show display control. __syntax__ <verbatim>function FileExplorerCtrl:Show(bShow)</verbatim> __parameters__ | *bShow* | | ---++++ !FileExplorerCtrl:GetNodeNamePath --------------------------- private functions: --------------------------- get node file path. __syntax__ <verbatim>function FileExplorerCtrl:GetNodeNamePath(node)</verbatim> __parameters__ | *node* | | ---++++ !FileExplorerCtrl.ValidateFolderRootNode cononicalize root folder __syntax__ <verbatim>function FileExplorerCtrl.ValidateFolderRootNode(node)</verbatim> __parameters__ | *node* | | ---++++ !FileExplorerCtrl:ResetTreeView rebuild tree view for the current root directory. __syntax__ <verbatim>function FileExplorerCtrl:ResetTreeView()</verbatim> ---++++ !FileExplorerCtrl:RefreshNode refresh the node according to its folder path. It will automatically add the first level child if any. __syntax__ <verbatim>function FileExplorerCtrl:RefreshNode(node)</verbatim> __parameters__ | *node* | | ---++++ !FileExplorerCtrl:GetIcon get the icon path for a given file name __syntax__ <verbatim>function FileExplorerCtrl:GetIcon(filename)</verbatim> __parameters__ | *filename* | | ---++++ !FileExplorerCtrl.SearchFiles only return the sub folders of the current folder * _param_ __rootfolder__ : the folder which will be searched. * _param_ __nMaxFilesNum__ : one can limit the total number of files in the search result. Default value is 50. the search will stop at this value even there are more matching files. * _param_ __filter__ : if nil, it defaults to "*." * _return_ __a__ : table array containing relative to rootfolder file name. __syntax__ <verbatim>function FileExplorerCtrl.SearchFiles(output, rootfolder,nMaxFilesNum, filter)</verbatim> __parameters__ | *output* | | | *rootfolder* | the folder which will be searched. | | *nMaxFilesNum* | | | *filter* | if nil, it defaults to "*." | ---++++ !FileExplorerCtrl.DrawNormalNodeHandler owner draw function of treeview __syntax__ <verbatim>function FileExplorerCtrl.DrawNormalNodeHandler(_parent,treeNode)</verbatim> __parameters__ | *parent* | | | *treeNode* | | ---++++ !FileExplorerCtrl.OnClick ---------------------------------------- event handlers: ---------------------------------------- event handler: user clicks a node __syntax__ <verbatim>function FileExplorerCtrl.OnClick(sCtrlName, nodePath)</verbatim> __parameters__ | *sCtrlName* | | | *nodePath* | | ---++++ !FileExplorerCtrl:ClickNode this function can be called from outside __syntax__ <verbatim>function FileExplorerCtrl:ClickNode(node)</verbatim> __parameters__ | *node* | | ---++++ !FileExplorerCtrl.OnToggleNode toggle folder node, it will cause node to be rebuilt. __syntax__ <verbatim>function FileExplorerCtrl.OnToggleNode(sCtrlName, nodePath)</verbatim> __parameters__ | *sCtrlName* | | | *nodePath* | | ---++++ !FileExplorerCtrl.OnToggleNodeChecked toggle folder node, it will cause node to be rebuilt. __syntax__ <verbatim>function FileExplorerCtrl.OnToggleNodeChecked(sCtrlName, nodePath)</verbatim> __parameters__ | *sCtrlName* | | | *nodePath* | | ---++++ !FileExplorerCtrl:SetCheckedPath 璁板綍琚偣鍑昏妭鐐圭殑璺緞 __syntax__ <verbatim>function FileExplorerCtrl:SetCheckedPath(nodePath,checked)</verbatim> __parameters__ | *nodePath* | | | *checked* | | ---++++ !FileExplorerCtrl:UpdateByPathList 鏇存柊FileExplorerCtrl __syntax__ <verbatim>function FileExplorerCtrl:UpdateByPathList(nodePath,pathList)</verbatim> __parameters__ | *nodePath* | | | *pathList* | | ---++++ !FileExplorerCtrl:FindTxtPath 浠庡凡缁忓瓨鍦ㄧ殑鍒楄〃(self.fromTxtPathList)涓壘 鏌愪釜鑺傜偣锛屽鏋滄壘鍒帮紝杩斿洖true __syntax__ <verbatim>function FileExplorerCtrl:FindTxtPath(list,nodeTxt)</verbatim> __parameters__ | *list* | | | *nodeTxt* | | ---++++ !FileExplorerCtrl:ClearFolderFilter 杞崲鏌愪釜鐩綍涓嬮潰鐨勯€氶厤绗︿负鍏蜂綋鏂囦欢璺緞 閫氶厤绗﹀彧鍙兘鍑虹幇鍦╯elf.fromTxtPathList閲岄潰 a/*.jpg ==> a/1.jpg,a/2.jpg ...... __syntax__ <verbatim>function FileExplorerCtrl:ClearFolderFilter(parentNode,parentNodePath)</verbatim> __parameters__ | *parentNode* | | | *parentNodePath* | | ---++++ !FileExplorerCtrl:HasFilter 鏍¢獙鏌愪釜鐩綍锛屽亣濡傚畠鐨勫瓙鐩綍鍏ㄩ儴娌℃湁琚€変腑锛岄€氱煡瀹冨拰瀹冪殑鐖惰妭鐐? --鍦ㄤ娇鐢ㄥ悓閰嶇鐨勬椂鍊欙紝鏈夊彲鑳藉嚭鐜拌繖绉嶆儏鍐?鐖剁洰褰曟槸閫変腑鐘舵€侊紝浣嗘槸鎵撳紑瀛愮洰褰曞悗鍙戠幇娌℃湁涓€涓槸鍖归厤鐨? function FileExplorerCtrl:OurChildenIsAllUnChecked(sCtrlName, nodePath) local self, node = CommonCtrl.TreeView.GetCtl(sCtrlName, nodePath) local reallyUnchecked = true; if(node) then local nSize = table.getn(node.Nodes); local i, childnode; for i=1, nSize do childnode = node.Nodes[i]; if(childnode.Checked == true)then reallyUnchecked = false; end end if(reallyUnchecked)then node.Checked = false; self:BeepParentNode(sCtrlName, nodePath); end end end 鍒ゆ柇涓€涓矾寰勬槸鍚︿负鏂囦欢澶? function FileExplorerCtrl:IsFolder(filePath) local rootPath = ParaIO.GetCurDirectory(0); local path = rootPath..filePath; local search_result = ParaIO.SearchFiles(path.."/","*", "", 0, 1, 0); local nCount = search_result:GetNumOfResult(); if(nCount>0) then return true; else return false; end end __syntax__ <verbatim>function FileExplorerCtrl:HasFilter(filePath)</verbatim> __parameters__ | *filePath* | | ---++++ !FileExplorerCtrl:GetText get the current file path __syntax__ <verbatim>function FileExplorerCtrl:GetText()</verbatim> ---++++ !FileExplorerCtrl:SetValue TODO: __syntax__ <verbatim>function FileExplorerCtrl:SetValue(filepath)</verbatim> __parameters__ | *filepath* | | ---++++ !FileExplorerCtrl:CreateFolder TODO: create a new folder * _return_ __true__ : if succeed. __syntax__ <verbatim>function FileExplorerCtrl:CreateFolder(folderName, rootDir)</verbatim> __parameters__ | *folderName* | | | *rootDir* | | | *return* | if succeed. | %STOPINCLUDE%
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2008-02-29
-
LiXizhi
Home
Site map
CCWeb web
HaqiTeen web
Main web
ParaEngine web
TWiki web
Main Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
导航页WebTopMenu
Preferences
开发指南
Getting Started
ParacraftSDK
NPL
MCML
NPL Reference Manual
美术Mod
Account
Log In
English
简体中文
簡體中文
E
dit
A
ttach
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback