$Did-tree for mdx TreeView

By Yochai on Mar 01, 2004

/*
By Yochai Timmer
These commands will help you control a Tree View list.
I've made $did-tree to act like the regular $did command, and supports the props used for
$did-tree(dialog,ID,N) Gives you the text of the Nth branch, You have to use branch loaction and give all the root IDs before like 2 3 4 etc..
$did-tree(dialog,ID,N).lines Gives you the number of lines under the Nth root. (Not including line 1 of course)
$did-tree(dialog,ID) gives you the selected line's text.
$did-tree(dialog,ID).len Gives you the selected line's length.
$did-tree(dialog,ID).sel Gives you the selected line's branch location.
$did-tree(dialog,ID).root Gives you the selected line's root.
$did-tree(dialog,ID).lines Gives you the number of lines in the corrent branch.
$did-tree(dialog,ID).Event Will return the last event for that ID
$did-tree(dialog,ID,N).Tooltip Will give you the Branch's tooltip

Example, Rootview:

-Root {tab} Tooltip - root
|-Branch1
|-Branch2
-Root2
|-THing
|--Subthing {tab} This is the tooltip

The basic law is that mdx uses line 1 in each Branch, so the actuall lines that you see start from line 2
So the location of "Subthing" would be: 3 2 2
and the location of Branch2 would be: 2 3

Now to call check writen in the First root, seconed line you would use this: $did-tree(Dialog,ID,2 3)

Now lets assume that "Subthing" is selected now:
$did-tree(dialog,ID) Gives you Subthing
$did-tree(dialog,ID).len gives you 8
$did-tree(dialog,ID).sel gives you 3 2 2
$did-tree(dialog,ID).root gives you 3
$did-tree(dialog,ID).lines gives you 1 (There's only 1 line in that branch)
$did-tree(dialog,ID).Tooltip gives you This is the tooltip

$did-tree(dialog,ID,2) will give you Root
$did-tree(dialog,ID,2).lines will give you 2 (there are 2 branches under "root")
$did-tree(dialog,ID,2).Tooltip will give you Tooltip - root
$did-tree(dialog,ID,2).Event will give you Sclick

I like using %vars cause it's easier to read %names than $1 $2 $4, but it's not necessery, and you can change that.
*/

;$Did-Tree By Yochai Timmer
Alias -l did-tree {
  var %dialog = $1
  var %id = $2
;It's not necessery to set the $1 and $2 to vars, but I  like to use named vars (Espcialy in examples)

  if (!$dialog(%dialog)) return
;Just checking...

   if ($3) {
; Checks if a specific location was requested

    var %Loc = $3-
;Sets the location

   if ($prop = lines) {
;Checks if the Property .lines was used

      did -i %dialog %id 1 cb root %loc
;always need to use cb (change branch) to get the requested location

     return $calc($did(%dialog,%id,0).lines -1)
;mdx default returns the number of lines + 1 (the options line), so you need to reduce by one to get the actuall number of lines

    }
    if ($numtok(%Loc,32) = 1) did -i %dialog %id 1 cb root
    else { did -i %dialog %id 1 cb root $gettok(%loc,1- $+ $calc($numtok(%loc,32) -1),32) }
;Changing to the requested branch...

    var %line = $gettok($did(%dialog,%id,$gettok(%Loc,-1,32)),7-,32)
;This sets %line to the branch's text

    if ($prop = tooltip) return $gettok(%line,2-,9)
;This returns the branch's tooltip

    return $gettok(%line,1,9)
;This returns the requested branch

  }
  var %entry = $did(%dialog,%id,1)
  if ($gettok(%entry,1,32) = slclick) var %loc = $gettok(%entry,4-,32)
  else var %loc = $gettok(%entry,3-,32)
;This checks the last event in the requested ID

  var %depth = $calc($numtok(%loc,32) -1)
  var %branch = $gettok(%loc,-1,32)
;Setting the depth of the branch, and the actuall branch position

  if (%depth = 0) did -i %dialog %id 1 cb root 
  else did -i %dialog %id 1 cb root $gettok(%loc,1- $+ %depth,32) 
;Changing to the requested branch

  var %line = $gettok($did(%dialog,%id,%branch),7-,32)
;This sets %line to the branch's text

  if (!$prop) return $gettok(%line,1,9)
;If no props were set it returns the branch's text

  if ($prop = root) return $gettok(%loc,1,32)
;returns the root ID

  if ($prop = sel) return %loc
;returns the branch's location

  if ($prop = lines) return $calc($did(%dialog,%id,0).lines -1)
;Returnes the number of lines in the selected branch

  if ($prop = len) return $len(%line)
;This returns the length of the branch's text

  if ($prop = tooltip) return $gettok(%line,2-,9)
;This returns the branch's tooltip

  if ($prop = event) return $gettok(%entry,1,32)
;This returns the last Event in the dialog

}

Comments

Sign in to comment.
CRadle_of_filth   -  Apr 12, 2004

what does this do again?

 Respond  
Yochai   -  Apr 12, 2004

Well, I would like to hear some comments :/

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.