Sort HaldCLUT directories (fixes #4123)
This commit is contained in:
@@ -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 )
|
||||
{
|
||||
@@ -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::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
|
||||
using Dirs = std::vector<std::pair<Glib::ustring, Gtk::TreeModel::Row>>;
|
||||
@@ -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<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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user