const CDataNode* CDataNode::Find( const CString& name ) const {GUCEF_TRACE; const CDataNode* n = FindSibling( name ); if ( nullptr != n ) { return n; } TDataNodeList::const_iterator m = m_children.cbegin(); while ( m != m_children.cend() ) { n = (*m)->Find( name ); if ( nullptr != n ) { return n; } ++m; } return nullptr; }
HTREEITEM FolderTree::SetSelectedPath(const tstring &sPath, bool bExpanded /* = false */) { tstring sSearch = sPath; sSearch = Text::toLower(sSearch); int nSearchLength = sSearch.size(); if(nSearchLength == 0) { //TRACE(_T("Cannot select a empty path\n")); return NULL; } //Remove initial part of path if the root folder is setup tstring sRootFolder = m_sRootFolder; sRootFolder = Text::toLower(sRootFolder); int nRootLength = sRootFolder.size(); if (nRootLength) { if(sSearch.find(sRootFolder) != 0) { //TRACE(_T("Could not select the path %s as the root has been configued as %s\n"), sPath, m_sRootFolder); return NULL; } sSearch = sSearch.substr(nRootLength); } //Remove trailing "\" from the path nSearchLength = sSearch.size(); if (nSearchLength > 3 && sSearch[nSearchLength-1] == _T('\\')) sSearch = sSearch.substr(0, nSearchLength-1); if (sSearch.empty()) return NULL; SetRedraw(FALSE); HTREEITEM hItemFound = TVI_ROOT; if (nRootLength && m_hRootedFolder) hItemFound = m_hRootedFolder; bool bDriveMatch = sRootFolder.empty(); bool bNetworkMatch = m_bDisplayNetwork && ((sSearch.size() > 2) && sSearch.find(_T("\\\\")) == 0); if (bNetworkMatch) { bDriveMatch = false; //Working here bool bHasPlus = HasPlusButton(m_hNetworkRoot); bool bHasChildren = (GetChildItem(m_hNetworkRoot) != NULL); if (bHasPlus && !bHasChildren) DoExpand(m_hNetworkRoot); else Expand(m_hNetworkRoot, TVE_EXPAND); hItemFound = FindServersNode(m_hNetworkRoot); sSearch = sSearch.substr(2); } if (bDriveMatch) { if (m_hMyComputerRoot) { //Working here bool bHasPlus = HasPlusButton(m_hMyComputerRoot); bool bHasChildren = (GetChildItem(m_hMyComputerRoot) != NULL); if (bHasPlus && !bHasChildren) DoExpand(m_hMyComputerRoot); else Expand(m_hMyComputerRoot, TVE_EXPAND); hItemFound = m_hMyComputerRoot; } } int nFound = sSearch.find(_T('\\')); while(nFound != tstring::npos) { tstring sMatch; if (bDriveMatch) { sMatch = sSearch.substr(0, nFound + 1); bDriveMatch = false; } else sMatch = sSearch.substr(0, nFound); hItemFound = FindSibling(hItemFound, sMatch); if (hItemFound == NULL) break; else if (!IsDrive(sPath)) { SelectItem(hItemFound); //Working here bool bHasPlus = HasPlusButton(hItemFound); bool bHasChildren = (GetChildItem(hItemFound) != NULL); if (bHasPlus && !bHasChildren) DoExpand(hItemFound); else Expand(hItemFound, TVE_EXPAND); } sSearch = sSearch.substr(nFound - 1); nFound = sSearch.find(_T('\\')); }; //The last item if (hItemFound) { if (sSearch.size()) hItemFound = FindSibling(hItemFound, sSearch); if (hItemFound) SelectItem(hItemFound); if (bExpanded) { //Working here bool bHasPlus = HasPlusButton(hItemFound); bool bHasChildren = (GetChildItem(hItemFound) != NULL); if (bHasPlus && !bHasChildren) DoExpand(hItemFound); else Expand(hItemFound, TVE_EXPAND); } } //Turn back on the redraw flag SetRedraw(TRUE); return hItemFound; }
HTREEITEM CTreeFileCtrl::SetSelectedPath(const CString& sPath, BOOL bExpanded) { CString sSearch(sPath); int nSearchLength = sSearch.GetLength(); if (nSearchLength == 0) { TRACE(_T("Cannot select a empty path\n")); return NULL; } //Remove trailing "\" from the path if (nSearchLength > 3 && sSearch.GetAt(nSearchLength-1) == _T('\\')) sSearch = sSearch.Left(nSearchLength-1); //Remove initial part of path if the root folder is setup int nRootLength = m_sRootFolder.GetLength(); if (nRootLength) { if (sSearch.Find(m_sRootFolder) != 0) { TRACE(_T("Could not select the path %s as the root has been configued as %s\n"), sPath, m_sRootFolder); return NULL; } sSearch = sSearch.Right(sSearch.GetLength() - 1 - nRootLength); } if (sSearch.IsEmpty()) return NULL; SetRedraw(FALSE); HTREEITEM hItemFound = TVI_ROOT; int nFound = sSearch.Find(_T('\\')); BOOL bDriveMatch = m_sRootFolder.IsEmpty(); while (nFound != -1) { CString sMatch; if (bDriveMatch) { sMatch = sSearch.Left(nFound + 1); bDriveMatch = FALSE; } else sMatch = sSearch.Left(nFound); hItemFound = FindSibling(hItemFound, sMatch); if (hItemFound == NULL) break; else Expand(hItemFound, TVE_EXPAND); sSearch = sSearch.Right(sSearch.GetLength() - nFound - 1); nFound = sSearch.Find(_T('\\')); }; //The last item if (hItemFound) { if (sSearch.GetLength()) hItemFound = FindSibling(hItemFound, sSearch); SelectItem(hItemFound); if (bExpanded) Expand(hItemFound, TVE_EXPAND); } SetRedraw(TRUE); return hItemFound; }