Exemplo n.º 1
0
bool ProjectViewModel::RemoveChildItem( const wxDataViewItem& parenItem, const Helium::Path& path )
{
    ProjectViewModelNode *parentNode = static_cast< ProjectViewModelNode* >( parenItem.GetID() );
    if ( !parentNode )
    {
        HELIUM_ASSERT( m_RootNode );
        parentNode = m_RootNode.Ptr();
    }

    S_ProjectViewModelNodeChildren::const_iterator foundChild = parentNode->GetChildren().end();
    for ( S_ProjectViewModelNodeChildren::const_iterator itr = parentNode->GetChildren().begin(),
        end = parentNode->GetChildren().end(); itr != end; ++itr )
    {
        if ( _tcsicmp( (*itr)->GetPath().Get().c_str(), path.Get().c_str() ) == 0 )
        {
            foundChild = itr;
            break;
        }
    }

    if ( foundChild != parentNode->GetChildren().end() )
    {
        RemoveItem( wxDataViewItem( (void*)(*foundChild) ) );

        return true;
    }
    return false;
}
Exemplo n.º 2
0
void ProjectViewModel::RemoveItem( const wxDataViewItem& item )
{
    ProjectViewModelNode *node = static_cast< ProjectViewModelNode* >( item.GetID() );
    if ( !node )
    {
        return;
    }

    // remove all of childNode's children
    while( node->GetChildren().size() > 0 )
    {
        RemoveItem( wxDataViewItem( (void*)( *node->GetChildren().begin() ) ) );
    }

    // remove it from the multimap
    for ( MM_ProjectViewModelNodesByPath::iterator lower = m_MM_ProjectViewModelNodesByPath.lower_bound( node->GetPath() ),
        upper = m_MM_ProjectViewModelNodesByPath.upper_bound( node->GetPath() );
        lower != upper && lower != m_MM_ProjectViewModelNodesByPath.end();
    ++lower )
    {
        if ( lower->second == node )
        {
            m_MM_ProjectViewModelNodesByPath.erase( lower );
            break;
        }
    }

    if ( node == m_RootNode )
    {
        return;
    }

    // Remove from the parent's childern
    // this should free the node if there are no more references to it
    ProjectViewModelNode *parentNode = node->GetParent();
    if ( parentNode )
    {
        parentNode->GetChildren().erase( node );
    }

    if ( parentNode == m_RootNode.Ptr() )
    {
        parentNode = NULL;
    }

    ItemDeleted( wxDataViewItem( (void*) parentNode ), item );
}
Exemplo n.º 3
0
unsigned int ProjectViewModel::GetChildren( const wxDataViewItem& item, wxDataViewItemArray& items ) const
{
    ProjectViewModelNode *parentNode = static_cast< ProjectViewModelNode* >( item.GetID() );
    if ( !parentNode )
    {
        parentNode = m_RootNode.Ptr();
    }

    if ( parentNode->GetChildren().size() < 1 )
    {
        return 0;
    }

    uint32_t numAdded = 0;
    for ( S_ProjectViewModelNodeChildren::const_iterator itr = parentNode->GetChildren().begin(),
        end = parentNode->GetChildren().end(); itr != end; ++itr, ++numAdded )
    {
        items.Add( wxDataViewItem( (void*) (*itr) ) );
    }

    return numAdded;
}
Exemplo n.º 4
0
bool ProjectViewModel::AddChildItem( const wxDataViewItem& parenItem, const Helium::Path& path )
{
    // Get the parent node
    ProjectViewModelNode *parentNode = static_cast< ProjectViewModelNode* >( parenItem.GetID() );
    if ( !parentNode )
    {
        HELIUM_ASSERT( m_RootNode );
        parentNode = m_RootNode.Ptr();
    }

    bool isContainer = path.HasExtension( TXT( "HeliumScene" ) );

    // Create the child node
    const Document* document = m_DocumentManager->FindDocument( path );
    Helium::StdInsert<S_ProjectViewModelNodeChildren>::Result inserted = parentNode->GetChildren().insert( new ProjectViewModelNode( this, parentNode, path, document, isContainer ) );
    if ( inserted.second )
    {
        ProjectViewModelNode* childNode = (*inserted.first);

        // See if the document is already open
        //MM_ProjectViewModelNodesByPath::iterator findNode = m_MM_ProjectViewModelNodesByPath.find( path );
        //if ( findNode != m_MM_ProjectViewModelNodesByPath.end()
        //    && findNode->first == path
        //    && findNode->second->GetDocument() ) 
        //{
        //    childNode->ConnectDocument( findNode->second->GetDocument() );
        //}

        // Add the node to the multimap and call ItemAdded
        m_MM_ProjectViewModelNodesByPath.insert( MM_ProjectViewModelNodesByPath::value_type( path, childNode ));
        if ( parentNode == m_RootNode.Ptr() )
        {
            parentNode = NULL;
        }
        ItemAdded( (void*)parentNode, (void*)childNode );

        return true;
    }
    return false;
}