CommonCtrl.FileDialog

File and directory listing common control (dialog)

Title File and directory listing common control (dialog)
Author(s) LiXizhi
Date 2006/3/6
File script/ide/FileDialog.lua

Description

TIP Sample Code

NPL.load("(gl)script/ide/FileDialog.lua");
local ctl = CommonCtrl.GetControl("FileTreeView1");
if(ctl==nil)then
   local ctl = CommonCtrl.FileTreeView:new{
      name = "FileTreeView1",
      alignment = "_lt",
      left=0, top=0,
      width = 200,
      height = 200,
      parent = nil,
      -- function DrawNodeEventHandler(parent,treeNode) end, where parent is the parent container in side which contents should be drawn. And treeNode is the TreeNode object to be drawn
      DrawNodeHandler = nil,
      sInitDir = "temp/",
      sFilePattern = "*.*",
      nMaxFileLevels = 0,
      nMaxNumFiles = 300,
   };
else
   ctl.sInitDir = "temp/";
   ctl.sFilePattern = "*.*";
   ctl:SetModified(true);   
end   
ctl:Refresh();
ctl.RootNode:CollapseAll();
ctl.RootNode:Expand(); -- only show first level
ctl:Show();

Member Functions

FileTreeView:new

 default member attributes
local FileTreeView = {
   -- the top level control name
   name = "FileTreeView1",
   -- normal window size
   alignment = "_lt",
   left = 0,
   top = 0,
   width = 300,
   height = 400, 
   -- the background of container
   container_bg = nil, 
   -- The root tree node. containing all tree node data
   RootNode = nil, 
   -- Default height of Tree Node
   DefaultNodeHeight = 24,
   -- default indentation
   DefaultIndentation = 10,
   -- Gets or sets a function by which the individual TreeNode control is drawn. The function should be of the format:
   -- function DrawNodeEventHandler(parent,treeNode) end, where parent is the parent container in side which contents should be drawn. And treeNode is the TreeNode object to be drawn
   -- if DrawNode is nil, the default FileTreeView.DrawFileItemHandler function will be used. 
   DrawNodeHandler = nil,
   -- Force no clipping or always using fast render. Unless you know that the unit scroll step is interger times of all TreeNode height. You can disable clipping at your own risk. 
   -- Software clipping is always used to clip all invisible TreeNodes. However, this option allows you to specify whether to use clipping for partially visible TreeNode. 
   NoClipping = nil,
   -- a function of type function (MenuItem, nodepathString) or nil. this function will be called for each menuitem onclick except the group node.
   onclick = nil,
   
   -- the initial directory. 
   sInitDir = "",
   -- e.g."*.", "*.x" or it could be table like {"*.lua", "*.raw"}
   sFilePattern = "*.*",
   -- max file levels. 0 shows files in the current directory.
   nMaxFileLevels = 3,
   -- max number of files in file listbox. e.g. 150
   nMaxNumFiles = 300,
   -- currently selected file path. 
   SelectedFilePath = "",
   -------------------------------------------
   -- private functions
   -------------------------------------------
   IsModified = true,
}
FileTreeView = FileTreeView;

constructor

syntax

function FileTreeView:new (o)

parameters

o  

FileTreeView:Destroy

Destroy the UI control

syntax

function FileTreeView:Destroy ()

FileTreeView.GetNodePath

return the node path of the input node. directory is separated by '/'

syntax

function FileTreeView.GetNodePath(node)

parameters

node  

FileTreeView.AddNewFile

  • param node : to which node the filepath is attached. It will create child node if necessary. this function is recursive.
  • param filepath : file name to add.

syntax

function FileTreeView.AddNewFile(node, filepath)

parameters

node to which node the filepath is attached. It will create child node if necessary. this function is recursive.
filepath  

FileTreeView:SetModified

set modified, always call this function after you have changed the menu items. this will cause the content menu to redraw next time it shows up.

syntax

function FileTreeView:SetModified(bModified)

parameters

bModified  

FileTreeView:GetSelectedFilePath

set modified, always call this function after you have changed the menu items. this will cause the content menu to redraw next time it shows up.

syntax

function FileTreeView:GetSelectedFilePath()

FileTreeView:Show

display the file treeview control

syntax

function FileTreeView:Show(bShow)

parameters

bShow  

FileTreeView.OnToggleNode

private function: called by default TreeNode UI

syntax

function FileTreeView.OnToggleNode(sCtrlName, nodePath)

parameters

sCtrlName  
nodePath  

FileTreeView.OnClickNode

private function: called by default TreeNode UI

syntax

function FileTreeView.OnClickNode(sCtrlName, nodePath)

parameters

sCtrlName  
nodePath  

FileTreeView.DrawFileItemHandler

default node renderer: it display a clickable check box for expandable node, followed by node text

syntax

function FileTreeView.DrawFileItemHandler(_parent,treeNode)

parameters

parent  
treeNode  

CommonCtrl.InitFileDialog

[[ Initializes a set UI objects for directory and file listing. Users can override the default behaviors of the UI controls. the Default behavior is this: listbox_dir shows directories, and is initialized to display sub directories of sInitDir. single click an item will display files in that directory in listbox_file. double click an item will display sub directories in listbox_dir.

  • param sInitDir : the initial directory.
  • param sFilePattern : e.g."*.", "*.x" or it could be table like {"*.lua", "*.raw"}
  • param nMaxFileLevels : max file levels. 0 shows files in the current directory.
  • param nMaxNumFiles : max number of files in file listbox. e.g. 150
  • param listbox :_file: a valid ParaUIObject of type listbox for file listing. This can be nil.
  • param listbox :_dir: a valid ParaUIObject of type listbox for directory listing. This can be nil.
  • param btn :_dir_uplevel: a valid ParaUIObject of type button for displaying the last directory.
]]

syntax

function CommonCtrl.InitFileDialog(sInitDir, sFilePattern, nMaxFileLevels, nMaxNumFiles, listbox_file, listbox_dir, btn_dir_uplevel)

parameters

sInitDir the initial directory.
sFilePattern  
nMaxFileLevels max file levels. 0 shows files in the current directory.
nMaxNumFiles  
listbox _file: a valid ParaUIObject of type listbox for file listing. This can be nil.
file  
listbox _file: a valid ParaUIObject of type listbox for file listing. This can be nil.
dir  
| btn | _dir_uplevel: a valid ParaUIObject of type button for displaying the last directory. ]] |
dir  
uplevel  


This topic: Main > NPL > FileDialog
Topic revision: r1 - 2008-02-29 - LiXizhi
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 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