HTREEITEM FileBrowser::createFolderItemsFromDirStruct(HTREEITEM hParentItem, const FolderInfo & directoryStructure) { HTREEITEM hFolderItem = nullptr; if (directoryStructure._parent == nullptr && hParentItem == nullptr) { TCHAR rootPath[MAX_PATH]; lstrcpy(rootPath, directoryStructure._rootPath.c_str()); size_t len = lstrlen(rootPath); if (rootPath[len - 1] == '\\') rootPath[len - 1] = '\0'; hFolderItem = _treeView.addItem(directoryStructure._name.c_str(), TVI_ROOT, INDEX_CLOSED_NODE, rootPath); } else { hFolderItem = _treeView.addItem(directoryStructure._name.c_str(), hParentItem, INDEX_CLOSED_NODE); } for (size_t i = 0; i < directoryStructure._subFolders.size(); ++i) { createFolderItemsFromDirStruct(hFolderItem, directoryStructure._subFolders[i]); } for (size_t i = 0; i < directoryStructure._files.size(); ++i) { _treeView.addItem(directoryStructure._files[i]._name.c_str(), hFolderItem, INDEX_LEAF); } _treeView.fold(hParentItem); return hFolderItem; }
void FileBrowser::addRootFolder(generic_string rootFolderPath) { // make sure there's no '\' at the end if (rootFolderPath[rootFolderPath.length() - 1] == '\\') { rootFolderPath = rootFolderPath.substr(0, rootFolderPath.length() - 1); } size_t nbFolderUpdaters = _folderUpdaters.size(); for (size_t i = 0; i < nbFolderUpdaters; ++i) { if (_folderUpdaters[i]->_rootFolder._rootPath == rootFolderPath) return; else { size_t pos = rootFolderPath.find(_folderUpdaters[i]->_rootFolder._rootPath); if (pos == 0) { //do nothing, go down to select the dir generic_string rootPath = _folderUpdaters[i]->_rootFolder._rootPath; generic_string pathSuffix = rootFolderPath.substr(rootPath.size() + 1, rootFolderPath.size() - rootPath.size()); vector<generic_string> linarPathArray = split(pathSuffix, '\\'); HTREEITEM foundItem = findInTree(rootPath, nullptr, linarPathArray); if (foundItem) _treeView.selectItem(foundItem); return; } pos = _folderUpdaters[i]->_rootFolder._rootPath.find(rootFolderPath); if (pos == 0) { ::MessageBox(_hParent, TEXT("A sub-folder of the folder you want to open exists.\rPlease remove it from the panel before you add this one."), rootFolderPath.c_str(), MB_OK); return; } } } std::vector<generic_string> patterns2Match; patterns2Match.push_back(TEXT("*.*")); TCHAR *label = ::PathFindFileName(rootFolderPath.c_str()); TCHAR rootLabel[MAX_PATH]; lstrcpy(rootLabel, label); size_t len = lstrlen(rootLabel); if (rootLabel[len - 1] == '\\') rootLabel[len - 1] = '\0'; FolderInfo directoryStructure(rootLabel, nullptr); getDirectoryStructure(rootFolderPath.c_str(), patterns2Match, directoryStructure, true, false); HTREEITEM hRootItem = createFolderItemsFromDirStruct(nullptr, directoryStructure); _treeView.expand(hRootItem); _folderUpdaters.push_back(new FolderUpdater(directoryStructure, this)); _folderUpdaters[_folderUpdaters.size() - 1]->startWatcher(); }
void FileBrowser::addRootFolder(generic_string rootFolderPath) { // make sure there's no '\' at the end if (rootFolderPath[rootFolderPath.length() - 1] == '\\') { rootFolderPath = rootFolderPath.substr(0, rootFolderPath.length() - 1); } size_t nbFolderUpdaters = _folderUpdaters.size(); for (size_t i = 0; i < nbFolderUpdaters; ++i) { if (_folderUpdaters[i]->_rootFolder._rootPath == rootFolderPath) return; else { size_t pos = rootFolderPath.find(_folderUpdaters[i]->_rootFolder._rootPath); if (pos == 0) { printStr(TEXT("do nothing, go down to select the dir.")); return; } pos = _folderUpdaters[i]->_rootFolder._rootPath.find(rootFolderPath); if (pos == 0) { printStr(TEXT("remove old, add this one")); return; } } } std::vector<generic_string> patterns2Match; patterns2Match.push_back(TEXT("*.*")); TCHAR *label = ::PathFindFileName(rootFolderPath.c_str()); TCHAR rootLabel[MAX_PATH]; lstrcpy(rootLabel, label); size_t len = lstrlen(rootLabel); if (rootLabel[len - 1] == '\\') rootLabel[len - 1] = '\0'; FolderInfo directoryStructure(rootLabel, nullptr); getDirectoryStructure(rootFolderPath.c_str(), patterns2Match, directoryStructure, true, false); HTREEITEM hRootItem = createFolderItemsFromDirStruct(nullptr, directoryStructure); _treeView.expand(hRootItem); _folderUpdaters.push_back(new FolderUpdater(directoryStructure, this)); _folderUpdaters[_folderUpdaters.size() - 1]->startWatcher(); }