# Help with project viewer

**URL:** <https://www.ruby-forum.com/t/help-with-project-viewer/157912>\
**Category:** wxRuby\
**Created:** [January 16, 2009, 3:15pm UTC](https://www.ruby-forum.com/t/help-with-project-viewer/157912 "2009-01-16T15:15:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [January 16, 2009, 3:15pm UTC](https://www.ruby-forum.com/t/help-with-project-viewer/157912/1 "2009-01-16T15:15:01Z")

</div>

I’ve just begun using wxRuby and I’ve been finding my feet with things  
quite easily, however there’s one thing I’m uncertain of at the moment  
which I’d like to do and that’s a project viewer.

I know that it would have to be using TreeCtrl.

If someone could explain to me how to build a custom Tree with my own  
folders and files that would be really appreciated.

I’m using it as a learning experience so that I can aid in creating a  
new IDE for the Sphere games engine. So there’s already a file structure  
I just don’t know how to recreate in in wxRuby.

---

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [January 16, 2009, 7:10pm UTC](https://www.ruby-forum.com/t/help-with-project-viewer/157912/2 "2009-01-16T19:10:16Z")

</div>

Hey James,

If your interested in a way to setup projects, take a look at my IDE  
that  
I’ve been working on. Currently, I’m in the process of re-implementing  
everything, but you can get a basics for what I did, in the old  
Subverison  
repo, found here: [http://wxride.rubyforge.org/svn/branch/alpha/wxRIDE/](http://wxride.rubyforge.org/svn/branch/alpha/wxRIDE/)

The main points that you would want to look at, is lib/project.rb, and  
lib/ui/PrjTree.rb and lib/ui/ProjectTree.rb. PrjTree.rb is the current  
one  
used by the cold, and ProjectTree.rb is the old one. It gives you two  
ideas  
on ways to go about this.

hth,

Mario

---

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [January 17, 2009, 8:43pm UTC](https://www.ruby-forum.com/t/help-with-project-viewer/157912/3 "2009-01-17T20:43:29Z")

</div>

Thanks for the replies.

I’ll take a look at those files you linked to.

I’m still trying to find my feet with the system but should hopefully  
pick it up fairly easily.

Obviously, i’ll post here again if I get stuck.

---

<div class="post-metadata">

**Author:** ![aftershock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8e7dd6/32.png) [@aftershock](https://www.ruby-forum.com/u/aftershock)\
**Post date:** [January 17, 2009, 9:47am UTC](https://www.ruby-forum.com/t/help-with-project-viewer/157912/4 "2009-01-17T09:47:07Z")

</div>

James Waudby wrote:

> I’ve just begun using wxRuby and I’ve been finding my feet with things  
> quite easily, however there’s one thing I’m uncertain of at the moment  
> which I’d like to do and that’s a project viewer.
> 
> I know that it would have to be using TreeCtrl.
> 
> If someone could explain to me how to build a custom Tree with my own  
> folders and files that would be really appreciated.

Firstly, there’s a generic directory / file tree widget built-in with  
wxRuby., called GenericDirCtrl. This is built using TreeCtrl, so if you  
know C++ it’s a decent source for study.

One challenge can be that traversing a large file system in Ruby is slow  
so the tree is slow to present. To get round this, you only present the  
currently open items (adding them via append\_item). For each item that  
is a directory, call set\_item\_has\_children to display it with an  
unopened ‘expand’ button. Then provide an evt\_tree\_item\_expanding event  
handler that appends the file/directory children as a directory is  
opened.

You’ll probably want to use the item\_data field (which attaches any Ruby  
object to an item in the treectrl) to store fuller information about  
each file/directory. This could just be the full path, or it could be a  
hash with extra info (eg SVN status, or stat-like data).

Each icon that you might use is stored in a ImageList, and the index of  
the relevant image (depending on file type, for example) is passed to  
calls to append\_item / add\_item.

As an aside, it would be nice to have a model-based TreeCtrl - one where  
a non-GUI class defines how objects are fetched and related, and the GUI  
class does the presenting work. It’s a nice way to write code, I find,  
for Grid - GridTableBase - and the development version of wxWidgets  
supports this, I believe.

a
