@@ -17,20 +17,15 @@
|
||||
#undef __class__
|
||||
#define __class__ "BufferView"
|
||||
|
||||
static void SortElementList(std::vector<appl::dataBufferStruct*>& _list) {
|
||||
std::vector<appl::dataBufferStruct *> tmpList = _list;
|
||||
// TODO : write it better
|
||||
static void SortElementList(std::vector<appl::dataBufferStruct>& _list) {
|
||||
std::vector<appl::dataBufferStruct> tmpList = _list;
|
||||
_list.clear();
|
||||
for(size_t iii=0; iii<tmpList.size(); iii++) {
|
||||
if (nullptr == tmpList[iii]) {
|
||||
continue;
|
||||
}
|
||||
size_t findPos = 0;
|
||||
for(size_t jjj=0; jjj<_list.size(); jjj++) {
|
||||
//EWOL_DEBUG("compare : \""<<*tmpList[iii] << "\" and \"" << *m_listDirectory[jjj] << "\"");
|
||||
if (_list[jjj] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (tmpList[iii]->m_bufferName.getNameFile() > _list[jjj]->m_bufferName.getNameFile()) {
|
||||
if (tmpList[iii].m_bufferName.getNameFile() > _list[jjj].m_bufferName.getNameFile()) {
|
||||
findPos = jjj+1;
|
||||
}
|
||||
}
|
||||
@@ -62,6 +57,7 @@ void BufferView::init() {
|
||||
if (m_bufferManager != nullptr) {
|
||||
m_bufferManager->signalNewBuffer.bind(shared_from_this(), &BufferView::onCallbackNewBuffer);
|
||||
m_bufferManager->signalSelectFile.bind(shared_from_this(), &BufferView::onCallbackselectNewFile);
|
||||
m_bufferManager->signalRemoveBuffer.bind(shared_from_this(), &BufferView::onCallbackBufferRemoved);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,36 +66,23 @@ BufferView::~BufferView() {
|
||||
}
|
||||
|
||||
void BufferView::removeAllElement() {
|
||||
for(auto &it : m_list) {
|
||||
delete(it);
|
||||
it = nullptr;
|
||||
}
|
||||
m_list.clear();
|
||||
}
|
||||
|
||||
void BufferView::insertAlphabetic(appl::dataBufferStruct* _dataStruct, bool _selectNewPosition) {
|
||||
if (_dataStruct == nullptr) {
|
||||
return;
|
||||
}
|
||||
void BufferView::insertAlphabetic(const appl::dataBufferStruct& _dataStruct, bool _selectNewPosition) {
|
||||
// alphabetical order:
|
||||
for (size_t iii = 0; iii < m_list.size(); ++iii) {
|
||||
if (m_list[iii] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (etk::tolower(m_list[iii]->m_bufferName.getNameFile()) > etk::tolower(_dataStruct->m_bufferName.getNameFile())) {
|
||||
if (etk::tolower(m_list[iii].m_bufferName.getNameFile()) > etk::tolower(_dataStruct.m_bufferName.getNameFile())) {
|
||||
m_list.insert(m_list.begin() + iii, _dataStruct);
|
||||
_dataStruct = nullptr;
|
||||
if (_selectNewPosition == true) {
|
||||
m_selectedID = iii;
|
||||
}
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (_dataStruct != nullptr) {
|
||||
m_list.push_back(_dataStruct);
|
||||
if (_selectNewPosition == true) {
|
||||
m_selectedID = m_list.size()-1;
|
||||
}
|
||||
m_list.push_back(_dataStruct);
|
||||
if (_selectNewPosition == true) {
|
||||
m_selectedID = m_list.size()-1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,11 +95,7 @@ void BufferView::onCallbackNewBuffer(const std::string& _value) {
|
||||
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");
|
||||
return;
|
||||
}
|
||||
appl::dataBufferStruct tmp(_value, buffer);
|
||||
if (m_openOrderMode == true) {
|
||||
m_list.push_back(tmp);
|
||||
} else {
|
||||
@@ -129,13 +108,10 @@ void BufferView::onCallbackNewBuffer(const std::string& _value) {
|
||||
void BufferView::onCallbackselectNewFile(const std::string& _value) {
|
||||
m_selectedID = -1;
|
||||
for (size_t iii=0; iii<m_list.size(); iii++) {
|
||||
if (m_list[iii] == nullptr) {
|
||||
if (m_list[iii].m_buffer == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (m_list[iii]->m_buffer == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (m_list[iii]->m_buffer->getFileName() != _value) {
|
||||
if (m_list[iii].m_buffer->getFileName() != _value) {
|
||||
continue;
|
||||
}
|
||||
m_selectedID = iii;
|
||||
@@ -146,15 +122,11 @@ void BufferView::onCallbackselectNewFile(const std::string& _value) {
|
||||
|
||||
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_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;
|
||||
appl::dataBufferStruct tmp = m_list[iii];
|
||||
m_list.erase(m_list.begin() + iii);
|
||||
insertAlphabetic(tmp, ((int64_t)iii == m_selectedID));
|
||||
break;
|
||||
@@ -164,6 +136,19 @@ void BufferView::onCallbackChangeName() {
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
void BufferView::onCallbackBufferRemoved(const std::shared_ptr<appl::Buffer>& _buffer) {
|
||||
APPL_ERROR("request remove buffer:");
|
||||
auto it = m_list.begin();
|
||||
while (it != m_list.end()) {
|
||||
if (it->m_buffer == _buffer) {
|
||||
it = m_list.erase(it);
|
||||
m_selectedID = -1;
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
markToRedraw();
|
||||
}
|
||||
void BufferView::onCallbackIsSave() {
|
||||
markToRedraw();
|
||||
}
|
||||
@@ -190,12 +175,11 @@ uint32_t BufferView::getNuberOfRaw() {
|
||||
|
||||
bool BufferView::getElement(int32_t _colomn, int32_t _raw, std::string& _myTextToWrite, etk::Color<>& _fg, etk::Color<>& _bg) {
|
||||
if( _raw >= 0
|
||||
&& _raw<(int64_t)m_list.size()
|
||||
&& m_list[_raw] != nullptr) {
|
||||
_myTextToWrite = m_list[_raw]->m_bufferName.getNameFile();
|
||||
&& _raw<(int64_t)m_list.size() ) {
|
||||
_myTextToWrite = m_list[_raw].m_bufferName.getNameFile();
|
||||
|
||||
if ( m_list[_raw]->m_buffer != nullptr
|
||||
&& m_list[_raw]->m_buffer->isModify() == false) {
|
||||
if ( m_list[_raw].m_buffer != nullptr
|
||||
&& m_list[_raw].m_buffer->isModify() == false) {
|
||||
_fg = (*m_paintingProperties)[m_colorTextNormal].getForeground();
|
||||
} else {
|
||||
_fg = (*m_paintingProperties)[m_colorTextModify].getForeground();
|
||||
@@ -219,12 +203,11 @@ bool BufferView::onItemEvent(int32_t _IdInput, enum ewol::key::status _typeEvent
|
||||
if (1 == _IdInput && _typeEvent == ewol::key::statusSingle) {
|
||||
APPL_INFO("Event on List : IdInput=" << _IdInput << " colomn=" << _colomn << " raw=" << _raw );
|
||||
if( _raw >= 0
|
||||
&& _raw<(int64_t)m_list.size()
|
||||
&& nullptr != m_list[_raw]) {
|
||||
if (m_list[_raw]->m_buffer != nullptr) {
|
||||
&& _raw<(int64_t)m_list.size()) {
|
||||
if (m_list[_raw].m_buffer != nullptr) {
|
||||
if (m_bufferManager != nullptr) {
|
||||
APPL_INFO("Select file :" << m_list[_raw]->m_buffer->getFileName() << " in list");
|
||||
m_bufferManager->open(m_list[_raw]->m_buffer->getFileName());
|
||||
APPL_INFO("Select file :" << m_list[_raw].m_buffer->getFileName() << " in list");
|
||||
m_bufferManager->open(m_list[_raw].m_buffer->getFileName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@@ -42,12 +42,12 @@ class BufferView : public ewol::widget::List {
|
||||
private:
|
||||
int32_t m_selectedIdRequested;
|
||||
int32_t m_selectedID;
|
||||
std::vector<appl::dataBufferStruct*> m_list;
|
||||
std::vector<appl::dataBufferStruct> m_list;
|
||||
/**
|
||||
* @brief Insert the element in the alphabetic order.
|
||||
* @param[in] _dataStruct element to add.
|
||||
*/
|
||||
void insertAlphabetic(appl::dataBufferStruct* _dataStruct, bool _selectNewPosition = false);
|
||||
void insertAlphabetic(const appl::dataBufferStruct& _dataStruct, bool _selectNewPosition = false);
|
||||
protected:
|
||||
// Constructeur
|
||||
BufferView();
|
||||
@@ -73,6 +73,7 @@ class BufferView : public ewol::widget::List {
|
||||
void onCallbackIsModify();
|
||||
void onCallbackNewBuffer(const std::string& _value);
|
||||
void onCallbackselectNewFile(const std::string& _value);
|
||||
void onCallbackBufferRemoved(const std::shared_ptr<appl::Buffer>& _buffer);
|
||||
};
|
||||
|
||||
|
||||
|
@@ -255,7 +255,8 @@ void MainWindows::onCallbackMenuEvent(const std::string& _value) {
|
||||
} else if (_value == "menu:open") {
|
||||
displayOpen();
|
||||
} else if (_value == "menu:close") {
|
||||
appl::WorkerCloseFile::create("");
|
||||
std::shared_ptr<appl::WorkerCloseFile> worker = appl::WorkerCloseFile::create();
|
||||
worker->startAction("");
|
||||
} else if (_value == "menu:close-all") {
|
||||
appl::WorkerCloseAllFile::create();
|
||||
} else if (_value == "menu:save") {
|
||||
|
@@ -91,16 +91,23 @@ void appl::TextViewer::onCallbackselectNewFile(const std::string& _value) {
|
||||
if (m_buffer != nullptr) {
|
||||
m_buffer->unBindAll(shared_from_this());
|
||||
bool needAdd = true;
|
||||
for (size_t iii=0; iii<m_drawingRemenber.size(); ++iii) {
|
||||
if (m_drawingRemenber[iii].first == m_buffer) {
|
||||
m_drawingRemenber[iii].second = m_originScrooled;
|
||||
auto it = m_drawingRemenber.begin();
|
||||
while (it != m_drawingRemenber.end()) {
|
||||
std::shared_ptr<appl::Buffer> tmpBuff = it->first.lock();
|
||||
if (tmpBuff == nullptr) {
|
||||
it = m_drawingRemenber.erase(it);
|
||||
continue;
|
||||
}
|
||||
if (tmpBuff == m_buffer) {
|
||||
it->second = m_originScrooled;
|
||||
APPL_VERBOSE("store origin : " << m_originScrooled);
|
||||
needAdd = false;
|
||||
break;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
if (needAdd == true) {
|
||||
m_drawingRemenber.push_back(std::make_pair(m_buffer, m_originScrooled));
|
||||
m_drawingRemenber.push_back(std::make_pair(std::weak_ptr<appl::Buffer>(m_buffer), m_originScrooled));
|
||||
APPL_VERBOSE("Push origin : " << m_originScrooled);
|
||||
}
|
||||
}
|
||||
@@ -112,7 +119,7 @@ void appl::TextViewer::onCallbackselectNewFile(const std::string& _value) {
|
||||
m_buffer->signalIsModify.bind(shared_from_this(), &appl::TextViewer::onCallbackIsModify);
|
||||
m_buffer->signalSelectChange.bind(shared_from_this(), &appl::TextViewer::onCallbackSelectChange);
|
||||
for (auto element : m_drawingRemenber) {
|
||||
if (element.first == m_buffer) {
|
||||
if (element.first.lock() == m_buffer) {
|
||||
m_originScrooled = element.second;
|
||||
APPL_VERBOSE("retrive origin : " << m_originScrooled);
|
||||
// TODO : Check if this element is not out of the display text ...
|
||||
|
@@ -54,7 +54,7 @@ namespace appl {
|
||||
private:
|
||||
ewol::compositing::Text m_displayText; //!< Text display properties.
|
||||
ewol::compositing::Drawing m_displayDrawing; //!< Other diaplay requested.
|
||||
std::vector<std::pair<std::shared_ptr<appl::Buffer>, vec2>> m_drawingRemenber;
|
||||
std::vector<std::pair<std::weak_ptr<appl::Buffer>, vec2>> m_drawingRemenber;
|
||||
public:
|
||||
void setFontSize(int32_t _size);
|
||||
void setFontName(const std::string& _fontName);
|
||||
|
@@ -45,14 +45,15 @@ void appl::WorkerCloseAllFile::init() {
|
||||
return;
|
||||
}
|
||||
// create the worker :
|
||||
m_worker = appl::WorkerCloseFile::create(m_bufferNameList.front());
|
||||
m_worker = appl::WorkerCloseFile::create();
|
||||
m_worker->signalCloseDone.bind(shared_from_this(), &appl::WorkerCloseAllFile::onCallbackCloseDone);
|
||||
m_worker->startAction(m_bufferNameList.front());
|
||||
// remove first element :
|
||||
m_bufferNameList.erase(m_bufferNameList.begin());
|
||||
if (m_bufferNameList.size() == 0) {
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
m_worker->signalCloseDone.bind(shared_from_this(), &appl::WorkerCloseAllFile::onCallbackCloseDone);
|
||||
}
|
||||
|
||||
appl::WorkerCloseAllFile::~WorkerCloseAllFile() {
|
||||
@@ -69,13 +70,14 @@ void appl::WorkerCloseAllFile::onCallbackCloseDone() {
|
||||
return;
|
||||
}
|
||||
// create the worker :
|
||||
m_worker = appl::WorkerCloseFile::create(m_bufferNameList.front());
|
||||
m_worker = appl::WorkerCloseFile::create();
|
||||
m_worker->signalCloseDone.bind(shared_from_this(), &appl::WorkerCloseAllFile::onCallbackCloseDone);
|
||||
m_worker->startAction(m_bufferNameList.front());
|
||||
// remove first element :
|
||||
m_bufferNameList.erase(m_bufferNameList.begin());
|
||||
if (m_bufferNameList.size() == 0) {
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
m_worker->signalCloseDone.bind(shared_from_this(), &appl::WorkerCloseAllFile::onCallbackCloseDone);
|
||||
}
|
||||
|
||||
|
@@ -25,8 +25,11 @@ appl::WorkerCloseFile::WorkerCloseFile() :
|
||||
m_bufferManager = appl::BufferManager::create();
|
||||
}
|
||||
|
||||
void appl::WorkerCloseFile::init(const std::string& _bufferName) {
|
||||
void appl::WorkerCloseFile::init() {
|
||||
ewol::object::Worker::init();
|
||||
}
|
||||
|
||||
void appl::WorkerCloseFile::startAction(const std::string& _bufferName) {
|
||||
m_bufferName = _bufferName;
|
||||
if (m_bufferManager == nullptr) {
|
||||
APPL_ERROR("can not call unexistant buffer manager ... ");
|
||||
@@ -38,7 +41,7 @@ void appl::WorkerCloseFile::init(const std::string& _bufferName) {
|
||||
std::shared_ptr<appl::Buffer> tmpp = m_bufferManager->getBufferSelected();
|
||||
if (tmpp == nullptr) {
|
||||
APPL_ERROR("No selected buffer now ...");
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
m_bufferName = tmpp->getFileName();
|
||||
@@ -57,12 +60,14 @@ void appl::WorkerCloseFile::init(const std::string& _bufferName) {
|
||||
if (m_buffer->isModify() == false) {
|
||||
signalCloseDone.emit();
|
||||
m_buffer->destroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<ewol::widget::StdPopUp> tmpPopUp = ewol::widget::StdPopUp::create();
|
||||
if (tmpPopUp == nullptr) {
|
||||
APPL_ERROR("Can not create a simple pop-up");
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
tmpPopUp->setTitle("<bold>Close un-saved file:</bold>");
|
||||
|
@@ -22,10 +22,15 @@ namespace appl {
|
||||
protected:
|
||||
// note : if == "" ==> current ...
|
||||
WorkerCloseFile();
|
||||
void init(const std::string& _bufferName);
|
||||
void init();
|
||||
public:
|
||||
DECLARE_FACTORY(WorkerCloseFile);
|
||||
virtual ~WorkerCloseFile();
|
||||
public:
|
||||
/**
|
||||
* @brief Action to do
|
||||
*/
|
||||
void startAction(const std::string& _bufferName);
|
||||
private:
|
||||
std::string m_bufferName;
|
||||
std::shared_ptr<appl::Buffer> m_buffer; //!< reference on the buffer (when rename, we have no more reference on the buffer
|
||||
|
Reference in New Issue
Block a user