bool SFTPTreeView::DoExpandItem(const wxTreeItemId& item) { MyClientData* cd = GetItemData(item); CHECK_PTR_RET_FALSE(cd); // already initialized this folder before? if(cd->IsInitialized()) { return true; } // get list of files and populate the tree SFTPAttribute::List_t attributes; try { attributes = m_sftp->List(cd->GetFullPath(), clSFTP::SFTP_BROWSE_FILES | clSFTP::SFTP_BROWSE_FOLDERS); } catch(clException& e) { ::wxMessageBox(e.What(), "SFTP", wxOK | wxICON_ERROR | wxCENTER, EventNotifier::Get()->TopFrame()); return false; } // Remove the dummy item and replace it with real items wxTreeItemIdValue cookie; wxTreeItemId dummyItem = m_treeCtrl->GetFirstChild(item, cookie); m_treeCtrl->Delete(dummyItem); cd->SetInitialized(true); int nNumOfRealChildren = 0; SFTPAttribute::List_t::iterator iter = attributes.begin(); for(; iter != attributes.end(); ++iter) { SFTPAttribute::Ptr_t attr = (*iter); if(attr->GetName() == "." || attr->GetName() == "..") continue; ++nNumOfRealChildren; // determine the icon index int imgIdx = wxNOT_FOUND; if(attr->IsFolder()) { imgIdx = m_bmpLoader->GetMimeImageId(FileExtManager::TypeFolder); } else { imgIdx = m_bmpLoader->GetMimeImageId(attr->GetName()); } if(imgIdx == wxNOT_FOUND) { imgIdx = m_bmpLoader->GetMimeImageId(FileExtManager::TypeText); } wxString path; path << cd->GetFullPath() << "/" << attr->GetName(); while(path.Replace("//", "/")) {} MyClientData* childClientData = new MyClientData(path); childClientData->SetIsFolder(attr->IsFolder()); wxTreeItemId child = m_treeCtrl->AppendItem(item, attr->GetName(), imgIdx, imgIdx, childClientData); // if its type folder, add a fake child item if(attr->IsFolder()) { m_treeCtrl->AppendItem(child, "<dummy>"); } } return nNumOfRealChildren > 0; }
bool SFTPAttribute::Compare(SFTPAttribute::Ptr_t one, SFTPAttribute::Ptr_t two) { if ( one->IsFolder() && !two->IsFolder() ) { return true; } else if ( !one->IsFolder() && two->IsFolder() ) { return false; } else { return one->GetName() < two->GetName(); } }