Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » TreeCtrl » Can't add/remove +/- sign [CanOpen()]
Can't add/remove +/- sign [CanOpen()] [message #24259] Thu, 07 January 2010 19:38 Go to next message
galious is currently offline  galious
Messages: 28
Registered: March 2008
Promising Member
Hi,

I'm having problems removing the +/- sign of a tree node. The use case is as follow:

I want to create a tree, where some nodes potentially are slow to add their child-nodes. Therefore for thee slow nodes I set CanOpen() on this node to display the +/- sign. Once a users tries to open the node and during the open action we identify no children are available I want to remove the +/- sign.

An example is added below. Once you navigate to a node without folders in it I expect the +/- sign to disappear, however this doesn't happen. How should I solve this?

BR,

Martin


#include "CtrlLib/CtrlLib.h"

using namespace Upp;

struct App : TopWindow {
    TreeCtrl   tree;

    typedef App CLASSNAME;

    void OpenDir(int id) {
        String path = tree[id];

        for(FindFile ff(AppendFileName(path, "*.*")); ff; ff.Next()) {
            String n = ff.GetName();

            if(n != "." && n != ".." && ff.IsFolder()) {
                tree.Add(id, CtrlImg::Dir(),
                          AppendFileName(path, n), n, true);
            }
        }
        
        // I expect to get the +/- sign removed if a folder does not contain other folders
        // using the following code:
        if (tree.GetChildCount(id) == 0)
        {
            tree.GetNode(id).CanOpen(false);
            tree.Close(id);
	        tree.RefreshItem(id);     
        }
    }

    void CloseDir(int id) {
        tree.RemoveChildren(id);
    }

    App() {
        Add(tree.SizePos());

        tree.WhenOpen = THISBACK(OpenDir);
        tree.WhenClose = THISBACK(CloseDir);

    #ifdef PLATFORM_WIN32
        String dir = String(GetExeFilePath()[0], 1) + ":\\";
    #else
        String dir = "/usr";
    #endif

        tree.SetRoot(CtrlImg::Dir(), dir);

        Sizeable();
    }
};

GUI_APP_MAIN
{
    App().Run();
}
Re: Can't add/remove +/- sign [CanOpen()] [message #24281 is a reply to message #24259] Fri, 08 January 2010 17:32 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
        if (tree.GetChildCount(id) == 0)
        {
            TreeCtrl::Node node = tree.GetNode(id);
            node.CanOpen(false);
            tree.SetNode(id, node);
        }


(Does not return reference but value and needs to be set again).

Mirek
Re: Can't add/remove +/- sign [CanOpen()] [message #24294 is a reply to message #24259] Sat, 09 January 2010 02:04 Go to previous messageGo to next message
galious is currently offline  galious
Messages: 28
Registered: March 2008
Promising Member
Of course, seems logical considering the 'pick' design of UPP.

Thanks,

Martin
Re: Can't add/remove +/- sign [CanOpen()] [message #24301 is a reply to message #24294] Sat, 09 January 2010 12:50 Go to previous message
mirek is currently offline  mirek
Messages: 11700
Registered: November 2005
Ultimate Member
galious wrote on Fri, 08 January 2010 20:04

Of course, seems logical considering the 'pick' design of UPP.

Thanks,

Martin


Well, the main reason there is that TreeCtrl needs to be updated if Node changes. Which would lead to too complex logic for GetNode returning the reference - Node would need to store pointer to TreeCtrl and update it accordingly. And standalone nodes would be complicated....
Previous Topic: Blinking tree when opening or closing nodes
Next Topic: OptionTree loses check state
Goto Forum:
  


Current Time: Sat Feb 16 12:59:59 CET 2019

Total time taken to generate the page: 0.00540 seconds