Sort HaldCLUT directories (fixes #4123)

This commit is contained in:
Flössie
2017-10-02 07:49:12 +02:00
parent 02807fc1de
commit c6c9ad5eef

View File

@@ -1,3 +1,6 @@
#include <map>
#include <set>
#include "filmsimulation.h"
#include <chrono>
@@ -56,8 +59,6 @@ bool notifySlowParseDir (const std::chrono::system_clock::time_point& startedAt)
}
typedef std::vector<Glib::ustring> Strings;
FilmSimulation::FilmSimulation()
: FoldableToolPanel( this, "filmsimulation", M("TP_FILMSIMULATION_LABEL"), false, true )
{
@@ -222,6 +223,21 @@ int ClutComboBox::parseDir (const Glib::ustring& path)
return 0;
}
const auto sorted_dir_dirs = [](const Glib::ustring& path) -> std::map<std::string, std::string>
{
std::map<std::string, std::string> 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
@@ -235,25 +251,16 @@ int ClutComboBox::parseDir (const Glib::ustring& path)
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)) {
const auto entryPath = Glib::build_filename (path, entry);
if (!Glib::file_test (entryPath, Glib::FILE_TEST_IS_DIR)) {
continue;
}
for (const auto& entry : sorted_dir_dirs(path)) {
auto newRow = row ? *m_model->append(row.children()) : *m_model->append();
newRow[m_columns.label] = entry;
newRow[m_columns.label] = entry.first;
nextDirs.emplace_back (entryPath, newRow);
nextDirs.emplace_back(entry.second, newRow);
}
} catch (Glib::Exception&) {}
@@ -271,12 +278,11 @@ int ClutComboBox::parseDir (const Glib::ustring& path)
}
// Fill menu structure with CLUT files
Strings entries;
std::set<Glib::ustring> entries;
auto fileCount = 0;
unsigned long fileCount = 0;
for (const auto& dir : dirs) {
const auto& path = dir.first;
const auto& row = dir.second;
@@ -284,22 +290,20 @@ int ClutComboBox::parseDir (const Glib::ustring& path)
try {
for (const auto& entry : Glib::Dir(path)) {
const auto entryPath = Glib::build_filename(path, entry);
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();