void CLocalTreeView::Refresh() { wxLogNull nullLog; const wxString separator = wxFileName::GetPathSeparator(); std::list<t_dir> dirsToCheck; #ifdef __WXMSW__ int prevErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); wxTreeItemIdValue tmp; wxTreeItemId child = GetFirstChild(m_drives, tmp); while (child) { if (IsExpanded(child)) { wxString drive = GetItemText(child); int pos = drive.Find(_T(" ")); if (pos != -1) drive = drive.Left(pos); t_dir dir; dir.dir = drive + separator; dir.item = child; dirsToCheck.push_back(dir); } child = GetNextSibling(child); } #else t_dir dir; dir.dir = separator; dir.item = GetRootItem(); dirsToCheck.push_back(dir); #endif CFilterManager filter; while (!dirsToCheck.empty()) { t_dir dir = dirsToCheck.front(); dirsToCheck.pop_front(); // Step 1: Check if directory exists CLocalFileSystem local_filesystem; if (!local_filesystem.BeginFindFiles(dir.dir, true)) { // Dir does exist (listed in parent) but may not be accessible. // Recurse into children anyhow, they might be accessible again. wxTreeItemIdValue value; wxTreeItemId child = GetFirstChild(dir.item, value); while (child) { t_dir subdir; subdir.dir = dir.dir + GetItemText(child) + separator; subdir.item = child; dirsToCheck.push_back(subdir); child = GetNextSibling(child); } continue; } // Step 2: Enumerate subdirectories on disk and sort them std::list<wxString> dirs; wxString file; const wxLongLong size(-1); bool was_link; bool is_dir; int attributes; wxDateTime date; while (local_filesystem.GetNextFile(file, was_link, is_dir, 0, &date, &attributes)) { if (file == _T("")) { wxGetApp().DisplayEncodingWarning(); continue; } if (filter.FilenameFiltered(file, dir.dir, true, size, true, attributes, date.IsValid() ? &date : 0)) continue; dirs.push_back(file); } dirs.sort(sortfunc); bool inserted = false; // Step 3: Merge list of subdirectories with subtree. wxTreeItemId child = GetLastChild(dir.item); std::list<wxString>::reverse_iterator iter = dirs.rbegin(); while (child || iter != dirs.rend()) { int cmp; if (child && iter != dirs.rend()) #ifdef __WXMSW__ cmp = GetItemText(child).CmpNoCase(*iter); #else cmp = GetItemText(child).Cmp(*iter); #endif else if (child) cmp = 1; else cmp = -1; if (!cmp) { // Found item with same name. Mark it for further processing if (!IsExpanded(child)) { wxString path = dir.dir + *iter + separator; if (!CheckSubdirStatus(child, path)) { t_dir subdir; subdir.dir = path; subdir.item = child; dirsToCheck.push_front(subdir); } } else { t_dir subdir; subdir.dir = dir.dir + *iter + separator; subdir.item = child; dirsToCheck.push_front(subdir); } child = GetPrevSibling(child); ++iter; } else if (cmp > 0) { // Subdirectory currently in tree no longer exists. // Delete child from tree, unless current selection // is in the subtree. wxTreeItemId sel = GetSelection(); while (sel && sel != child) sel = GetItemParent(sel); wxTreeItemId prev = GetPrevSibling(child); if (!sel) Delete(child); child = prev; } else if (cmp < 0) { // New subdirectory, add treeitem wxString fullname = dir.dir + *iter + separator; wxTreeItemId newItem = AppendItem(dir.item, *iter, GetIconIndex(::dir, fullname), #ifdef __WXMSW__ -1 #else GetIconIndex(opened_dir, fullname) #endif ); CheckSubdirStatus(newItem, fullname); ++iter; inserted = true; } } if (inserted) SortChildren(dir.item); }
void CLocalTreeView::DisplayDir(wxTreeItemId parent, const wxString& dirname, const wxString& knownSubdir /*=_T("")*/) { fz::local_filesys local_filesys; { wxLogNull log; if (!local_filesys.begin_find_files(fz::to_native(dirname), true)) { if (!knownSubdir.empty()) { wxTreeItemId item = GetSubdir(parent, knownSubdir); if (item != wxTreeItemId()) return; const wxString fullName = dirname + knownSubdir; item = AppendItem(parent, knownSubdir, GetIconIndex(iconType::dir, fullName), #ifdef __WXMSW__ -1 #else GetIconIndex(iconType::opened_dir, fullName) #endif ); CheckSubdirStatus(item, fullName); } else { m_setSelection = true; DeleteChildren(parent); m_setSelection = false; } return; } } wxASSERT(parent); m_setSelection = true; DeleteChildren(parent); m_setSelection = false; CFilterManager filter; bool matchedKnown = false; fz::native_string file; bool wasLink; int attributes; bool is_dir; static int64_t const size(-1); fz::datetime date; while (local_filesys.get_next_file(file, wasLink, is_dir, 0, &date, &attributes)) { wxASSERT(is_dir); if (file.empty()) { wxGetApp().DisplayEncodingWarning(); continue; } wxString file_wx = file; wxString fullName = dirname + file_wx; #ifdef __WXMSW__ if (file_wx.CmpNoCase(knownSubdir)) #else if (file_wx != knownSubdir) #endif { if (filter.FilenameFiltered(file_wx, dirname, true, size, true, attributes, date)) continue; } else matchedKnown = true; wxTreeItemId item = AppendItem(parent, file_wx, GetIconIndex(iconType::dir, fullName), #ifdef __WXMSW__ -1 #else GetIconIndex(iconType::opened_dir, fullName) #endif ); CheckSubdirStatus(item, fullName); } if (!matchedKnown && !knownSubdir.empty()) { const wxString fullName = dirname + knownSubdir; wxTreeItemId item = AppendItem(parent, knownSubdir, GetIconIndex(iconType::dir, fullName), #ifdef __WXMSW__ -1 #else GetIconIndex(iconType::opened_dir, fullName) #endif ); CheckSubdirStatus(item, fullName); } SortChildren(parent); }
void CLocalTreeView::DisplayDir(wxTreeItemId parent, const wxString& dirname, const wxString& knownSubdir /*=_T("")*/) { CLocalFileSystem local_filesystem; { wxLogNull log; if (!local_filesystem.BeginFindFiles(dirname, true)) { if (knownSubdir != _T("")) { wxTreeItemId item = GetSubdir(parent, knownSubdir); if (item != wxTreeItemId()) return; const wxString fullName = dirname + knownSubdir; item = AppendItem(parent, knownSubdir, GetIconIndex(::dir, fullName), #ifdef __WXMSW__ -1 #else GetIconIndex(opened_dir, fullName) #endif ); CheckSubdirStatus(item, fullName); } else { m_setSelection = true; DeleteChildren(parent); m_setSelection = false; } return; } } wxASSERT(parent); m_setSelection = true; DeleteChildren(parent); m_setSelection = false; CFilterManager filter; bool matchedKnown = false; wxString file; bool wasLink; int attributes; bool is_dir; const wxLongLong size(-1); wxDateTime date; while (local_filesystem.GetNextFile(file, wasLink, is_dir, 0, &date, &attributes)) { wxASSERT(is_dir); if (file == _T("")) { wxGetApp().DisplayEncodingWarning(); continue; } wxString fullName = dirname + file; #ifdef __WXMSW__ if (file.CmpNoCase(knownSubdir)) #else if (file != knownSubdir) #endif { if (filter.FilenameFiltered(file, dirname, true, size, true, attributes, date.IsValid() ? &date : 0)) continue; } else matchedKnown = true; wxTreeItemId item = AppendItem(parent, file, GetIconIndex(::dir, fullName), #ifdef __WXMSW__ -1 #else GetIconIndex(opened_dir, fullName) #endif ); CheckSubdirStatus(item, fullName); } if (!matchedKnown && knownSubdir != _T("")) { const wxString fullName = dirname + knownSubdir; wxTreeItemId item = AppendItem(parent, knownSubdir, GetIconIndex(::dir, fullName), #ifdef __WXMSW__ -1 #else GetIconIndex(opened_dir, fullName) #endif ); CheckSubdirStatus(item, fullName); } SortChildren(parent); }
void CLocalTreeView::Refresh() { wxLogNull nullLog; const wxString separator = wxFileName::GetPathSeparator(); std::list<t_dir> dirsToCheck; #ifdef __WXMSW__ int prevErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); wxTreeItemIdValue tmp; wxTreeItemId child = GetFirstChild(m_drives, tmp); while (child) { if (IsExpanded(child)) { wxString drive = GetItemText(child); int pos = drive.Find(_T(" ")); if (pos != -1) drive = drive.Left(pos); t_dir dir; dir.dir = drive + separator; dir.item = child; dirsToCheck.push_back(dir); } child = GetNextSibling(child); } #else t_dir dir; dir.dir = separator; dir.item = GetRootItem(); dirsToCheck.push_back(dir); #endif CFilterManager filter; while (!dirsToCheck.empty()) { t_dir dir = dirsToCheck.front(); dirsToCheck.pop_front(); CLocalFileSystem local_filesystem; if (!local_filesystem.BeginFindFiles(dir.dir, true)) { // Dir does exist (listed in parent) but may not be accessible. // Recurse into children anyhow, they might be accessible again. wxTreeItemIdValue value; wxTreeItemId child = GetFirstChild(dir.item, value); while (child) { t_dir subdir; subdir.dir = dir.dir + GetItemText(child) + separator; subdir.item = child; dirsToCheck.push_back(subdir); child = GetNextSibling(child); } continue; } std::list<wxString> dirs; wxString file; const wxLongLong size(-1); bool was_link; bool is_dir; int attributes; while (local_filesystem.GetNextFile(file, was_link, is_dir, 0, 0, &attributes)) { if (file == _T("")) { wxGetApp().DisplayEncodingWarning(); continue; } if (filter.FilenameFiltered(file, dir.dir, true, size, true, attributes)) continue; dirs.push_back(file); } dirs.sort(sortfunc); bool inserted = false; wxTreeItemId child = GetLastChild(dir.item); std::list<wxString>::reverse_iterator iter = dirs.rbegin(); while (child && iter != dirs.rend()) { #ifdef __WXMSW__ int cmp = GetItemText(child).CmpNoCase(*iter); #else int cmp = GetItemText(child).Cmp(*iter); #endif if (!cmp) { if (!IsExpanded(child)) { wxString path = dir.dir + *iter + separator; if (!CheckSubdirStatus(child, path)) { t_dir subdir; subdir.dir = path; subdir.item = child; dirsToCheck.push_front(subdir); } } else { t_dir subdir; subdir.dir = dir.dir + *iter + separator; subdir.item = child; dirsToCheck.push_front(subdir); } child = GetPrevSibling(child); iter++; } else if (cmp > 0) { wxTreeItemId sel = GetSelection(); while (sel && sel != child) sel = GetItemParent(sel); wxTreeItemId prev = GetPrevSibling(child); if (!sel) Delete(child); child = prev; } else if (cmp < 0) { wxString fullname = dir.dir + *iter + separator; wxTreeItemId newItem = AppendItem(dir.item, *iter, GetIconIndex(::dir, fullname), #ifdef __WXMSW__ -1 #else GetIconIndex(opened_dir, fullname) #endif ); CheckSubdirStatus(newItem, fullname); iter++; inserted = true; } } while (child) { wxTreeItemId sel = GetSelection(); while (sel && sel != child) sel = GetItemParent(sel); wxTreeItemId prev = GetPrevSibling(child); if (!sel) Delete(child); child = prev; } while (iter != dirs.rend()) { wxString fullname = dir.dir + *iter + separator; wxTreeItemId newItem = AppendItem(dir.item, *iter, GetIconIndex(::dir, fullname), #ifdef __WXMSW__ -1 #else GetIconIndex(opened_dir, fullname) #endif ); CheckSubdirStatus(newItem, fullname); iter++; inserted = true; } if (inserted) SortChildren(dir.item); } #ifdef __WXMSW__ SetErrorMode(prevErrorMode); #endif }