2016-05-02 22:01:55 +02:00
|
|
|
/** @file
|
2013-10-20 18:14:22 +02:00
|
|
|
* @author Edouard DUPIN
|
|
|
|
* @copyright 2010, Edouard DUPIN, all right reserved
|
|
|
|
* @license GPL v3 (see license file)
|
|
|
|
*/
|
2016-10-03 22:01:55 +02:00
|
|
|
#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>
|
2013-10-22 21:34:13 +02:00
|
|
|
|
2014-09-18 22:27:54 +02:00
|
|
|
appl::textPluginManager::textPluginManager() {
|
2013-10-20 18:14:22 +02:00
|
|
|
|
|
|
|
}
|
2017-08-28 00:09:10 +02:00
|
|
|
void appl::textPluginManager::init(const etk::String& _name) {
|
2015-08-11 23:21:41 +02:00
|
|
|
gale::Resource::init(_name);
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
void appl::textPluginManager::addDefaultPlugin() {
|
2014-08-07 23:41:48 +02:00
|
|
|
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());
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
|
2016-07-19 22:03:39 +02:00
|
|
|
void appl::textPluginManager::addPlugin(ememory::SharedPtr<appl::TextViewerPlugin> _plugin) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (_plugin == nullptr) {
|
2013-10-20 18:14:22 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-08-29 22:52:21 +02:00
|
|
|
APPL_DEBUG("Add plugin : " << _plugin->getObjectType());
|
2017-08-28 00:09:10 +02:00
|
|
|
m_list.pushBack(_plugin);
|
2013-10-20 18:14:22 +02:00
|
|
|
if (_plugin->isAvaillableOnEventEntry() == true) {
|
2017-08-28 00:09:10 +02:00
|
|
|
m_listOnEventEntry.pushBack(_plugin);
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
if (_plugin->isAvaillableOnEventInput() == true) {
|
2017-08-28 00:09:10 +02:00
|
|
|
m_listOnEventInput.pushBack(_plugin);
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
if (_plugin->isAvaillableOnWrite() == true) {
|
2017-08-28 00:09:10 +02:00
|
|
|
m_listOnWrite.pushBack(_plugin);
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
if (_plugin->isAvaillableOnReplace() == true) {
|
2017-08-28 00:09:10 +02:00
|
|
|
m_listOnReplace.pushBack(_plugin);
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
if (_plugin->isAvaillableOnRemove() == true) {
|
2017-08-28 00:09:10 +02:00
|
|
|
m_listOnRemove.pushBack(_plugin);
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
2014-08-27 22:58:21 +02:00
|
|
|
if (_plugin->isAvaillableOnReceiveShortCut() == true) {
|
2017-08-28 00:09:10 +02:00
|
|
|
m_listOnReceiveShortCutViewer.pushBack(_plugin);
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
if (_plugin->isAvaillableOnCursorMove() == true) {
|
2017-08-28 00:09:10 +02:00
|
|
|
m_listOnCursorMove.pushBack(_plugin);
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
2016-07-19 22:03:39 +02:00
|
|
|
ememory::SharedPtr<appl::TextViewer> viewer = m_currentViewer.lock();
|
2014-08-29 22:52:21 +02:00
|
|
|
if (viewer != nullptr) {
|
|
|
|
_plugin->onPluginEnable(*viewer);
|
|
|
|
}
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void appl::textPluginManager::connect(appl::TextViewer& _widget) {
|
2016-07-19 22:03:39 +02:00
|
|
|
m_currentViewer = ememory::dynamicPointerCast<appl::TextViewer>(_widget.sharedFromThis());
|
2014-09-18 22:27:54 +02:00
|
|
|
for (auto &it : m_list) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (it == nullptr) {
|
2013-10-20 18:14:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-26 21:42:51 +02:00
|
|
|
it->onPluginEnable(_widget);
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void appl::textPluginManager::disconnect(appl::TextViewer& _widget) {
|
2014-09-18 22:27:54 +02:00
|
|
|
m_currentViewer.reset();
|
|
|
|
for (auto &it : m_list) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (it == nullptr) {
|
2013-10-20 18:14:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-26 21:42:51 +02:00
|
|
|
it->onPluginDisable(_widget);
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool appl::textPluginManager::onEventEntry(appl::TextViewer& _textDrawer,
|
2013-12-13 21:50:40 +01:00
|
|
|
const ewol::event::Entry& _event) {
|
2014-09-18 22:27:54 +02:00
|
|
|
for (auto &it : m_listOnEventEntry) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (it == nullptr) {
|
2013-10-20 18:14:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-26 21:42:51 +02:00
|
|
|
if (it->onEventEntry(_textDrawer, _event) == true ) {
|
2013-10-20 18:14:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool appl::textPluginManager::onEventInput(appl::TextViewer& _textDrawer,
|
2013-12-13 21:50:40 +01:00
|
|
|
const ewol::event::Input& _event) {
|
2014-09-18 22:27:54 +02:00
|
|
|
for (auto &it : m_listOnEventInput) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (it == nullptr) {
|
2013-10-20 18:14:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-26 21:42:51 +02:00
|
|
|
if (it->onEventInput(_textDrawer, _event) == true ) {
|
2013-10-20 18:14:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool appl::textPluginManager::onWrite(appl::TextViewer& _textDrawer,
|
|
|
|
const appl::Buffer::Iterator& _pos,
|
2017-08-28 00:09:10 +02:00
|
|
|
const etk::String& _data) {
|
2014-09-18 22:27:54 +02:00
|
|
|
for (auto &it : m_listOnWrite) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (it == nullptr) {
|
2013-10-20 18:14:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-26 21:42:51 +02:00
|
|
|
if (it->onWrite(_textDrawer, _pos, _data) == true ) {
|
2013-10-20 18:14:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool appl::textPluginManager::onReplace(appl::TextViewer& _textDrawer,
|
|
|
|
const appl::Buffer::Iterator& _pos,
|
2017-08-28 00:09:10 +02:00
|
|
|
const etk::String& _data,
|
2013-10-20 18:14:22 +02:00
|
|
|
const appl::Buffer::Iterator& _posEnd) {
|
2014-09-18 22:27:54 +02:00
|
|
|
for (auto &it : m_listOnReplace) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (it == nullptr) {
|
2013-10-20 18:14:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-26 21:42:51 +02:00
|
|
|
if (it->onReplace(_textDrawer, _pos, _data, _posEnd) == true ) {
|
2013-10-20 18:14:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool appl::textPluginManager::onRemove(appl::TextViewer& _textDrawer,
|
|
|
|
const appl::Buffer::Iterator& _pos,
|
|
|
|
const appl::Buffer::Iterator& _posEnd) {
|
2014-09-18 22:27:54 +02:00
|
|
|
for (auto &it : m_listOnRemove) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (it == nullptr) {
|
2013-10-20 18:14:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-26 21:42:51 +02:00
|
|
|
if (it->onRemove(_textDrawer, _pos, _posEnd) == true ) {
|
2013-10-20 18:14:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-27 22:58:21 +02:00
|
|
|
bool appl::textPluginManager::onReceiveShortCut(appl::TextViewer& _textDrawer,
|
2017-08-28 00:09:10 +02:00
|
|
|
const etk::String& _shortCutName) {
|
2014-09-18 22:27:54 +02:00
|
|
|
for (auto &it : m_listOnReceiveShortCutViewer) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (it == nullptr) {
|
2013-10-20 18:14:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-08-27 22:58:21 +02:00
|
|
|
if (it->onReceiveShortCut(_textDrawer, _shortCutName) == true ) {
|
2013-10-20 18:14:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool appl::textPluginManager::onCursorMove(appl::TextViewer& _textDrawer,
|
|
|
|
const appl::Buffer::Iterator& _pos) {
|
2014-09-18 22:27:54 +02:00
|
|
|
for (auto &it : m_listOnCursorMove) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (it == nullptr) {
|
2013-10-20 18:14:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-26 21:42:51 +02:00
|
|
|
if (it->onCursorMove(_textDrawer, _pos) == true ) {
|
2013-10-20 18:14:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|