[HELP] Recursive sync wxDir and wxTreeCtrl

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
mykula91
In need of some credit
In need of some credit
Posts: 6
Joined: Sun Aug 06, 2017 12:49 pm

[HELP] Recursive sync wxDir and wxTreeCtrl

Post by mykula91 »

Hello,

I am new in wxWidgets. I need to write application, such as file browser. It is neede to expand and collapses all subdirectories.
I have a problem with recursion in enumerating the tree.

Code: Select all

 
 wxDir dir3, dir2;
    wxString myParentFolder = _T("C:/Qt");
    wxString filename;
    bool cont, can;
    wxString temp;


bool newTreeFrame::UdateTree(wxString myParentFolder, wxTreeItemId root,  bool cont)
    {
        dir3.Open( myParentFolder );
        cont = dir3.GetFirst(&filename);

        if (cont)
        {
            Child = my_treectrl->AppendItem(root,filename, 0);
            UdateTree((myParentFolder+"/"+filename), Child, cont);
        }
        else
        {
            return false;
        }

    }
User avatar
doublemax
Moderator
Moderator
Posts: 19164
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [HELP] Recursive sync wxDir and wxTreeCtrl

Post by doublemax »

What exactly is the problem?

And did you look into wxGenericDirCtrl ? It sounds like it does what you need.
http://docs.wxwidgets.org/trunk/classwx ... _ctrl.html

Build the "widgets" sample that comes with wxWidgets to see the control in action.
Use the source, Luke!
mykula91
In need of some credit
In need of some credit
Posts: 6
Joined: Sun Aug 06, 2017 12:49 pm

Re: [HELP] Recursive sync wxDir and wxTreeCtrl

Post by mykula91 »

wxGenericDirCtrl resolved my problem. Thanks very much for your help.
mykula91
In need of some credit
In need of some credit
Posts: 6
Joined: Sun Aug 06, 2017 12:49 pm

Re: [HELP] Recursive sync wxDir and wxTreeCtrl

Post by mykula91 »

I have a second question - is it possible to save the state of wxGenericDirCtrl object between sessions?
User avatar
doublemax
Moderator
Moderator
Posts: 19164
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [HELP] Recursive sync wxDir and wxTreeCtrl

Post by doublemax »

mykula91 wrote:I have a second question - is it possible to save the state of wxGenericDirCtrl object between sessions?
You mean which folders are expanded and which not? There is no function for this in wxGenericDirCtrl itself, you'd have to implement that yourself.
Use the source, Luke!
mykula91
In need of some credit
In need of some credit
Posts: 6
Joined: Sun Aug 06, 2017 12:49 pm

Re: [HELP] Recursive sync wxDir and wxTreeCtrl

Post by mykula91 »

Is wxPersistentManager would be a good idea? I have no experience with using this tool.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7481
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: [HELP] Recursive sync wxDir and wxTreeCtrl

Post by ONEEYEMAN »

Hi,
I think wxPersistentyManager is for storing and retrieving the control position/size.
I may be wrong though. Try it.

Thank you.
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: [HELP] Recursive sync wxDir and wxTreeCtrl

Post by evstevemd »

mykula91 wrote:Is wxPersistentManager would be a good idea? I have no experience with using this tool.
OneEyeMan is correct. Use wxConfig or similar for storing whatever you want and store it before program exits and restore immediately after UI creation is done!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?