Автор: Taroxx
Дата сообщения: 13.08.2013 20:55
[more] [more] Подскажите как сделать многоуровневое дерево, где каждый node - открываемый пдф во внешней программе.
Исходя из того, что есть в шаблонах, получается только дерево с одной цепочкой, а все остальные попадают в руут.
В скрипте странице прописываю:
Connectors = _SourceFolder .. "\\connectors";
-- Variable: Connectors
function AddToTree(sFullPath)
-- Split the path
tPathParts = String.SplitPath(sFullPath);
-- Get length of root folder (so we know how many chars to skip)
nRootLength = String.Length(Connectors);
-- sFullPath minus last character
sFullFolderPath = tPathParts.Drive .. tPathParts.Folder;
nFullFolderPathLength = String.Length(sFullFolderPath);
sFullFolderPath = String.Mid(sFullFolderPath, 1, nFullFolderPathLength - 1);
-- Check of PDF should be inserted into root of tree
if(String.Compare(Connectors, sFullFolderPath) == 0) then
-- We're inserting this PDF into the root, configure node values
tNodeData = {};
tNodeData['Text']=tPathParts.Filename;
tNodeData['Data']=sFullPath;
tNodeData['ImageIndex']="0";
-- Insert the node
Tree.InsertNode("Tree1", Tree.GetChildCount("Tree1", "0") + 1, tNodeData);
else
-- We need to search for an existing node by 'folder' value (ie sub folder) ... so let's create the search string
-- Initialize
sSearchString = tPathParts.Folder;
-- Strip the last slash off
sSearchString = String.TrimRight(sSearchString, '\\');
-- Find the last occuring slash (will be before the final folder name
nPosLastSlash = String.ReverseFind(sSearchString, '\\');
-- Get rid of all the stuff before the last occuring slash
sSearchString = String.Mid(sSearchString, nPosLastSlash + 1, -1);
-- Search the tree by node name (folder name)
sFoundNodeIndex = Tree.FindNodeByText("Tree1", "0", sSearchString);
if sFoundNodeIndex == "" then
-- Node wasn't found, create it
-- Create node data (data part is left blank ... this is a 'category', not a document)
tNodeData = {};
tNodeData['Text']=sSearchString;
tNodeData['Data']="";
tNodeData['ImageIndex']="1";
sParentIndex = Tree.GetChildCount("Tree1", "0") + 1;
Tree.InsertNode("Tree1", sParentIndex, tNodeData);
else
sParentIndex = sFoundNodeIndex;
end
-- Insert actual file
tNodeData = {};
tNodeData['Text']=tPathParts.Filename;
tNodeData['Data']=sFullPath;
tNodeData['ImageIndex']="0";
Tree.InsertNode("Tree1", sParentIndex .. "." .. (Tree.GetChildCount("Tree1", sParentIndex) + 1), tNodeData);
end
return true;
end
-- Find all PDF's in the folder
File.Find(Connectors, "*.pdf", true, false, nil, AddToTree); [/more] [/more]