edn/sources/appl/Gui/BufferView.cpp

261 lines
7.2 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-10-09 22:00:24 +02:00
static void SortElementList(etk::Vector<appl::dataBufferStruct*>& _list) {
etk::Vector<appl::dataBufferStruct *> tmpList = _list;
_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);
_list.insert(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);
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;
}
appl::dataBufferStruct* tmp = new appl::dataBufferStruct(_msg.getData(), buffer);
if (tmp == NULL) {
APPL_ERROR("Allocation error of the tmp buffer list element");
return;
}
m_list.pushBack(tmp);
markToRedraw();
}
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-10-07 22:04:21 +02:00
m_list.pushBack(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;
}
m_list.remove(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-10-09 22:00:24 +02:00
bool BufferView::getTitle(int32_t _colomn, etk::UString &_myTitle, etk::Color<> &_fg, etk::Color<> &_bg) {
_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-10-09 22:00:24 +02:00
bool BufferView::getElement(int32_t _colomn, int32_t _raw, etk::UString& _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();
/*
if (true == m_list[_raw]->m_isModify) {
_fg = (*m_paintingProperties)[m_colorTextModify].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_selectedIdRequested == m_list[_raw]->m_bufferID) {
m_selectedID = _raw;
// stop searching
m_selectedIdRequested = -1;
// set the raw visible :
setRawVisible(m_selectedID);
}
*/
/*
if (m_selectedID == _raw) {
_bg = (*m_paintingProperties)[m_colorBackgroundSelect].getForeground();
}
*/
} else {
_myTextToWrite = "ERROR";
}
2013-10-23 21:19:30 +02:00
/*
bool isModify;
basicColor_te selectFG = COLOR_LIST_TEXT_NORMAL;
basicColor_te selectBG = COLOR_LIST_BG_1;
2013-10-07 22:04:21 +02:00
// when requested a new display selection == > reset the previous one ...
if (m_selectedIdRequested != -1) {
m_selectedID = -1;
}
2013-10-09 22:00:24 +02:00
if( _raw >= 0
&& _raw<m_list.size()
&& NULL != m_list[_raw]) {
_myTextToWrite = m_list[_raw]->m_bufferName.getNameFile();
2013-10-09 22:00:24 +02:00
if (true == m_list[_raw]->m_isModify) {
selectFG = COLOR_LIST_TEXT_MODIFY;
} else {
selectFG = COLOR_LIST_TEXT_NORMAL;
}
2013-10-09 22:00:24 +02:00
if (_raw%2 == 0) {
selectBG = COLOR_LIST_BG_1;
} else {
selectBG = COLOR_LIST_BG_2;
}
// the buffer change of selection ...
2013-10-09 22:00:24 +02:00
if (m_selectedIdRequested == m_list[_raw]->m_bufferID) {
m_selectedID = _raw;
// stop searching
m_selectedIdRequested = -1;
// set the raw visible :
2013-10-07 22:04:21 +02:00
setRawVisible(m_selectedID);
}
2013-10-09 22:00:24 +02:00
if (m_selectedID == _raw) {
selectBG = COLOR_LIST_BG_SELECTED;
}
} else {
2013-10-09 22:00:24 +02:00
_myTextToWrite = "ERROR";
}
2013-10-09 22:00:24 +02:00
_fg = ColorizeManager::get(selectFG);
_bg = ColorizeManager::get(selectBG);
2013-10-23 21:19:30 +02:00
*/
return true;
}
2013-10-09 22:00:24 +02:00
bool BufferView::onItemEvent(int32_t _IdInput, ewol::keyEvent::status_te _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]) {
//m_selectedIdRequested = m_list[_raw]->m_buffer;
//sendMultiCast(ednMsgBufferId, m_list[_raw]->m_buffer);
}
}
2013-10-07 22:04:21 +02:00
markToRedraw();
return false;
}