diff --git a/rtgui/filmsimulation.cc b/rtgui/filmsimulation.cc index a1471f970..716b686e9 100644 --- a/rtgui/filmsimulation.cc +++ b/rtgui/filmsimulation.cc @@ -1,3 +1,6 @@ +#include +#include + #include "filmsimulation.h" #include @@ -56,8 +59,6 @@ bool notifySlowParseDir (const std::chrono::system_clock::time_point& startedAt) } -typedef std::vector Strings; - FilmSimulation::FilmSimulation() : FoldableToolPanel( this, "filmsimulation", M("TP_FILMSIMULATION_LABEL"), false, true ) { @@ -216,13 +217,28 @@ int ClutComboBox::fillFromDir (const Glib::ustring& path) return result; } -int ClutComboBox::parseDir (const Glib::ustring& path) +int ClutComboBox::parseDir(const Glib::ustring& path) { - if (path.empty () || !Glib::file_test (path, Glib::FILE_TEST_IS_DIR)) { + if (path.empty() || !Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) { return 0; } - const auto startedAt = std::chrono::system_clock::now (); + const auto sorted_dir_dirs = [](const Glib::ustring& path) -> std::map + { + std::map res; + + for (const auto& dir : Glib::Dir(path)) { + const std::string full_path = Glib::build_filename(path, dir); + + if (Glib::file_test(full_path, Glib::FILE_TEST_IS_DIR)) { + res.emplace(dir, full_path); + } + } + + return res; + }; + + const auto startedAt = std::chrono::system_clock::now(); // Build menu of limited directory structure using breadth-first search using Dirs = std::vector>; @@ -232,89 +248,77 @@ int ClutComboBox::parseDir (const Glib::ustring& path) Dirs currDirs; Dirs nextDirs; - currDirs.emplace_back (path, Gtk::TreeModel::Row ()); - - while (!currDirs.empty ()) { + currDirs.emplace_back(path, Gtk::TreeModel::Row()); + while (!currDirs.empty()) { for (auto& dir : currDirs) { - const auto& path = dir.first; const auto& row = dir.second; try { - for (const auto& entry : Glib::Dir (path)) { + for (const auto& entry : sorted_dir_dirs(path)) { + auto newRow = row ? *m_model->append(row.children()) : *m_model->append(); + newRow[m_columns.label] = entry.first; - const auto entryPath = Glib::build_filename (path, entry); - - if (!Glib::file_test (entryPath, Glib::FILE_TEST_IS_DIR)) { - continue; - } - - auto newRow = row ? *m_model->append (row.children ()) : *m_model->append (); - newRow[m_columns.label] = entry; - - nextDirs.emplace_back (entryPath, newRow); + nextDirs.emplace_back(entry.second, newRow); } } catch (Glib::Exception&) {} - dirs.push_back (std::move (dir)); + dirs.push_back(std::move(dir)); - if (!notifySlowParseDir (startedAt)) { - m_model->clear (); + if (!notifySlowParseDir(startedAt)) { + m_model->clear(); return 0; } } - currDirs.clear (); - currDirs.swap (nextDirs); + currDirs.clear(); + currDirs.swap(nextDirs); } } // Fill menu structure with CLUT files - Strings entries; + std::set entries; - auto fileCount = 0; + unsigned long fileCount = 0; for (const auto& dir : dirs) { - const auto& path = dir.first; const auto& row = dir.second; - entries.clear (); + entries.clear(); try { - for (const auto& entry : Glib::Dir (path)) { + for (const auto& entry : Glib::Dir(path)) { + const auto entryPath = Glib::build_filename(path, entry); - const auto entryPath = Glib::build_filename (path, entry); - - if (!Glib::file_test (entryPath, Glib::FILE_TEST_IS_REGULAR)) { + if (!Glib::file_test(entryPath, Glib::FILE_TEST_IS_REGULAR)) { continue; } - entries.push_back (entryPath); + entries.insert(entryPath); } } catch (Glib::Exception&) {} - std::sort (entries.begin (), entries.end ()); - for (const auto& entry : entries) { - - Glib::ustring name, extension, profileName; + Glib::ustring name; + Glib::ustring extension; + Glib::ustring profileName; HaldCLUT::splitClutFilename (entry, name, extension, profileName); - extension = extension.casefold (); - if (extension.compare ("tif") != 0 && extension.compare ("png") != 0) { + extension = extension.casefold(); + if (extension.compare("tif") != 0 && extension.compare("png") != 0) { continue; } - auto newRow = row ? *m_model->append (row.children ()) : *m_model->append (); + auto newRow = row ? *m_model->append(row.children()) : *m_model->append(); newRow[m_columns.label] = name; newRow[m_columns.clutFilename] = entry; ++fileCount; - if (!notifySlowParseDir (startedAt)) { - m_model->clear (); + if (!notifySlowParseDir(startedAt)) { + m_model->clear(); return 0; } }