#!/bin/sh # MetaCard 2.4 stack # The following is not ASCII text, # so now would be a good time to q out of more exec mc $0 "$@" 6CFX_TreeField" ffff33ff33ff%  Califex Tree Field  X UMonaco UVerdana UProFont UArial WArialWArial Uverdana Uverdana UArial UArial WArial WArial ULucida Grande menuGroup P)on TreeClicked pline, pchanged put empty into fld "level" put the VisibleCat of fld "tree" into fld "viscat" set the delimiter of fld "tree" to fld "delim" put the ChosenPath of fld "tree" into fld "path" put the ChosenLine of fld "tree" into fld "line" of grp "chosen" put the ChosenText of fld "tree" into fld "text" of grp "chosen" end TreeClicked on preopenCard if the platform is "macOS" then set the lookandfeel to "macintosh" put empty into fld "cat" put empty into fld "path" put empty into fld "tree" put empty into fld "viscat" put empty into fld "line" put empty into fld "level" put empty into fld "show" put " | " into fld "delim" put fld "jose" into fld "outline" set the hilite of btn "HandleOnly" to false set the HandleOnly of fld "tree" to false set the hilite of btn "useImages" to false set the UseImages of fld "tree" to false disable grp "cat" disable grp "viscat" disable grp "tree" disable grp "chosen" disable grp "expandto" disable btn "fullexpansion" end preopenCard    cREVGeneral bookmarks handlerListTreeClicked preopenCardscriptSelectionchar 385 to 384 tempScript8

on TreeClicked pline, pchanged

put empty into fld "level"

put the VisibleCat of fld "tree" into fld "viscat"

set the delimiter of fld "tree" to fld "delim"

put the ChosenPath of fld "tree" into fld "path"

put the ChosenLine of fld "tree" into fld "line" of grp "chosen"

put the ChosenText of fld "tree" into fld "text" of grp "chosen"

end TreeClicked

on preopenCard

put empty into fld "cat"

put empty into fld "path"

put empty into fld "tree"

put empty into fld "viscat"

put empty into fld "line"

put empty into fld "level"

put empty into fld "show"

put " | " into fld "delim"

put fld "jose" into fld "outline"

set the hilite of btn "HandleOnly" to false

set the HandleOnly of fld "tree" to false

set the hilite of btn "useImages" to false

set the UseImages of fld "tree" to false

disable grp "cat"

disable grp "viscat"

disable grp "tree"

disable grp "chosen"

disable grp "expandto"

disable btn "fullexpansion"

end preopenCard

prevHandler TreeClickedscript !"#&()*-.' expandTo,kfon mouseUp if fld "level" is not a number then put 0 into fld "level" if the target contains "expand" then add 1 to fld "level" else if the target contains "contract" then put max( fld "level" - 1, 0 ) into fld "level" end if set the Expansion of fld "tree" to fld "level" put the VisibleCat of fld "Tree" into fld "viscat" end mouseUp a! Expand to: leveli`   expandeg>>  contracteg<<  Tree FieldJ@tree,iW. Tree Field: tree (z, /* --- TREE field for Metacard 2.4+ and Runtime Revolution --- Tereza Snyder ( tereza@califexsoftware.com), Sept 2001 --- Inspired by the TREE field by Jos L. Rodrguez Illera (jlrodrig@ariadna.d5.ub.es) --- Freeware. If you enhance it, please send us copies. ======================================================================== ----------- INSTRUCTIONS ------------- SETUP: Copy this field to your stack. Set the UseImages property of this field to true or false, and if true, set each Handle[] for +,-, and = with image IDs. Set the HandleOnly property of this field to true or false to allow expansion/contraction only when clicking on =,-,or = (or images). Set the Delimiter property of this field to a string to separate elements of the ChosenPath. Set the Tree property of this field to a tabbed outline. >>>> IMPORTANT: Write a TreeClicked handler in the card or stack to catch messages from clicks on the field. <<<< AFTER SETUP, POSSIBLY IN YOUR TreeClicked HANDLER: Get the ChosenPath of this field to obtain the path to the selected line. Set the ChosenPath of this field to open the outline to a path (delimited by the Delimiter). Get the ChosenText of this field to obtain the unadorned text of the selected line. Set the ChosenText of this field to open the outline to the first instance of the whole text. Get the ChosenLine of this field to obtain the line number (in the full outline) of the selected line. Set the ChosenLine of this field to open the outline to a line number (of the full outline). Set the Expansion of this field to expand the outline uniformly to the specified level. Get the FullExpansion of this field to obtain the outline, tabbed and without handles. Inspect the handlers below for details. ======================================================================== */ -- FOR ACCESSING THE ITEMS IN THE CATALOG CONSTANT cLine=1, cDepth=2, cIsExpanded=3, cIsParent=4, cNext=5, cParentLine=6, cChildren=7 LOCAL tCat -- USERS MUST HAVE A TreeClicked HANDLER -- OR COMMENT OUT CALL HERE on mouseDown put item 1 of the hilitedLines of me into tLine put false into tChanged if NOT (the HandleOnly of me) OR (the clickChar is in "+-") then put ClickTree (tLine) into tChanged if tChanged then DrawTree TreeClicked tLine, tChanged end mouseDown -- USERS MUST PROVIDE PROPERLY TABBED TEXT WHEN SETTING THE "Tree" -- (DOES NO VALIDITY CHECKING) setprop Tree pTabbedText put empty into tCat put empty into me set the Tree of me to empty set the TreeText of me to empty set the TreeTop of me to empty set the Treecat of me to empty if pTabbedText is empty then EXIT Tree put pTabbedText into tOriginal -- BASIC CAT: cLine, cDepth, cIsExpanded put 1 into N repeat for each line L in tOriginal put N & "," & offset ( word 1 of L, L) & "," & "0" & "," & cr after tCat add 1 to N end repeat -- CONSTRUCT CAT RECURSIVELY FROM BASIC CAT put 1 into tNextNum put the number of lines in tCat into tMax repeat until tNextNum > tMax put AddFamily( tNextNum, 0, tMax ) into tNextNum end repeat set the TreeCat of me to tCat set the TreeMax of me to the number of lines in tCat -- MAKE FULLY-COLLAPSED CAT put empty into tTop repeat for each line L in tCat if item cDepth of L is 1 then put L & cr after tTop end repeat set the TreeTop of me to tTop -- STORE TEXT WITHOUT TABS replace tab with empty in tOriginal set the TreeText of me to tOriginal --/// set the TreeTabs of me to format( "\t\t\t\t\t\t\t\t\t\t\t" ) -- uncomment to reinitialize ExpandTo 1 DrawTree end Tree -- RETURNS THE PATH TO THE SELECTED LINE IN THE VISIBLE TREE -- USING THE Delimiter TO SEPARATE ITEMS getprop ChosenPath LOCAL tPath if me is empty or the hilitedLines of me is empty then RETURN empty get line (item 1 of the hilitedlines of me) of the VisibleCat of me put line (item cLine of it) of the TreeText of me into tPath repeat until (item cParentLine of it is 0) put line (item cParentLine of it) of the TreeText of me & (the Delimiter of me) & tPath into tPath get line (item cParentLine of it) of the TreeCat of me end repeat RETURN tPath end ChosenPath -- OPENS TO AND HILITES THE LINE REPRESENTED BY pPath -- pPath SHOULD USE THE Delimiter TO SEPARATE ITEMS setprop ChosenPath pPath LOCAL tPath expandto 1 set the hilitedlines of me to empty if pPath is empty then EXIT ChosenPath replace the delimiter of me with "," in pPath set the wholeMatches to true put 0 into tSkip repeat for each item I in pPath get lineOffset( I, the TreeText of me, tSkip) if it is 0 then EXIT ChosenPath -- NOT FOUND add it to tSkip end repeat get ExpandToLine( tSkip ) DrawTree set the hilitedLines of me to it end ChosenPath -- RETURNS THE BARE TEXT OF THE THE SELECTED LINE IN THE VISIBLE TREE getprop ChosenText if me is empty or the hilitedLines of me is empty then RETURN empty get line (item 1 of the hilitedlines of me) of the VisibleCat of me RETURN line (item cLine of it) of the TreeText of me end ChosenText -- OPENS TO, AND HILITES, THE FIRST LINE MATCHING pText setprop ChosenText pText expandto 1 set the hilitedlines of me to empty if pText is empty then EXIT ChosenText set the wholeMatches to true get lineOffset(pText, the TreeText of me) if it is 0 then EXIT ChosenText -- NOT FOUND get ExpandToLine( it ) DrawTree set the hilitedLines of me to it end ChosenText -- RETURNS THE LINE NUMBER OF THE SELECTED LINE IN THE FULL OUTLINE -- RETURNS 0 FOR NONE SELECTED getprop ChosenLine if me is empty or the hilitedLines of me is empty then RETURN 0 get line( item 1 of the hilitedlines of me) of the VisibleCat of me RETURN item cLine of it end ChosenLine -- OPENS TO, AND HILITES, THE pLineth LINE OF THE FULL OUTLINE setprop ChosenLine pLine expandto 1 set the hilitedlines of me to empty if pLine is 0 then EXIT ChosenLine get ExpandToLine( pLine ) DrawTree set the hilitedLines of me to it end ChosenLine on ShowParent if me is empty or the hilitedLines of me is empty then EXIT ShowParent get line( item 1 of the hilitedlines of me) of the VisibleCat of me get item cParentLine of it if it <> 0 then set the ChosenLine of me to it end if end ShowParent on ShowChild if me is empty or the hilitedLines of me is empty then EXIT ShowChild get line( item 1 of the hilitedlines of me) of the VisibleCat of me if item cIsParent of it <> 0 then set the ChosenLine of me to ( word 1 of item cChildren of it) end if end ShowChild -- RETURNS THE PLAIN OUTLINE FULLY EXPANDED WITH TABS getProp FullExpansion LOCAL tText, tOutline put the TreeText of me into tText put the TreeCat of me into tCat put 1 into N repeat for each line L in tText put (char 1 to (item cDepth of line N of tCat)-1 of the TreeTabs of me) & L & cr into line N of tOutline add 1 to N end repeat RETURN tOutline end FullExpansion -- pLevel IS THE DEEPEST LEVEL TO SHOW: 0 FOR NONE, 1 FOR THE ROOTS, ETC. setprop Expansion pLevel LOCAL tText, tViscat put empty into me set the hilitedLines of me to empty ExpandTo pLevel DrawTree end Expansion -- OPENS OR CLOSES THE TREE TO THE REQUESTED LEVEL on ExpandTo pLevel LOCAL tViscat if pLevel is 1 then -- OPTIMIZED set the VisibleCat of me to the TreeTop of me else put the TreeCat of me into tCat repeat for each line L in tCat if item cDepth of L <= pLevel then if item cIsParent of L is 1 AND item cDepth of L < pLevel then put 1 into item cIsExpanded of L end if put L & cr after tVisCat end if end repeat set the VisibleCat of me to tVisCat end if end ExpandTo -- OPENS THE TREE TO THE REQUESTED LINE -- RETURNS ITS LINE NUMBER IN THE VISIBLE TREE function ExpandToLine pLine LOCAL tVisCat, tFamily put line pLine of the TreeCat of me into tFamily if tFamily is empty then EXIT ExpandToLine repeat until item cParentLine of tFamily is 0 put line (item cParentLine of line 1 of tFamily) of the TreeCat of me & cr before tFamily end repeat set the VisibleCat of me to the TreeTop of me repeat with N = 1 to (the number of lines in tFamily) -1 get lineOffset ( cr & item 1 of line N of tFamily, cr & the VisibleCat of me) get clickTree( it ) end repeat RETURN lineOffset ( the last line of tFamily, the VisibleCat of me) end ExpandToLine -- a recursive function that, given a line in the catalog, -- returns the line number of next item at the same or lesser depth -- while building the catalog data for that line and the intervening lines -- in the variable tCat function AddFamily pLineNum, pParent pMax LOCAL tDepth, tChildren, tNextNum put item cDepth of line pLineNum of tCat into tDepth put pLineNum + 1 into tNextNum put empty into tChildren repeat until tNextNum > pMax OR item cDepth of line tNextNum of tCat <= tDepth put tNextNum & space after tChildren put AddFamily( tNextNum, pLineNum, pMax ) into tNextNum end repeat if (tNextNum - pLineNum) > 1 then get 1 else get 0 -- is it a parent node? put it & "," & tNextNum & "," & pParent & "," & tChildren after line pLineNum of tCat RETURN tNextNum end AddFamily -- RETURNS TRUE IF A CLICK ON pLineNum CHANGES THE TREE function ClickTree pLineNum put the VisibleCat of me into tVisibleCat if pLineNum is 0 then -- special case for initialization put the TreeTop of me into tVisibleCat else get line pLineNum of tVisibleCat if item cIsParent of it is 1 then if item cIsExpanded of it is 1 then -- EXPANDED, MUST CONTRACT put 0 into item cIsExpanded of line pLineNum of tVisibleCat if item cNext of it >= the TreeMax of me then put line 1 to (pLineNum) of tVisibleCat into tVisibleCat else delete line (pLineNum + 1) to ( lineOffset( cr & item cNext of it, tVisibleCat) ) of tVisibleCat end if else -- CONTRACTED, MUST EXPAND put 1 into item cIsExpanded of line pLineNum of tVisibleCat repeat for each word W in item cChildren of it put cr & line W of the TreeCat of me after tExp end repeat put tExp after line pLineNum of tVisibleCat end if else -- A LEAF RETURN false end if end if set the VisibleCat of me to tVisibleCat RETURN true end ClickTree on DrawTree LOCAL tScroll, tLines lock screen put the hilitedLines of me into tLines put the scroll of me into tScroll put empty into me put 1 into N repeat for each line L in the VisibleCat of me if item cIsExpanded of L is 1 then get "-" else if item cIsParent of L is 0 then get "=" else get "+" put (char 1 to (item cDepth of L)-1 of the TreeTabs of me) & it & space & (line (item cLine of L) of the TreeText of me) & cr after me if the UseImages of me then set the imageSource of char (item cDepth of L) of line N of me to the Handle[it] of me end if add 1 to N end repeat delete last char of me -- EXTRA CR set the hilitedLines of me to tLines set the scroll of me to tScroll unlock screen end DrawTree X" TreeTabs TreeTop*1,1,0,1,17,0,2 7 16 17,1,0,1,20,0,18 19 UseImagestrue HandleOnlyfalseTreeMax19TreeTreeCat>1,1,0,1,17,0,2 7 16 2,2,0,1,7,1,3 4 3,3,0,0,4,2, 4,3,0,1,7,2,5 6 5,4,0,0,6,4, 6,4,0,0,7,4, 7,2,0,1,16,1,8 12 13 8,3,0,1,12,7,9 11 9,4,0,1,11,8,10 10,5,0,0,11,9, 11,4,0,0,12,8, 12,3,0,0,13,7, 13,3,0,1,16,7,14 15 14,4,0,0,15,13, 15,4,0,0,16,13, 16,2,0,0,17,1, 17,1,0,1,20,0,18 19 18,2,0,0,19,17, 19,2,0,0,20,17, TreeTextproject main a MA1 MA2 MA2 alfa MA2 beta main b MB1 MB1 alfa MB1 last a MB1 beta MB2 MB3 MB3 alfa MB3 beta2 main c project2 MC1 MC2 VisibleCat*1,1,0,1,17,0,2 7 16 17,1,0,1,20,0,18 19 delimiter |   cREVGeneralscriptChecksum3`/_1>+P_ bookmarks handlerListmouseDown Tree ChosenPath ChosenPath ChosenText ChosenText ChosenLine ChosenLine ShowParent ShowChild FullExpansion Expansion ExpandTo ExpandToLine AddFamily ClickTree DrawTree tempScript prevHandler ClickTreescriptSelectionchar 11001 to 11000script6

/*

--- TREE field for Metacard 2.4+ and Runtime Revolution

--- Tereza Snyder ( tereza@califexsoftware.com), Sept 2001

--- Inspired by the TREE field by José L. Rodríguez Illera (jlrodrig@ariadna.d5.ub.es)

--- Freeware. If you enhance it, please send us copies.

========================================================================

----------- INSTRUCTIONS -------------

SETUP:

Copy this field to your stack.

Set the UseImages property of this field to true or false, and if true, set each Handle[] for +,-, and = with image IDs.

Set the HandleOnly property of this field to true or false to allow expansion/contraction only when clicking on =,-,or = (or images).

Set the Delimiter property of this field to a string to separate elements of the ChosenPath.

Set the Tree property of this field to a tabbed outline.

>>>> IMPORTANT: Write a TreeClicked handler in the card or stack to catch messages from clicks on the field. <<<<

AFTER SETUP, POSSIBLY IN YOUR TreeClicked HANDLER:

Get the ChosenPath of this field to obtain the path to the selected line.

Set the ChosenPath of this field to open the outline to a path (delimited by the Delimiter).

Get the ChosenText of this field to obtain the unadorned text of the selected line.

Set the ChosenText of this field to open the outline to the first instance of the whole text.

Get the ChosenLine of this field to obtain the line number (in the full outline) of the selected line.

Set the ChosenLine of this field to open the outline to a line number (of the full outline).

Set the Expansion of this field to expand the outline uniformly to the specified level.

Get the FullExpansion of this field to obtain the outline, tabbed and without handles.

Inspect the handlers below for details.

========================================================================

*/

-- FOR ACCESSING THE ITEMS IN THE CATALOG

CONSTANT cLine=1, cDepth=2, cIsExpanded=3, cIsParent=4, cNext=5, cParentLine=6, cChildren=7

LOCAL tCat

-- USERS MUST HAVE A TreeClicked HANDLER

-- OR COMMENT OUT CALL HERE

on mouseDown

put item 1 of the hilitedLines of me into tLine

put false into tChanged

if NOT (the HandleOnly of me) OR (the clickChar is in "+-")

then put ClickTree (tLine) into tChanged

if tChanged then DrawTree

TreeClicked tLine, tChanged

end mouseDown

-- USERS MUST PROVIDE PROPERLY TABBED TEXT WHEN SETTING THE "Tree"

-- (DOES NO VALIDITY CHECKING)

setprop Tree pTabbedText

put empty into tCat

put empty into me

set the Tree of me to empty

set the TreeText of me to empty

set the TreeTop of me to empty

set the Treecat of me to empty

if pTabbedText is empty then EXIT Tree

put pTabbedText into tOriginal

-- BASIC CAT: cLine, cDepth, cIsExpanded

put 1 into N

repeat for each line L in tOriginal

put N & "," & offset ( word 1 of L, L) & "," & "0" & "," & cr after tCat

add 1 to N

end repeat

-- CONSTRUCT CAT RECURSIVELY FROM BASIC CAT

put 1 into tNextNum

put the number of lines in tCat into tMax

repeat until tNextNum > tMax

put AddFamily( tNextNum, 0, tMax ) into tNextNum

end repeat

set the TreeCat of me to tCat

set the TreeMax of me to the number of lines in tCat

-- MAKE FULLY-COLLAPSED CAT

put empty into tTop

repeat for each line L in tCat

if item cDepth of L is 1 then put L & cr after tTop

end repeat

set the TreeTop of me to tTop

-- STORE TEXT WITHOUT TABS

replace tab with empty in tOriginal

set the TreeText of me to tOriginal

--/// set the TreeTabs of me to format( "\t\t\t\t\t\t\t\t\t\t\t" ) -- uncomment to reinitialize

ExpandTo 1

DrawTree

end Tree

-- RETURNS THE PATH TO THE SELECTED LINE IN THE VISIBLE TREE

-- USING THE Delimiter TO SEPARATE ITEMS

getprop ChosenPath

LOCAL tPath

if me is empty or the hilitedLines of me is empty then RETURN empty

get line (item 1 of the hilitedlines of me) of the VisibleCat of me

put line (item cLine of it) of the TreeText of me into tPath

repeat until (item cParentLine of it is 0)

put line (item cParentLine of it) of the TreeText of me & (the Delimiter of me) & tPath into tPath

get line (item cParentLine of it) of the TreeCat of me

end repeat

RETURN tPath

end ChosenPath

-- OPENS TO AND HILITES THE LINE REPRESENTED BY pPath

-- pPath SHOULD USE THE Delimiter TO SEPARATE ITEMS

setprop ChosenPath pPath

LOCAL tPath

expandto 1

set the hilitedlines of me to empty

if pPath is empty then EXIT ChosenPath

replace the delimiter of me with "," in pPath

set the wholeMatches to true

put 0 into tSkip

repeat for each item I in pPath

get lineOffset( I, the TreeText of me, tSkip)

if it is 0 then EXIT ChosenPath -- NOT FOUND

add it to tSkip

end repeat

get ExpandToLine( tSkip )

DrawTree

set the hilitedLines of me to it

end ChosenPath

-- RETURNS THE BARE TEXT OF THE THE SELECTED LINE IN THE VISIBLE TREE

getprop ChosenText

if me is empty or the hilitedLines of me is empty then RETURN empty

get line (item 1 of the hilitedlines of me) of the VisibleCat of me

RETURN line (item cLine of it) of the TreeText of me

end ChosenText

-- OPENS TO, AND HILITES, THE FIRST LINE MATCHING pText

setprop ChosenText pText

expandto 1

set the hilitedlines of me to empty

if pText is empty then EXIT ChosenText

set the wholeMatches to true

get lineOffset(pText, the TreeText of me)

if it is 0 then EXIT ChosenText -- NOT FOUND

get ExpandToLine( it )

DrawTree

set the hilitedLines of me to it

end ChosenText

-- RETURNS THE LINE NUMBER OF THE SELECTED LINE IN THE FULL OUTLINE

-- RETURNS 0 FOR NONE SELECTED

getprop ChosenLine

if me is empty or the hilitedLines of me is empty then RETURN 0

get line( item 1 of the hilitedlines of me) of the VisibleCat of me

RETURN item cLine of it

end ChosenLine

-- OPENS TO, AND HILITES, THE pLineth LINE OF THE FULL OUTLINE

setprop ChosenLine pLine

expandto 1

set the hilitedlines of me to empty

if pLine is 0 then EXIT ChosenLine

get ExpandToLine( pLine )

DrawTree

set the hilitedLines of me to it

end ChosenLine

on ShowParent

if me is empty or the hilitedLines of me is empty then EXIT ShowParent

get line( item 1 of the hilitedlines of me) of the VisibleCat of me

get item cParentLine of it

if it <> 0 then

set the ChosenLine of me to it

end if

end ShowParent

on ShowChild

if me is empty or the hilitedLines of me is empty then EXIT ShowChild

get line( item 1 of the hilitedlines of me) of the VisibleCat of me

if item cIsParent of it <> 0 then

set the ChosenLine of me to ( word 1 of item cChildren of it)

end if

end ShowChild

-- RETURNS THE PLAIN OUTLINE FULLY EXPANDED WITH TABS

getProp FullExpansion

LOCAL tText, tOutline

put the TreeText of me into tText

put the TreeCat of me into tCat

put 1 into N

repeat for each line L in tText

put (char 1 to (item cDepth of line N of tCat)-1 of the TreeTabs of me) & L & cr into line N of tOutline

add 1 to N

end repeat

RETURN tOutline

end FullExpansion

-- pLevel IS THE DEEPEST LEVEL TO SHOW: 0 FOR NONE, 1 FOR THE ROOTS, ETC.

setprop Expansion pLevel

LOCAL tText, tViscat

put empty into me

set the hilitedLines of me to empty

ExpandTo pLevel

DrawTree

end Expansion

-- OPENS OR CLOSES THE TREE TO THE REQUESTED LEVEL

on ExpandTo pLevel

LOCAL tViscat

if pLevel is 1 then -- OPTIMIZED

set the VisibleCat of me to the TreeTop of me

else

put the TreeCat of me into tCat

repeat for each line L in tCat

if item cDepth of L <= pLevel then

if item cIsParent of L is 1 AND item cDepth of L < pLevel then

put 1 into item cIsExpanded of L

end if

put L & cr after tVisCat

end if

end repeat

set the VisibleCat of me to tVisCat

end if

end ExpandTo

-- OPENS THE TREE TO THE REQUESTED LINE

-- RETURNS ITS LINE NUMBER IN THE VISIBLE TREE

function ExpandToLine pLine

LOCAL tVisCat, tFamily

put line pLine of the TreeCat of me into tFamily

if tFamily is empty then EXIT ExpandToLine

repeat until item cParentLine of tFamily is 0

put line (item cParentLine of line 1 of tFamily) of the TreeCat of me & cr before tFamily

end repeat

set the VisibleCat of me to the TreeTop of me

repeat with N = 1 to (the number of lines in tFamily) -1

get lineOffset ( cr & item 1 of line N of tFamily, cr & the VisibleCat of me)

get clickTree( it )

end repeat

RETURN lineOffset ( the last line of tFamily, the VisibleCat of me)

end ExpandToLine

-- a recursive function that, given a line in the catalog,

-- returns the line number of next item at the same or lesser depth

-- while building the catalog data for that line and the intervening lines

-- in the variable tCat

function AddFamily pLineNum, pParent pMax

LOCAL tDepth, tChildren, tNextNum

put item cDepth of line pLineNum of tCat into tDepth

put pLineNum + 1 into tNextNum

put empty into tChildren

repeat until tNextNum > pMax OR item cDepth of line tNextNum of tCat <= tDepth

put tNextNum & space after tChildren

put AddFamily( tNextNum, pLineNum, pMax ) into tNextNum

end repeat

if (tNextNum - pLineNum) > 1 then get 1 else get 0 -- is it a parent node?

put it & "," & tNextNum & "," & pParent & "," & tChildren after line pLineNum of tCat

RETURN tNextNum

end AddFamily

-- RETURNS TRUE IF A CLICK ON pLineNum CHANGES THE TREE

function ClickTree pLineNum

put the VisibleCat of me into tVisibleCat

if pLineNum is 0 then -- special case for initialization

put the TreeTop of me into tVisibleCat

else

get line pLineNum of tVisibleCat

if item cIsParent of it is 1 then

if item cIsExpanded of it is 1 then -- EXPANDED, MUST CONTRACT

put 0 into item cIsExpanded of line pLineNum of tVisibleCat

if item cNext of it >= the TreeMax of me then

put line 1 to (pLineNum) of tVisibleCat into tVisibleCat

else

delete line (pLineNum + 1) to ( lineOffset( cr & item cNext of it, tVisibleCat) ) of tVisibleCat

end if

else -- CONTRACTED, MUST EXPAND

put 1 into item cIsExpanded of line pLineNum of tVisibleCat

repeat for each word W in item cChildren of it

put cr & line W of the TreeCat of me after tExp

end repeat

put tExp after line pLineNum of tVisibleCat

end if

else -- A LEAF

RETURN false

end if

end if

set the VisibleCat of me to tVisibleCat

RETURN true

end ClickTree

on DrawTree

LOCAL tScroll, tLines

lock screen

put the hilitedLines of me into tLines

put the scroll of me into tScroll

put empty into me

put 1 into N

repeat for each line L in the VisibleCat of me

if item cIsExpanded of L is 1 then get "-"

else if item cIsParent of L is 0 then get "="

else get "+"

put (char 1 to (item cDepth of L)-1 of the TreeTabs of me) & it & space & (line (item cLine of L) of the TreeText of me) & cr after me

if the UseImages of me then

set the imageSource of char (item cDepth of L) of line N of me to the Handle[it] of me

end if

add 1 to N

end repeat

delete last char of me -- EXTRA CR

set the hilitedLines of me to tLines

set the scroll of me to tScroll

unlock screen

end DrawTree

Handle+15000=15002-15001  + project @15000  + project2 @15000  `i Y 7 UseImages@euon mouseUp set the UseImages of fld "tree" to the hilite of me set the expansion of fld "tree" to 1 end mouseUp gX Use Images:  collapsed,ie]7!+ )`fh5 cREVTable currentview15000  15000  leaf,i]7!= )`h5  15002   expanded,i]7!- )`h5  15001  : right.png y} SPNG  IHDR r|sBIT|d pHYs  ~tEXtCreation Time09.15.018nIENDB`: down.png } IPNG  IHDR r|sBIT|d pHYs  ~tEXtCreation Time09.15.013-~IENDB`: spot.png @ ؉PNG  IHDR r|sBIT|d pHYs  ~tEXtCreation Time09.15.01by Tereza Snyder, <tereza@califexsoftware.com>, Sept. 2001 Inspired by TREE field by José L. Rodríguez Illera <jlrodrig@ariadna.d5.ub.es>

To operate this test stack, click the TEST button, then click on the tree field and other controls.

See the script of the field "tree" for instructions for use.

 cREVGeneral bookmarks handlerList prevHandler tempScriptscript  by Tereza Snyder, , Sept. 2001 Inspired by TREE field by Jos L. Rodrguez Illera fTo operate this test stack, click the TEST button, then click on the tree field and other controls. =See the script of the field "tree" for instructions for use.  !text ,i.Tabbed Outline ==> +jose j" project  main a  MA1  MA2 MA2 alfa MA2 beta  main b  MB1 MB1 alfa  MB1 last a MB1 beta  MB2  MB3 MB3 alfa MB3 beta2  main c project2  MC1  MC2,` outline(j" project  main a  MA1  MA2 MA2 alfa MA2 beta  main b  MB1 MB1 alfa  MB1 last a MB1 beta  MB2  MB3 MB3 alfa MB3 beta2  main c project2  MC1  MC2` "cat ,i.Tree Catalog ==> catj33" 1,1,0,1,17,0,2 7 16 2,2,0,1,7,1,3 4 3,3,0,0,4,2, 4,3,0,1,7,2,5 6 5,4,0,0,6,4, 6,4,0,0,7,4, 7,2,0,1,16,1,8 12 13 8,3,0,1,12,7,9 11 9,4,0,1,11,8,10 10,5,0,0,11,9, 11,4,0,0,12,8, 12,3,0,0,13,7, 13,3,0,1,16,7,14 15 14,4,0,0,15,13, 15,4,0,0,16,13, 16,2,0,0,17,1, 17,1,0,1,20,0,18 19 18,2,0,0,19,17, 19,2,0,0,20,17, `| #viscat ,i.Catalog of visible tree ==> viscat(z<---TREE field for Metacard, Version 1, Sept 2001 ---Freeware. ---If you make enhacements, please send me a copy: jlrodrig@ariadna.d5.ub.es =========================================================================== LOCAL tVisibleCat LOCAL tTabs LOCAL tCat setprop Tree pTabbedText put empty into tCat put pTabbedText into tOriginal put 1 into N repeat for each line L in tOriginal put N & "," & offset ( word 1 of L, L) & "," & "0" & "," & cr after tCat add 1 to N end repeat put 1 into tNextNum put the number of lines in tCat into tMax repeat until tNextNum > tMax put AddFamily( tNextNum, tMax ) into tNextNum end repeat set the TreeCat of me to tCat set the TreeMax of me to the number of lines in tCat put empty into tTop repeat for each line L in tCat if item 2 of L is 1 then put L & cr after tTop end repeat set the TreeTop of me to tTop replace tab with empty in tOriginal set the TreeText of me to tOriginal put format( "\t\t\t\t\t\t\t\t\t\t\t" ) into tTabs CollapseTree end Tree -- a recursive function that, given a line in the catalog, -- returns the linenumber of next item at the same or lesser depth -- while building the catalog data for that line and the intervening lines -- in the variable tCat function AddFamily pLineNum, pMax LOCAL tDepth, tChildren, tNextNum put item 2 of line pLineNum of tCat into tDepth put pLineNum + 1 into tNextNum put empty into tChildren repeat until tNextNum >= pMax OR item 2 of line tNextNum of tCat <= tDepth put tNextNum & space after tChildren put AddFamily( tNextNum, pMax ) into tNextNum end repeat if (tNextNum - pLineNum) > 1 then get 1 else get 0 -- is it a parent node? put it & "," & tNextNum & "," & tChildren after line pLineNum of tCat RETURN tNextNum end AddFamily -- returns true if a click on pLineNum changes the tree function ClickTree pLineNum put the params &cr& tVisibleCat if pLineNum is 0 then -- special case for initialization put the TreeTop of me into tVisibleCat else get line pLineNum of tVisibleCat if item 4 of it is 1 then -- not a leaf if item 3 of it is 1 then -- expanded, must contract put 0 into item 3 of line pLineNum of tVisibleCat if item 5 of it >= the TreeMax of me then put line 1 to (pLineNum) of tVisibleCat into tVisibleCat else delete line (pLineNum + 1) to ( lineOffset( cr & item 5 of it, tVisibleCat) ) of tVisibleCat end if else -- contracted, must expand put 1 into item 3 of line pLineNum of tVisibleCat repeat for each word W in item 6 of it put cr & line W of the TreeCat of me after tExp end repeat put tExp after line pLineNum of tVisibleCat end if else -- a leaf RETURN false end if end if RETURN true end ClickTree on CollapseTree pLineNum put empty into me get ClickTree( 0 ) DrawTree end CollapseTree on mouseDown if ClickTree (word 2 of the clickLine) then DrawTree end mouseDown On DrawTree LOCAL tScroll, tLines lock screen put the hilitedLines of me into tLines put the scroll of me into tScroll put empty into me repeat for each line L in tVisibleCat if item 3 of L is 1 then get "-" else if item 4 of L is 0 then get "=" else get "+" put char 1 to (item 2 of L) of tTabs & it & (line (item 1 of L) of the TreeText of me) & cr after me -- set the imageSource... end repeat set the scroll of me to tScroll set the hilitedLines of me to tLines unlock screen end DrawTree 33" TreeTop#1,1,0,1,17,2 7 16 17,1,0,1,19,18 arbolvisto- project - main a - MA1 - MA2 - MA2 alfa - MA2 beta - main b - MB1 + MB1 alfa - MB1 beta - MB2 + MB3 - main c + project2 TreeMax19catalogovisto1 1 1 1 15 2 7 16 2 2 1 1 4 3 4 3 3 0 0 4 3 1 1 2 5 6 5 4 0 0 6 4 0 0 7 2 1 1 8 8 12 13 8 3 1 1 3 9 11 9 4 0 1 1 10 11 4 0 0 12 3 0 0 13 3 0 1 2 14 15 16 2 0 0 17 1 0 1 2 18 19arbolproject main a MA1 MA2 MA2 alfa MA2 beta main b MB1 MB1 alfa MB1 last a MB1 beta MB2 MB3 MB3 alfa MB3 beta2 main c project2 MC1 MC2TreeCat1,1,0,1,17,2 7 16 2,2,0,1,7,3 4 3,3,0,0,4, 4,3,0,1,7,5 6 5,4,0,0,6, 6,4,0,0,7, 7,2,0,1,16,8 12 13 8,3,0,1,12,9 11 9,4,0,1,11,10 10,5,0,0,11, 11,4,0,0,12, 12,3,0,0,13, 13,3,0,1,16,14 15 14,4,0,0,15, 15,4,0,0,16, 16,2,0,0,17, 17,1,0,1,19,18 18,2,0,0,19, 19,2,0,0,20, catalogo1 1 0 1 15 2 7 16 2 2 0 1 4 3 4 3 3 0 0 4 3 0 1 2 5 6 5 4 0 0 6 4 0 0 7 2 0 1 8 8 12 13 8 3 0 1 3 9 11 9 4 0 1 1 10 10 5 0 0 11 4 0 0 12 3 0 0 13 3 0 1 2 14 15 14 4 0 0 15 4 0 0 16 2 0 0 17 1 0 1 2 18 19 18 2 0 0 19 2 0 0 TreeTextproject main a MA1 MA2 MA2 alfa MA2 beta main b MB1 MB1 alfa MB1 last a MB1 beta MB2 MB3 MB3 alfa MB3 beta2 main c project2 MC1 MC2 VisibleCat#1,1,0,1,17,2 7 16 17,1,0,1,19,18  1,1,1,1,17,0,2 7 16 2,2,1,1,7,1,3 4 3,3,0,0,4,2, 4,3,1,1,7,2,5 6 5,4,0,0,6,4, 6,4,0,0,7,4, 7,2,1,1,16,1,8 12 13 8,3,1,1,12,7,9 11 9,4,1,1,11,8,10 10,5,0,0,11,9, 11,4,0,0,12,8, 12,3,0,0,13,7, 13,3,0,1,16,7,14 15 16,2,0,0,17,1, 17,1,0,1,20,0,18 19 `? &fullexpansione+won mouseUp set the hilite of me to true put the FullExpansion of fld "tree" into fld "fullexpansion" show fld "fullexpansion" wait until the mouseclick hide fld "fullexpansion" set the hilite of me to false end mouseUp ff}Full Expansion (choseni, chosenpath,i$Path to chosen line: path`33  "project | main b | MB1 | MB1 alfa  ,i?=$ Delimiter: delimkpFon closeField set the delimiter of fld "tree" to me end closeField @;   |  chosen,ic$Chosen: text`33C  MB1 alfa  line(`33  9   )version on mouseUp if the shiftkey is down then add .1 to word 2 of me else if the optionkey is down then subtract .1 from word 2 of me end mouseUp \ cREVTable currentview version 2.1 version 2.1*Fileewon mouseUp answer file "tabbed text file" if the result is empty then put it into tFile open file tFile for read read from file tFile until eof close file tFile preopencard put it into fld "outline" end if end mouseUp Import from Text File -i4\3$K@8`+TESTEon mouseUp set the HandleOnly of fld "Tree" to the hilite of btn "HandleOnly" set the UseImages of fld "Tree" to the hilite of btn "UseImages" set the Handle["+"] of fld "Tree" to fld 1 of grp "collapsed" set the Handle["-"] of fld "Tree" to fld 1 of grp "expanded" set the Handle["="] of fld "Tree" to fld 1 of grp "leaf" set the Tree of fld "tree" to fld "outline" put the TreeCat of fld "Tree" into fld "cat" put the Visiblecat of fld "tree" into fld "visCat" enable grp "cat" enable grp "viscat" enable grp "tree" enable grp "chosen" enable grp "expandto" enable btn "fullexpansion" enable grp "show" end mouseUp @Ah .showiI,/ showpath,i$$Path, text, or line number to show: 0showipZon closeField click at the loc of btn "show" end closeField on mouseUp end mouseUp "type a line number, path, or text 6ShowEw+on mouseUp get fld "show" if it contains the Delimiter of fld "tree" then set the ChosenPath of fld "tree" to it else if it is a number then set the ChosenLine of fld "tree" to it else set the ChosenText of fld "tree" to it TreeClicked the SelectedLine of fld "tree" end mouseUp 8"type a line number, path, or text  'fullExpansion ilevel51  project  main a  MA1  MA2 MA2 alfa MA2 beta  main b  MB1 MB1 alfa  MB1 last a MB1 beta  MB2  MB3 MB3 alfa MB3 beta2  main c project2  MC1  MC2   HandleOnly@evon mouseUp set the HandleOnly of fld "tree" to the hilite of me set the expansion of fld "tree" to 1 end mouseUp fLAllow clicks only on 'handles'