edn/sources/appl/init.cpp

182 lines
5.8 KiB
C++
Raw Normal View History

2016-05-02 22:01:55 +02:00
/** @file
* @author Edouard DUPIN
2012-11-25 11:55:06 +01:00
* @copyright 2010, Edouard DUPIN, all right reserved
* @license GPL v3 (see license file)
*/
2016-10-03 22:01:55 +02:00
#include <etk/types.hpp>
#include <ewol/ewol.hpp>
#include <ewol/object/Object.hpp>
#include <ewol/widget/Manager.hpp>
2012-04-24 09:42:14 +02:00
2016-10-03 22:01:55 +02:00
#include <appl/debug.hpp>
#include <appl/global.hpp>
#include <etk/os/FSNode.hpp>
#include <etk/tool.hpp>
#include <unistd.h>
2016-10-03 22:01:55 +02:00
//#include <ewol/config.hpp>
#include <gale/context/commandLine.hpp>
//#include <ewol/UserConfig.hpp>
#include <ewol/context/Context.hpp>
#include <appl/TextPluginManager.hpp>
#include <appl/BufferManager.hpp>
#include <appl/HighlightManager.hpp>
#include <appl/Gui/MainWindows.hpp>
#include <appl/Gui/Search.hpp>
#include <appl/ctags/readtags.hpp>
#include <appl/globalMsg.hpp>
#include <appl/TextPluginCtags.hpp>
2013-11-11 20:20:25 +01:00
class MainApplication : public ewol::context::Application {
private:
2016-07-19 22:03:39 +02:00
ememory::SharedPtr<appl::BufferManager> m_bufferManager;
ememory::SharedPtr<appl::textPluginManager> m_pluginManager;
public:
2016-03-16 23:09:36 +01:00
virtual void onCreate(ewol::Context& _context) override {
2016-10-14 21:12:41 +02:00
APPL_INFO(" == > CREATE ... " << PROJECT_NAME << " v" << APPL_VERSION << " (START) [" << gale::getBoardType() << "] (" << gale::getCompilationMode() << ") (BEGIN)");
2015-05-12 21:16:32 +02:00
for( int32_t iii=0 ; iii<_context.getCmd().size(); iii++) {
2017-08-28 00:09:10 +02:00
etk::String tmpppp = _context.getCmd().get(iii);
2015-05-12 21:16:32 +02:00
if ( tmpppp == "-h"
|| tmpppp == "--help") {
APPL_INFO(" --ctags=xxx c-flags-file-name" );
2015-05-12 21:16:32 +02:00
APPL_INFO(" -h/--help display this help" );
exit(0);
}
}
//etk::theme::setName("COLOR", "color/black/");
etk::theme::setName("COLOR", "color/white/");
// TODO : remove this : Move if in the windows properties
_context.setSize(vec2(800, 600));
_context.setTitle("edn");
// select internal data for font ...
_context.getFontDefault().setUseExternal(true);
#ifdef __TARGET_OS__Android
_context.getFontDefault().set("FreeSerif", 19);
#else
_context.getFontDefault().set("FreeSerif;DejaVuSansMono",14);
#endif
// set the application icon ...
_context.setIcon("DATA:icon.png");
APPL_INFO("==> CREATE ... " PROJECT_NAME " (END)");
}
2016-03-16 23:09:36 +01:00
void onStart(ewol::Context& _context) override {
APPL_INFO("==> START ... " PROJECT_NAME " (BEGIN)");
// init internal global value
globals::init();
// init ALL Singleton :
//()CTagsManager::getInstance();
m_bufferManager = appl::BufferManager::create();
m_pluginManager = appl::textPluginManager::create();
appl::highlightManager::init();
// Request load of the user configuration ...
//ewol::userConfig::load();
char cCurrentPath[FILENAME_MAX];
// get the curent program folder
if (!getcwd(cCurrentPath, FILENAME_MAX)) {
return;
}
cCurrentPath[FILENAME_MAX - 1] = '\0';
//APPL_INFO("The current working directory is " << cCurrentPath);
2016-07-19 22:03:39 +02:00
ememory::SharedPtr<MainWindows> basicWindows = MainWindows::create();
2018-06-19 22:31:29 +02:00
if (basicWindows == null) {
APPL_ERROR("Can not allocate the basic windows");
2016-03-16 23:09:36 +01:00
_context.exit(-1);
return;
}
// create the specific windows
_context.setWindows(basicWindows);
2014-08-28 22:31:00 +02:00
// need to add default plugin, because they depend on the Menu widget wich might be named : "appl-menu-interface"
m_pluginManager->addDefaultPlugin();
// add files
APPL_INFO("show list of files : ");
for( int32_t iii=0 ; iii<_context.getCmd().size(); iii++) {
2017-08-28 00:09:10 +02:00
etk::String tmpppp = _context.getCmd().get(iii);
if (tmpppp.startWith("--ctags=") == true) {
etk::FSNode file(tmpppp);
etk::String name = tmpppp.extract(8);
APPL_INFO("Load ctag file : \"" << name << "\"" );
appl::setCtagsFileName(name);
2015-05-12 21:16:32 +02:00
} else if ( tmpppp == "-h"
|| tmpppp == "--help") {
// nothing to do ...
} else {
etk::FSNode file(tmpppp);
2016-04-08 22:10:37 +02:00
if (file.getNodeType() == etk::typeNode_file) {
2017-08-28 00:09:10 +02:00
etk::String name = file.getName();
2014-10-23 23:52:19 +02:00
APPL_INFO("need load file : \"" << name << "\"" );
m_bufferManager->open(name);
} else if (file.getNodeType() == etk::typeNode_folder) {
2017-08-28 00:09:10 +02:00
etk::Vector<etk::String> listOfFiles = file.folderGetSub(false, true, ".*");
for (auto &it: listOfFiles) {
etk::FSNode file2(it);
if (file2.getNodeType() == etk::typeNode_file) {
2017-08-28 00:09:10 +02:00
etk::String name = file2.getName();
APPL_INFO("need load file : \"" << name << "\"" );
m_bufferManager->open(name);
}
}
2014-10-23 23:52:19 +02:00
}
}
}
APPL_INFO("==> START ... " PROJECT_NAME " (END)");
return;
}
2016-03-16 23:09:36 +01:00
void onStop(ewol::Context& _context) override {
APPL_INFO("==> STOP ... " PROJECT_NAME " (START)");
appl::highlightManager::unInit();
//Kill all singleton
m_pluginManager.reset();
m_bufferManager.reset();
APPL_INFO("==> STOP ... " PROJECT_NAME " (END)");
}
2016-03-16 23:09:36 +01:00
void onKillDemand(ewol::Context& _context) override {
APPL_INFO("==> User demand kill ... " PROJECT_NAME " (START)");
2018-06-19 22:31:29 +02:00
if (m_bufferManager == null) {
2016-03-16 23:09:36 +01:00
_context.exit(0);
}
APPL_TODO("Implement the check of buffer not saved ...");
_context.exit(0);
APPL_INFO("==> User demand kill ... " PROJECT_NAME " (END)");
}
};
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[]) {
/*
APPL_ERROR(" base signature = " << typeid(&MainApplication::init).name());
2017-08-28 00:09:10 +02:00
APPL_ERROR(" base signature = " << typeid(etk::String).name());
APPL_CRITICAL(" END ");
*/
// this is really bad ...
for( int32_t iii=0 ; iii<_argc; iii++) {
etk::String tmpppp = _argv[iii];
if (tmpppp.startWith("--ctags=") == true) {
etk::FSNode file(tmpppp);
etk::String name = tmpppp.extract(8);
APPL_INFO("Load ctag file : \"" << name << "\"" );
appl::setCtagsFileName(name);
}
}
// second possibility
return ewol::run(ETK_NEW(MainApplication), _argc, _argv);
2012-11-22 21:39:15 +01:00
}