diff --git a/sources/appl/Gui/TextViewer.h b/sources/appl/Gui/TextViewer.h index 5027743..6740a1d 100644 --- a/sources/appl/Gui/TextViewer.h +++ b/sources/appl/Gui/TextViewer.h @@ -246,6 +246,67 @@ namespace appl { } return m_buffer->end(); } + /** + * @brief Get an Iterator on the start selection. + * @return The Iterator + */ + appl::Buffer::Iterator selectStart(void) { + if (m_buffer==NULL) { + return appl::Buffer::Iterator(); + } + return m_buffer->selectStart(); + } + /** + * @brief Get an Iterator on the stop selection. + * @return The Iterator + */ + appl::Buffer::Iterator selectStop(void) { + if (m_buffer==NULL) { + return appl::Buffer::Iterator(); + } + return m_buffer->selectStop(); + } + /** + * @brief get the start of a line with the position in the buffer. + * @param[in] _pos position in the buffer. + * @return The position in the buffer of the start of the line. + */ + appl::Buffer::Iterator getStartLine(const appl::Buffer::Iterator& _pos) { + if (m_buffer==NULL) { + return appl::Buffer::Iterator(); + } + return m_buffer->getStartLine(_pos); + } + /** + * @brief get the end of a line with the position in the buffer. + * @param[in] _pos position in the buffer. + * @return The position in the buffer of the end of the line. + */ + appl::Buffer::Iterator getEndLine(const appl::Buffer::Iterator& _pos) { + if (m_buffer==NULL) { + return appl::Buffer::Iterator(); + } + return m_buffer->getEndLine(_pos); + } + /** + * @brief Register of the arrival of a Multicast message + * @param[in] _messageId Event Id waiting for... + */ + void ext_registerMultiCast(const char* const _messageId) { + registerMultiCast(_messageId); + } + /** + * @brief add a specific shortcut with his description + * @param[in] _descriptiveString Description string of the shortcut + * @param[in] _generateEventId Event generic of the element + * @param[in] _data Associate data wit the event + */ + virtual void ext_shortCutAdd(const char * _descriptiveString, + const char * _generateEventId, + std::string _data="", + bool _broadcast=false) { + shortCutAdd(_descriptiveString, _generateEventId, _data, _broadcast); + } }; }; diff --git a/sources/appl/TextPluginManager.cpp b/sources/appl/TextPluginManager.cpp index fa5536f..d11992f 100644 --- a/sources/appl/TextPluginManager.cpp +++ b/sources/appl/TextPluginManager.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #undef __class__ #define __class__ "textPluginManager" @@ -78,6 +79,7 @@ void appl::textPluginManager::addDefaultPlugin(void) { appl::textPluginManager::addPlugin(new appl::TextPluginMultiLineTab()); appl::textPluginManager::addPlugin(new appl::TextPluginAutoIndent()); appl::textPluginManager::addPlugin(new appl::TextPluginHistory()); + appl::textPluginManager::addPlugin(new appl::TextPluginRmLine()); } void appl::textPluginManager::addPlugin(appl::TextViewerPlugin* _plugin) { diff --git a/sources/appl/TextPluginRmLine.cpp b/sources/appl/TextPluginRmLine.cpp new file mode 100644 index 0000000..4fd383c --- /dev/null +++ b/sources/appl/TextPluginRmLine.cpp @@ -0,0 +1,53 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license GPL v3 (see license file) + */ + + +#include +#include +#include + +#undef __class__ +#define __class__ "TextPluginRmLine" + + +appl::TextPluginRmLine::TextPluginRmLine(void) { + m_activateOnReceiveMessage = true; +} + +void appl::TextPluginRmLine::onPluginEnable(appl::TextViewer& _textDrawer) { + // add event : + _textDrawer.ext_registerMultiCast(ednMsgGuiRm); + _textDrawer.ext_shortCutAdd("ctrl+w", ednMsgGuiRm); +} + +void appl::TextPluginRmLine::onPluginDisable(appl::TextViewer& _textDrawer) { + // TODO : unknow function ... +} + +bool appl::TextPluginRmLine::onReceiveMessage(appl::TextViewer& _textDrawer, + const ewol::EMessage& _msg) { + if (isEnable() == false) { + return false; + } + if (_msg.getMessage() == ednMsgGuiRm) { + if (_textDrawer.hasBuffer() == false) { + return false; + } + if (_textDrawer.hasTextSelected() == true) { + appl::Buffer::Iterator start = _textDrawer.getStartLine(_textDrawer.selectStart()); + appl::Buffer::Iterator end = _textDrawer.getEndLine(_textDrawer.selectStop())+1; + _textDrawer.replace("", start, end); + } else { + appl::Buffer::Iterator start = _textDrawer.getStartLine(_textDrawer.cursor()); + appl::Buffer::Iterator end = _textDrawer.getEndLine(_textDrawer.cursor())+1; + _textDrawer.replace("", start, end); + } + return true; + } + return false; +} diff --git a/sources/appl/TextPluginRmLine.h b/sources/appl/TextPluginRmLine.h new file mode 100644 index 0000000..d863617 --- /dev/null +++ b/sources/appl/TextPluginRmLine.h @@ -0,0 +1,33 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license GPL v3 (see license file) + */ + +#ifndef __APPL_TEXT_RM_LINE_H__ +#define __APPL_TEXT_RM_LINE_H__ + +#include +#include +#include +#include +#include + +namespace appl { + class TextPluginRmLine : public appl::TextViewerPlugin { + public: + TextPluginRmLine(void); + ~TextPluginRmLine(void) { + // nothing to do ... + }; + public: + virtual void onPluginEnable(appl::TextViewer& _textDrawer); + virtual void onPluginDisable(appl::TextViewer& _textDrawer); + virtual bool onReceiveMessage(appl::TextViewer& _textDrawer, const ewol::EMessage& _msg); + }; +}; + + +#endif diff --git a/sources/lutin_edn.py b/sources/lutin_edn.py index 57b39f4..bf2ddf6 100755 --- a/sources/lutin_edn.py +++ b/sources/lutin_edn.py @@ -40,6 +40,7 @@ def Create(target): 'appl/TextPluginMultiLineTab.cpp', 'appl/TextPluginAutoIndent.cpp', 'appl/TextPluginHistory.cpp', + 'appl/TextPluginRmLine.cpp', 'appl/TextPluginManager.cpp']) # Generic color management for the text editor :