From dcdfbe3647e955def01f43f434ef73ef31e69e33 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 28 May 2013 22:09:53 +0200 Subject: [PATCH] [DEV] Save configuration of the user --- sources/appl/Gui/MainWindows.cpp | 4 +- sources/appl/global.cpp | 137 +++++++++++++++++++++++++------ sources/appl/global.h | 3 +- sources/appl/globalMsg.cpp | 1 + sources/appl/globalMsg.h | 1 + sources/appl/init.cpp | 8 +- 6 files changed, 127 insertions(+), 27 deletions(-) diff --git a/sources/appl/Gui/MainWindows.cpp b/sources/appl/Gui/MainWindows.cpp index 3cf508d..53a50db 100644 --- a/sources/appl/Gui/MainWindows.cpp +++ b/sources/appl/Gui/MainWindows.cpp @@ -234,7 +234,7 @@ MainWindows::MainWindows(void) // add generic shortcut ... // (shift, control, alt, meta, uniChar_t unicodeValue, const char * generateEventId, etk::UString& data) ShortCutAdd("ctrl+o", ednMsgGuiOpen, "", true); - ShortCutAdd("ctrl+n", ednMsgGuiNew, "", true); + ShortCutAdd("ctrl+n", ednMsgGuiNew, "", true); ShortCutAdd("ctrl+s", ednMsgGuiSave, "current", true); ShortCutAdd("ctrl+shift+s", ednMsgGuiSave, "All", true); @@ -384,6 +384,8 @@ void MainWindows::OnReceiveMessage(const ewol::EMessage& _msg) } else if (_msg.GetMessage() == ednMsgGuiReloadShader) { ewol::resource::ReLoadResources(); ewol::ForceRedrawAll(); + } else if (_msg.GetMessage() == ednMsgGuiExit) { + // TODO ... } return; diff --git a/sources/appl/global.cpp b/sources/appl/global.cpp index 316ae0e..2594ef8 100644 --- a/sources/appl/global.cpp +++ b/sources/appl/global.cpp @@ -12,75 +12,166 @@ #include #include #include +#include #undef __class__ #define __class__ "globals" - - - -erreurCode_te globals::init(void) +class myParamGlobal : public ewol::EObject { - erreurCode_te ret = ERR_NONE; - + public: + static const char * const configEOL; + static const char * const configAutoIndent; + static const char * const configShowTabChar; + static const char * const configShowSpaceChar; + public: + bool m_displayEOL; + bool m_AutoIndent; + bool m_displayTabChar; + bool m_displaySpaceChar; + public : + myParamGlobal(void) { + m_static = true; // Note : Set the object static notification( Must be set or assert at the end of process) + SetName("edn_global_param"); + m_displayEOL=false; + m_AutoIndent = true; + m_displayTabChar = true; + m_displaySpaceChar = true; + RegisterConfig(configEOL, "bool", NULL, "Display end of line character"); + RegisterConfig(configAutoIndent, "bool", NULL, "Auto indent when create new line"); + RegisterConfig(configShowTabChar, "bool", NULL, "Display the Tab char"); + RegisterConfig(configShowSpaceChar, "bool", NULL, "Display the space char"); + } + + bool OnSetConfig(const ewol::EConfig& _conf) + { + // Not set the EObject node parameter (name ==> not change ...) + if (_conf.GetConfig() == configEOL) { + m_displayEOL = _conf.GetData().ToBool(); + return true; + } + if (_conf.GetConfig() == configAutoIndent) { + m_AutoIndent = _conf.GetData().ToBool(); + return true; + } + if (_conf.GetConfig() == configShowTabChar) { + m_displayTabChar = _conf.GetData().ToBool(); + return true; + } + if (_conf.GetConfig() == configShowSpaceChar) { + m_displaySpaceChar = _conf.GetData().ToBool(); + return true; + } + return false; + } + bool OnGetConfig(const char* _config, etk::UString& _result) const + { + // Not set the EObject node parameter (name ==> not change ...) + if (_config == configEOL) { + if (true==m_displayEOL) { + _result = "true"; + } else { + _result = "false"; + } + return true; + } + if (_config == configAutoIndent) { + if (true==m_AutoIndent) { + _result = "true"; + } else { + _result = "false"; + } + return true; + } + if (_config == configShowTabChar) { + if (true==m_displayTabChar) { + _result = "true"; + } else { + _result = "false"; + } + return true; + } + if (_config == configShowSpaceChar) { + if (true==m_displaySpaceChar) { + _result = "true"; + } else { + _result = "false"; + } + return true; + } + return false; + } +}; - return ret; +const char * const myParamGlobal::configEOL = "eol"; +const char * const myParamGlobal::configAutoIndent = "auto-indent"; +const char * const myParamGlobal::configShowTabChar = "display-tab"; +const char * const myParamGlobal::configShowSpaceChar = "display-space"; + +static myParamGlobal& l_obj(void) +{ + static myParamGlobal s_obj; + return s_obj; } +void globals::Init(void) +{ + ewol::userConfig::AddUserConfig(&l_obj()); +} + +void globals::UnInit(void) +{ + // nothing to do ... + //ewol::userConfig::RmUserConfig(&l_obj()); +} + + // ----------------------------------------------------------- -static bool displayEOL = false; bool globals::IsSetDisplayEndOfLine(void) { - return displayEOL; + return l_obj().m_displayEOL; } void globals::SetDisplayEndOfLine(bool newVal) { - APPL_INFO("Set EndOfLine " << newVal); - displayEOL = newVal; + l_obj().m_displayEOL = newVal; //ewol::widgetMessageMultiCast::Send(-1, ednMsgUserDisplayChange); } // ----------------------------------------------------------- -static bool displaySpaceChar = true; bool globals::IsSetDisplaySpaceChar(void) { - return displaySpaceChar; + return l_obj().m_displaySpaceChar; } void globals::SetDisplaySpaceChar(bool newVal) { - APPL_INFO("Set SpaceChar " << newVal); - displaySpaceChar = newVal; + l_obj().m_displaySpaceChar = newVal; //ewol::widgetMessageMultiCast::Send(-1, ednMsgUserDisplayChange); } // ----------------------------------------------------------- -static bool displayTabChar = true; bool globals::IsSetDisplayTabChar(void) { - return displayTabChar; + return l_obj().m_displayTabChar; } void globals::SetDisplayTabChar(bool newVal) { - APPL_INFO("Set SpaceChar " << newVal); - displayTabChar = newVal; + l_obj().m_displayTabChar = newVal; //ewol::widgetMessageMultiCast::Send(-1, ednMsgUserDisplayChange); } // ----------------------------------------------------------- -static bool AutoIndent = true; bool globals::IsSetAutoIndent(void) { - return AutoIndent; + return l_obj().m_AutoIndent; } void globals::SetAutoIndent(bool newVal) { - APPL_INFO("Set AutoIndent " << newVal); - AutoIndent = newVal; + l_obj().m_AutoIndent = newVal; } // ----------------------------------------------------------- diff --git a/sources/appl/global.h b/sources/appl/global.h index a7e40fb..d9963cc 100644 --- a/sources/appl/global.h +++ b/sources/appl/global.h @@ -15,7 +15,8 @@ namespace globals { - erreurCode_te init(void); + void Init(void); + void UnInit(void); int32_t getNbColoneBorder(void); int32_t getNbLineBorder(void); diff --git a/sources/appl/globalMsg.cpp b/sources/appl/globalMsg.cpp index efed566..55da641 100644 --- a/sources/appl/globalMsg.cpp +++ b/sources/appl/globalMsg.cpp @@ -18,6 +18,7 @@ extern const char* const ednMsgGuiClose = "edn-Msg-Gui-Close"; extern const char* const ednMsgGuiSave = "edn-Msg-Gui-Save"; extern const char* const ednMsgGuiSaveAs = "edn-Msg-Gui-SaveAs"; extern const char* const ednMsgProperties = "edn-Msg-Gui-Properties"; +extern const char* const ednMsgGuiExit = "edn-Msg-Gui-quit"; extern const char* const ednMsgGuiUndo = "edn-Msg-Gui-Undo"; extern const char* const ednMsgGuiRedo = "edn-Msg-Gui-Redo"; diff --git a/sources/appl/globalMsg.h b/sources/appl/globalMsg.h index 39e4943..e9c218e 100644 --- a/sources/appl/globalMsg.h +++ b/sources/appl/globalMsg.h @@ -18,6 +18,7 @@ extern const char* const ednMsgGuiSave; // data : "" extern const char* const ednMsgGuiSaveAs; // data : "" extern const char* const ednMsgProperties; // data : "" + extern const char* const ednMsgGuiExit; // data : "" extern const char* const ednMsgGuiUndo; // data : "" extern const char* const ednMsgGuiRedo; // data : "" diff --git a/sources/appl/init.cpp b/sources/appl/init.cpp index d19151c..a5165d4 100644 --- a/sources/appl/init.cpp +++ b/sources/appl/init.cpp @@ -27,6 +27,7 @@ #include #include #include +#include MainWindows * basicWindows = NULL; @@ -79,7 +80,7 @@ void APP_Init(void) ewol::SetIcon("DATA:icon.png"); // init internal global value - globals::init(); + globals::Init(); // set the application icon ... ewol::SetIcon("DATA:icon.png"); @@ -96,7 +97,10 @@ void APP_Init(void) HighlightManager::Init(); HighlightManager::loadLanguages(); cTagsManager::Init(); - + + // Request load of the user configuration ... + ewol::userConfig::Load(); + char cCurrentPath[FILENAME_MAX]; // get the curent program folder if (!getcwd(cCurrentPath, FILENAME_MAX)) {