edn/sources/appl/init.cpp

161 lines
4.1 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)
*/
2012-11-25 11:55:06 +01:00
#include <etk/types.h>
2012-04-24 09:42:14 +02:00
#include <etk/UString.h>
#include <ewol/ewol.h>
2013-09-02 06:45:12 +02:00
#include <ewol/renderer/EObject.h>
#include <ewol/widget/WidgetManager.h>
2012-04-24 09:42:14 +02:00
2013-10-25 20:49:26 +02:00
#include <appl/debug.h>
2012-04-24 09:42:14 +02:00
#include <appl/global.h>
2012-11-01 10:47:36 +01:00
#include <etk/os/FSNode.h>
2012-07-13 18:12:14 +02:00
#include <etk/tool.h>
#include <unistd.h>
2013-09-02 06:45:12 +02:00
//#include <ewol/config.h>
2012-11-25 11:55:06 +01:00
#include <ewol/commandLine.h>
2013-09-02 06:45:12 +02:00
//#include <ewol/UserConfig.h>
#include <ewol/renderer/eContext.h>
#include <appl/TextPluginManager.h>
#include <appl/BufferManager.h>
#include <appl/HighlightManager.h>
#include <appl/Gui/MainWindows.h>
#include <appl/Gui/Search.h>
#include <appl/ctags/readtags.h>
#include <appl/globalMsg.h>
2013-11-11 20:20:25 +01:00
#include <vector>
#include <string>
#include <etk/unicode.h>
2012-11-22 21:39:15 +01:00
/**
* @brief Main of the program (This can be set in every case, but it is not used in Andoid...).
* @param std IO
* @return std IO
*/
2013-11-11 20:20:25 +01:00
int main(int _argc, const char *_argv[]) {
2013-09-02 06:45:12 +02:00
// only one things to do:
2013-10-09 22:00:24 +02:00
return ewol::run(_argc, _argv);
2012-11-22 21:39:15 +01:00
}
2013-10-29 21:13:45 +01:00
appl::BufferManager* bufferManager = NULL;
2012-11-22 21:39:15 +01:00
2013-11-11 20:20:25 +01:00
etk::CCout& operator <<(etk::CCout& _os, const std::u32string& _obj) {
2013-11-14 21:57:10 +01:00
std::vector<char32_t> tmpp;
2013-11-11 20:20:25 +01:00
for (size_t iii=0; iii<_obj.size(); ++iii) {
2013-11-14 21:57:10 +01:00
tmpp.push_back(_obj[iii]);
2013-11-11 20:20:25 +01:00
}
2013-11-14 21:57:10 +01:00
std::vector<char> output_UTF8;
2013-11-11 20:20:25 +01:00
unicode::convertUnicodeToUtf8(tmpp, output_UTF8);
2013-11-14 21:57:10 +01:00
output_UTF8.push_back('\0');
2013-11-11 20:20:25 +01:00
_os << &output_UTF8[0];
return _os;
}
/**
2013-10-07 22:04:21 +02:00
* @brief main application function initialisation
*/
2013-11-11 20:20:25 +01:00
bool APP_Init(ewol::eContext& _context) {
2013-11-28 22:23:42 +01:00
APPL_INFO(" == > init APPL v" << APPL_VERSION << " (START) [" << ewol::getBoardType() << "] (" << ewol::getCompilationMode() << ")");
2013-01-11 23:14:15 +01:00
etk::theme::setName("COLOR", "colorWhite/");
2013-10-07 22:04:21 +02:00
// TODO : remove this : Move if in the windows properties
_context.setSize(vec2(800, 600));
2013-09-02 06:45:12 +02:00
// select internal data for font ...
2013-10-07 22:04:21 +02:00
_context.getFontDefault().setUseExternal(true);
2012-08-10 12:11:28 +02:00
#ifdef __TARGET_OS__Android
2013-10-07 22:04:21 +02:00
_context.getFontDefault().set("FreeSerif", 19);
2012-02-17 18:25:38 +01:00
#else
2013-10-07 22:04:21 +02:00
_context.getFontDefault().set("FreeSerif;DejaVuSansMono",14);
2012-02-17 18:25:38 +01:00
#endif
2013-01-01 21:58:39 +01:00
// set the application icon ...
2013-10-07 22:04:21 +02:00
_context.setIcon("DATA:icon.png");
2013-01-01 21:58:39 +01:00
// init internal global value
2013-10-07 22:04:21 +02:00
globals::init();
// init ALL Singleton :
//(void)CTagsManager::getInstance();
2013-10-29 21:13:45 +01:00
bufferManager = appl::BufferManager::keep();
2013-10-25 22:12:34 +02:00
appl::highlightManager::init();
appl::textPluginManager::init();
appl::textPluginManager::addDefaultPlugin();
2013-05-28 22:09:53 +02:00
// Request load of the user configuration ...
2013-10-07 22:04:21 +02:00
//ewol::userConfig::load();
2013-05-28 22:09:53 +02:00
char cCurrentPath[FILENAME_MAX];
// get the curent program folder
if (!getcwd(cCurrentPath, FILENAME_MAX)) {
2013-09-02 06:45:12 +02:00
return false;
}
cCurrentPath[FILENAME_MAX - 1] = '\0';
2012-04-23 10:15:43 +02:00
//APPL_INFO("The current working directory is " << cCurrentPath);
2013-09-02 06:45:12 +02:00
2013-09-02 21:06:50 +02:00
MainWindows* basicWindows = new MainWindows();
2012-02-02 13:57:57 +01:00
if (NULL == basicWindows) {
2012-04-23 10:15:43 +02:00
APPL_ERROR("Can not allocate the basic windows");
2013-10-09 22:00:24 +02:00
_context.stop();
2013-09-02 06:45:12 +02:00
return false;
2012-02-02 13:57:57 +01:00
}
// create the specific windows
2013-10-07 22:04:21 +02:00
_context.setWindows(basicWindows);
2012-02-24 12:45:39 +01:00
// add files
2012-04-23 10:15:43 +02:00
APPL_INFO("show list of files : ");
bool ctagDetected = false;
2013-10-07 22:04:21 +02:00
for( int32_t iii=0 ; iii<_context.getCmd().size(); iii++) {
2013-11-14 21:57:10 +01:00
std::string tmpppp = _context.getCmd().get(iii);
if (tmpppp == "-t") {
ctagDetected = true;
} else if (true == ctagDetected) {
APPL_INFO("Load ctag file : \"" << tmpppp << "\"" );
ctagDetected = false;
2013-10-09 22:00:24 +02:00
_context.getEObjectManager().multiCast().anonymousSend(ednMsgCtagsLoadFile, tmpppp);
} else {
APPL_INFO("need load file : \"" << tmpppp << "\"" );
2013-10-29 21:13:45 +01:00
bufferManager->open(tmpppp);
}
}
2012-02-24 12:45:39 +01:00
2013-11-11 20:20:25 +01:00
APPL_INFO(" == > init " PROJECT_NAME " (END)");
2013-09-02 06:45:12 +02:00
return true;
}
/**
* @brief main application function Un-Initialisation
*/
2013-11-11 20:20:25 +01:00
void APP_UnInit(ewol::eContext& _context) {
APPL_INFO(" == > Un-Init " PROJECT_NAME " (START)");
2013-10-07 22:04:21 +02:00
ewol::Windows* tmpWindows = _context.getWindows();
2013-09-02 21:06:50 +02:00
2013-10-07 22:04:21 +02:00
_context.setWindows(NULL);
2012-12-02 20:34:00 +01:00
2013-09-02 21:06:50 +02:00
if (NULL != tmpWindows) {
delete(tmpWindows);
tmpWindows = NULL;
2012-12-02 20:34:00 +01:00
}
appl::textPluginManager::unInit();
2012-04-23 10:15:43 +02:00
APPL_INFO("Stop Hightlight");
2013-10-25 22:12:34 +02:00
appl::highlightManager::unInit();
//Kill all singleton
2013-10-29 21:13:45 +01:00
if (bufferManager != NULL) {
APPL_INFO("Stop BufferManager");
appl::BufferManager::release(bufferManager);
bufferManager = NULL;
}
2013-11-11 20:20:25 +01:00
APPL_INFO(" == > Un-Init " PROJECT_NAME " (END)");
2012-02-02 13:57:57 +01:00
}