[DEV] Reorder BufferView
This commit is contained in:
parent
b3ffe8c212
commit
771a8826c4
@ -39,7 +39,8 @@ static void SortElementList(std::vector<appl::dataBufferStruct*>& _list) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferView::BufferView(void) {
|
BufferView::BufferView(void) :
|
||||||
|
m_openOrderMode(false) {
|
||||||
addObjectType("appl::BufferView");
|
addObjectType("appl::BufferView");
|
||||||
setCanHaveFocus(true);
|
setCanHaveFocus(true);
|
||||||
registerMultiCast(ednMsgBufferListChange);
|
registerMultiCast(ednMsgBufferListChange);
|
||||||
@ -79,6 +80,33 @@ void BufferView::removeAllElement(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BufferView::insertAlphabetic(appl::dataBufferStruct* _dataStruct, bool _selectNewPosition) {
|
||||||
|
if (_dataStruct == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// alphabetical order:
|
||||||
|
for (size_t iii = 0; iii < m_list.size(); ++iii) {
|
||||||
|
if (m_list[iii] == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (to_lower(m_list[iii]->m_bufferName.getNameFile()) > to_lower(_dataStruct->m_bufferName.getNameFile())) {
|
||||||
|
m_list.insert(m_list.begin() + iii, _dataStruct);
|
||||||
|
_dataStruct = NULL;
|
||||||
|
if (_selectNewPosition == true) {
|
||||||
|
m_selectedID = iii;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_dataStruct != NULL) {
|
||||||
|
m_list.push_back(_dataStruct);
|
||||||
|
if (_selectNewPosition == true) {
|
||||||
|
m_selectedID = m_list.size()-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void BufferView::onReceiveMessage(const ewol::EMessage& _msg) {
|
void BufferView::onReceiveMessage(const ewol::EMessage& _msg) {
|
||||||
widget::List::onReceiveMessage(_msg);
|
widget::List::onReceiveMessage(_msg);
|
||||||
if (_msg.getMessage() == appl::MsgSelectNewFile) {
|
if (_msg.getMessage() == appl::MsgSelectNewFile) {
|
||||||
@ -95,16 +123,30 @@ void BufferView::onReceiveMessage(const ewol::EMessage& _msg) {
|
|||||||
APPL_ERROR("Allocation error of the tmp buffer list element");
|
APPL_ERROR("Allocation error of the tmp buffer list element");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_list.push_back(tmp);
|
if (m_openOrderMode == true) {
|
||||||
|
m_list.push_back(tmp);
|
||||||
|
} else {
|
||||||
|
insertAlphabetic(tmp);
|
||||||
|
}
|
||||||
markToRedraw();
|
markToRedraw();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_msg.getMessage() == appl::Buffer::eventChangeName) {
|
if (_msg.getMessage() == appl::Buffer::eventChangeName) {
|
||||||
for (auto element : m_list) {
|
for (size_t iii = 0; iii < m_list.size(); ++iii) {
|
||||||
if (element == NULL) {
|
if (m_list[iii] == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
element->m_bufferName = element->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] = NULL;
|
||||||
|
m_list.erase(m_list.begin() + iii);
|
||||||
|
insertAlphabetic(tmp, (iii == m_selectedID));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
markToRedraw();
|
markToRedraw();
|
||||||
return;
|
return;
|
||||||
|
@ -46,15 +46,20 @@ class BufferView : public widget::List
|
|||||||
int32_t m_selectedIdRequested;
|
int32_t m_selectedIdRequested;
|
||||||
int32_t m_selectedID;
|
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);
|
||||||
public:
|
public:
|
||||||
// Constructeur
|
// Constructeur
|
||||||
BufferView(void);
|
BufferView(void);
|
||||||
~BufferView(void);
|
~BufferView(void);
|
||||||
// Derived function
|
// Derived function
|
||||||
const char * const getObjectType(void) { return "ApplBufferView"; };
|
|
||||||
// Derived function
|
|
||||||
virtual void onReceiveMessage(const ewol::EMessage& _msg);
|
virtual void onReceiveMessage(const ewol::EMessage& _msg);
|
||||||
virtual void onObjectRemove(ewol::EObject* _removeObject);
|
virtual void onObjectRemove(ewol::EObject* _removeObject);
|
||||||
|
private:
|
||||||
|
bool m_openOrderMode; //!< true if the order is the opening order mode, otherwise, Alphabetic order
|
||||||
protected:
|
protected:
|
||||||
// function call to display the list :
|
// function call to display the list :
|
||||||
virtual etk::Color<> getBasicBG(void);
|
virtual etk::Color<> getBasicBG(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user