Add detection of HECL Projects for directory listings

Crash fixes for translator
This commit is contained in:
Phillip Stephens 2016-01-04 23:50:35 -08:00
parent 6e3614ec28
commit 020407052a
3 changed files with 23 additions and 5 deletions

@ -1 +1 @@
Subproject commit 3d6218a9d246c07cc974397f91d9f94b15fa3e85
Subproject commit 0ec87939d230a73107c676115e359f8eeb9d783e

View File

@ -136,6 +136,7 @@ private:
std::string m_sizeCol;
std::string m_dirStr;
std::string m_projStr;
std::string m_fileStr;
size_t columnCount() const {return 3;}
@ -198,7 +199,12 @@ private:
HECL::SystemUTF8View nameUtf8(d.m_name);
ent.m_name = nameUtf8.str();
if (d.m_isDir)
ent.m_type = m_dirStr;
{
if (HECL::SearchForProject(d.m_path))
ent.m_type = m_projStr;
else
ent.m_type = m_dirStr;
}
else
{
ent.m_type = m_fileStr;
@ -250,6 +256,7 @@ private:
m_typeCol = vm.translateOr("type", "Type");
m_sizeCol = vm.translateOr("size", "Size");
m_dirStr = vm.translateOr("directory", "Directory");
m_projStr = vm.translateOr("hecl_project", "HECL Project");
m_fileStr = vm.translateOr("file", "File");
}

View File

@ -13,9 +13,14 @@ Locale::Locale(const std::string& name, const std::string& fullName,
yaml_parser_set_input_string(reader.getParser(), yamlSource, yamlLength);
reader.parse();
m_rootNode = std::move(reader.releaseRootNode());
m_langNode = m_rootNode->findMapChild(name.c_str());
if (!m_langNode)
Log.report(LogVisor::FatalError, "no root node '%s' found in locale", name.c_str());
if (m_rootNode)
{
m_langNode = m_rootNode->findMapChild(name.c_str());
if (!m_langNode)
Log.report(LogVisor::FatalError, "no root node '%s' found in locale", name.c_str());
}
else
Log.report(LogVisor::Warning, "locale empty");
}
void Translator::setLocale(const Locale* targetLocale)
@ -47,11 +52,17 @@ static const std::string* RecursiveLookup(const Athena::io::YAMLNode& node,
const std::string* Translator::translate(const std::string& key) const
{
if ((&m_targetLocale->rootNode()) == nullptr)
return nullptr;
return RecursiveLookup(m_targetLocale->rootNode(), key.cbegin(), key.cend());
}
std::string Translator::translateOr(const std::string& key, const char* vor) const
{
if ((&m_targetLocale->rootNode()) == nullptr)
return vor;
const std::string* find = RecursiveLookup(m_targetLocale->rootNode(), key.cbegin(), key.cend());
if (find)
return *find;