[DEV] transform plugin manager in unique resource

This commit is contained in:
Edouard DUPIN 2014-09-18 22:27:54 +02:00
parent b8962cc3b9
commit 2c3a64933d
9 changed files with 161 additions and 181 deletions

View File

@ -41,6 +41,7 @@ appl::TextViewer::TextViewer() :
// load buffer manager: // load buffer manager:
m_bufferManager = appl::BufferManager::create(); m_bufferManager = appl::BufferManager::create();
m_pluginManager = appl::textPluginManager::create();
m_viewerManager = appl::ViewerManager::create(); m_viewerManager = appl::ViewerManager::create();
// load color properties // load color properties
@ -58,7 +59,7 @@ appl::TextViewer::TextViewer() :
void appl::TextViewer::init(const std::string& _fontName, int32_t _fontSize) { void appl::TextViewer::init(const std::string& _fontName, int32_t _fontSize) {
ewol::widget::WidgetScrolled::init(); ewol::widget::WidgetScrolled::init();
m_displayText.setFont(_fontName, _fontSize); m_displayText.setFont(_fontName, _fontSize);
appl::textPluginManager::connect(*this); m_pluginManager->connect(*this);
// last created has focus ... // last created has focus ...
setCurrentSelect(); setCurrentSelect();
signalShortcut.bind(shared_from_this(), &appl::TextViewer::onCallbackShortCut); 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::TextViewer::~TextViewer() {
appl::textPluginManager::disconnect(*this); m_pluginManager->disconnect(*this);
} }
void appl::TextViewer::onCallbackShortCut(const std::string& _value) { void appl::TextViewer::onCallbackShortCut(const std::string& _value) {
if (appl::textPluginManager::onReceiveShortCut(*this, _value) == true) { if (m_pluginManager->onReceiveShortCut(*this, _value) == true) {
return; return;
} }
} }
@ -383,7 +384,7 @@ bool appl::TextViewer::onEventEntry(const ewol::event::Entry& _event) {
return false; return false;
} }
// First call plugin // First call plugin
if (appl::textPluginManager::onEventEntry(*this, _event) == true) { if (m_pluginManager->onEventEntry(*this, _event) == true) {
markToRedraw(); markToRedraw();
return true; return true;
} }
@ -505,7 +506,7 @@ bool appl::TextViewer::onEventInput(const ewol::event::Input& _event) {
} }
APPL_VERBOSE("event : " << _event); APPL_VERBOSE("event : " << _event);
// Second call plugin // Second call plugin
if (appl::textPluginManager::onEventInput(*this, _event) == true) { if (m_pluginManager->onEventInput(*this, _event) == true) {
markToRedraw(); markToRedraw();
return true; return true;
} }
@ -751,7 +752,7 @@ bool appl::TextViewer::moveCursor(const appl::Buffer::Iterator& _pos) {
return false; return false;
} }
markToRedraw(); markToRedraw();
if (appl::textPluginManager::onCursorMove(*this, _pos) == true) { if (m_pluginManager->onCursorMove(*this, _pos) == true) {
updateScrolling(); updateScrolling();
return true; return true;
} }
@ -775,13 +776,13 @@ bool appl::TextViewer::write(const std::string& _data, const appl::Buffer::Itera
return false; return false;
} }
markToRedraw(); 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... // no call of the move cursor, because pluging might call theses function to copy and cut data...
updateScrolling(); updateScrolling();
return true; return true;
} }
bool ret = m_buffer->write(_data, _pos); bool ret = m_buffer->write(_data, _pos);
appl::textPluginManager::onCursorMove(*this, m_buffer->cursor()); m_pluginManager->onCursorMove(*this, m_buffer->cursor());
updateScrolling(); updateScrolling();
return ret; return ret;
} }
@ -791,13 +792,13 @@ bool appl::TextViewer::replace(const std::string& _data, const appl::Buffer::Ite
return false; return false;
} }
markToRedraw(); 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... // no call of the move cursor, because pluging might call theses function to copy and cut data...
updateScrolling(); updateScrolling();
return true; return true;
} }
bool ret = m_buffer->replace(_data, _pos, _posEnd); bool ret = m_buffer->replace(_data, _pos, _posEnd);
appl::textPluginManager::onCursorMove(*this, m_buffer->cursor()); m_pluginManager->onCursorMove(*this, m_buffer->cursor());
updateScrolling(); updateScrolling();
return ret; return ret;
} }
@ -821,11 +822,11 @@ void appl::TextViewer::remove() {
return; return;
} }
markToRedraw(); 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; return;
} }
m_buffer->removeSelection(); m_buffer->removeSelection();
appl::textPluginManager::onCursorMove(*this, m_buffer->cursor()); m_pluginManager->onCursorMove(*this, m_buffer->cursor());
} }

View File

@ -22,6 +22,7 @@
#include <utility> #include <utility>
namespace appl { namespace appl {
class textPluginManager;
class TextViewer : public ewol::widget::WidgetScrolled { class TextViewer : public ewol::widget::WidgetScrolled {
private: private:
std::shared_ptr<appl::GlyphPainting> m_paintingProperties; //!< element painting property std::shared_ptr<appl::GlyphPainting> m_paintingProperties; //!< element painting property
@ -34,6 +35,7 @@ namespace appl {
int32_t m_colorNormal; int32_t m_colorNormal;
private: private:
std::shared_ptr<appl::BufferManager> m_bufferManager; //!< handle on the buffer manager std::shared_ptr<appl::BufferManager> m_bufferManager; //!< handle on the buffer manager
std::shared_ptr<appl::textPluginManager> m_pluginManager; //!< Plugin manager interface
std::shared_ptr<appl::ViewerManager> m_viewerManager; //!< handle on the buffer manager std::shared_ptr<appl::ViewerManager> m_viewerManager; //!< handle on the buffer manager
protected: protected:
TextViewer(); TextViewer();

View File

@ -8,6 +8,7 @@
#include <appl/TextPlugin.h> #include <appl/TextPlugin.h>
#include <appl/TextPluginManager.h>
#include <appl/debug.h> #include <appl/debug.h>
#undef __class__ #undef __class__
@ -28,6 +29,8 @@ appl::TextViewerPlugin::TextViewerPlugin() :
if (m_menuInterface.expired() == true) { if (m_menuInterface.expired() == true) {
APPL_ERROR("Can not acces to the Menu interface"); 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() { void appl::TextViewerPlugin::init() {

View File

@ -16,8 +16,11 @@
#include <ewol/widget/Menu.h> #include <ewol/widget/Menu.h>
namespace appl { namespace appl {
class textPluginManager;
class TextViewerPlugin : public ewol::Object { class TextViewerPlugin : public ewol::Object {
friend class appl::TextViewer; friend class appl::TextViewer;
protected:
std::weak_ptr<appl::textPluginManager> m_pluginManager;
protected: protected:
TextViewerPlugin(); TextViewerPlugin();
void init(); void init();

View File

@ -149,7 +149,10 @@ bool appl::TextPluginHistory::onDataWrite(appl::TextViewer& _textDrawer,
clearRedo(_data); clearRedo(_data);
_data.m_undo.push_back(tmpElement); _data.m_undo.push_back(tmpElement);
} }
appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor()); std::shared_ptr<appl::textPluginManager> mng = m_pluginManager.lock();
if (mng!=nullptr) {
mng->onCursorMove(_textDrawer, _textDrawer.cursor());
}
return true; return true;
} }
@ -174,7 +177,10 @@ bool appl::TextPluginHistory::onDataReplace(appl::TextViewer& _textDrawer,
clearRedo(_data); clearRedo(_data);
_data.m_undo.push_back(tmpElement); _data.m_undo.push_back(tmpElement);
} }
appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor()); std::shared_ptr<appl::textPluginManager> mng = m_pluginManager.lock();
if (mng!=nullptr) {
mng->onCursorMove(_textDrawer, _textDrawer.cursor());
}
return true; return true;
} }
@ -196,7 +202,10 @@ bool appl::TextPluginHistory::onDataRemove(appl::TextViewer& _textDrawer,
_data.m_undo.push_back(tmpElement); _data.m_undo.push_back(tmpElement);
} }
_textDrawer.removeDirect(); _textDrawer.removeDirect();
appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor()); std::shared_ptr<appl::textPluginManager> mng = m_pluginManager.lock();
if (mng!=nullptr) {
mng->onCursorMove(_textDrawer, _textDrawer.cursor());
}
return true; return true;
} }

View File

@ -19,58 +19,11 @@
#undef __class__ #undef __class__
#define __class__ "textPluginManager" #define __class__ "textPluginManager"
static std::list<std::shared_ptr<appl::TextViewerPlugin>>& getList() { appl::textPluginManager::textPluginManager() {
static std::list<std::shared_ptr<appl::TextViewerPlugin>> s_list;
return s_list;
}
static std::vector<std::shared_ptr<appl::TextViewerPlugin>>& getListOnEventEntry() {
static std::vector<std::shared_ptr<appl::TextViewerPlugin>> s_list;
return s_list;
}
static std::vector<std::shared_ptr<appl::TextViewerPlugin>>& getListOnEventInput() {
static std::vector<std::shared_ptr<appl::TextViewerPlugin>> s_list;
return s_list;
}
static std::vector<std::shared_ptr<appl::TextViewerPlugin>>& getListOnWrite() {
static std::vector<std::shared_ptr<appl::TextViewerPlugin>> s_list;
return s_list;
}
static std::vector<std::shared_ptr<appl::TextViewerPlugin>>& getListOnReplace() {
static std::vector<std::shared_ptr<appl::TextViewerPlugin>> s_list;
return s_list;
}
static std::vector<std::shared_ptr<appl::TextViewerPlugin>>& getListOnRemove() {
static std::vector<std::shared_ptr<appl::TextViewerPlugin>> s_list;
return s_list;
}
static std::vector<std::shared_ptr<appl::TextViewerPlugin>>& getListonReceiveShortCutViewer() {
static std::vector<std::shared_ptr<appl::TextViewerPlugin>> s_list;
return s_list;
}
static std::vector<std::shared_ptr<appl::TextViewerPlugin>>& getListOnCursorMove() {
static std::vector<std::shared_ptr<appl::TextViewerPlugin>> s_list;
return s_list;
}
static std::weak_ptr<appl::TextViewer>& getViewerConnected() {
static std::weak_ptr<appl::TextViewer> s_widget;
return s_widget;
}
void appl::textPluginManager::init() {
} }
void appl::textPluginManager::init(const std::string& _name) {
void appl::textPluginManager::unInit() { ewol::Resource::init(_name);
// remove all sub plugin class:
getListOnEventEntry().clear();
getListOnEventInput().clear();
getListOnWrite().clear();
getListOnReplace().clear();
getListOnRemove().clear();
getListonReceiveShortCutViewer().clear();
getListOnCursorMove().clear();
getList().clear();
} }
void appl::textPluginManager::addDefaultPlugin() { void appl::textPluginManager::addDefaultPlugin() {
@ -88,37 +41,37 @@ void appl::textPluginManager::addPlugin(const std::shared_ptr<appl::TextViewerPl
return; return;
} }
APPL_DEBUG("Add plugin : " << _plugin->getObjectType()); APPL_DEBUG("Add plugin : " << _plugin->getObjectType());
getList().push_back(_plugin); m_list.push_back(_plugin);
if (_plugin->isAvaillableOnEventEntry() == true) { if (_plugin->isAvaillableOnEventEntry() == true) {
getListOnEventEntry().push_back(_plugin); m_listOnEventEntry.push_back(_plugin);
} }
if (_plugin->isAvaillableOnEventInput() == true) { if (_plugin->isAvaillableOnEventInput() == true) {
getListOnEventInput().push_back(_plugin); m_listOnEventInput.push_back(_plugin);
} }
if (_plugin->isAvaillableOnWrite() == true) { if (_plugin->isAvaillableOnWrite() == true) {
getListOnWrite().push_back(_plugin); m_listOnWrite.push_back(_plugin);
} }
if (_plugin->isAvaillableOnReplace() == true) { if (_plugin->isAvaillableOnReplace() == true) {
getListOnReplace().push_back(_plugin); m_listOnReplace.push_back(_plugin);
} }
if (_plugin->isAvaillableOnRemove() == true) { if (_plugin->isAvaillableOnRemove() == true) {
getListOnRemove().push_back(_plugin); m_listOnRemove.push_back(_plugin);
} }
if (_plugin->isAvaillableOnReceiveShortCut() == true) { if (_plugin->isAvaillableOnReceiveShortCut() == true) {
getListonReceiveShortCutViewer().push_back(_plugin); m_listOnReceiveShortCutViewer.push_back(_plugin);
} }
if (_plugin->isAvaillableOnCursorMove() == true) { if (_plugin->isAvaillableOnCursorMove() == true) {
getListOnCursorMove().push_back(_plugin); m_listOnCursorMove.push_back(_plugin);
} }
std::shared_ptr<appl::TextViewer> viewer = getViewerConnected().lock(); std::shared_ptr<appl::TextViewer> viewer = m_currentViewer.lock();
if (viewer != nullptr) { if (viewer != nullptr) {
_plugin->onPluginEnable(*viewer); _plugin->onPluginEnable(*viewer);
} }
} }
void appl::textPluginManager::connect(appl::TextViewer& _widget) { void appl::textPluginManager::connect(appl::TextViewer& _widget) {
getViewerConnected() = std::dynamic_pointer_cast<appl::TextViewer>(_widget.shared_from_this()); m_currentViewer = std::dynamic_pointer_cast<appl::TextViewer>(_widget.shared_from_this());
for (auto &it : getList()) { for (auto &it : m_list) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
} }
@ -127,8 +80,8 @@ void appl::textPluginManager::connect(appl::TextViewer& _widget) {
} }
void appl::textPluginManager::disconnect(appl::TextViewer& _widget) { void appl::textPluginManager::disconnect(appl::TextViewer& _widget) {
getViewerConnected().reset(); m_currentViewer.reset();
for (auto &it : getList()) { for (auto &it : m_list) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
} }
@ -138,7 +91,7 @@ void appl::textPluginManager::disconnect(appl::TextViewer& _widget) {
bool appl::textPluginManager::onEventEntry(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onEventEntry(appl::TextViewer& _textDrawer,
const ewol::event::Entry& _event) { const ewol::event::Entry& _event) {
for (auto &it : getListOnEventEntry()) { for (auto &it : m_listOnEventEntry) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
} }
@ -151,7 +104,7 @@ bool appl::textPluginManager::onEventEntry(appl::TextViewer& _textDrawer,
bool appl::textPluginManager::onEventInput(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onEventInput(appl::TextViewer& _textDrawer,
const ewol::event::Input& _event) { const ewol::event::Input& _event) {
for (auto &it : getListOnEventInput()) { for (auto &it : m_listOnEventInput) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
} }
@ -165,7 +118,7 @@ bool appl::textPluginManager::onEventInput(appl::TextViewer& _textDrawer,
bool appl::textPluginManager::onWrite(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _pos,
const std::string& _data) { const std::string& _data) {
for (auto &it : getListOnWrite()) { for (auto &it : m_listOnWrite) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
} }
@ -180,7 +133,7 @@ bool appl::textPluginManager::onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _pos,
const std::string& _data, const std::string& _data,
const appl::Buffer::Iterator& _posEnd) { const appl::Buffer::Iterator& _posEnd) {
for (auto &it : getListOnReplace()) { for (auto &it : m_listOnReplace) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
} }
@ -194,7 +147,7 @@ bool appl::textPluginManager::onReplace(appl::TextViewer& _textDrawer,
bool appl::textPluginManager::onRemove(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd) { const appl::Buffer::Iterator& _posEnd) {
for (auto &it : getListOnRemove()) { for (auto &it : m_listOnRemove) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
} }
@ -207,7 +160,7 @@ bool appl::textPluginManager::onRemove(appl::TextViewer& _textDrawer,
bool appl::textPluginManager::onReceiveShortCut(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onReceiveShortCut(appl::TextViewer& _textDrawer,
const std::string& _shortCutName) { const std::string& _shortCutName) {
for (auto &it : getListonReceiveShortCutViewer()) { for (auto &it : m_listOnReceiveShortCutViewer) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
} }
@ -220,7 +173,7 @@ bool appl::textPluginManager::onReceiveShortCut(appl::TextViewer& _textDrawer,
bool appl::textPluginManager::onCursorMove(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onCursorMove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos) { const appl::Buffer::Iterator& _pos) {
for (auto &it : getListOnCursorMove()) { for (auto &it : m_listOnCursorMove) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
} }

View File

@ -16,15 +16,23 @@
#include <appl/TextPlugin.h> #include <appl/TextPlugin.h>
namespace appl { namespace appl {
namespace textPluginManager { class textPluginManager : public ewol::Resource {
/** private:
* @brief Init the plugin manager for writer. std::weak_ptr<appl::TextViewer> m_currentViewer;
*/ std::list<std::shared_ptr<appl::TextViewerPlugin>> m_list;
void init(); std::vector<std::shared_ptr<appl::TextViewerPlugin>> m_listOnEventEntry;
/** std::vector<std::shared_ptr<appl::TextViewerPlugin>> m_listOnEventInput;
* @brief UnInit the plugin manager for writer. std::vector<std::shared_ptr<appl::TextViewerPlugin>> m_listOnWrite;
*/ std::vector<std::shared_ptr<appl::TextViewerPlugin>> m_listOnReplace;
void unInit(); std::vector<std::shared_ptr<appl::TextViewerPlugin>> m_listOnRemove;
std::vector<std::shared_ptr<appl::TextViewerPlugin>> m_listOnReceiveShortCutViewer;
std::vector<std::shared_ptr<appl::TextViewerPlugin>> 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 * @brief Add default plugin list
*/ */

View File

@ -55,6 +55,7 @@ void appl::TextPluginSelectAll::onPluginDisable(appl::TextViewer& _textDrawer) {
m_menuIdSelectNone = -1; m_menuIdSelectNone = -1;
} }
bool appl::TextPluginSelectAll::onReceiveShortCut(appl::TextViewer& _textDrawer, bool appl::TextPluginSelectAll::onReceiveShortCut(appl::TextViewer& _textDrawer,
const std::string& _shortCutName) { const std::string& _shortCutName) {
if (isEnable() == false) { if (isEnable() == false) {

View File

@ -32,6 +32,7 @@
class MainApplication : public ewol::context::Application { class MainApplication : public ewol::context::Application {
private: private:
std::shared_ptr<appl::BufferManager> m_bufferManager; std::shared_ptr<appl::BufferManager> m_bufferManager;
std::shared_ptr<appl::textPluginManager> m_pluginManager;
public: public:
bool init(ewol::Context& _context, size_t _initId) { bool init(ewol::Context& _context, size_t _initId) {
APPL_INFO(" == > init APPL v" << APPL_VERSION << " (START) [" << ewol::getBoardType() << "] (" << ewol::getCompilationMode() << ")"); 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 : // init ALL Singleton :
//()CTagsManager::getInstance(); //()CTagsManager::getInstance();
m_bufferManager = appl::BufferManager::create(); m_bufferManager = appl::BufferManager::create();
m_pluginManager = appl::textPluginManager::create();
appl::highlightManager::init(); appl::highlightManager::init();
appl::textPluginManager::init();
// Request load of the user configuration ... // Request load of the user configuration ...
//ewol::userConfig::load(); //ewol::userConfig::load();
@ -84,8 +85,7 @@ class MainApplication : public ewol::context::Application {
_context.setWindows(basicWindows); _context.setWindows(basicWindows);
// need to add default plugin, because they depend on the Menu widget wich might be named : "appl-menu-interface" // 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 // add files
APPL_INFO("show list of files : "); APPL_INFO("show list of files : ");
@ -113,10 +113,10 @@ class MainApplication : public ewol::context::Application {
} }
void unInit(ewol::Context& _context) { void unInit(ewol::Context& _context) {
APPL_INFO(" == > Un-Init " PROJECT_NAME " (START)"); APPL_INFO(" == > Un-Init " PROJECT_NAME " (START)");
appl::textPluginManager::unInit();
APPL_INFO("Stop Hightlight"); APPL_INFO("Stop Hightlight");
appl::highlightManager::unInit(); appl::highlightManager::unInit();
//Kill all singleton //Kill all singleton
m_pluginManager.reset();
m_bufferManager.reset(); m_bufferManager.reset();
APPL_INFO(" == > Un-Init " PROJECT_NAME " (END)"); APPL_INFO(" == > Un-Init " PROJECT_NAME " (END)");
} }