From 4c9fb8a74ebc3c943f6856da72e15844fc5eb3c0 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 21 Oct 2013 22:11:16 +0200 Subject: [PATCH] [DEV] start dev of smart indent --- sources/appl/Buffer/TextPluginAutoIndent.cpp | 93 ++++++++++++-------- sources/appl/Buffer/TextPluginAutoIndent.h | 32 +++++++ sources/appl/Buffer/TextPluginManager.cpp | 2 + sources/appl/Buffer/TextPluginMultiLineTab.h | 3 +- sources/appl/Gui/TextViewer.h | 2 + sources/lutin_edn.py | 1 + 6 files changed, 97 insertions(+), 36 deletions(-) diff --git a/sources/appl/Buffer/TextPluginAutoIndent.cpp b/sources/appl/Buffer/TextPluginAutoIndent.cpp index e08490e..82f74b2 100644 --- a/sources/appl/Buffer/TextPluginAutoIndent.cpp +++ b/sources/appl/Buffer/TextPluginAutoIndent.cpp @@ -1,38 +1,61 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license GPL v3 (see license file) + */ + +#include +#include +#include + + +appl::TextPluginAutoIndent::TextPluginAutoIndent(void) { + m_activateOnEventEntry = true; +} + +bool appl::TextPluginAutoIndent::onEventEntry(appl::TextViewer& _textDrawer, + const ewol::EventEntry& _event) { + /* + if (enable == false) { + return false; + } + */ // just forward event == > manage directly in the buffer - if (_event.getType() == ewol::keyEvent::keyboardChar) { - //APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent); - if (_event.getStatus() != ewol::keyEvent::statusDown) { - return false; + if (_event.getType() != ewol::keyEvent::keyboardChar) { + return false; + } + //APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent); + if (_event.getStatus() != ewol::keyEvent::statusDown) { + return false; + } + if (_event.getChar() != etk::UChar::Return) { + return false; + } + if (_event.getSpecialKey().isSetShift() == false) { + return false; + } + appl::Buffer::Iterator startLine = _textDrawer.m_buffer->cursor(); + if (_textDrawer.m_buffer->hasTextSelected() == true) { + startLine = _textDrawer.m_buffer->selectStart(); + } + etk::UString data = etk::UChar::Return; + + for (appl::Buffer::Iterator it = startLine; + it != _textDrawer.m_buffer->end(); + ++it) { + if (*it == etk::UChar::Space) { + data.append(etk::UChar::Space); + } else if(*it == etk::UChar::Tabulation) { + data.append(etk::UChar::Tabulation); + } else { + break; } - etk::UChar localValue = _event.getChar(); - if (localValue == etk::UChar::Return) { - if (true == _event.getSpecialKey().isSetShift()) { - localValue = etk::UChar::CarrierReturn; - } else { - /* - m_data.insert(m_cursorPos, '\n'); - if (true == globals::isSetAutoIndent() ) { - int32_t l_lineStart; - // get the begin of the line or the begin of the line befor selection - if (false == haveSelectionActive) { - l_lineStart = m_EdnBuf.StartOfLine(m_cursorPos); - } else { - l_lineStart = m_EdnBuf.StartOfLine(SelectionStart); - } - // add same characters in the temporar buffer - for (int32_t kk=l_lineStart; kk +#include +#include +#include +#include + +namespace appl { + class TextPluginAutoIndent : public appl::TextViewerPlugin { + public: + TextPluginAutoIndent(void); + ~TextPluginAutoIndent(void) { + // nothing to do ... + }; + public: + virtual bool onEventEntry(appl::TextViewer& _textDrawer, + const ewol::EventEntry& _event); + }; +}; + + +#endif diff --git a/sources/appl/Buffer/TextPluginManager.cpp b/sources/appl/Buffer/TextPluginManager.cpp index 902200f..ab29b40 100644 --- a/sources/appl/Buffer/TextPluginManager.cpp +++ b/sources/appl/Buffer/TextPluginManager.cpp @@ -10,6 +10,7 @@ #include #include #include +#include static etk::Vector& getList(void) { static etk::Vector s_list; @@ -71,6 +72,7 @@ void appl::textPluginManager::unInit(void) { void appl::textPluginManager::addDefaultPlugin(void) { appl::textPluginManager::addPlugin(new appl::TextPluginCopy()); appl::textPluginManager::addPlugin(new appl::TextPluginMultiLineTab()); + appl::textPluginManager::addPlugin(new appl::TextPluginAutoIndent()); } void appl::textPluginManager::addPlugin(appl::TextViewerPlugin* _plugin) { diff --git a/sources/appl/Buffer/TextPluginMultiLineTab.h b/sources/appl/Buffer/TextPluginMultiLineTab.h index 3da34a1..5bd29ad 100644 --- a/sources/appl/Buffer/TextPluginMultiLineTab.h +++ b/sources/appl/Buffer/TextPluginMultiLineTab.h @@ -29,4 +29,5 @@ namespace appl { }; -#endif \ No newline at end of file +#endif + diff --git a/sources/appl/Gui/TextViewer.h b/sources/appl/Gui/TextViewer.h index 84eac7f..ff7c263 100644 --- a/sources/appl/Gui/TextViewer.h +++ b/sources/appl/Gui/TextViewer.h @@ -21,10 +21,12 @@ namespace appl { class TextViewerPlugin; class TextPluginCopy; class TextPluginMultiLineTab; + class TextPluginAutoIndent; class TextViewer : public widget::WidgetScrooled { friend class appl::TextViewerPlugin; friend class appl::TextPluginCopy; friend class appl::TextPluginMultiLineTab; + friend class appl::TextPluginAutoIndent; public: TextViewer(const etk::UString& _fontName="", int32_t _fontSize=-1); virtual ~TextViewer(void); diff --git a/sources/lutin_edn.py b/sources/lutin_edn.py index 5ce196e..cd549d1 100755 --- a/sources/lutin_edn.py +++ b/sources/lutin_edn.py @@ -33,6 +33,7 @@ def Create(target): 'appl/Buffer/TextPlugin.cpp', 'appl/Buffer/TextPluginCopy.cpp', 'appl/Buffer/TextPluginMultiLineTab.cpp', + 'appl/Buffer/TextPluginAutoIndent.cpp', 'appl/Buffer/TextPluginManager.cpp', 'appl/Buffer/BufferManager.cpp'])