edn/sources/appl/Gui/BufferView.cpp

260 lines
7.3 KiB
C++
Raw Normal View History

/**
* @author Edouard DUPIN
2012-11-25 11:55:06 +01:00
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
2013-10-25 20:49:26 +02:00
#include <appl/debug.h>
2012-04-24 09:42:14 +02:00
#include <appl/global.h>
#include <BufferView.h>
#include <BufferManager.h>
2013-10-25 22:12:34 +02:00
//#include <ColorizeManager.h>
#include <MainWindows.h>
2013-09-02 06:45:12 +02:00
#include <ewol/renderer/EObject.h>
#undef __class__
2013-10-09 22:00:24 +02:00
#define __class__ "BufferView"
2013-11-14 21:57:10 +01:00
static void SortElementList(std::vector<appl::dataBufferStruct*>& _list) {
std::vector<appl::dataBufferStruct *> tmpList = _list;
2013-10-09 22:00:24 +02:00
_list.clear();
2013-10-07 22:04:21 +02:00
for(int32_t iii=0; iii<tmpList.size(); iii++) {
2013-10-09 22:00:24 +02:00
if (NULL == tmpList[iii]) {
continue;
}
int32_t findPos = 0;
for(int32_t jjj=0; jjj<_list.size(); jjj++) {
//EWOL_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
if (_list[jjj] == NULL) {
continue;
}
if (tmpList[iii]->m_bufferName.getNameFile() > _list[jjj]->m_bufferName.getNameFile()) {
findPos = jjj+1;
2012-10-18 11:09:19 +02:00
}
}
2013-10-09 22:00:24 +02:00
//EWOL_DEBUG("position="<<findPos);
2013-11-14 21:57:10 +01:00
_list.insert(_list.begin()+findPos, tmpList[iii]);
2012-10-18 11:09:19 +02:00
}
}
2013-10-09 22:00:24 +02:00
BufferView::BufferView(void) {
2013-10-07 22:04:21 +02:00
setCanHaveFocus(true);
2013-10-09 22:00:24 +02:00
registerMultiCast(ednMsgBufferListChange);
registerMultiCast(ednMsgBufferState);
registerMultiCast(ednMsgBufferId);
registerMultiCast(appl::MsgSelectNewFile);
2013-11-07 21:08:57 +01:00
registerMultiCast(appl::MsgSelectChange);
registerMultiCast(appl::MsgNameChange);
m_selectedID = -1;
m_selectedIdRequested = -1;
// load buffer manager:
m_bufferManager = appl::BufferManager::keep();
// load color properties
m_paintingProperties = appl::GlyphPainting::keep("THEME:COLOR:bufferList.json");
// get all id properties ...
m_colorBackground1 = m_paintingProperties->request("backgroung1");
m_colorBackground2 = m_paintingProperties->request("backgroung2");
m_colorBackgroundSelect = m_paintingProperties->request("backgroungSelected");
m_colorTextNormal = m_paintingProperties->request("textNormal");
m_colorTextModify = m_paintingProperties->request("textModify");
}
2013-10-09 22:00:24 +02:00
BufferView::~BufferView(void) {
2013-10-07 22:04:21 +02:00
removeAllElement();
}
2012-02-29 18:06:08 +01:00
2013-10-09 22:00:24 +02:00
void BufferView::removeAllElement(void) {
2013-10-07 22:04:21 +02:00
for(int32_t iii=0; iii<m_list.size(); iii++) {
2012-10-18 11:09:19 +02:00
if (NULL!=m_list[iii]) {
delete(m_list[iii]);
m_list[iii] = NULL;
}
}
2013-10-07 22:04:21 +02:00
m_list.clear();
if (m_bufferManager != NULL) {
appl::BufferManager::release(m_bufferManager);
}
2012-10-18 11:09:19 +02:00
}
2012-02-29 18:06:08 +01:00
2013-10-09 22:00:24 +02:00
void BufferView::onReceiveMessage(const ewol::EMessage& _msg) {
2013-10-07 22:04:21 +02:00
widget::List::onReceiveMessage(_msg);
if (_msg.getMessage() == appl::MsgSelectNewFile) {
appl::Buffer* buffer = m_bufferManager->get(_msg.getData());
if (buffer == NULL) {
APPL_ERROR("event on element nor exist : " << _msg.getData());
return;
}
2013-11-07 21:08:57 +01:00
buffer->registerOnEvent(this, appl::Buffer::eventIsSave);
buffer->registerOnEvent(this, appl::Buffer::eventIsModify);
buffer->registerOnEvent(this, appl::Buffer::eventChangeName);
appl::dataBufferStruct* tmp = new appl::dataBufferStruct(_msg.getData(), buffer);
if (tmp == NULL) {
APPL_ERROR("Allocation error of the tmp buffer list element");
return;
}
2013-11-14 21:57:10 +01:00
m_list.push_back(tmp);
markToRedraw();
2013-11-07 21:08:57 +01:00
return;
}
if (_msg.getMessage() == appl::Buffer::eventChangeName) {
for (auto element : m_list) {
if (element == NULL) {
continue;
}
element->m_bufferName = element->m_buffer->getFileName();
}
markToRedraw();
return;
}
2013-11-07 21:08:57 +01:00
if (_msg.getMessage() == appl::Buffer::eventIsSave) {
markToRedraw();
return;
}
if (_msg.getMessage() == appl::Buffer::eventIsModify) {
markToRedraw();
return;
}
APPL_DEBUG("message : " << _msg);
if (_msg.getMessage() == appl::MsgSelectChange) {
m_selectedID = -1;
appl::Buffer* tmpBuffer = NULL;
if (m_bufferManager != NULL) {
tmpBuffer = m_bufferManager->getBufferSelected();
}
if (tmpBuffer != NULL) {
for (esize_t iii=0; iii<m_list.size(); iii++) {
if (m_list[iii] == NULL) {
continue;
}
if (m_list[iii]->m_buffer != tmpBuffer) {
continue;
}
m_selectedID = iii;
break;
}
}
markToRedraw();
return;
}
2013-10-07 22:04:21 +02:00
if (_msg.getMessage() == ednMsgBufferListChange) {
2012-10-18 11:09:19 +02:00
// clean The list
2013-10-07 22:04:21 +02:00
removeAllElement();
// get all the buffer name and properties:
2013-10-29 21:13:45 +01:00
int32_t nbBufferOpen = 0; // BufferManager::size();
2012-10-18 11:09:19 +02:00
for (int32_t iii=0; iii<nbBufferOpen; iii++) {
2013-10-29 21:13:45 +01:00
/*
2013-10-09 22:00:24 +02:00
if (BufferManager::exist(iii)) {
2013-10-07 22:04:21 +02:00
BufferText* tmpBuffer = BufferManager::get(iii);
if (NULL != tmpBuffer) {
2013-10-07 22:04:21 +02:00
bool isModify = tmpBuffer->isModify();
etk::FSNode name = tmpBuffer->getFileName();
appl::dataBufferStruct* tmpElement = new appl::dataBufferStruct(name, iii, isModify);
if (NULL != tmpElement) {
2013-11-14 21:57:10 +01:00
m_list.push_back(tmpElement);
} else {
APPL_ERROR("Allocation error of the tmp buffer list element");
}
2012-10-18 11:09:19 +02:00
}
}
2013-10-29 21:13:45 +01:00
*/
2012-10-18 11:09:19 +02:00
}
if (true == globals::OrderTheBufferList() ) {
SortElementList(m_list);
}
2013-10-07 22:04:21 +02:00
markToRedraw();
}else if (_msg.getMessage() == ednMsgBufferId) {
2013-10-29 21:13:45 +01:00
m_selectedIdRequested = 0; //BufferManager::getSelected();
2013-10-07 22:04:21 +02:00
markToRedraw();
}else if (_msg.getMessage() == ednMsgBufferState) {
// update list of modify section ...
for (int32_t iii=0; iii<m_list.size(); iii++) {
2012-10-18 11:09:19 +02:00
if (NULL!=m_list[iii]) {
2013-10-09 22:00:24 +02:00
//m_list[iii]->m_isModify = BufferManager::get(m_list[iii]->m_bufferID)->isModify();
2012-10-18 11:09:19 +02:00
}
}
2013-10-07 22:04:21 +02:00
markToRedraw();
}
}
void BufferView::onObjectRemove(ewol::EObject* _removeObject) {
widget::List::onObjectRemove(_removeObject);
for (esize_t iii=0; iii<m_list.size(); iii++) {
if (m_list[iii] == NULL) {
continue;
}
if (m_list[iii]->m_buffer != _removeObject) {
continue;
}
2013-11-14 21:57:10 +01:00
m_list.erase(m_list.begin()+iii);
markToRedraw();
return;
}
}
2013-10-09 22:00:24 +02:00
etk::Color<> BufferView::getBasicBG(void) {
return (*m_paintingProperties)[m_colorBackground1].getForeground();
}
2013-10-09 22:00:24 +02:00
uint32_t BufferView::getNuberOfColomn(void) {
return 1;
}
2013-11-14 21:57:10 +01:00
bool BufferView::getTitle(int32_t _colomn, std::string &_myTitle, etk::Color<> &_fg, etk::Color<> &_bg) {
2013-10-09 22:00:24 +02:00
_myTitle = "Buffers : ";
return true;
}
2013-10-09 22:00:24 +02:00
uint32_t BufferView::getNuberOfRaw(void) {
2013-10-07 22:04:21 +02:00
return m_list.size();
}
2013-11-14 21:57:10 +01:00
bool BufferView::getElement(int32_t _colomn, int32_t _raw, std::string& _myTextToWrite, etk::Color<>& _fg, etk::Color<>& _bg) {
if( _raw >= 0
&& _raw<m_list.size()
&& NULL != m_list[_raw]) {
_myTextToWrite = m_list[_raw]->m_bufferName.getNameFile();
2013-11-07 21:08:57 +01:00
if ( m_list[_raw]->m_buffer != NULL
&& m_list[_raw]->m_buffer->isModify() == false) {
_fg = (*m_paintingProperties)[m_colorTextNormal].getForeground();
} else {
_fg = (*m_paintingProperties)[m_colorTextModify].getForeground();
}
if (_raw%2 == 0) {
_bg = (*m_paintingProperties)[m_colorBackground1].getForeground();
} else {
_bg = (*m_paintingProperties)[m_colorBackground2].getForeground();
}
// the buffer change of selection ...
if (m_selectedID == _raw) {
_bg = (*m_paintingProperties)[m_colorBackgroundSelect].getForeground();
}
} else {
_myTextToWrite = "ERROR";
}
return true;
}
2013-11-11 20:20:25 +01:00
bool BufferView::onItemEvent(int32_t _IdInput, enum ewol::keyEvent::status _typeEvent, int32_t _colomn, int32_t _raw, float _x, float _y)
{
2013-10-09 22:00:24 +02:00
if (1 == _IdInput && _typeEvent == ewol::keyEvent::statusSingle) {
APPL_INFO("Event on List : IdInput=" << _IdInput << " colomn=" << _colomn << " raw=" << _raw );
if( _raw >= 0
&& _raw<m_list.size()
&& NULL != m_list[_raw]) {
2013-11-07 21:08:57 +01:00
if (m_list[_raw]->m_buffer != NULL) {
sendMultiCast(appl::MsgSelectNewFile, m_list[_raw]->m_buffer->getFileName());
m_selectedID = _raw;
markToRedraw();
return true;
}
}
}
return false;
}