Page 1 of 1

Project Browser

Posted: Wed Mar 18, 2009 8:35 pm
by Waudby
Hi everyone, I'm new here and to wxWidgets, I was recommended by people to use this to help develop applications easier.

Now onto my question, I'm trying to develop an IDE for a game engine I use, and I'm stuck creating the Project Tree. Basically, each Game Project has a set of standard folders;

•Animations
•Fonts
•Maps
•Save
•Other
•Scripts
•Spritesets
•Sounds
•Windowstyles

and these are located within the main folder of the project, this main folder can also have other files in it too.

I was wondering how to go about only adding the folders in the directory to the TreeCtrl on the top level and then in each folder check for sub folders and files.

Any help would be appreciated.

Posted: Wed Mar 18, 2009 8:46 pm
by mc2r
I'd use wxDir(http://docs.wxwidgets.org/stable/wx_wxdir.html#wxdir) to enumerate the files under each directory.

To add them to the tree control make a hidden root and then add the listed directories to it as children and they will show up as if they were each individual root items.

http://docs.wxwidgets.org/stable/wx_wxt ... wxtreectrl

-Max

Posted: Wed Mar 18, 2009 8:48 pm
by Auria
Hi,

I never did this myself but believe this could help you :
http://docs.wxwidgets.org/stable/wx_wxg ... ricdirctrl

Posted: Wed Mar 18, 2009 8:50 pm
by mc2r
Auria wrote:Hi,

I never did this myself but believe this could help you :
http://docs.wxwidgets.org/stable/wx_wxg ... ricdirctrl
I don't think this is exactly what the OP is looking for. IIRC... it will do what the OP wants for one directory but not with the dozen directories they are looking for. Its been a long long time since I played with this control though, so I may be way off.

-Max

Posted: Wed Mar 18, 2009 8:58 pm
by Waudby
Thanks for the quick replies, I have tried using wxRuby before, quite some time ago though and I thought that wxGenericDirCtrl, gave the users entire hard drive directories as well? Not just for the current project.

I've searched through the forums to see if someone else has asked the same question and stumbled across that

Code: Select all

	  wxDir dir(directory);
    
      //Create a new tree 
      wxTreeCtrl* tcDir = new wxTreeCtrl(this, -1, wxDefaultPosition, wxSize(150,200),  wxTR_HAS_BUTTONS); 

	  //the root node. 
	  wxTreeItemId  rootNode; 

	  //Add the root item with the name of the working dir, and remember that node. 

	  rootNode = tcDir->AddRoot("Game", 0, 0); 

	  if ( !dir.IsOpened() ) 
      { 
          // deal with the error here - wxDir would already log an error message 
          // explaining the exact reason of the failure 
          return; 
      } 

      wxString filename; 

      bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS); 
      while ( cont ) 
      { 
          tcDir->AppendItem(rootNode, filename); 
          cont = dir.GetNext(&filename);
      }
I've tried to implement this and it works so far, but it only adds the top level folders to the Tree, but it's a start.

Is there a way to extend this idea and maybe during the while loop, check to see if the current directory has sub files and directories?

Posted: Thu Mar 19, 2009 12:18 pm
by Waudby
Sorry for the double posting (don't know if it's a problem here)

But i'd just like to bump this again and ask if there is anyone who has managed to do this, or knows how to?

Posted: Thu Mar 19, 2009 2:59 pm
by mc2r
Waudby wrote:

Code: Select all

      bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS); 
      while ( cont ) 
      { 
          tcDir->AppendItem(rootNode, filename); 
          cont = dir.GetNext(&filename);
      }
I've tried to implement this and it works so far, but it only adds the top level folders to the Tree, but it's a start.

Is there a way to extend this idea and maybe during the while loop, check to see if the current directory has sub files and directories?
What exactly are you having a problem with? The example you posted shows you everything you need.

What I would do is make a function to add a directory to a node. In the function I'd call wxDir like you are to get the files and other directories. For the files add them to the newely added directory node, for the directories call the function again recursivly.

Don't forget to read the docs

http://docs.wxwidgets.org/stable/wx_wxdir.html#wxdir
http://docs.wxwidgets.org/stable/wx_fil ... efunctions
http://docs.wxwidgets.org/stable/wx_wxt ... wxtreectrl

-Max

Posted: Thu Mar 19, 2009 3:12 pm
by Waudby
So that way would work even if the top level node, for examples, the folder that contains the script, has a sub folder and that sub folder also contains a sub folder?

I'll try this out and let you know how it goes.

Posted: Thu Mar 19, 2009 3:39 pm
by Waudby
Okay, I've ran into a problem (due to my small amount of experience with this).

With the code I gave in the example, how would I extend that so I could get the name of the added item for instance;

I did tc->AppendItem(rootNode, filename), now if I wanted to add files and folders to that newly added item, how would I reference it?

I'm not asking for somebody to code this for me, however code examples would be useful as a learning tool.

Posted: Thu Mar 19, 2009 4:17 pm
by mc2r
Waudby wrote:With the code I gave in the example, how would I extend that so I could get the name of the added item for instance;

I did tc->AppendItem(rootNode, filename), now if I wanted to add files and folders to that newly added item, how would I reference it?
http://docs.wxwidgets.org/stable/wx_wxtreectrl.html#wxtreectrlappenditem wrote:wxTreeCtrl::AppendItem

wxTreeItemId AppendItem(const wxTreeItemId& parent, const wxString& text, int image = -1, int selImage = -1, wxTreeItemData* data = NULL)
AppendItem returns the wxTreeItemId for the added node.

AppendItem takes a wxTreeItemId for the node it should add a node to. so

Code: Select all

wxTreeNodeId dirNode = tc->AppendItem(rootNode, directory);
tc->AppendItem(dirNode, filename);
Please take this as its meant and not as me just being a jerk. But the docs really do answer a lot of the questions that a programmer starting with wxWidgets has. It really would behove you to read the links I provided in the previous post thoroughly.

If you are using a class wxTreeCtrl for instance read its page and pay attention to the arguments and the return values. A good place to start are the functions used in any examples you've found.

Most any easy/beginner type questions have also been answered in the forum as well. Reading through a few threads that you would find if you search for "wxTreeCtrl AppendItem" you would surely find an example that would work for you.


-Max

Posted: Thu Mar 19, 2009 4:54 pm
by Waudby
Thanks for answering that.
I'll try searching through the forums a bit more thoroughly next time.

Posted: Fri Mar 20, 2009 1:22 pm
by Waudby
Okay, I've managed to get the Tree exactly how I want basically, the next stage is to add the folder images and icons.

Image

As you can see from the image about, it's looking pretty bare but the layout is correct.

My next question is...

With the images for the tree, how can I make it so different types of file have different types of images?

As you can see from the image above, a script file has the extension .js, how can I make these have their own type of image assigned to them?