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 <BufferManager.h>
|
2013-09-02 06:45:12 +02:00
|
|
|
#include <ewol/renderer/EObject.h>
|
|
|
|
#include <ewol/renderer/EObjectManager.h>
|
2011-07-20 10:33:24 +02:00
|
|
|
|
|
|
|
#undef __class__
|
2012-02-20 20:30:26 +01:00
|
|
|
#define __class__ "classBufferManager"
|
|
|
|
|
2012-02-29 18:06:08 +01:00
|
|
|
class classBufferManager: public ewol::EObject
|
2012-02-20 20:30:26 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructeur
|
|
|
|
classBufferManager(void);
|
|
|
|
~classBufferManager(void);
|
2012-03-14 09:26:14 +01:00
|
|
|
const char * const GetObjectType(void)
|
|
|
|
{
|
2012-07-24 17:48:18 +02:00
|
|
|
return "ApplBufferManager";
|
2012-03-14 09:26:14 +01:00
|
|
|
}
|
2012-02-20 20:30:26 +01:00
|
|
|
public:
|
2013-05-12 21:08:31 +02:00
|
|
|
virtual void OnReceiveMessage(const ewol::EMessage& _msg);
|
2012-02-20 20:30:26 +01:00
|
|
|
private:
|
|
|
|
// return the ID of the buffer allocated
|
|
|
|
// create a buffer with no element
|
|
|
|
int32_t Create(void);
|
|
|
|
// open curent filename
|
2012-11-01 10:47:36 +01:00
|
|
|
int32_t Open(etk::FSNode &myFile);
|
2012-02-20 20:30:26 +01:00
|
|
|
bool Remove(int32_t BufferID);
|
|
|
|
public:
|
|
|
|
int32_t GetSelected(void) { return m_idSelected;};
|
|
|
|
//void SetSelected(int32_t id) {m_idSelected = id;};
|
2012-11-20 22:16:30 +01:00
|
|
|
BufferText* Get(int32_t BufferID);
|
2012-02-20 20:30:26 +01:00
|
|
|
bool Exist(int32_t BufferID);
|
2012-11-01 10:47:36 +01:00
|
|
|
bool Exist(etk::FSNode &myFile);
|
|
|
|
int32_t GetId(etk::FSNode &myFile);
|
2012-02-20 20:30:26 +01:00
|
|
|
// return the number of buffer (open in the past) if 5 buffer open and 4 close ==> return 5
|
|
|
|
uint32_t Size(void);
|
|
|
|
uint32_t SizeOpen(void);
|
|
|
|
int32_t WitchBuffer(int32_t iEmeElement);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2012-11-20 22:16:30 +01:00
|
|
|
etk::Vector<BufferText*> listBuffer; //!< element List of the char Elements
|
2012-02-20 20:30:26 +01:00
|
|
|
|
|
|
|
void RemoveAll(void); //!< remove all buffer
|
|
|
|
int32_t m_idSelected;
|
|
|
|
};
|
|
|
|
|
2011-07-20 10:33:24 +02:00
|
|
|
|
|
|
|
// Constructeur
|
2012-02-20 20:30:26 +01:00
|
|
|
classBufferManager::classBufferManager(void)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
|
|
|
m_idSelected = -1;
|
2012-02-29 18:06:08 +01:00
|
|
|
RegisterMultiCast(ednMsgGuiNew);
|
|
|
|
RegisterMultiCast(ednMsgOpenFile);
|
|
|
|
RegisterMultiCast(ednMsgGuiClose);
|
|
|
|
RegisterMultiCast(ednMsgGuiSave);
|
|
|
|
RegisterMultiCast(ednMsgCodeViewSelectedId);
|
|
|
|
RegisterMultiCast(ednMsgBufferId);
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
2012-02-20 20:30:26 +01:00
|
|
|
classBufferManager::~classBufferManager(void)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
|
|
|
//clean All Buffer
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_INFO("~classBufferManager::RemoveAll();");
|
2011-07-20 10:33:24 +02:00
|
|
|
RemoveAll();
|
|
|
|
// clear The list of Buffer
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_INFO("~classBufferManager::listBuffer.Clear();");
|
2012-08-09 14:26:30 +02:00
|
|
|
listBuffer.Clear();
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-12 21:08:31 +02:00
|
|
|
void classBufferManager::OnReceiveMessage(const ewol::EMessage& _msg)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
2013-05-12 21:08:31 +02:00
|
|
|
ewol::EObject::OnReceiveMessage(_msg);
|
2012-02-29 18:06:08 +01:00
|
|
|
|
2013-05-12 21:08:31 +02:00
|
|
|
if (_msg.GetMessage() == ednMsgBufferId) {
|
2012-02-14 19:29:53 +01:00
|
|
|
// select a new buffer ID :
|
2013-05-12 21:08:31 +02:00
|
|
|
if (_msg.GetData() == "") {
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_ERROR("Request select buffer ID = \"\" ");
|
2012-02-14 19:29:53 +01:00
|
|
|
} else {
|
|
|
|
int32_t newID = -1;
|
2013-05-12 21:08:31 +02:00
|
|
|
sscanf(_msg.GetData().c_str(), "%d", &newID);
|
2012-02-14 19:29:53 +01:00
|
|
|
if(true == Exist(newID)) {
|
|
|
|
m_idSelected = newID;
|
|
|
|
} else {
|
|
|
|
m_idSelected = -1;
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_ERROR("Request a non existant ID : " << newID << " reset to -1...");
|
2012-02-14 19:29:53 +01:00
|
|
|
}
|
|
|
|
}
|
2013-05-12 21:08:31 +02:00
|
|
|
} else if (_msg.GetMessage() == ednMsgGuiNew) {
|
2012-02-03 18:14:45 +01:00
|
|
|
int32_t newOne = Create();
|
|
|
|
if (-1 != newOne) {
|
2012-02-09 17:20:52 +01:00
|
|
|
m_idSelected = newOne;
|
2012-02-29 18:06:08 +01:00
|
|
|
SendMultiCast(ednMsgBufferId, m_idSelected);
|
|
|
|
SendMultiCast(ednMsgBufferListChange);
|
2012-02-03 18:14:45 +01:00
|
|
|
}
|
2013-05-12 21:08:31 +02:00
|
|
|
} else if (_msg.GetMessage() == ednMsgOpenFile) {
|
|
|
|
if (_msg.GetData() != "" ) {
|
|
|
|
etk::FSNode myFile(_msg.GetData());
|
2013-06-12 22:58:11 +02:00
|
|
|
if (myFile.GetNodeType() == etk::FSN_FILE) {
|
|
|
|
APPL_DEBUG("request open file = \"" << _msg.GetData() << "\" ?= \"" << myFile << "\"");
|
|
|
|
int32_t newOne = Open(myFile);
|
|
|
|
if (-1 != newOne) {
|
|
|
|
m_idSelected = newOne;
|
|
|
|
SendMultiCast(ednMsgBufferId, m_idSelected);
|
|
|
|
SendMultiCast(ednMsgBufferListChange);
|
|
|
|
} else {
|
|
|
|
// TODO : notify user that we can not open the request file...
|
|
|
|
APPL_ERROR("Can not open the file : \"" << myFile << "\"");
|
|
|
|
}
|
2012-05-10 17:47:52 +02:00
|
|
|
} else {
|
2013-06-12 22:58:11 +02:00
|
|
|
APPL_ERROR("Request to open an Unknox element file : " << myFile << " type:" << myFile.GetNodeType());
|
2012-02-05 22:03:36 +01:00
|
|
|
}
|
|
|
|
}
|
2013-05-12 21:08:31 +02:00
|
|
|
} else if (_msg.GetMessage() == ednMsgGuiSave) {
|
|
|
|
if (_msg.GetData() == "") {
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_ERROR("Null data for close file ... ");
|
2012-02-09 17:20:52 +01:00
|
|
|
} else {
|
2013-05-12 21:08:31 +02:00
|
|
|
if (_msg.GetData() == "current") {
|
2012-02-09 17:20:52 +01:00
|
|
|
// Check buffer existence
|
|
|
|
if(true == Exist(m_idSelected)) {
|
|
|
|
// If no name ==> request a Gui display ...
|
|
|
|
if (Get(m_idSelected)->HaveName() == false) {
|
2012-02-29 18:06:08 +01:00
|
|
|
SendMultiCast(ednMsgGuiSaveAs, "current");
|
2012-02-09 17:20:52 +01:00
|
|
|
} else {
|
|
|
|
Get(m_idSelected)->Save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int32_t newId;
|
2013-05-12 21:08:31 +02:00
|
|
|
sscanf(_msg.GetData().c_str(), "%d", &newId);
|
2012-02-09 17:20:52 +01:00
|
|
|
if (false == Exist(newId)) {
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_ERROR("Request a save As with a non existant ID=" << newId);
|
2012-02-09 17:20:52 +01:00
|
|
|
} else {
|
|
|
|
// If no name ==> request a Gui display ...
|
|
|
|
if (Get(newId)->HaveName() == false) {
|
2012-02-29 18:06:08 +01:00
|
|
|
SendMultiCast(ednMsgGuiSaveAs, newId);
|
2012-02-09 17:20:52 +01:00
|
|
|
} else {
|
|
|
|
Get(m_idSelected)->Save();
|
|
|
|
}
|
|
|
|
}
|
2012-02-29 18:06:08 +01:00
|
|
|
SendMultiCast(ednMsgBufferState, "saved");
|
2012-02-09 17:20:52 +01:00
|
|
|
}
|
|
|
|
}
|
2013-05-12 21:08:31 +02:00
|
|
|
} else if (_msg.GetMessage() == ednMsgGuiClose) {
|
|
|
|
if (_msg.GetData() == "") {
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_ERROR("Null data for close file ... ");
|
2012-02-08 18:05:19 +01:00
|
|
|
} else {
|
2013-05-12 21:08:31 +02:00
|
|
|
if (_msg.GetData() == "All") {
|
2012-02-08 18:05:19 +01:00
|
|
|
|
2012-02-14 19:29:53 +01:00
|
|
|
} else {
|
|
|
|
int32_t closeID = -1;
|
2013-05-12 21:08:31 +02:00
|
|
|
if (_msg.GetData() == "current") {
|
2012-02-14 19:29:53 +01:00
|
|
|
closeID = m_idSelected;
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_DEBUG("Close specific buffer ID" << closeID);
|
2012-02-14 19:29:53 +01:00
|
|
|
} else {
|
|
|
|
// close specific buffer ...
|
2013-05-12 21:08:31 +02:00
|
|
|
sscanf(_msg.GetData().c_str(), "%d", &closeID);
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_DEBUG("Close specific buffer ID="<< closeID);
|
2012-02-14 19:29:53 +01:00
|
|
|
}
|
|
|
|
if(true == Exist(closeID)) {
|
|
|
|
// Get the new display buffer
|
|
|
|
if (m_idSelected == closeID) {
|
|
|
|
// Try previous buffer
|
|
|
|
int32_t destBuffer = -1;
|
|
|
|
for(int32_t ii=closeID-1; ii >= 0; ii--) {
|
|
|
|
if (true == Exist(ii) ) {
|
|
|
|
destBuffer = ii;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// try next buffer
|
|
|
|
if (-1 == destBuffer) {
|
2012-08-09 14:26:30 +02:00
|
|
|
for(int32_t ii=closeID+1; ii < listBuffer.Size(); ii++) {
|
2012-02-14 19:29:53 +01:00
|
|
|
if (true == Exist(ii) ) {
|
|
|
|
destBuffer = ii;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// set it to the currect display
|
|
|
|
m_idSelected = destBuffer;
|
2012-05-12 08:58:05 +02:00
|
|
|
SendMultiCast(ednMsgBufferId, destBuffer);
|
2012-02-14 19:29:53 +01:00
|
|
|
}
|
|
|
|
// Remove requested buffer
|
|
|
|
Remove(closeID);
|
2012-02-29 18:06:08 +01:00
|
|
|
SendMultiCast(ednMsgBufferListChange);
|
2012-02-14 19:29:53 +01:00
|
|
|
} else {
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_ERROR("Request Close of a non existant ID : " << closeID);
|
2012-02-14 19:29:53 +01:00
|
|
|
}
|
2012-02-08 18:05:19 +01:00
|
|
|
}
|
|
|
|
}
|
2013-05-12 21:08:31 +02:00
|
|
|
} else if (_msg.GetMessage() == ednMsgCodeViewSelectedId) {
|
2012-02-09 17:20:52 +01:00
|
|
|
//Change the selected buffer
|
2013-05-12 21:08:31 +02:00
|
|
|
if (_msg.GetData() == "") {
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_ERROR("Null data for changing buffer ID file ... ");
|
2012-02-09 17:20:52 +01:00
|
|
|
} else {
|
|
|
|
int32_t newId;
|
2013-05-12 21:08:31 +02:00
|
|
|
sscanf(_msg.GetData().c_str(), "%d", &newId);
|
2012-02-09 17:20:52 +01:00
|
|
|
if (true == Exist(newId)) {
|
|
|
|
m_idSelected = newId;
|
|
|
|
} else {
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_ERROR("code biew request the selection of an non -existant buffer ==> reset to -1");
|
2012-02-09 17:20:52 +01:00
|
|
|
m_idSelected = -1;
|
|
|
|
}
|
2012-02-29 18:06:08 +01:00
|
|
|
SendMultiCast(ednMsgBufferId, m_idSelected);
|
|
|
|
SendMultiCast(ednMsgBufferListChange);
|
2012-02-09 17:20:52 +01:00
|
|
|
}
|
2012-02-03 18:14:45 +01:00
|
|
|
}
|
2012-01-31 18:26:04 +01:00
|
|
|
/*
|
2011-07-20 10:33:24 +02:00
|
|
|
switch (id)
|
|
|
|
{
|
2011-08-03 14:39:39 +02:00
|
|
|
// Check buffer existence
|
|
|
|
if(true == Exist(dataID)) {
|
|
|
|
// If no name ==> request a Gui display ...
|
|
|
|
if (Get(dataID)->HaveName() == false) {
|
2012-04-23 10:15:43 +02:00
|
|
|
SendMessage(APPL_MSG__GUI_SHOW_SAVE_AS, dataID);
|
2011-08-03 14:39:39 +02:00
|
|
|
} else {
|
|
|
|
Get(dataID)->Save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
2012-01-31 18:26:04 +01:00
|
|
|
*/
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Remove all buffer opened
|
|
|
|
*
|
|
|
|
* @param[in,out] ---
|
|
|
|
*
|
|
|
|
* @return ---
|
|
|
|
*
|
|
|
|
*/
|
2012-02-20 20:30:26 +01:00
|
|
|
void classBufferManager::RemoveAll(void)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
|
|
|
int32_t i;
|
2012-08-09 14:26:30 +02:00
|
|
|
for (i=0; i<listBuffer.Size(); i++) {
|
2011-07-20 10:33:24 +02:00
|
|
|
Remove(i);
|
|
|
|
}
|
2012-02-29 18:06:08 +01:00
|
|
|
SendMultiCast(ednMsgGuiClose, "All");
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Create a new buffer with no name and empty
|
|
|
|
*
|
|
|
|
* @param[in,out] ---
|
|
|
|
*
|
|
|
|
* @return The ID of the curent buffer where the file is loaded
|
|
|
|
*
|
|
|
|
*/
|
2012-02-20 20:30:26 +01:00
|
|
|
int32_t classBufferManager::Create(void)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
|
|
|
// allocate a new Buffer
|
2012-11-20 22:16:30 +01:00
|
|
|
BufferText *myBuffer = new BufferText();
|
2011-07-20 10:33:24 +02:00
|
|
|
// Add at the list of element
|
2012-08-09 14:26:30 +02:00
|
|
|
listBuffer.PushBack(myBuffer);
|
|
|
|
int32_t basicID = listBuffer.Size() - 1;
|
2011-07-20 10:33:24 +02:00
|
|
|
return basicID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief open a file with the name set in parameters
|
|
|
|
*
|
|
|
|
* @param[in] filename curent filename
|
|
|
|
*
|
|
|
|
* @return The ID of the curent buffer where the file is loaded
|
|
|
|
*
|
|
|
|
* @todo : check if this file is not curently open and return the old ID
|
|
|
|
*
|
|
|
|
*/
|
2012-11-01 10:47:36 +01:00
|
|
|
int32_t classBufferManager::Open(etk::FSNode &myFile)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
2012-05-10 17:47:52 +02:00
|
|
|
if (false == Exist(myFile)) {
|
|
|
|
// allocate a new Buffer
|
2012-11-20 22:16:30 +01:00
|
|
|
BufferText *myBuffer = new BufferText(myFile);
|
2012-05-10 17:47:52 +02:00
|
|
|
// Add at the list of element
|
2012-08-09 14:26:30 +02:00
|
|
|
listBuffer.PushBack(myBuffer);
|
|
|
|
return listBuffer.Size() - 1;
|
2012-05-10 17:47:52 +02:00
|
|
|
} else {
|
|
|
|
// the buffer already existed ==> we open it ...
|
|
|
|
return GetId(myFile);
|
|
|
|
}
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-20 22:16:30 +01:00
|
|
|
BufferText * classBufferManager::Get(int32_t BufferID)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
|
|
|
// possible special case : -1;
|
|
|
|
if (-1 >= BufferID) {
|
2012-11-20 22:16:30 +01:00
|
|
|
return NULL;
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
// check if the Buffer existed
|
2012-08-09 14:26:30 +02:00
|
|
|
if (BufferID < listBuffer.Size()) {
|
2011-07-20 10:33:24 +02:00
|
|
|
// check if the buffer already existed
|
|
|
|
if (NULL != listBuffer[BufferID]) {
|
|
|
|
return listBuffer[BufferID];
|
|
|
|
} else {
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_ERROR("non existing Buffer " << BufferID);
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
} else {
|
2012-08-09 14:26:30 +02:00
|
|
|
APPL_ERROR("call an non existing Buffer number too hight : " << BufferID << " > " << listBuffer.Size());
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
2012-11-20 22:16:30 +01:00
|
|
|
return NULL;
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-20 20:30:26 +01:00
|
|
|
bool classBufferManager::Exist(int32_t BufferID)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
|
|
|
if (-1 >= BufferID) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// check if the Buffer existed
|
2012-08-09 14:26:30 +02:00
|
|
|
if (BufferID < listBuffer.Size()) {
|
2011-07-20 10:33:24 +02:00
|
|
|
// check if the buffer already existed
|
|
|
|
if (NULL != listBuffer[BufferID]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-01 10:47:36 +01:00
|
|
|
bool classBufferManager::Exist(etk::FSNode &myFile )
|
2011-08-05 14:31:47 +02:00
|
|
|
{
|
|
|
|
if (-1 == GetId(myFile)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-01 10:47:36 +01:00
|
|
|
int32_t classBufferManager::GetId(etk::FSNode &myFile)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
|
|
|
int32_t iii;
|
|
|
|
// check if the Buffer existed
|
2012-08-09 14:26:30 +02:00
|
|
|
for (iii=0; iii < listBuffer.Size(); iii++) {
|
2011-07-20 10:33:24 +02:00
|
|
|
// check if the buffer already existed
|
|
|
|
if (NULL != listBuffer[iii]) {
|
2011-08-05 14:31:47 +02:00
|
|
|
if ( listBuffer[iii]->GetFileName() == myFile) {
|
2011-07-20 10:33:24 +02:00
|
|
|
return iii;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return the number of buffer (open in the past) if 5 buffer open and 4 close ==> return 5
|
2012-02-20 20:30:26 +01:00
|
|
|
uint32_t classBufferManager::Size(void)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
2012-08-09 14:26:30 +02:00
|
|
|
return listBuffer.Size();
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
2012-02-14 19:29:53 +01:00
|
|
|
// nb of opens file Now ...
|
2012-02-20 20:30:26 +01:00
|
|
|
uint32_t classBufferManager::SizeOpen(void)
|
2012-02-14 19:29:53 +01:00
|
|
|
{
|
|
|
|
uint32_t jjj = 0;
|
|
|
|
// check if the Buffer existed
|
2012-08-09 14:26:30 +02:00
|
|
|
for (int32_t iii=0; iii<listBuffer.Size(); iii++) {
|
2012-02-14 19:29:53 +01:00
|
|
|
// check if the buffer already existed
|
|
|
|
if (NULL != listBuffer[iii]) {
|
|
|
|
jjj++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return jjj;
|
|
|
|
}
|
2011-07-20 10:33:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
*
|
|
|
|
* @param[in,out] ---
|
|
|
|
*
|
|
|
|
* @return ---
|
|
|
|
*
|
|
|
|
*/
|
2012-02-20 20:30:26 +01:00
|
|
|
bool classBufferManager::Remove(int32_t BufferID)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
|
|
|
if (-1 >= BufferID) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// check if the Buffer existed
|
2012-08-09 14:26:30 +02:00
|
|
|
if (BufferID < listBuffer.Size()) {
|
2011-07-20 10:33:24 +02:00
|
|
|
// check if the buffer already existed
|
|
|
|
if (NULL != listBuffer[BufferID]) {
|
|
|
|
// TODO : Check if it saved...
|
|
|
|
/*
|
|
|
|
if (false == IsSaved(BufferID) ) {
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_INFO("Buffer " << BufferID << " : Not Saved", BufferID);
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
// Delete the Buffer
|
|
|
|
delete( listBuffer[BufferID] );
|
|
|
|
listBuffer[BufferID] = NULL;
|
2012-02-27 18:15:56 +01:00
|
|
|
/*
|
2012-02-09 17:20:52 +01:00
|
|
|
ewol::widgetMessageMultiCast::Send(GetWidgetId(), ednMsgBufferListChange);
|
2012-02-27 18:15:56 +01:00
|
|
|
*/
|
2011-07-20 10:33:24 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_INFO("non existing Buffer " << BufferID);
|
2011-07-20 10:33:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-09 14:26:30 +02:00
|
|
|
APPL_INFO("call an non existing Buffer number too hight : " << BufferID << " > " << listBuffer.Size());
|
2011-07-20 10:33:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief to get the element 14 in the buffer
|
|
|
|
*
|
|
|
|
* @param[in,out] ---
|
|
|
|
*
|
|
|
|
* @return ---
|
|
|
|
*
|
|
|
|
*/
|
2012-02-20 20:30:26 +01:00
|
|
|
int32_t classBufferManager::WitchBuffer(int32_t iEmeElement)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
|
|
|
int32_t i;
|
2012-08-09 14:26:30 +02:00
|
|
|
for (i=0; i<listBuffer.Size(); i++) {
|
2011-07-20 10:33:24 +02:00
|
|
|
if (NULL != listBuffer[i]) {
|
|
|
|
iEmeElement--;
|
|
|
|
// find the element :
|
|
|
|
if (0 == iEmeElement) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-20 20:30:26 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Namespace part :
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static classBufferManager * localManager = NULL;
|
|
|
|
|
|
|
|
void BufferManager::Init(void)
|
|
|
|
{
|
2012-11-02 21:32:15 +01:00
|
|
|
if (NULL != localManager) {
|
2012-02-20 20:30:26 +01:00
|
|
|
EWOL_ERROR("classBufferManager ==> already exist, just unlink the previous ...");
|
|
|
|
localManager = NULL;
|
|
|
|
}
|
|
|
|
localManager = new classBufferManager();
|
|
|
|
|
|
|
|
if (NULL == localManager) {
|
|
|
|
EWOL_CRITICAL("Allocation of classBufferManager not done ...");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BufferManager::UnInit(void)
|
|
|
|
{
|
|
|
|
if (NULL == localManager) {
|
|
|
|
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
|
|
|
|
return;
|
|
|
|
}
|
2012-08-13 18:00:30 +02:00
|
|
|
delete(localManager);
|
2012-02-20 20:30:26 +01:00
|
|
|
localManager = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t BufferManager::GetSelected(void)
|
|
|
|
{
|
|
|
|
if (NULL == localManager) {
|
|
|
|
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return localManager->GetSelected();
|
|
|
|
}
|
|
|
|
|
2012-11-20 22:16:30 +01:00
|
|
|
BufferText * BufferManager::Get(int32_t BufferID)
|
2012-02-20 20:30:26 +01:00
|
|
|
{
|
|
|
|
if (NULL == localManager) {
|
|
|
|
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return localManager->Get(BufferID);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BufferManager::Exist(int32_t BufferID)
|
|
|
|
{
|
|
|
|
if (NULL == localManager) {
|
|
|
|
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return localManager->Exist(BufferID);
|
|
|
|
}
|
|
|
|
|
2012-11-01 10:47:36 +01:00
|
|
|
bool BufferManager::Exist(etk::FSNode &myFile)
|
2012-02-20 20:30:26 +01:00
|
|
|
{
|
|
|
|
if (NULL == localManager) {
|
|
|
|
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return localManager->Exist(myFile);
|
|
|
|
}
|
2011-07-20 10:33:24 +02:00
|
|
|
|
2012-11-01 10:47:36 +01:00
|
|
|
int32_t BufferManager::GetId(etk::FSNode &myFile)
|
2012-02-20 20:30:26 +01:00
|
|
|
{
|
|
|
|
if (NULL == localManager) {
|
|
|
|
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return localManager->GetId(myFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t BufferManager::Size(void)
|
|
|
|
{
|
|
|
|
if (NULL == localManager) {
|
|
|
|
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return localManager->Size();
|
|
|
|
}
|
2011-07-20 10:33:24 +02:00
|
|
|
|
2012-02-20 20:30:26 +01:00
|
|
|
uint32_t BufferManager::SizeOpen(void)
|
|
|
|
{
|
|
|
|
if (NULL == localManager) {
|
|
|
|
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return localManager->SizeOpen();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t BufferManager::WitchBuffer(int32_t iEmeElement)
|
|
|
|
{
|
|
|
|
if (NULL == localManager) {
|
|
|
|
EWOL_ERROR("classBufferManager ==> request UnInit, but does not exist ...");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return localManager->WitchBuffer(iEmeElement);
|
|
|
|
}
|
2011-07-20 10:33:24 +02:00
|
|
|
|
|
|
|
|