Project Browser
Project Browser
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.
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.
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
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
Hi,
I never did this myself but believe this could help you :
http://docs.wxwidgets.org/stable/wx_wxg ... ricdirctrl
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.Auria wrote:Hi,
I never did this myself but believe this could help you :
http://docs.wxwidgets.org/stable/wx_wxg ... ricdirctrl
-Max
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
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?
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);
}
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.Waudby wrote: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.Code: Select all
bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS); while ( cont ) { tcDir->AppendItem(rootNode, filename); cont = dir.GetNext(&filename); }
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 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
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.
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.
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?
AppendItem returns the wxTreeItemId for the added node.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 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);
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
Okay, I've managed to get the Tree exactly how I want basically, the next stage is to add the folder images and icons.
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?
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?