2013-10-21 21:47:28 +02:00
|
|
|
/**
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
*
|
|
|
|
* @copyright 2010, Edouard DUPIN, all right reserved
|
|
|
|
*
|
|
|
|
* @license GPL v3 (see license file)
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-10-28 21:47:51 +01:00
|
|
|
#include <appl/TextPluginMultiLineTab.h>
|
2013-10-21 21:47:28 +02:00
|
|
|
#include <appl/Gui/TextViewer.h>
|
|
|
|
|
2013-10-22 21:34:13 +02:00
|
|
|
#undef __class__
|
|
|
|
#define __class__ "TextPluginMultiLineTab"
|
2013-10-21 21:47:28 +02:00
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
appl::TextPluginMultiLineTab::TextPluginMultiLineTab() {
|
2013-10-21 21:47:28 +02:00
|
|
|
m_activateOnEventEntry = true;
|
2014-05-26 21:42:51 +02:00
|
|
|
addObjectType("appl::TextPluginMultiLineTab");
|
2013-10-21 21:47:28 +02:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:41:48 +02:00
|
|
|
|
2013-10-21 21:47:28 +02:00
|
|
|
bool appl::TextPluginMultiLineTab::onEventEntry(appl::TextViewer& _textDrawer,
|
2013-12-13 21:50:40 +01:00
|
|
|
const ewol::event::Entry& _event) {
|
2013-10-22 21:34:13 +02:00
|
|
|
if (isEnable() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-11 23:21:41 +02:00
|
|
|
if (_event.getType() != gale::key::keyboard_char) {
|
2013-10-21 21:47:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent);
|
2015-08-11 23:21:41 +02:00
|
|
|
if (_event.getStatus() != gale::key::status_down) {
|
2013-10-21 21:47:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-11-14 21:57:10 +01:00
|
|
|
char32_t localValue = _event.getChar();
|
2013-12-28 14:23:25 +01:00
|
|
|
if (localValue != u32char::Tabulation) {
|
2013-10-21 21:47:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-11-24 16:07:43 +01:00
|
|
|
if (_textDrawer.hasTextSelected() == false) {
|
2013-10-21 21:47:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-11-24 16:07:43 +01:00
|
|
|
appl::Buffer::Iterator itStart = _textDrawer.selectStart();
|
|
|
|
appl::Buffer::Iterator itStop = _textDrawer.selectStop();
|
2013-10-21 21:47:28 +02:00
|
|
|
// get the compleate section of the buffer :
|
2013-11-24 16:07:43 +01:00
|
|
|
itStart = _textDrawer.getStartLine(itStart);
|
|
|
|
itStop = _textDrawer.getEndLine(itStop);
|
2013-10-21 21:47:28 +02:00
|
|
|
// copy the curent data in a classicle string:
|
2013-11-14 21:57:10 +01:00
|
|
|
std::string data;
|
2013-11-24 16:07:43 +01:00
|
|
|
_textDrawer.copy(data, itStart, itStop);
|
2013-10-21 21:47:28 +02:00
|
|
|
// TODO : Change this ...
|
|
|
|
bool m_useTabs = true;
|
2014-06-02 21:04:35 +02:00
|
|
|
size_t m_tabDist = 4;
|
2013-10-21 21:47:28 +02:00
|
|
|
|
2013-12-13 21:50:40 +01:00
|
|
|
if (true == _event.getSpecialKey().getShift() ) {
|
2013-10-21 21:47:28 +02:00
|
|
|
// un-indent
|
2013-12-28 14:23:25 +01:00
|
|
|
data.insert(0, 1, u32char::Return);
|
2014-06-02 21:04:35 +02:00
|
|
|
for (size_t iii=1; iii<data.size(); ++iii) {
|
|
|
|
if ((char32_t)data[iii-1] != u32char::Return) {
|
2013-11-20 21:57:00 +01:00
|
|
|
continue;
|
|
|
|
}
|
2014-06-02 21:04:35 +02:00
|
|
|
if((char32_t)data[iii] == u32char::Tabulation) {
|
2013-11-21 21:13:54 +01:00
|
|
|
data.erase(iii, 1);
|
2014-06-02 21:04:35 +02:00
|
|
|
} else if((char32_t)data[iii] == u32char::Space) {
|
|
|
|
for (size_t jjj=0; jjj<m_tabDist && jjj+iii<data.size() ; jjj++) {
|
|
|
|
if((char32_t)data[iii] == u32char::Space) {
|
2013-11-21 21:13:54 +01:00
|
|
|
data.erase(iii, 1);
|
2014-06-02 21:04:35 +02:00
|
|
|
} else if((char32_t)data[iii] == u32char::Tabulation) {
|
2013-11-21 21:13:54 +01:00
|
|
|
data.erase(iii, 1);
|
2013-11-20 21:57:00 +01:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
break;
|
2013-10-21 21:47:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
2013-11-21 21:13:54 +01:00
|
|
|
data.erase(0, 1);
|
2013-10-21 21:47:28 +02:00
|
|
|
} else {
|
|
|
|
// indent
|
2013-12-28 14:23:25 +01:00
|
|
|
data.insert(0, 1, u32char::Return);
|
2014-06-02 21:04:35 +02:00
|
|
|
for (size_t iii=1; iii<data.size(); iii++) {
|
|
|
|
if ((char32_t)data[iii-1] != u32char::Return) {
|
2013-11-20 21:57:00 +01:00
|
|
|
continue;
|
|
|
|
}
|
2013-12-13 21:50:40 +01:00
|
|
|
if (true == _event.getSpecialKey().getCtrl() ) {
|
2013-12-28 14:23:25 +01:00
|
|
|
data.insert(iii, 1, u32char::Space);
|
2013-11-20 21:57:00 +01:00
|
|
|
} else if (true == m_useTabs) {
|
2013-12-28 14:23:25 +01:00
|
|
|
data.insert(iii, 1, u32char::Tabulation);
|
2013-11-20 21:57:00 +01:00
|
|
|
} else {
|
2013-12-28 14:23:25 +01:00
|
|
|
data.insert(iii, m_tabDist, u32char::Space);
|
2013-10-21 21:47:28 +02:00
|
|
|
}
|
|
|
|
}
|
2013-11-21 21:13:54 +01:00
|
|
|
data.erase(0, 1);
|
2013-10-21 21:47:28 +02:00
|
|
|
}
|
|
|
|
// Real replace of DATA :
|
|
|
|
_textDrawer.replace(data, itStart, itStop);
|
2013-11-24 16:07:43 +01:00
|
|
|
_textDrawer.select(itStart, itStart+data.size());
|
2013-10-21 21:47:28 +02:00
|
|
|
return true;
|
|
|
|
}
|