[DEV] start dev of smart indent

This commit is contained in:
Edouard DUPIN 2013-10-21 22:11:16 +02:00
parent e6480b8cac
commit 4c9fb8a74e
6 changed files with 97 additions and 36 deletions

View File

@ -1,38 +1,61 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Buffer/TextPluginAutoIndent.h>
#include <ewol/clipBoard.h>
#include <appl/Gui/TextViewer.h>
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<m_cursorPos; kk++) {
if (' ' == m_EdnBuf[kk]) {
tmpVect.pushBack(' ');
} else if('\t' == m_EdnBuf[kk]) {
tmpVect.pushBack('\t');
} else {
break;
}
}
}
m_selectMode = false;
moveCursor(m_cursorPos + 1);
return true;
*/
}
}
APPL_DEBUG("kjhkjhkjhkjh : '" << data << "'");
_textDrawer.write(data);
return true;
}

View File

@ -0,0 +1,32 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_PLUGIN_AUTO_INDENT_H__
#define __APPL_TEXT_PLUGIN_AUTO_INDENT_H__
#include <etk/types.h>
#include <ewol/renderer/EObject.h>
#include <appl/Gui/TextViewer.h>
#include <ewol/compositing/Text.h>
#include <appl/Buffer/TextPlugin.h>
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

View File

@ -10,6 +10,7 @@
#include <appl/Debug.h>
#include <appl/Buffer/TextPluginCopy.h>
#include <appl/Buffer/TextPluginMultiLineTab.h>
#include <appl/Buffer/TextPluginAutoIndent.h>
static etk::Vector<appl::TextViewerPlugin *>& getList(void) {
static etk::Vector<appl::TextViewerPlugin *> 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) {

View File

@ -29,4 +29,5 @@ namespace appl {
};
#endif
#endif

View File

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

View File

@ -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'])