On 14/12/04 12:07 am, "Pedja" <[EMAIL PROTECTED]> wrote:
> I have a tree structure (as text) that looks like some sort of folder
> listing that I need to use as a navigation method.
>
> Here is a dummy example:
>
> "rootFolder"
> "rootFolder\data"
> "rootFolder\data\folder1"
> "rootFolder\data\folder1\About"
> "rootFolder\data\folder1\About\Untitled 1.txt"
> "rootFolder\data\folder1\images"
...
>The cXtraTreeview will spit out immediately something like this:
>
> -- "Node
> {
> Text = RootFolder
> ImageIndex = 0
> SelectedIndex = 0
> NAME = All Developments
> Node
> {
> Text = StartPoint
> ImageIndex = 1
> SelectedIndex = 1
> NAME = Section0
> Node
> {
> Text = Main Menu
> ImageIndex = 2
> SelectedIndex = 2
> NAME = Section
Hi Pedja,
I am not sure how you determine the values of the Node, ImageIndex,
SelectedIndex and NAME attributes, but the handler below should get you
started.
You might want to keep a running total of the number of nodes that have been
created, so that each node is created with a value one higher than the
previous one.
You might want to populate the other values in a second pass.
Cheers,
James
----------------------------------------------------------------------------
on ConvertToNestedList(aString) ---------------------------------------
-- INPUT: <aString> must be a text string containing a separate
-- file or folder path on each line, surrounded by quote
-- marks, as in:
-- ""rootFolder"
-- "rootFolder\data"
-- "rootFolder\data\folder1"
-- "rootFolder\data\folder1\About"
-- "rootFolder\data\folder1\About\Untitled 1.txt"
-- "rootFolder\data\folder1\images"
-- "rootFolder\data\folder1\images\Untitled 1.jpg"
-- "rootFolder\data\folder1\images\Untitled 2.jpg"
-- "rootFolder\Data2"
-- "rootFolder\Data2\Text"
-- "rootFolder\Data2\Text\Untitled 1.txt""
-- The paths for a given sub-folder must be listed together.
-- All folders for a given path name must be listed before
-- the files or folders that appear inside it. The Windows
-- path delimiter is assumed.
-- OUTPUT: Returns a nested list with the structure:
-- [1: [#text: "rootFolder",
-- #imageIndex: 0,
-- #selectedIndex: 0,
-- #name: "",
-- 1: [#text: "data",
-- #imageIndex: 0,
-- #selectedIndex: 0,
-- #name: "",
-- 1: [...],
-- 2: [...], ...],
-- 2: [#text: "Data2",
-- #imageIndex: 0,
-- #selectedIndex: 0,
-- #name: "",
-- 1: [...], ...],
-- ...],
-- ...]
---------------------------------------------------------------------
vOutput = [:]
vSubLists = [] -- list of folder names
vSubCount = 0 -- number of items in vSubLists
vIndexList = [] -- path to current folder in vOutput
vItemDelimiter = the itemDelimiter
the itemDelimiter = "\"
vLineCount = the number of lines of aString
repeat with i = 1 to vLineCount
vPath = line i of aString
vPath = value(vPath) -- removes quotes
-- Determine where the current item should be inserted in the
-- nested list
vItemCount = the number of items of vPath
repeat with j = 1 to vItemCount
vItem = item j of vPath
if j > vSubCount then
-- This item is a sub-item of the previous one
vSublists.append(vItem)
vIndex = 1 -- first item in new folder
vIndexList.append(vIndex)
vSubCount = j
else
if vItem = vSubLists[j] then
-- This item shares (part of) the same path as the previous
-- one
else
-- This item's path diverges from the previous one. Delete
-- all subsequent folder and file names.
repeat while vSubCount > j
vSubLists.deleteAt(vSubCount) -- name
vIndexList.deleteAt(vSubCount) -- position in nested list
vSubCount = vSubCount - 1
end repeat
-- Create a sister file or folder
vSublists[j] = vItem
-- Update the path to the current item
vIndex = vIndexList[j]
vIndex = vIndex + 1
vIndexList[j] = vIndex
end if
end if
end repeat
-- Create an entry for the nested list
vItemList = [:]
vItemList[#text] = vItem
-- Customize the following if required
vItemList[#imageIndex] = 0
vItemList[#selectedIndex] = 0
vItemList[#name] = ""
-- Place the entry at the right place in the nested list
vParent = vOutput
vDepthCount = vSubCount - 1
repeat with k = 1 to vDepthCount
vChild = vIndexList[k]
vParent = vParent.getaProp(vChild)
end repeat
vParent.addProp(vIndex, vItemList)
end repeat
the itemDelimiter = vItemDelimiter
return vOutput
end ConvertToNestedList
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]