2016-05-02 22:01:55 +02:00
|
|
|
/** @file
|
2013-10-21 22:11:16 +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/TextPluginAutoIndent.hpp>
|
|
|
|
#include <gale/context/clipBoard.hpp>
|
|
|
|
#include <appl/Gui/TextViewer.hpp>
|
2017-03-07 21:42:24 +01:00
|
|
|
#include <appl/global.hpp>
|
2013-10-21 22:11:16 +02:00
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
appl::TextPluginAutoIndent::TextPluginAutoIndent() {
|
2013-10-21 22:11:16 +02:00
|
|
|
m_activateOnEventEntry = true;
|
2014-05-26 21:42:51 +02:00
|
|
|
addObjectType("appl::TextPluginAutoIndent");
|
2013-10-21 22:11:16 +02:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:41:48 +02:00
|
|
|
|
2013-10-21 22:11:16 +02:00
|
|
|
bool appl::TextPluginAutoIndent::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) {
|
2013-10-21 22:11:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-03-07 21:42:24 +01:00
|
|
|
// The user disable with global parameter
|
|
|
|
if (globals::isSetAutoIndent() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
//APPL_DEBUG("KB EVENT : " << _event);
|
2013-10-20 18:14:22 +02:00
|
|
|
// just forward event == > manage directly in the buffer
|
2016-04-29 23:16:07 +02:00
|
|
|
if (_event.getType() != gale::key::keyboard::character) {
|
2013-10-21 22:11:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-29 23:16:07 +02:00
|
|
|
if (_event.getStatus() != gale::key::status::down) {
|
2013-10-21 22:11:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-12-28 14:23:25 +01:00
|
|
|
if (_event.getChar() != u32char::Return) {
|
2013-10-21 22:11:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-12-13 21:50:40 +01:00
|
|
|
if (_event.getSpecialKey().getShift() == true) {
|
2013-10-21 22:11:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-11-24 16:07:43 +01:00
|
|
|
appl::Buffer::Iterator startLine = _textDrawer.cursor();
|
|
|
|
if (_textDrawer.hasTextSelected() == true) {
|
|
|
|
startLine = _textDrawer.selectStart();
|
2013-10-21 22:11:16 +02:00
|
|
|
}
|
2013-11-24 16:07:43 +01:00
|
|
|
startLine = _textDrawer.getStartLine(startLine);
|
2013-11-14 21:57:10 +01:00
|
|
|
std::string data = "\n";
|
2013-10-21 22:11:16 +02:00
|
|
|
|
2013-10-22 21:34:13 +02:00
|
|
|
|
2013-11-25 21:03:02 +01:00
|
|
|
for (appl::Buffer::Iterator it = startLine;
|
2013-10-26 13:16:30 +02:00
|
|
|
(bool)it == true;
|
2013-10-21 22:11:16 +02:00
|
|
|
++it) {
|
2013-12-28 14:23:25 +01:00
|
|
|
if (*it == u32char::Space) {
|
|
|
|
data += u32char::Space;
|
|
|
|
} else if(*it == u32char::Tabulation) {
|
|
|
|
data += u32char::Tabulation;
|
2013-10-21 22:11:16 +02:00
|
|
|
} else {
|
|
|
|
break;
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
2013-10-21 22:11:16 +02:00
|
|
|
}
|
|
|
|
_textDrawer.write(data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|