/** * @author Edouard DUPIN * * @copyright 2010, Edouard DUPIN, all right reserved * * @license GPL v3 (see license file) */ #include #include #include #include #include #undef __class__ #define __class__ "highlightManager" // TODO : Review this in a generic unique resource ... static std::vector>& s_list() { static std::vector> list; return list; } void appl::highlightManager::init() { std::vector>& hlList = s_list(); if (hlList.size() != 0) { APPL_ERROR("HighlightManager == > already exist, just unlink the previous ..."); hlList.clear(); } APPL_DEBUG("HighlightManager == > INIT"); etk::FSNode myFile("DATA:languages/"); // get the subfolder list : std::vector list = myFile.folderGetSubList(false, true, false,false); for (auto &it : list) { if (it == nullptr) { continue; } if (it->getNodeType() != etk::FSN_FOLDER) { continue; } std::string filename = it->getName() + "/highlight.xml"; APPL_DEBUG("Load xml name : " << filename); std::shared_ptr myHightLine = appl::Highlight::create(filename); if (myHightLine != nullptr) { hlList.push_back(myHightLine); } else { APPL_ERROR("Can not allocate HighLight"); } } // display : /* for (auto &it : hlList) { if (it == nullptr) { continue; } it->display(); } */ } void appl::highlightManager::unInit() { std::vector>& hlList = s_list(); if (hlList.size() == 0) { APPL_DEBUG("HighlightManager ==> no highlight"); hlList.clear(); return; } hlList.clear(); } std::string appl::highlightManager::getTypeExtention(const std::string& _extention) { if (_extention.size() == 0) { return ""; } APPL_DEBUG("Try to find type for extention : '" << _extention << "' in " << s_list().size() << " types"); std::vector>& hlList = s_list(); for (auto &it : hlList) { if (it == nullptr) { continue; } APPL_DEBUG(" check : " << it->getTypeName()); if (it->hasExtention(_extention) == true) { APPL_DEBUG("Find type for extention : " << _extention << " type : " << it->getTypeName()); return it->getTypeName(); } } return ""; } std::string appl::highlightManager::getFileWithTypeType(const std::string& _type) { if (_type.size() == 0) { return ""; } for (auto &it : s_list()) { if (it == nullptr) { continue; } if (it->getTypeName() == _type) { return it->getName(); } } return ""; } std::vector appl::highlightManager::getTypeList() { std::vector ret; return ret; }