Example #1
0
wxTreeItemId ObjectListDialogsHelper::AddObjectsToList(wxTreeCtrl * objectsList, const gd::ClassWithObjects & objects, bool globalObjects, bool substituteIfEmpty)
{
    bool searching = searchText.empty() ? false : true;

    wxTreeItemId lastAddedItem;
    for ( unsigned int i = 0;i < objects.GetObjectsCount();i++ )
    {
        std::string name = objects.GetObject(i).GetName();

        //Only add objects if they match the search criteria
        if ((objectTypeAllowed.empty() || objects.GetObject(i).GetType() == objectTypeAllowed ) &&
            ( !searching || (searching && boost::to_upper_copy(name).find(searchText) != std::string::npos)) )
        {
            /*int thumbnailID = -1;
            wxBitmap thumbnail;
            if ( objects.GetObject(i).GenerateThumbnail(project, thumbnail)  && thumbnail.IsOk() )
            {
                objectsImagesList->Add(thumbnail);
                thumbnailID = objectsImagesList->GetImageCount()-1;
            }*/

            wxTreeItemId item = objectsList->AppendItem( objectsList->GetRootItem(),
                objects.GetObject(i).GetName()/*, thumbnailID*/ );
            objectsList->SetItemData(item, new gd::TreeItemStringData(globalObjects ? "GlobalObject" : "LayoutObject"));
            if ( globalObjects ) objectsList->SetItemTextColour(item, wxColour(40,40,45));

            lastAddedItem = item;
        }
    }

    if ( substituteIfEmpty && !globalObjects && objects.GetObjectsCount() == 0 )
    {
        wxTreeItemId item = objectsList->AppendItem( objectsList->GetRootItem(), _("No objects"), 0 );
        //substituteObjItem = item; Todo: Getter for the substitute.
        lastAddedItem = item;
    }

    return lastAddedItem;
}
wxTreeItemId ObjectListDialogsHelper::AddObjectsToList(wxTreeCtrl * objectsList, wxTreeItemId rootItem, const gd::ClassWithObjects & objects, bool globalObjects)
{
    bool searching = searchText.empty() ? false : true;

    wxTreeItemId lastAddedItem;
    for ( std::size_t i = 0;i < objects.GetObjectsCount();i++ )
    {
        gd::String name = objects.GetObject(i).GetName();

        //Only add objects if they match the search criteria
        if ((objectTypeAllowed.empty() || objects.GetObject(i).GetType() == objectTypeAllowed ) &&
            ( !searching || (searching && name.CaseFold().find(searchText.CaseFold()) != gd::String::npos)) )
        {
            wxTreeItemId item = objectsList->AppendItem(rootItem, "theobject");
            MakeObjectItem(objectsList, item, objects.GetObject(i), globalObjects);

            lastAddedItem = item;
        }
    }

    return lastAddedItem;
}