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
|
|
|
*/
|
|
|
|
|
2013-10-25 20:49:26 +02:00
|
|
|
#include <appl/debug.h>
|
2012-04-24 09:42:14 +02:00
|
|
|
#include <appl/global.h>
|
2013-11-23 18:30:52 +01:00
|
|
|
#include <appl/Gui/BufferView.h>
|
|
|
|
#include <appl/BufferManager.h>
|
2013-10-25 22:12:34 +02:00
|
|
|
//#include <ColorizeManager.h>
|
2013-11-23 18:30:52 +01:00
|
|
|
#include <appl/Gui/MainWindows.h>
|
2013-12-13 21:50:40 +01:00
|
|
|
#include <ewol/object/Object.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-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();
|
2014-06-02 21:04:35 +02:00
|
|
|
for(size_t iii=0; iii<tmpList.size(); iii++) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (nullptr == tmpList[iii]) {
|
2013-10-09 22:00:24 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-06-02 21:04:35 +02:00
|
|
|
size_t findPos = 0;
|
|
|
|
for(size_t jjj=0; jjj<_list.size(); jjj++) {
|
2013-10-09 22:00:24 +02:00
|
|
|
//EWOL_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
|
2014-06-05 22:01:24 +02:00
|
|
|
if (_list[jjj] == nullptr) {
|
2013-10-09 22:00:24 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
BufferView::BufferView() :
|
2013-11-25 21:03:21 +01:00
|
|
|
m_openOrderMode(false) {
|
2013-11-20 21:57:00 +01:00
|
|
|
addObjectType("appl::BufferView");
|
2013-10-07 22:04:21 +02:00
|
|
|
setCanHaveFocus(true);
|
2011-07-20 10:33:24 +02:00
|
|
|
m_selectedID = -1;
|
2012-05-10 17:48:23 +02:00
|
|
|
m_selectedIdRequested = -1;
|
2013-10-30 21:16:38 +01:00
|
|
|
// load buffer manager:
|
2014-08-07 23:41:48 +02:00
|
|
|
m_bufferManager = appl::BufferManager::create();
|
2013-10-30 21:16:38 +01:00
|
|
|
// load color properties
|
2014-08-07 23:41:48 +02:00
|
|
|
m_paintingProperties = appl::GlyphPainting::create("THEME:COLOR:bufferList.json");
|
2013-10-30 21:16:38 +01:00
|
|
|
// 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");
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:41:48 +02:00
|
|
|
void BufferView::init() {
|
|
|
|
ewol::widget::List::init();
|
2014-08-25 22:44:42 +02:00
|
|
|
if (m_bufferManager != nullptr) {
|
|
|
|
m_bufferManager->signalNewBuffer.bind(shared_from_this(), &BufferView::onCallbackNewBuffer);
|
|
|
|
m_bufferManager->signalSelectFile.bind(shared_from_this(), &BufferView::onCallbackselectNewFile);
|
|
|
|
}
|
2014-08-07 23:41:48 +02:00
|
|
|
}
|
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
BufferView::~BufferView() {
|
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
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
void BufferView::removeAllElement() {
|
2014-06-02 21:04:35 +02:00
|
|
|
for(auto &it : m_list) {
|
|
|
|
delete(it);
|
2014-06-05 22:01:24 +02:00
|
|
|
it = nullptr;
|
2012-10-18 11:09:19 +02:00
|
|
|
}
|
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-11-25 21:03:21 +01:00
|
|
|
void BufferView::insertAlphabetic(appl::dataBufferStruct* _dataStruct, bool _selectNewPosition) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (_dataStruct == nullptr) {
|
2013-11-25 21:03:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// alphabetical order:
|
|
|
|
for (size_t iii = 0; iii < m_list.size(); ++iii) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (m_list[iii] == nullptr) {
|
2013-11-25 21:03:21 +01:00
|
|
|
continue;
|
|
|
|
}
|
2014-08-13 22:30:47 +02:00
|
|
|
if (etk::tolower(m_list[iii]->m_bufferName.getNameFile()) > etk::tolower(_dataStruct->m_bufferName.getNameFile())) {
|
2013-11-25 21:03:21 +01:00
|
|
|
m_list.insert(m_list.begin() + iii, _dataStruct);
|
2014-06-05 22:01:24 +02:00
|
|
|
_dataStruct = nullptr;
|
2013-11-25 21:03:21 +01:00
|
|
|
if (_selectNewPosition == true) {
|
|
|
|
m_selectedID = iii;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-05 22:01:24 +02:00
|
|
|
if (_dataStruct != nullptr) {
|
2013-11-25 21:03:21 +01:00
|
|
|
m_list.push_back(_dataStruct);
|
|
|
|
if (_selectNewPosition == true) {
|
|
|
|
m_selectedID = m_list.size()-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-25 22:44:42 +02:00
|
|
|
|
|
|
|
void BufferView::onCallbackNewBuffer(const std::string& _value) {
|
|
|
|
std::shared_ptr<appl::Buffer> buffer = m_bufferManager->get(_value);
|
|
|
|
if (buffer == nullptr) {
|
|
|
|
APPL_ERROR("event on element nor exist : " << _value);
|
2013-11-07 21:08:57 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-08-25 22:44:42 +02:00
|
|
|
buffer->signalIsSave.bind(shared_from_this(), &BufferView::onCallbackIsSave);
|
|
|
|
buffer->signalIsModify.bind(shared_from_this(), &BufferView::onCallbackIsModify);
|
|
|
|
buffer->signalChangeName.bind(shared_from_this(), &BufferView::onCallbackChangeName);
|
|
|
|
appl::dataBufferStruct* tmp = new appl::dataBufferStruct(_value, buffer);
|
|
|
|
if (tmp == nullptr) {
|
|
|
|
APPL_ERROR("Allocation error of the tmp buffer list element");
|
2013-11-07 21:08:57 +01:00
|
|
|
return;
|
2013-10-30 21:16:38 +01:00
|
|
|
}
|
2014-08-25 22:44:42 +02:00
|
|
|
if (m_openOrderMode == true) {
|
|
|
|
m_list.push_back(tmp);
|
|
|
|
} else {
|
|
|
|
insertAlphabetic(tmp);
|
|
|
|
}
|
|
|
|
markToRedraw();
|
|
|
|
}
|
|
|
|
void BufferView::onCallbackselectNewFile(const std::string& _value) {
|
|
|
|
m_selectedID = -1;
|
|
|
|
std::shared_ptr<appl::Buffer> tmpBuffer;
|
|
|
|
if (m_bufferManager != nullptr) {
|
|
|
|
tmpBuffer = m_bufferManager->getBufferSelected();
|
|
|
|
}
|
|
|
|
if (tmpBuffer != nullptr) {
|
|
|
|
for (size_t iii=0; iii<m_list.size(); iii++) {
|
|
|
|
if (m_list[iii] == nullptr) {
|
|
|
|
continue;
|
2012-10-18 11:09:19 +02:00
|
|
|
}
|
2014-08-25 22:44:42 +02:00
|
|
|
if (m_list[iii]->m_buffer != tmpBuffer) {
|
|
|
|
continue;
|
2012-10-18 11:09:19 +02:00
|
|
|
}
|
2014-08-25 22:44:42 +02:00
|
|
|
m_selectedID = iii;
|
|
|
|
break;
|
2012-10-18 11:09:19 +02:00
|
|
|
}
|
2012-02-03 18:14:45 +01:00
|
|
|
}
|
2014-08-25 22:44:42 +02:00
|
|
|
markToRedraw();
|
2012-02-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
2014-08-25 05:55:06 +02:00
|
|
|
void BufferView::onCallbackChangeName() {
|
|
|
|
for (size_t iii = 0; iii < m_list.size(); ++iii) {
|
|
|
|
if (m_list[iii] == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (m_list[iii]->m_bufferName != m_list[iii]->m_buffer->getFileName()) {
|
|
|
|
m_list[iii]->m_bufferName = m_list[iii]->m_buffer->getFileName();
|
|
|
|
if (m_openOrderMode == false) {
|
|
|
|
// re-order the fine in the correct position
|
|
|
|
appl::dataBufferStruct* tmp = m_list[iii];
|
|
|
|
m_list[iii] = nullptr;
|
|
|
|
m_list.erase(m_list.begin() + iii);
|
|
|
|
insertAlphabetic(tmp, ((int64_t)iii == m_selectedID));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
markToRedraw();
|
|
|
|
}
|
|
|
|
void BufferView::onCallbackIsSave() {
|
|
|
|
markToRedraw();
|
|
|
|
}
|
|
|
|
void BufferView::onCallbackIsModify() {
|
|
|
|
markToRedraw();
|
|
|
|
}
|
2012-02-03 18:14:45 +01:00
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
etk::Color<> BufferView::getBasicBG() {
|
2013-10-30 21:16:38 +01:00
|
|
|
return (*m_paintingProperties)[m_colorBackground1].getForeground();
|
2012-02-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
uint32_t BufferView::getNuberOfColomn() {
|
2012-02-03 18:14:45 +01:00
|
|
|
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 : ";
|
2012-02-03 18:14:45 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-15 21:37:39 +02:00
|
|
|
uint32_t BufferView::getNuberOfRaw() {
|
2013-10-07 22:04:21 +02:00
|
|
|
return m_list.size();
|
2012-02-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
|
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) {
|
2013-10-30 21:16:38 +01:00
|
|
|
if( _raw >= 0
|
2014-06-02 21:04:35 +02:00
|
|
|
&& _raw<(int64_t)m_list.size()
|
|
|
|
&& m_list[_raw] != nullptr) {
|
2013-10-30 21:16:38 +01:00
|
|
|
_myTextToWrite = m_list[_raw]->m_bufferName.getNameFile();
|
2013-11-07 21:08:57 +01:00
|
|
|
|
2014-06-05 22:01:24 +02:00
|
|
|
if ( m_list[_raw]->m_buffer != nullptr
|
2013-11-07 21:08:57 +01:00
|
|
|
&& m_list[_raw]->m_buffer->isModify() == false) {
|
|
|
|
_fg = (*m_paintingProperties)[m_colorTextNormal].getForeground();
|
|
|
|
} else {
|
2013-10-30 21:16:38 +01:00
|
|
|
_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";
|
|
|
|
}
|
2012-02-03 18:14:45 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-13 21:50:40 +01:00
|
|
|
bool BufferView::onItemEvent(int32_t _IdInput, enum ewol::key::status _typeEvent, int32_t _colomn, int32_t _raw, float _x, float _y)
|
2012-02-03 18:14:45 +01:00
|
|
|
{
|
2013-12-13 21:50:40 +01:00
|
|
|
if (1 == _IdInput && _typeEvent == ewol::key::statusSingle) {
|
2013-10-09 22:00:24 +02:00
|
|
|
APPL_INFO("Event on List : IdInput=" << _IdInput << " colomn=" << _colomn << " raw=" << _raw );
|
|
|
|
if( _raw >= 0
|
2014-06-02 21:04:35 +02:00
|
|
|
&& _raw<(int64_t)m_list.size()
|
2014-06-05 22:01:24 +02:00
|
|
|
&& nullptr != m_list[_raw]) {
|
|
|
|
if (m_list[_raw]->m_buffer != nullptr) {
|
2014-08-25 22:44:42 +02:00
|
|
|
if (m_bufferManager != nullptr) {
|
|
|
|
m_bufferManager->open(m_list[_raw]->m_buffer->getFileName());
|
|
|
|
}
|
2013-11-07 21:08:57 +01:00
|
|
|
m_selectedID = _raw;
|
|
|
|
markToRedraw();
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-03 18:14:45 +01:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|