This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-12-11 13:42:21

AddZero
Scratcher
Registered: 2007-08-11
Posts: 100+

File Browser - Editable Tree List

http://scratch.mit.edu/projects/AddZero/346118#
This is for browsing/adding to data in scratch in a tree.  I'll add the delete/copy/paste functions soon.
This has many uses, like your computer's file system.
directories inside of directories...
It's like having lists inside of lists.

---EDIT: Sorry, I wrote WAY to much here.  Feel free to skip to the end. The point is:  How else can you do this?  What's the best way to have lists that you can add/remove from to, and sort though fast? ...without having to search though the whole list?


This could be useful in paces where you want to add and remove lists as needed.
It will also be useful for my 3d modeling/cad system for storing/editing/removing objects.   (I started it so I could try this genetic programming method: http://www.stromcode.com/2008/03/01/evo)

So here's the tree data we want to store:

Code:

Colors
  Red
  Yellow
Earth
  North-America
    USA
      California
        Oakland
    Canada
  Europe
    Denmark
    England
  Antarctica

I want to be able to go into 'Europe' and get Denmark, England.

We could put it in two lists like this:

Code:

NameList       Level
----------------------
Colors         1
Red            2
Yellow         2
Earth          1
North-America  2
USA            3
California     4
Oakland        5
Canada         3
Europe         2
Denmark        3
England        3
Antarctica     2

So lets go down to Earth.
Is it Colors? nope.
is it Red? nope.
is it Yellow? nope.
is it Earth? yes!
then Europe, We would have to go through all of the items on the lists till we get to 'Europe'.  Slow.

So I did it this way:

Code:

NameList       ItemSize
----------------------
Colors         3
Red            0
Yellow         0
Earth          9
North-America  4
USA            2
California     1
Oakland        0
Canada         0
Europe         2
Denmark        0
England        0
Antarctica     0

ItemSize holds how many items are inside the current item.

So now as I look for Earth starting from the top,
I see Colors has 3 Items in it so I skip 3 down to Earth,
That's what I want so I add that to my CurrentPathName and save the index of that item(4) to the CurrentPathIndex list. 
I continue down and see North-America has 4 items, so I skip 4 down the list and see 'Europe' I add that to my CurrentPathName and CurrentPathIndex lists, now we can see Denmark and England!

If we want to go back to Earth, we just delete the last item from the CurrentPathName and CurrentPathIndex lists.


To add an item we just insert at the end of the current level (Index+currentlevel size), then +1 to the ItemSize of each of the parents in CurrentPathIndex

To delete a tree we just the delete [ItemSize] items from the list.  (We don't have to search down each item to find the end of the tree.) then -1 to the ItemSize of each of the parents in CurrentPathIndex

I'll write more and clarify things if there's interest.

Do you know a faster/better way to do this?

---EDIT: How would you solve this problem: so you can store/remove and find information fast from lists with the least number of steps?

Last edited by AddZero (2008-12-12 11:35:22)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#2 2009-09-06 21:07:22

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: File Browser - Editable Tree List

I'd like some more carification. I don't understand.


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#3 2009-09-08 00:14:12

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: File Browser - Editable Tree List

I would make two lists:
one for the values, one for the path.
So, to use XML as an example.
If we have the file:

Code:

<xml>
   <level1>
      <level2>level2 info1</level2>
      <level2>level2 info2</level2>
      <level2>level2 info3</level2>
      <level2>
         <level3>level3 info</level3>
      </level2>
   </level1>
</xml>

Now, we take this and extract the data:
1) level2 info1
2) level2 info2
3) level2 info3
4) level3 info
And extract the corresponding pathnames, to Xpath:
1) xml/level1/level2[1]/
2) xml/level1/level2[2]/
3) xml/level1/level2[3]/
4) xml/level1/level2[4]/level3/
From this data, we can build the tree:
1) read path 1.
2) create xml node.
3) create level1 node.
4) create level2 node.
5) note that there are more level 2's in this root.
6) add data for path 1.
7) read path 2.
8) note that xml node is already there, and there aren't any copies.
9) note that level1 node is already there, and there aren't any copies.
10) remember that there are copies of level2.
11) read that this is the second level2 in this level1.
12) add data for path 2.
13) continue on similarly.
As you can see, this is just a functional outline... but it should work.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#4 2009-12-10 23:38:55

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: File Browser - Editable Tree List

I see. Good way to do it!


Hai.

Offline

 

#5 2009-12-11 08:21:25

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: File Browser - Editable Tree List

billyedward wrote:

I would make two lists:
one for the values, one for the path.
So, to use XML as an example.
If we have the file:

Code:

<xml>
   <level1>
      <level2>level2 info1</level2>
      <level2>level2 info2</level2>
      <level2>level2 info3</level2>
      <level2>
         <level3>level3 info</level3>
      </level2>
   </level1>
</xml>

Now, we take this and extract the data:
1) level2 info1
2) level2 info2
3) level2 info3
4) level3 info
And extract the corresponding pathnames, to Xpath:
1) xml/level1/level2[1]/
2) xml/level1/level2[2]/
3) xml/level1/level2[3]/
4) xml/level1/level2[4]/level3/
From this data, we can build the tree:
1) read path 1.
2) create xml node.
3) create level1 node.
4) create level2 node.
5) note that there are more level 2's in this root.
6) add data for path 1.
7) read path 2.
8) note that xml node is already there, and there aren't any copies.
9) note that level1 node is already there, and there aren't any copies.
10) remember that there are copies of level2.
11) read that this is the second level2 in this level1.
12) add data for path 2.
13) continue on similarly.
As you can see, this is just a functional outline... but it should work.

O_o XML! BTW you have to put this in an XML file first

Code:

<? xml version = "1.0" encoding = "utf-8" ?>

Offline

 

#6 2009-12-11 20:51:18

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: File Browser - Editable Tree List

ThePCKid wrote:

O_o XML! BTW you have to put this in an XML file first

He's giving an example.


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#7 2009-12-11 21:21:13

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: File Browser - Editable Tree List

Greatdane wrote:

ThePCKid wrote:

O_o XML! BTW you have to put this in an XML file first

He's giving an example.

I'm not stupid!

Offline

 

#8 2009-12-31 13:18:43

AddZero
Scratcher
Registered: 2007-08-11
Posts: 100+

Re: File Browser - Editable Tree List

cool, thanks for the the thoughtful responses, just noticed, sorry.

I'm working on a new version now.

from the project:
"instead of two lists, just one, each 'file' has a header, starting with how long (how many lines till the next file at that level) that file is, the name, the type. (1 for folder) the creator, the color of the icon. so the header is 5 lines long, if it is a folder type, the user can navigate into that.(adds that folder to the path list) then lists everything inside that folder. I'm still working on that one, should be out soon. "

This will be a 'file manager menu' type front end for projects that store information.
like my lathe 3d modeler and music program. (I'm working on)

I'll try to explain how it works better when I release it.


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#9 2010-01-02 13:53:09

scratchycat625625
Scratcher
Registered: 2009-06-05
Posts: 17

Re: File Browser - Editable Tree List

AddZero wrote:

cool, thanks for the the thoughtful responses, just noticed, sorry.

I'm working on a new version now.

from the project:
"instead of two lists, just one, each 'file' has a header, starting with how long (how many lines till the next file at that level) that file is, the name, the type. (1 for folder) the creator, the color of the icon. so the header is 5 lines long, if it is a folder type, the user can navigate into that.(adds that folder to the path list) then lists everything inside that folder. I'm still working on that one, should be out soon. "

This will be a 'file manager menu' type front end for projects that store information.
like my lathe 3d modeler and music program. (I'm working on)

I'll try to explain how it works better when I release it.

Nice. Something I've been thinking about for a long time is designing a text-based code- a bit like HTML or C++ within Scratch. You could then implement a file browser into an OS  design to make a fully-working OS... You could even make an installer, to install other projects onto your system!  big_smile


Plug 'n' play... How do they know my street name?

Offline

 

#10 2010-01-11 18:07:47

computernut401
Scratcher
Registered: 2008-09-15
Posts: 5

Re: File Browser - Editable Tree List

Yeah, if you made a interpreter-based code and a program to interpret it, you could just copy the code of someone else's app into your file system and the "OS" would be able to run it.

That'd be pretty hard in Scratch, though.

Offline

 

Board footer