diff --git a/sources/appl/Gui/TextViewer.cpp b/sources/appl/Gui/TextViewer.cpp index b50fbd3..2f0f07d 100644 --- a/sources/appl/Gui/TextViewer.cpp +++ b/sources/appl/Gui/TextViewer.cpp @@ -41,6 +41,7 @@ appl::TextViewer::TextViewer() : // load buffer manager: m_bufferManager = appl::BufferManager::create(); + m_pluginManager = appl::textPluginManager::create(); m_viewerManager = appl::ViewerManager::create(); // load color properties @@ -58,7 +59,7 @@ appl::TextViewer::TextViewer() : void appl::TextViewer::init(const std::string& _fontName, int32_t _fontSize) { ewol::widget::WidgetScrolled::init(); m_displayText.setFont(_fontName, _fontSize); - appl::textPluginManager::connect(*this); + m_pluginManager->connect(*this); // last created has focus ... setCurrentSelect(); signalShortcut.bind(shared_from_this(), &appl::TextViewer::onCallbackShortCut); @@ -76,11 +77,11 @@ void appl::TextViewer::init(const std::string& _fontName, int32_t _fontSize) { } appl::TextViewer::~TextViewer() { - appl::textPluginManager::disconnect(*this); + m_pluginManager->disconnect(*this); } void appl::TextViewer::onCallbackShortCut(const std::string& _value) { - if (appl::textPluginManager::onReceiveShortCut(*this, _value) == true) { + if (m_pluginManager->onReceiveShortCut(*this, _value) == true) { return; } } @@ -383,7 +384,7 @@ bool appl::TextViewer::onEventEntry(const ewol::event::Entry& _event) { return false; } // First call plugin - if (appl::textPluginManager::onEventEntry(*this, _event) == true) { + if (m_pluginManager->onEventEntry(*this, _event) == true) { markToRedraw(); return true; } @@ -505,7 +506,7 @@ bool appl::TextViewer::onEventInput(const ewol::event::Input& _event) { } APPL_VERBOSE("event : " << _event); // Second call plugin - if (appl::textPluginManager::onEventInput(*this, _event) == true) { + if (m_pluginManager->onEventInput(*this, _event) == true) { markToRedraw(); return true; } @@ -751,7 +752,7 @@ bool appl::TextViewer::moveCursor(const appl::Buffer::Iterator& _pos) { return false; } markToRedraw(); - if (appl::textPluginManager::onCursorMove(*this, _pos) == true) { + if (m_pluginManager->onCursorMove(*this, _pos) == true) { updateScrolling(); return true; } @@ -775,13 +776,13 @@ bool appl::TextViewer::write(const std::string& _data, const appl::Buffer::Itera return false; } markToRedraw(); - if (appl::textPluginManager::onWrite(*this, _pos, _data) == true) { + if (m_pluginManager->onWrite(*this, _pos, _data) == true) { // no call of the move cursor, because pluging might call theses function to copy and cut data... updateScrolling(); return true; } bool ret = m_buffer->write(_data, _pos); - appl::textPluginManager::onCursorMove(*this, m_buffer->cursor()); + m_pluginManager->onCursorMove(*this, m_buffer->cursor()); updateScrolling(); return ret; } @@ -791,13 +792,13 @@ bool appl::TextViewer::replace(const std::string& _data, const appl::Buffer::Ite return false; } markToRedraw(); - if (appl::textPluginManager::onReplace(*this, _pos, _data, _posEnd) == true) { + if (m_pluginManager->onReplace(*this, _pos, _data, _posEnd) == true) { // no call of the move cursor, because pluging might call theses function to copy and cut data... updateScrolling(); return true; } bool ret = m_buffer->replace(_data, _pos, _posEnd); - appl::textPluginManager::onCursorMove(*this, m_buffer->cursor()); + m_pluginManager->onCursorMove(*this, m_buffer->cursor()); updateScrolling(); return ret; } @@ -821,11 +822,11 @@ void appl::TextViewer::remove() { return; } markToRedraw(); - if (appl::textPluginManager::onRemove(*this, m_buffer->selectStart(), m_buffer->selectStop()) == true) { + if (m_pluginManager->onRemove(*this, m_buffer->selectStart(), m_buffer->selectStop()) == true) { return; } m_buffer->removeSelection(); - appl::textPluginManager::onCursorMove(*this, m_buffer->cursor()); + m_pluginManager->onCursorMove(*this, m_buffer->cursor()); } diff --git a/sources/appl/Gui/TextViewer.h b/sources/appl/Gui/TextViewer.h index 1f2248c..e77fabc 100644 --- a/sources/appl/Gui/TextViewer.h +++ b/sources/appl/Gui/TextViewer.h @@ -22,6 +22,7 @@ #include namespace appl { + class textPluginManager; class TextViewer : public ewol::widget::WidgetScrolled { private: std::shared_ptr m_paintingProperties; //!< element painting property @@ -34,6 +35,7 @@ namespace appl { int32_t m_colorNormal; private: std::shared_ptr m_bufferManager; //!< handle on the buffer manager + std::shared_ptr m_pluginManager; //!< Plugin manager interface std::shared_ptr m_viewerManager; //!< handle on the buffer manager protected: TextViewer(); diff --git a/sources/appl/TextPlugin.cpp b/sources/appl/TextPlugin.cpp index 7160c8b..7dc280b 100644 --- a/sources/appl/TextPlugin.cpp +++ b/sources/appl/TextPlugin.cpp @@ -8,6 +8,7 @@ #include +#include #include #undef __class__ @@ -28,6 +29,8 @@ appl::TextViewerPlugin::TextViewerPlugin() : if (m_menuInterface.expired() == true) { APPL_ERROR("Can not acces to the Menu interface"); } + // get a reference on the plugin manager... + m_pluginManager = appl::textPluginManager::create(); } void appl::TextViewerPlugin::init() { diff --git a/sources/appl/TextPlugin.h b/sources/appl/TextPlugin.h index 1609345..b68b76c 100644 --- a/sources/appl/TextPlugin.h +++ b/sources/appl/TextPlugin.h @@ -16,8 +16,11 @@ #include namespace appl { + class textPluginManager; class TextViewerPlugin : public ewol::Object { friend class appl::TextViewer; + protected: + std::weak_ptr m_pluginManager; protected: TextViewerPlugin(); void init(); diff --git a/sources/appl/TextPluginHistory.cpp b/sources/appl/TextPluginHistory.cpp index 816df06..59a4b89 100644 --- a/sources/appl/TextPluginHistory.cpp +++ b/sources/appl/TextPluginHistory.cpp @@ -149,7 +149,10 @@ bool appl::TextPluginHistory::onDataWrite(appl::TextViewer& _textDrawer, clearRedo(_data); _data.m_undo.push_back(tmpElement); } - appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor()); + std::shared_ptr mng = m_pluginManager.lock(); + if (mng!=nullptr) { + mng->onCursorMove(_textDrawer, _textDrawer.cursor()); + } return true; } @@ -174,7 +177,10 @@ bool appl::TextPluginHistory::onDataReplace(appl::TextViewer& _textDrawer, clearRedo(_data); _data.m_undo.push_back(tmpElement); } - appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor()); + std::shared_ptr mng = m_pluginManager.lock(); + if (mng!=nullptr) { + mng->onCursorMove(_textDrawer, _textDrawer.cursor()); + } return true; } @@ -196,7 +202,10 @@ bool appl::TextPluginHistory::onDataRemove(appl::TextViewer& _textDrawer, _data.m_undo.push_back(tmpElement); } _textDrawer.removeDirect(); - appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor()); + std::shared_ptr mng = m_pluginManager.lock(); + if (mng!=nullptr) { + mng->onCursorMove(_textDrawer, _textDrawer.cursor()); + } return true; } diff --git a/sources/appl/TextPluginManager.cpp b/sources/appl/TextPluginManager.cpp index 225c997..2326595 100644 --- a/sources/appl/TextPluginManager.cpp +++ b/sources/appl/TextPluginManager.cpp @@ -19,58 +19,11 @@ #undef __class__ #define __class__ "textPluginManager" -static std::list>& getList() { - static std::list> s_list; - return s_list; -} -static std::vector>& getListOnEventEntry() { - static std::vector> s_list; - return s_list; -} -static std::vector>& getListOnEventInput() { - static std::vector> s_list; - return s_list; -} -static std::vector>& getListOnWrite() { - static std::vector> s_list; - return s_list; -} -static std::vector>& getListOnReplace() { - static std::vector> s_list; - return s_list; -} -static std::vector>& getListOnRemove() { - static std::vector> s_list; - return s_list; -} -static std::vector>& getListonReceiveShortCutViewer() { - static std::vector> s_list; - return s_list; -} -static std::vector>& getListOnCursorMove() { - static std::vector> s_list; - return s_list; -} - -static std::weak_ptr& getViewerConnected() { - static std::weak_ptr s_widget; - return s_widget; -} - -void appl::textPluginManager::init() { +appl::textPluginManager::textPluginManager() { } - -void appl::textPluginManager::unInit() { - // remove all sub plugin class: - getListOnEventEntry().clear(); - getListOnEventInput().clear(); - getListOnWrite().clear(); - getListOnReplace().clear(); - getListOnRemove().clear(); - getListonReceiveShortCutViewer().clear(); - getListOnCursorMove().clear(); - getList().clear(); +void appl::textPluginManager::init(const std::string& _name) { + ewol::Resource::init(_name); } void appl::textPluginManager::addDefaultPlugin() { @@ -88,37 +41,37 @@ void appl::textPluginManager::addPlugin(const std::shared_ptrgetObjectType()); - getList().push_back(_plugin); + m_list.push_back(_plugin); if (_plugin->isAvaillableOnEventEntry() == true) { - getListOnEventEntry().push_back(_plugin); + m_listOnEventEntry.push_back(_plugin); } if (_plugin->isAvaillableOnEventInput() == true) { - getListOnEventInput().push_back(_plugin); + m_listOnEventInput.push_back(_plugin); } if (_plugin->isAvaillableOnWrite() == true) { - getListOnWrite().push_back(_plugin); + m_listOnWrite.push_back(_plugin); } if (_plugin->isAvaillableOnReplace() == true) { - getListOnReplace().push_back(_plugin); + m_listOnReplace.push_back(_plugin); } if (_plugin->isAvaillableOnRemove() == true) { - getListOnRemove().push_back(_plugin); + m_listOnRemove.push_back(_plugin); } if (_plugin->isAvaillableOnReceiveShortCut() == true) { - getListonReceiveShortCutViewer().push_back(_plugin); + m_listOnReceiveShortCutViewer.push_back(_plugin); } if (_plugin->isAvaillableOnCursorMove() == true) { - getListOnCursorMove().push_back(_plugin); + m_listOnCursorMove.push_back(_plugin); } - std::shared_ptr viewer = getViewerConnected().lock(); + std::shared_ptr viewer = m_currentViewer.lock(); if (viewer != nullptr) { _plugin->onPluginEnable(*viewer); } } void appl::textPluginManager::connect(appl::TextViewer& _widget) { - getViewerConnected() = std::dynamic_pointer_cast(_widget.shared_from_this()); - for (auto &it : getList()) { + m_currentViewer = std::dynamic_pointer_cast(_widget.shared_from_this()); + for (auto &it : m_list) { if (it == nullptr) { continue; } @@ -127,8 +80,8 @@ void appl::textPluginManager::connect(appl::TextViewer& _widget) { } void appl::textPluginManager::disconnect(appl::TextViewer& _widget) { - getViewerConnected().reset(); - for (auto &it : getList()) { + m_currentViewer.reset(); + for (auto &it : m_list) { if (it == nullptr) { continue; } @@ -138,7 +91,7 @@ void appl::textPluginManager::disconnect(appl::TextViewer& _widget) { bool appl::textPluginManager::onEventEntry(appl::TextViewer& _textDrawer, const ewol::event::Entry& _event) { - for (auto &it : getListOnEventEntry()) { + for (auto &it : m_listOnEventEntry) { if (it == nullptr) { continue; } @@ -151,7 +104,7 @@ bool appl::textPluginManager::onEventEntry(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onEventInput(appl::TextViewer& _textDrawer, const ewol::event::Input& _event) { - for (auto &it : getListOnEventInput()) { + for (auto &it : m_listOnEventInput) { if (it == nullptr) { continue; } @@ -165,7 +118,7 @@ bool appl::textPluginManager::onEventInput(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onWrite(appl::TextViewer& _textDrawer, const appl::Buffer::Iterator& _pos, const std::string& _data) { - for (auto &it : getListOnWrite()) { + for (auto &it : m_listOnWrite) { if (it == nullptr) { continue; } @@ -180,7 +133,7 @@ bool appl::textPluginManager::onReplace(appl::TextViewer& _textDrawer, const appl::Buffer::Iterator& _pos, const std::string& _data, const appl::Buffer::Iterator& _posEnd) { - for (auto &it : getListOnReplace()) { + for (auto &it : m_listOnReplace) { if (it == nullptr) { continue; } @@ -194,7 +147,7 @@ bool appl::textPluginManager::onReplace(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onRemove(appl::TextViewer& _textDrawer, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) { - for (auto &it : getListOnRemove()) { + for (auto &it : m_listOnRemove) { if (it == nullptr) { continue; } @@ -207,7 +160,7 @@ bool appl::textPluginManager::onRemove(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onReceiveShortCut(appl::TextViewer& _textDrawer, const std::string& _shortCutName) { - for (auto &it : getListonReceiveShortCutViewer()) { + for (auto &it : m_listOnReceiveShortCutViewer) { if (it == nullptr) { continue; } @@ -220,7 +173,7 @@ bool appl::textPluginManager::onReceiveShortCut(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onCursorMove(appl::TextViewer& _textDrawer, const appl::Buffer::Iterator& _pos) { - for (auto &it : getListOnCursorMove()) { + for (auto &it : m_listOnCursorMove) { if (it == nullptr) { continue; } diff --git a/sources/appl/TextPluginManager.h b/sources/appl/TextPluginManager.h index 9d03703..d0ffc58 100644 --- a/sources/appl/TextPluginManager.h +++ b/sources/appl/TextPluginManager.h @@ -16,98 +16,106 @@ #include namespace appl { - namespace textPluginManager { - /** - * @brief Init the plugin manager for writer. - */ - void init(); - /** - * @brief UnInit the plugin manager for writer. - */ - void unInit(); - /** - * @brief Add default plugin list - */ - void addDefaultPlugin(); - /** - * @brief Add a plugin. - * @param[in] _plugin Plugin pointer to add. - */ - void addPlugin(const std::shared_ptr& _plugin); - /** - * @brief connect a new widget to the plugin. - * @param[in] _widget Reference on the widget caller. - */ - void connect(appl::TextViewer& _widget); - /** - * @brief dis-connect a new widget to the plugin. - * @param[in] _widget Reference on the widget caller. - */ - void disconnect(appl::TextViewer& _widget); - /** - * @brief On entry event call. - * @param[in] _widget Reference on the widget caller. - * @param[in] _event Generic event. - * @return true if the event might not propagate anymore. - */ - bool onEventEntry(appl::TextViewer& _widget, - const ewol::event::Entry& _event); - /** - * @brief On Input event call. - * @param[in] _widget Reference on the widget caller. - * @param[in] _event Generic event. - * @return true if the event might not propagate anymore - */ - bool onEventInput(appl::TextViewer& _textDrawer, - const ewol::event::Input& _event); - /** - * @brief Called when data is written in the buffer. - * @param[in] _widget Reference on the widget caller. - * @param[in] _pos Position in the buffer where data might be witten. - * @param[in] _data Input stream written. - * @return true if the event might not propagate anymore - */ - bool onWrite(appl::TextViewer& _textDrawer, - const appl::Buffer::Iterator& _pos, - const std::string& _data); - /** - * @brief Called when data is written in the buffer, and some are removed. - * @param[in] _widget Reference on the widget caller. - * @param[in] _pos Position in the buffer where data might be witten. - * @param[in] _data Input stream written. - * @param[in] _posEnd end replace position. - * @return true if the event might not propagate anymore - */ - bool onReplace(appl::TextViewer& _textDrawer, - const appl::Buffer::Iterator& _pos, - const std::string& _data, - const appl::Buffer::Iterator& _posEnd); - /** - * @brief Called when data is removed. - * @param[in] _widget Reference on the widget caller. - * @param[in] _pos Position in the buffer where data might be witten. - * @param[in] _posEnd end replace position. - * @return true if the event might not propagate anymore - */ - bool onRemove(appl::TextViewer& _textDrawer, - const appl::Buffer::Iterator& _pos, - const appl::Buffer::Iterator& _posEnd); - /** - * @brief Called when a message arrive. - * @param[in] _widget Reference on the widget caller. - * @param[in] _shortCutName shortcut properties. - * @return true if the event might not propagate anymore - */ - bool onReceiveShortCut(appl::TextViewer& _textDrawer, - const std::string& _shortCutName); - /** - * @brief Called when Cursor move of position. - * @param[in] _widget Reference on the widget caller. - * @param[in] _pos New cursor position. - * @return true if the event might not propagate anymore - */ - bool onCursorMove(appl::TextViewer& _textDrawer, - const appl::Buffer::Iterator& _pos); + class textPluginManager : public ewol::Resource { + private: + std::weak_ptr m_currentViewer; + std::list> m_list; + std::vector> m_listOnEventEntry; + std::vector> m_listOnEventInput; + std::vector> m_listOnWrite; + std::vector> m_listOnReplace; + std::vector> m_listOnRemove; + std::vector> m_listOnReceiveShortCutViewer; + std::vector> m_listOnCursorMove; + protected: + textPluginManager(); + void init(const std::string& _name); + public: + DECLARE_RESOURCE_SINGLE_FACTORY(textPluginManager, "plugin-Manager"); + virtual ~textPluginManager() {}; + /** + * @brief Add default plugin list + */ + void addDefaultPlugin(); + /** + * @brief Add a plugin. + * @param[in] _plugin Plugin pointer to add. + */ + void addPlugin(const std::shared_ptr& _plugin); + /** + * @brief connect a new widget to the plugin. + * @param[in] _widget Reference on the widget caller. + */ + void connect(appl::TextViewer& _widget); + /** + * @brief dis-connect a new widget to the plugin. + * @param[in] _widget Reference on the widget caller. + */ + void disconnect(appl::TextViewer& _widget); + /** + * @brief On entry event call. + * @param[in] _widget Reference on the widget caller. + * @param[in] _event Generic event. + * @return true if the event might not propagate anymore. + */ + bool onEventEntry(appl::TextViewer& _widget, + const ewol::event::Entry& _event); + /** + * @brief On Input event call. + * @param[in] _widget Reference on the widget caller. + * @param[in] _event Generic event. + * @return true if the event might not propagate anymore + */ + bool onEventInput(appl::TextViewer& _textDrawer, + const ewol::event::Input& _event); + /** + * @brief Called when data is written in the buffer. + * @param[in] _widget Reference on the widget caller. + * @param[in] _pos Position in the buffer where data might be witten. + * @param[in] _data Input stream written. + * @return true if the event might not propagate anymore + */ + bool onWrite(appl::TextViewer& _textDrawer, + const appl::Buffer::Iterator& _pos, + const std::string& _data); + /** + * @brief Called when data is written in the buffer, and some are removed. + * @param[in] _widget Reference on the widget caller. + * @param[in] _pos Position in the buffer where data might be witten. + * @param[in] _data Input stream written. + * @param[in] _posEnd end replace position. + * @return true if the event might not propagate anymore + */ + bool onReplace(appl::TextViewer& _textDrawer, + const appl::Buffer::Iterator& _pos, + const std::string& _data, + const appl::Buffer::Iterator& _posEnd); + /** + * @brief Called when data is removed. + * @param[in] _widget Reference on the widget caller. + * @param[in] _pos Position in the buffer where data might be witten. + * @param[in] _posEnd end replace position. + * @return true if the event might not propagate anymore + */ + bool onRemove(appl::TextViewer& _textDrawer, + const appl::Buffer::Iterator& _pos, + const appl::Buffer::Iterator& _posEnd); + /** + * @brief Called when a message arrive. + * @param[in] _widget Reference on the widget caller. + * @param[in] _shortCutName shortcut properties. + * @return true if the event might not propagate anymore + */ + bool onReceiveShortCut(appl::TextViewer& _textDrawer, + const std::string& _shortCutName); + /** + * @brief Called when Cursor move of position. + * @param[in] _widget Reference on the widget caller. + * @param[in] _pos New cursor position. + * @return true if the event might not propagate anymore + */ + bool onCursorMove(appl::TextViewer& _textDrawer, + const appl::Buffer::Iterator& _pos); }; }; diff --git a/sources/appl/TextPluginSelectAll.cpp b/sources/appl/TextPluginSelectAll.cpp index 40b1d7d..4689a75 100644 --- a/sources/appl/TextPluginSelectAll.cpp +++ b/sources/appl/TextPluginSelectAll.cpp @@ -55,6 +55,7 @@ void appl::TextPluginSelectAll::onPluginDisable(appl::TextViewer& _textDrawer) { m_menuIdSelectNone = -1; } + bool appl::TextPluginSelectAll::onReceiveShortCut(appl::TextViewer& _textDrawer, const std::string& _shortCutName) { if (isEnable() == false) { diff --git a/sources/appl/init.cpp b/sources/appl/init.cpp index c1755c3..0882ced 100644 --- a/sources/appl/init.cpp +++ b/sources/appl/init.cpp @@ -32,6 +32,7 @@ class MainApplication : public ewol::context::Application { private: std::shared_ptr m_bufferManager; + std::shared_ptr m_pluginManager; public: bool init(ewol::Context& _context, size_t _initId) { APPL_INFO(" == > init APPL v" << APPL_VERSION << " (START) [" << ewol::getBoardType() << "] (" << ewol::getCompilationMode() << ")"); @@ -58,9 +59,9 @@ class MainApplication : public ewol::context::Application { // init ALL Singleton : //()CTagsManager::getInstance(); m_bufferManager = appl::BufferManager::create(); + m_pluginManager = appl::textPluginManager::create(); appl::highlightManager::init(); - appl::textPluginManager::init(); // Request load of the user configuration ... //ewol::userConfig::load(); @@ -84,8 +85,7 @@ class MainApplication : public ewol::context::Application { _context.setWindows(basicWindows); // need to add default plugin, because they depend on the Menu widget wich might be named : "appl-menu-interface" - appl::textPluginManager::addDefaultPlugin(); - + m_pluginManager->addDefaultPlugin(); // add files APPL_INFO("show list of files : "); @@ -113,10 +113,10 @@ class MainApplication : public ewol::context::Application { } void unInit(ewol::Context& _context) { APPL_INFO(" == > Un-Init " PROJECT_NAME " (START)"); - appl::textPluginManager::unInit(); APPL_INFO("Stop Hightlight"); appl::highlightManager::unInit(); //Kill all singleton + m_pluginManager.reset(); m_bufferManager.reset(); APPL_INFO(" == > Un-Init " PROJECT_NAME " (END)"); }