[DEV] new staep to owner

This commit is contained in:
Edouard DUPIN 2014-05-25 21:17:06 +02:00
parent d18b202e75
commit 2157099f0a
4 changed files with 34 additions and 23 deletions

View File

@ -42,12 +42,12 @@ ewol::object::Shared<appl::Buffer> appl::BufferManager::createNewBuffer() {
ewol::object::Shared<appl::Buffer> appl::BufferManager::get(const std::string& _fileName, bool _createIfNeeded) {
APPL_INFO("get(" << _fileName << "," << _createIfNeeded << ")");
for (int32_t iii = 0; iii < m_list.size(); ++iii) {
if (m_list[iii] == NULL) {
for (auto &it : m_list) {
if (it == NULL) {
continue;
}
if (m_list[iii]->getFileName() == _fileName) {
return m_list[iii];
if (it->getFileName() == _fileName) {
return it;
}
}
if (_createIfNeeded == true) {
@ -76,22 +76,32 @@ void appl::BufferManager::onObjectRemove(const ewol::object::Shared<ewol::Object
if (m_bufferSelected == _removeObject) {
setBufferSelected(NULL);
}
for (int32_t iii = 0; iii < m_list.size(); ++iii) {
if (m_list[iii] != _removeObject) {
for (auto it(m_list.begin()); it!=m_list.end(); ++it) {
if (*it != _removeObject) {
continue;
}
m_list[iii] = NULL;
m_list.erase(m_list.begin()+iii);
return;
m_list.erase(it);
it = m_list.begin();
}
}
ewol::object::Shared<appl::Buffer> appl::BufferManager::get(int32_t _id) {
int32_t id = 0;
for (auto it : m_list) {
if (id == _id) {
return it;
}
id++;
}
return m_list.back();
}
bool appl::BufferManager::exist(const std::string& _fileName) {
for (int32_t iii = 0; iii < m_list.size(); ++iii) {
if (m_list[iii] == NULL) {
for (auto it : m_list) {
if (it == nullptr) {
continue;
}
if (m_list[iii]->getFileName() == _fileName) {
if (it->getFileName() == _fileName) {
return true;
}
}

View File

@ -9,6 +9,7 @@
#ifndef __BUFFER_MANAGER_H__
#define __BUFFER_MANAGER_H__
#include <list>
#include <appl/Buffer.h>
#include <appl/globalMsg.h>
#include <ewol/widget/Widget.h>
@ -21,7 +22,7 @@ namespace appl {
public:
~BufferManager();
private:
std::vector<ewol::object::Shared<appl::Buffer>> m_list; // list of all buffer curently open
std::list<ewol::object::Owner<appl::Buffer>> m_list; // list of all buffer curently open
public:
/**
* @brief Get a specific buffer with his name (can create a new buffer).
@ -53,9 +54,7 @@ namespace appl {
* @param[in] _id Number of buffer
* @return pointer on the buffer
*/
ewol::object::Shared<appl::Buffer> get(int32_t _id) {
return m_list[_id];
}
ewol::object::Shared<appl::Buffer> get(int32_t _id);
/**
* @brief Create a new buffer empty.
* @return Created buffer or NULL.

View File

@ -15,10 +15,8 @@
#include <ewol/widget/List.h>
#include <ewol/widget/Windows.h>
namespace appl
{
class dataBufferStruct
{
namespace appl {
class dataBufferStruct {
public:
etk::FSNode m_bufferName;
ewol::object::Shared<appl::Buffer> m_buffer;
@ -31,8 +29,7 @@ namespace appl
};
};
class BufferView : public ewol::widget::List
{
class BufferView : public ewol::widget::List {
private:
ewol::object::Shared<appl::BufferManager> m_bufferManager; //!< handle on the buffer manager
private:

View File

@ -116,7 +116,12 @@ namespace appl {
};
public:
virtual void onObjectRemove(const ewol::object::Shared<ewol::Object>& _removeObject) {
// TODO : plop
for (auto it(m_specificData.begin()); it != m_specificData.end(); ++it) {
if (it->first == _removeObject) {
m_specificData.erase(it);
it = m_specificData.begin();
}
}
};
};
};