edn/sources/appl/HighlightManager.cpp

114 lines
2.7 KiB
C++
Raw Normal View History

/**
* @author Edouard DUPIN
2012-11-25 11:55:06 +01:00
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
2013-10-25 20:49:26 +02:00
#include <appl/debug.h>
2012-04-24 09:42:14 +02:00
#include <appl/global.h>
#include <appl/HighlightManager.h>
2013-12-13 21:50:40 +01:00
#include <ewol/object/Object.h>
#include <ewol/object/Manager.h>
#undef __class__
2013-10-23 21:19:30 +02:00
#define __class__ "highlightManager"
2014-06-02 21:04:35 +02:00
// TODO : Review this in a generic unique resource ...
static std::vector<std::shared_ptr<appl::Highlight>>& s_list() {
static std::vector<std::shared_ptr<appl::Highlight>> list;
2013-10-23 21:19:30 +02:00
return list;
}
2012-02-19 22:33:43 +01:00
void appl::highlightManager::init() {
std::vector<std::shared_ptr<appl::Highlight>>& hlList = s_list();
2013-10-23 21:19:30 +02:00
if (hlList.size() != 0) {
2013-10-07 22:04:21 +02:00
APPL_ERROR("HighlightManager == > already exist, just unlink the previous ...");
2013-10-23 21:19:30 +02:00
hlList.clear();
2012-02-19 22:33:43 +01:00
}
APPL_DEBUG("HighlightManager == > INIT");
2013-10-23 21:19:30 +02:00
etk::FSNode myFile("DATA:languages/");
// get the subfolder list :
2013-11-14 21:57:10 +01:00
std::vector<etk::FSNode *> list = myFile.folderGetSubList(false, true, false,false);
2014-06-02 21:04:35 +02:00
for (auto &it : list) {
2014-06-05 22:01:24 +02:00
if (it == nullptr) {
2013-10-23 21:19:30 +02:00
continue;
}
2014-06-02 21:04:35 +02:00
if (it->getNodeType() != etk::FSN_FOLDER) {
2013-10-23 21:19:30 +02:00
continue;
}
2014-06-02 21:04:35 +02:00
std::string filename = it->getName() + "/highlight.xml";
2013-10-23 21:19:30 +02:00
APPL_DEBUG("Load xml name : " << filename);
std::shared_ptr<appl::Highlight> myHightLine = appl::Highlight::create(filename);
2014-06-05 22:01:24 +02:00
if (myHightLine != nullptr) {
2013-11-14 21:57:10 +01:00
hlList.push_back(myHightLine);
2013-10-25 22:12:34 +02:00
} else {
APPL_ERROR("Can not allocate HighLight");
}
}
// display :
/*
2014-06-02 21:04:35 +02:00
for (auto &it : hlList) {
2014-06-05 22:01:24 +02:00
if (it == nullptr) {
2013-10-25 22:12:34 +02:00
continue;
}
2014-06-02 21:04:35 +02:00
it->display();
}
*/
}
void appl::highlightManager::unInit() {
std::vector<std::shared_ptr<Highlight>>& hlList = s_list();
2013-10-23 21:19:30 +02:00
if (hlList.size() == 0) {
APPL_DEBUG("HighlightManager ==> no highlight");
hlList.clear();
2012-02-19 22:33:43 +01:00
return;
}
2013-10-23 21:19:30 +02:00
hlList.clear();
2011-08-19 16:09:58 +02:00
}
2013-11-14 21:57:10 +01:00
std::string appl::highlightManager::getTypeExtention(const std::string& _extention) {
2013-10-27 11:34:45 +01:00
if (_extention.size() == 0) {
return "";
}
APPL_DEBUG("Try to find type for extention : '" << _extention << "' in " << s_list().size() << " types");
std::vector<std::shared_ptr<Highlight>>& hlList = s_list();
2014-06-02 21:04:35 +02:00
for (auto &it : hlList) {
2014-06-05 22:01:24 +02:00
if (it == nullptr) {
2013-10-27 11:34:45 +01:00
continue;
}
2014-06-02 21:04:35 +02:00
APPL_DEBUG(" check : " << it->getTypeName());
if (it->hasExtention(_extention) == true) {
APPL_DEBUG("Find type for extention : " << _extention
2014-06-02 21:04:35 +02:00
<< " type : " << it->getTypeName());
return it->getTypeName();
2013-10-27 11:34:45 +01:00
}
}
return "";
}
2013-11-14 21:57:10 +01:00
std::string appl::highlightManager::getFileWithTypeType(const std::string& _type) {
2013-10-27 11:34:45 +01:00
if (_type.size() == 0) {
return "";
}
2014-06-02 21:04:35 +02:00
for (auto &it : s_list()) {
2014-06-05 22:01:24 +02:00
if (it == nullptr) {
2013-10-27 11:34:45 +01:00
continue;
}
2014-06-02 21:04:35 +02:00
if (it->getTypeName() == _type) {
return it->getName();
2013-10-27 11:34:45 +01:00
}
}
2013-10-23 21:19:30 +02:00
return "";
}
std::vector<std::string> appl::highlightManager::getTypeList() {
2013-11-14 21:57:10 +01:00
std::vector<std::string> ret;
2013-10-23 21:19:30 +02:00
return ret;
}