edn/sources/appl/TextPluginAutoIndent.cpp

63 lines
1.6 KiB
C++
Raw Normal View History

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>
#include <appl/global.hpp>
2013-10-21 22:11:16 +02:00
appl::TextPluginAutoIndent::TextPluginAutoIndent() {
2013-10-21 22:11:16 +02:00
m_activateOnEventEntry = true;
addObjectType("appl::TextPluginAutoIndent");
2013-10-21 22:11:16 +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;
}
// 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);
// just forward event == > manage directly in the buffer
if (_event.getType() != gale::key::keyboard::character) {
2013-10-21 22:11:16 +02:00
return false;
}
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;
}
appl::Buffer::Iterator startLine = _textDrawer.cursor();
if (_textDrawer.hasTextSelected() == true) {
startLine = _textDrawer.selectStart();
2013-10-21 22:11:16 +02: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;
(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-21 22:11:16 +02:00
}
_textDrawer.write(data);
return true;
}