Re: Building and Saving Treeviews

new topic     » goto parent     » topic index » view thread      » older message » newer message

Tony,

I *think* the following routines added to the tvedit.exw demo will allow you
to save a user created tree & then re-create it properly;  you'll have to
add two menu choices for save & get the tv, & should probably make a better
check for the existence of the saved tv file, but these routines seem to
handle re-create after delete items ok, and also re-create after delete
items & then add new items, including delete "root".

You should also probably test it more than I have  :)

For test purposes, I renamed each item I created in the demo with an
in-order number, so I could more easily see what might be happening with
each after deletions & additions & re-creations.

Dan Moyer

--<routines to add to  tvedit.exw demo follow>

-- saves tree data to file:
procedure Click_MenuSave(integer self, integer event, sequence parms)
   sequence temp
   integer wrongIndex
   temp = {}

   handle = open( "Tree.txt", "w" )

-- for each element in folders, make an empty sequence in temp;
   for n = 1 to length(folders) do
     temp &= {{}}
   end for


-- look at each element in folder, one at a time;
-- put that into the sequence at same position in temp;
-- look for parent of item in temp, place that id after item,
-- then place items text right after that.

   for n = 1 to length( folders) do
     temp[n] &= folders[n]
     temp[n] &= {getTVParent(temp[n][1])}
     temp[n] &= {getTVText(temp[n][1])}
   end for


-- now see if any of the items, because of deletions, might have "wrong"
-- "index" (?) numbers, & "correct" (?) them:
-- ("correct" means the items should be listed "in order", and all items
--  which are children of any corrected item should be referred to that
--  corrected reference)

   for m = 1 to length(temp) do
     if not equal (m, temp[m][1]) then
        wrongIndex = temp[m][1]
        temp[m][1] = m
        for n = 1 to length(temp) do
            if equal (wrongIndex, temp[n][2]) then
               temp[n][2] = m
            end if
        end for
     end if
   end for


   print(handle, temp)
   close(handle)

end procedure
-----------------------------------------------------------------
--  clears existing tree, retrieves saved tree info,
--  then rebuilds tree with the saved info:
procedure Click_MenuGetTree(integer self, integer event, sequence parms)
sequence savedTree, result
savedTree = {}

-- first empty the tree:
  eraseItems(TV)

-- now get saved items:
   handle = open( "Tree.txt", "r" )
   result = get(handle)
   if result[1] = GET_SUCCESS then
      savedTree = result[2]
      folders = {}
      for n = 1 to length(savedTree) do
         folders &= addTVItem( TV, closefolder, openfolder, savedTree[n][3]
, savedTree[n][2] )
      end for
   end if
   close(handle)
end procedure
-------------------------------------------------

<end routines>


----- Original Message -----
From: "Tony Steward" <lockmaster67 at aol.com>
To: "EUforum" <EUforum at topica.com>
Sent: Friday, October 18, 2002 11:00 PM
Subject: RE: Building and Saving Treeviews


>
> Hi Dan
> Thanks for the help keep it coming (when you have time), I started
> heading in a similar direction last nite.
>
> Thanks
> Tony
>
> Dan Moyer wrote:
> > Tony,
> >
> > The routines I sent which worked don't seem to work if an item is
> > *deleted*
> > from the tree  :(
> >
> > Dan
> >
> > ----- Original Message -----
> > From: "Tony Steward" <lockmaster67 at aol.com>
> > To: "EUforum" <EUforum at topica.com>
> > Sent: Wednesday, October 16, 2002 11:56 PM
> > Subject: Building and Saving Treeviews
> >
> >
> > > Hi All,
> > > I asked this before but never really got the answers I wanted and I
ran
> > > out of time. Now with time on my hands I'll try again.
> > >
> > > I am looking at the example that comes with win32lib 57.9.
> > > When a user creates a treeview as in the example titled tvedit.exw how
> > > can I save this TV to disk and rebuild it again later when I don't
know
> > > how many branches/sub branches a user may have created.
> > >
> > > Thanks
> > > Tony Steward
> > >
> > > Give your hardest tasks to your lasiest workers.
> > > They will always find the easiest way to complete it.
> > >
> > >
> Give your hardest tasks to your lasiest workers.
> They will always find the easiest way to complete it.
>
>
>
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu