2011-07-20 10:33:24 +02:00
|
|
|
/**
|
|
|
|
* @author Edouard DUPIN
|
2012-11-25 11:55:06 +01:00
|
|
|
*
|
|
|
|
* @copyright 2010, Edouard DUPIN, all right reserved
|
|
|
|
*
|
|
|
|
* @license GPL v3 (see license file)
|
2011-07-20 10:33:24 +02:00
|
|
|
*/
|
|
|
|
|
2012-04-23 10:15:43 +02:00
|
|
|
#include <appl/Debug.h>
|
2012-04-24 09:42:14 +02:00
|
|
|
#include <appl/global.h>
|
2012-01-11 15:26:53 +01:00
|
|
|
#include <BufferView.h>
|
|
|
|
#include <BufferManager.h>
|
|
|
|
#include <ColorizeManager.h>
|
|
|
|
#include <MainWindows.h>
|
2013-09-02 06:45:12 +02:00
|
|
|
#include <ewol/renderer/EObject.h>
|
2011-07-20 10:33:24 +02:00
|
|
|
|
|
|
|
#undef __class__
|
2013-10-09 22:00:24 +02:00
|
|
|
#define __class__ "BufferView"
|
2011-07-20 10:33:24 +02:00
|
|
|
|
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);
|
2011-07-20 10:33:24 +02:00
|
|
|
m_selectedID = -1;
|
2012-05-10 17:48:23 +02:00
|
|
|
m_selectedIdRequested = -1;
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
2013-10-09 22:00:24 +02:00
|
|
|
BufferView::~BufferView(void) {
|
2013-10-07 22:04:21 +02:00
|
|
|
removeAllElement();
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
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();
|
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() == 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:
|
|
|
|
int32_t nbBufferOpen = BufferManager::size();
|
2012-10-18 11:09:19 +02:00
|
|
|
for (int32_t iii=0; iii<nbBufferOpen; iii++) {
|
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);
|
2012-11-20 22:16:30 +01:00
|
|
|
if (NULL != tmpBuffer) {
|
2013-10-07 22:04:21 +02:00
|
|
|
bool isModify = tmpBuffer->isModify();
|
|
|
|
etk::FSNode name = tmpBuffer->getFileName();
|
2012-11-20 22:16:30 +01:00
|
|
|
appl::dataBufferStruct* tmpElement = new appl::dataBufferStruct(name, iii, isModify);
|
|
|
|
if (NULL != tmpElement) {
|
2013-10-07 22:04:21 +02:00
|
|
|
m_list.pushBack(tmpElement);
|
2012-11-20 22:16:30 +01:00
|
|
|
} else {
|
|
|
|
APPL_ERROR("Allocation error of the tmp buffer list element");
|
|
|
|
}
|
2012-10-18 11:09:19 +02:00
|
|
|
}
|
2013-10-09 22:00:24 +02: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) {
|
|
|
|
m_selectedIdRequested = BufferManager::getSelected();
|
|
|
|
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();
|
2012-02-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-09 22:00:24 +02:00
|
|
|
etk::Color<> BufferView::getBasicBG(void) {
|
2013-10-23 21:19:30 +02:00
|
|
|
return etk::color::none; //ColorizeManager::get(COLOR_LIST_BG_1);
|
2012-02-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
2013-10-09 22:00:24 +02:00
|
|
|
uint32_t BufferView::getNuberOfColomn(void) {
|
2012-02-03 18:14:45 +01:00
|
|
|
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 : ";
|
2012-02-03 18:14:45 +01:00
|
|
|
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();
|
2012-02-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
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) {
|
2013-10-23 21:19:30 +02:00
|
|
|
/*
|
2012-02-03 18:14:45 +01: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 ...
|
2012-05-10 17:48:23 +02:00
|
|
|
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();
|
2012-02-03 18:14:45 +01:00
|
|
|
|
2013-10-09 22:00:24 +02:00
|
|
|
if (true == m_list[_raw]->m_isModify) {
|
2012-02-03 18:14:45 +01:00
|
|
|
selectFG = COLOR_LIST_TEXT_MODIFY;
|
|
|
|
} else {
|
|
|
|
selectFG = COLOR_LIST_TEXT_NORMAL;
|
|
|
|
}
|
2013-10-09 22:00:24 +02:00
|
|
|
if (_raw%2 == 0) {
|
2012-02-03 18:14:45 +01:00
|
|
|
selectBG = COLOR_LIST_BG_1;
|
|
|
|
} else {
|
|
|
|
selectBG = COLOR_LIST_BG_2;
|
|
|
|
}
|
2012-05-10 17:48:23 +02:00
|
|
|
// the buffer change of selection ...
|
2013-10-09 22:00:24 +02:00
|
|
|
if (m_selectedIdRequested == m_list[_raw]->m_bufferID) {
|
|
|
|
m_selectedID = _raw;
|
2012-05-10 17:48:23 +02:00
|
|
|
// stop searching
|
|
|
|
m_selectedIdRequested = -1;
|
2013-06-12 22:58:11 +02:00
|
|
|
// set the raw visible :
|
2013-10-07 22:04:21 +02:00
|
|
|
setRawVisible(m_selectedID);
|
2012-05-10 17:48:23 +02:00
|
|
|
}
|
2013-10-09 22:00:24 +02:00
|
|
|
if (m_selectedID == _raw) {
|
2012-02-03 18:14:45 +01:00
|
|
|
selectBG = COLOR_LIST_BG_SELECTED;
|
|
|
|
}
|
|
|
|
} else {
|
2013-10-09 22:00:24 +02:00
|
|
|
_myTextToWrite = "ERROR";
|
2012-02-03 18:14:45 +01:00
|
|
|
}
|
2013-10-09 22:00:24 +02:00
|
|
|
_fg = ColorizeManager::get(selectFG);
|
|
|
|
_bg = ColorizeManager::get(selectBG);
|
2013-10-23 21:19:30 +02:00
|
|
|
*/
|
2012-02-03 18:14:45 +01: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)
|
2012-02-03 18:14:45 +01:00
|
|
|
{
|
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_bufferID;
|
|
|
|
sendMultiCast(ednMsgBufferId, m_list[_raw]->m_bufferID);
|
2012-02-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
markToRedraw();
|
2012-01-31 18:26:04 +01:00
|
|
|
return false;
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
2012-02-03 18:14:45 +01:00
|
|
|
|
|
|
|
|