edn/sources/appl/TextPluginManager.cpp

181 lines
5.1 KiB
C++

/** @file
* @author Edouard DUPIN
* @copyright 2010, Edouard DUPIN, all right reserved
* @license GPL v3 (see license file)
*/
#include <appl/TextPluginManager.hpp>
#include <appl/debug.hpp>
#include <appl/TextPluginCopy.hpp>
#include <appl/TextPluginMultiLineTab.hpp>
#include <appl/TextPluginAutoIndent.hpp>
#include <appl/TextPluginHistory.hpp>
#include <appl/TextPluginRmLine.hpp>
#include <appl/TextPluginSelectAll.hpp>
#include <appl/TextPluginCtags.hpp>
appl::textPluginManager::textPluginManager() {
}
void appl::textPluginManager::init(const etk::String& _name) {
gale::Resource::init(_name);
}
void appl::textPluginManager::addDefaultPlugin() {
appl::textPluginManager::addPlugin(appl::TextPluginCopy::create());
appl::textPluginManager::addPlugin(appl::TextPluginMultiLineTab::create());
appl::textPluginManager::addPlugin(appl::TextPluginAutoIndent::create());
appl::textPluginManager::addPlugin(appl::TextPluginHistory::create());
appl::textPluginManager::addPlugin(appl::TextPluginRmLine::create());
appl::textPluginManager::addPlugin(appl::TextPluginSelectAll::create());
appl::textPluginManager::addPlugin(appl::TextPluginCtags::create());
}
void appl::textPluginManager::addPlugin(ememory::SharedPtr<appl::TextViewerPlugin> _plugin) {
if (_plugin == null) {
return;
}
APPL_DEBUG("Add plugin : " << _plugin->getObjectType());
m_list.pushBack(_plugin);
if (_plugin->isAvaillableOnEventEntry() == true) {
m_listOnEventEntry.pushBack(_plugin);
}
if (_plugin->isAvaillableOnEventInput() == true) {
m_listOnEventInput.pushBack(_plugin);
}
if (_plugin->isAvaillableOnWrite() == true) {
m_listOnWrite.pushBack(_plugin);
}
if (_plugin->isAvaillableOnReplace() == true) {
m_listOnReplace.pushBack(_plugin);
}
if (_plugin->isAvaillableOnRemove() == true) {
m_listOnRemove.pushBack(_plugin);
}
if (_plugin->isAvaillableOnReceiveShortCut() == true) {
m_listOnReceiveShortCutViewer.pushBack(_plugin);
}
if (_plugin->isAvaillableOnCursorMove() == true) {
m_listOnCursorMove.pushBack(_plugin);
}
ememory::SharedPtr<appl::TextViewer> viewer = m_currentViewer.lock();
if (viewer != null) {
_plugin->onPluginEnable(*viewer);
}
}
void appl::textPluginManager::connect(appl::TextViewer& _widget) {
m_currentViewer = ememory::dynamicPointerCast<appl::TextViewer>(_widget.sharedFromThis());
for (auto &it : m_list) {
if (it == null) {
continue;
}
it->onPluginEnable(_widget);
}
}
void appl::textPluginManager::disconnect(appl::TextViewer& _widget) {
m_currentViewer.reset();
for (auto &it : m_list) {
if (it == null) {
continue;
}
it->onPluginDisable(_widget);
}
}
bool appl::textPluginManager::onEventEntry(appl::TextViewer& _textDrawer,
const ewol::event::Entry& _event) {
for (auto &it : m_listOnEventEntry) {
if (it == null) {
continue;
}
if (it->onEventEntry(_textDrawer, _event) == true ) {
return true;
}
}
return false;
}
bool appl::textPluginManager::onEventInput(appl::TextViewer& _textDrawer,
const ewol::event::Input& _event) {
for (auto &it : m_listOnEventInput) {
if (it == null) {
continue;
}
if (it->onEventInput(_textDrawer, _event) == true ) {
return true;
}
}
return false;
}
bool appl::textPluginManager::onWrite(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const etk::String& _data) {
for (auto &it : m_listOnWrite) {
if (it == null) {
continue;
}
if (it->onWrite(_textDrawer, _pos, _data) == true ) {
return true;
}
}
return false;
}
bool appl::textPluginManager::onReplace(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const etk::String& _data,
const appl::Buffer::Iterator& _posEnd) {
for (auto &it : m_listOnReplace) {
if (it == null) {
continue;
}
if (it->onReplace(_textDrawer, _pos, _data, _posEnd) == true ) {
return true;
}
}
return false;
}
bool appl::textPluginManager::onRemove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos,
const appl::Buffer::Iterator& _posEnd) {
for (auto &it : m_listOnRemove) {
if (it == null) {
continue;
}
if (it->onRemove(_textDrawer, _pos, _posEnd) == true ) {
return true;
}
}
return false;
}
bool appl::textPluginManager::onReceiveShortCut(appl::TextViewer& _textDrawer,
const etk::String& _shortCutName) {
for (auto &it : m_listOnReceiveShortCutViewer) {
if (it == null) {
continue;
}
if (it->onReceiveShortCut(_textDrawer, _shortCutName) == true ) {
return true;
}
}
return false;
}
bool appl::textPluginManager::onCursorMove(appl::TextViewer& _textDrawer,
const appl::Buffer::Iterator& _pos) {
for (auto &it : m_listOnCursorMove) {
if (it == null) {
continue;
}
if (it->onCursorMove(_textDrawer, _pos) == true ) {
return true;
}
}
return false;
}