[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:
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());
}

View File

@ -22,6 +22,7 @@
#include <utility>
namespace appl {
class textPluginManager;
class TextViewer : public ewol::widget::WidgetScrolled {
private:
std::shared_ptr<appl::GlyphPainting> m_paintingProperties; //!< element painting property
@ -34,6 +35,7 @@ namespace appl {
int32_t m_colorNormal;
private:
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
protected:
TextViewer();

View File

@ -8,6 +8,7 @@
#include <appl/TextPlugin.h>
#include <appl/TextPluginManager.h>
#include <appl/debug.h>
#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() {

View File

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

View File

@ -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<appl::textPluginManager> 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<appl::textPluginManager> 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<appl::textPluginManager> mng = m_pluginManager.lock();
if (mng!=nullptr) {
mng->onCursorMove(_textDrawer, _textDrawer.cursor());
}
return true;
}

View File

@ -19,58 +19,11 @@
#undef __class__
#define __class__ "textPluginManager"
static std::list<std::shared_ptr<appl::TextViewerPlugin>>& getList() {
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() {
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_ptr<appl::TextViewerPl
return;
}
APPL_DEBUG("Add plugin : " << _plugin->getObjectType());
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<appl::TextViewer> viewer = getViewerConnected().lock();
std::shared_ptr<appl::TextViewer> viewer = m_currentViewer.lock();
if (viewer != nullptr) {
_plugin->onPluginEnable(*viewer);
}
}
void appl::textPluginManager::connect(appl::TextViewer& _widget) {
getViewerConnected() = std::dynamic_pointer_cast<appl::TextViewer>(_widget.shared_from_this());
for (auto &it : getList()) {
m_currentViewer = std::dynamic_pointer_cast<appl::TextViewer>(_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;
}

View File

@ -16,98 +16,106 @@
#include <appl/TextPlugin.h>
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<appl::TextViewerPlugin>& _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<appl::TextViewer> m_currentViewer;
std::list<std::shared_ptr<appl::TextViewerPlugin>> m_list;
std::vector<std::shared_ptr<appl::TextViewerPlugin>> m_listOnEventEntry;
std::vector<std::shared_ptr<appl::TextViewerPlugin>> m_listOnEventInput;
std::vector<std::shared_ptr<appl::TextViewerPlugin>> m_listOnWrite;
std::vector<std::shared_ptr<appl::TextViewerPlugin>> m_listOnReplace;
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
*/
void addDefaultPlugin();
/**
* @brief Add a plugin.
* @param[in] _plugin Plugin pointer to add.
*/
void addPlugin(const std::shared_ptr<appl::TextViewerPlugin>& _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);
};
};

View File

@ -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) {

View File

@ -32,6 +32,7 @@
class MainApplication : public ewol::context::Application {
private:
std::shared_ptr<appl::BufferManager> m_bufferManager;
std::shared_ptr<appl::textPluginManager> 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)");
}