| 914 | node = nullptr; |
| 915 | } |
| 916 | void FileDialog::m_setDirectory(const std::filesystem::path& p, bool addHistory) |
| 917 | { |
| 918 | bool isSameDir = m_currentDirectory == p; |
| 919 | |
| 920 | if (addHistory && !isSameDir) |
| 921 | m_backHistory.push(m_currentDirectory); |
| 922 | |
| 923 | m_currentDirectory = p; |
| 924 | #ifdef _WIN32 |
| 925 | // drives don't work well without the backslash symbol |
| 926 | if (p.u8string().size() == 2 && p.u8string()[1] == ':') |
| 927 | m_currentDirectory = std::filesystem::u8path(p.u8string() + "\\"); |
| 928 | #endif |
| 929 | |
| 930 | m_clearIconPreview(); |
| 931 | m_content.clear(); // p == "" after this line, due to reference |
| 932 | m_selectedFileItem = -1; |
| 933 | |
| 934 | if (m_type == IFD_DIALOG_DIRECTORY || m_type == IFD_DIALOG_FILE) |
| 935 | m_inputTextbox[0] = 0; |
| 936 | m_selections.clear(); |
| 937 | |
| 938 | if (!isSameDir) { |
| 939 | m_searchBuffer[0] = 0; |
| 940 | m_clearIcons(); |
| 941 | } |
| 942 | |
| 943 | if (p.u8string() == "Quick Access") { |
| 944 | for (auto& node : m_treeCache) { |
| 945 | if (node->Path == p) |
| 946 | for (auto& c : node->Children) |
| 947 | m_content.push_back(FileData(c->Path)); |
| 948 | } |
| 949 | } |
| 950 | else if (p.u8string() == "This PC") { |
| 951 | for (auto& node : m_treeCache) { |
| 952 | if (node->Path == p) |
| 953 | for (auto& c : node->Children) |
| 954 | m_content.push_back(FileData(c->Path)); |
| 955 | } |
| 956 | } |
| 957 | else { |
| 958 | std::error_code ec; |
| 959 | if (std::filesystem::exists(m_currentDirectory, ec)) |
| 960 | for (const auto& entry : std::filesystem::directory_iterator(m_currentDirectory, ec)) { |
| 961 | FileData info(entry.path()); |
| 962 | |
| 963 | // skip files when IFD_DIALOG_DIRECTORY |
| 964 | if (!info.IsDirectory && m_type == IFD_DIALOG_DIRECTORY) |
| 965 | continue; |
| 966 | |
| 967 | // check if filename matches search query |
| 968 | if (m_searchBuffer[0]) { |
| 969 | std::string filename = info.Path.u8string(); |
| 970 | |
| 971 | std::string filenameSearch = filename; |
| 972 | std::string query(m_searchBuffer); |
| 973 | std::transform(filenameSearch.begin(), filenameSearch.end(), filenameSearch.begin(), ::tolower); |