コード例 #1
0
ファイル: ProjectViewModel.cpp プロジェクト: euler0/Helium
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;
}
コード例 #2
0
ファイル: ProjectViewModel.cpp プロジェクト: euler0/Helium
bool ProjectViewModel::GetAttr( const wxDataViewItem& item, unsigned int column, wxDataViewItemAttr& attr ) const
{
    if ( !item.IsOk() )
    {
        return false;
    }

    ProjectViewModelNode *node = static_cast< ProjectViewModelNode* >( item.GetID() );
    HELIUM_ASSERT( node );

    // bold the entry if the node is active
    attr.SetBold( node->m_IsActive );

    // italicize the entry if it is modified
    attr.SetItalic( ( node->GetDocument() && node->GetDocument()->HasChanged() ) );

    Path nodePath = node->GetPath().GetAbsolutePath( m_Project->a_Path.Get() );
    if ( !nodePath.Exists() )
    {
        attr.SetColour( *wxRED );
    }
    else
    {
        attr.SetColour( *wxBLACK );
    }

    return true;
}
コード例 #3
0
ファイル: ProjectPanel.cpp プロジェクト: foolhuang/Helium
void ProjectPanel::OnActivateItem( wxDataViewEvent& event )
{
    ProjectViewModelNode *node = static_cast< ProjectViewModelNode* >( event.GetItem().GetID() );
    if ( !node )
    {
        return;
    }

    const FilePath& path = node->GetPath().GetAbsolutePath( m_Project->a_Path.Get() );
    HELIUM_ASSERT( !path.empty() );

    if ( !path.Exists() )
    {
#pragma TODO( "Walk the user through locating the missing file." )
        wxMessageBox( wxT( "Unfortunately, the file you're trying to load does not exist.  In the future, we'll help you find and fix this reference.  For now, all we can do is apologize." ), wxT( "Nonexistent File" ), wxOK | wxICON_ERROR );
        return;
    }

    if ( path.HasExtension( TXT( "HeliumScene" ) ) )
    {
        wxGetApp().GetFrame()->CloseAllScenes();
        wxGetApp().GetFrame()->OpenScene( path );
        return;
    }

    // we've gotten to an item we don't know how to activate yet
    HELIUM_BREAK();
}
コード例 #4
0
ファイル: ProjectViewModel.cpp プロジェクト: euler0/Helium
bool ProjectViewModel::IsContainer( const wxDataViewItem& item ) const
{
    // root node can have children
    if ( !item.IsOk() )
    {
        return true;
    }

    ProjectViewModelNode *node = static_cast< ProjectViewModelNode* >( item.GetID() );
    return node ? node->IsContainer() : false;
}
コード例 #5
0
ファイル: ProjectViewModel.cpp プロジェクト: euler0/Helium
void ProjectViewModel::OnDocumenClosed( const DocumentEventArgs& args )
{
    const Document* document = static_cast< const Document* >( args.m_Document );
    HELIUM_ASSERT( document );

    for ( MM_ProjectViewModelNodesByPath::iterator lower = m_MM_ProjectViewModelNodesByPath.lower_bound( document->GetPath() ),
        upper = m_MM_ProjectViewModelNodesByPath.upper_bound( document->GetPath() );
        lower != upper && lower != m_MM_ProjectViewModelNodesByPath.end();
    ++lower )
    {
        ProjectViewModelNode *node = lower->second;
        node->DisconnectDocument();
    }

}
コード例 #6
0
ファイル: ProjectViewModel.cpp プロジェクト: euler0/Helium
wxDataViewItem ProjectViewModel::GetParent( const wxDataViewItem& item ) const
{
    if ( !item.IsOk() )
    {
        return wxDataViewItem( 0 );
    }

    ProjectViewModelNode *node = static_cast< ProjectViewModelNode* >( item.GetID() );
    if ( !node
        || node == m_RootNode.Ptr()
        || !node->GetParent()
        || node->GetParent() == m_RootNode.Ptr() )
    {
        return wxDataViewItem( 0 );
    }

    return wxDataViewItem( (void*) node->GetParent() );
}
コード例 #7
0
ファイル: ProjectViewModel.cpp プロジェクト: euler0/Helium
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;
}
コード例 #8
0
ファイル: ProjectViewModel.cpp プロジェクト: euler0/Helium
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;
}
コード例 #9
0
ファイル: ProjectViewModel.cpp プロジェクト: euler0/Helium
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 );
}
コード例 #10
0
ファイル: ProjectViewModel.cpp プロジェクト: euler0/Helium
void ProjectViewModel::GetValue( wxVariant& variant, const wxDataViewItem& item, unsigned int column ) const
{
    if ( !item.IsOk()
        || ( column < 0 )
        || ( column >= m_ColumnLookupTable.size() ) )
    {
        return;
    }

    ProjectViewModelNode *node = static_cast< ProjectViewModelNode* >( item.GetID() );
    if ( !node )
    {
        return;
    }

    switch( m_ColumnLookupTable.at( column ) )
    {
    default:
        break;

    case ProjectModelColumns::Name:
        {            
            uint32_t docStatus = node->GetDocumentStatus();

            wxString name = node->GetName();
            if ( HasFlags<uint32_t>( docStatus, DocumentStatus::Changed ) )
            {
                name = wxString( TXT( '*' ) ) + name; 
            }

            wxBitmap bitmap = wxArtProvider::GetBitmap( GetArtIDFromPath( node->GetPath() ), wxART_OTHER, wxSize(16, 16) );
            if ( docStatus > 0 )
            {
                wxImage image = bitmap.ConvertToImage();
                HELIUM_ASSERT( image.Ok() );

                int overlayWidth = image.GetWidth() / 2;
                int overlayHeight = image.GetHeight() / 2;

                wxImage overlayImage;

                if ( HasFlags<uint32_t>( docStatus, DocumentStatus::Saving ) )
                {
                    overlayImage = wxArtProvider::GetBitmap( ArtIDs::Status::Busy, wxART_OTHER, wxSize( overlayWidth, overlayHeight ) ).ConvertToImage();
                    HELIUM_ASSERT( overlayImage.Ok() );
                }
                else if ( HasFlags<uint32_t>( docStatus, DocumentStatus::Loading ) )
                {
                    overlayImage = wxArtProvider::GetBitmap( ArtIDs::Status::Busy, wxART_OTHER, wxSize( overlayWidth, overlayHeight ) ).ConvertToImage();
                    HELIUM_ASSERT( overlayImage.Ok() );
                }
                else if ( HasFlags<uint32_t>( docStatus, DocumentStatus::Changed ) )
                {
                    overlayImage = wxArtProvider::GetBitmap( ArtIDs::Actions::Edit, wxART_OTHER, wxSize( overlayWidth, overlayHeight ) ).ConvertToImage();
                    HELIUM_ASSERT( overlayImage.Ok() );
                }

                if ( overlayImage.Ok() )
                {
                    if ( overlayImage.GetWidth() != overlayWidth || overlayImage.GetHeight() != overlayHeight )
                    {
                        overlayImage.Rescale( overlayWidth, overlayHeight );
                    }

                    int x = 0;
                    int y = 0;
                    IconArtFile::CalculatePlacement( image, overlayImage, OverlayQuadrants::BottomRight, x, y );
                    image.Paste( overlayImage, x, y, wxIMAGE_ALPHA_BLEND_COMPOSITE );
                }

                bitmap = wxBitmap( image );
            }

            wxIcon icon;
            icon.CopyFromBitmap( bitmap );

            variant << wxDataViewIconText( name, icon );

        }
        break;

    //case ProjectModelColumns::Icon:
    //    {
    //        int32_t imageID = GlobalFileIconsTable().GetIconIDFromPath( node->GetPath() );
    //        wxVariant bitmapVariant;
    //        bitmapVariant.
    //        variant = GlobalFileIconsTable().GetSmallImageList()->GetBitmap( imageID );
    //    }
    //    break;

    case ProjectModelColumns::Details:
        {
            variant = node->GetDetails();
        }
        break;

    case ProjectModelColumns::FileSize:
        {
            variant = node->GetFileSize();
        }
        break;
    }
}