2011-07-20 10:33:24 +02:00
|
|
|
/**
|
|
|
|
*******************************************************************************
|
|
|
|
* @file BufferManager.cpp
|
|
|
|
* @brief Editeur De N'ours : Text Buffer manager (sources)
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
* @date 08/12/2010
|
|
|
|
* @par Project
|
|
|
|
* Edn
|
|
|
|
*
|
|
|
|
* @par Copyright
|
|
|
|
* Copyright 2010 Edouard DUPIN, all right reserved
|
|
|
|
*
|
|
|
|
* This software is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY.
|
|
|
|
*
|
|
|
|
* Licence summary :
|
|
|
|
* You can modify and redistribute the sources code and binaries.
|
|
|
|
* You can send me the bug-fix
|
|
|
|
* You can not earn money with this Software (if the source extract from Edn
|
|
|
|
* represent less than 50% of original Sources)
|
|
|
|
* Term of the licence in in the file licence.txt.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-04-23 10:15:43 +02:00
|
|
|
#include <appl/Debug.h>
|
2012-01-11 15:26:53 +01:00
|
|
|
#include <tools_globals.h>
|
|
|
|
#include <BufferManager.h>
|
2012-02-28 18:22:49 +01:00
|
|
|
#include <ewol/EObject.h>
|
2012-02-29 18:06:08 +01:00
|
|
|
#include <ewol/EObjectManager.h>
|
2011-07-20 10:33:24 +02:00
|
|
|
|
|
|
|
#undef __class__
|
2012-02-20 20:30:26 +01:00
|
|
|
#define __class__ "classBufferManager"
|
|
|
|
|
2012-03-14 09:26:14 +01:00
|
|
|
//!< EObject name :
|
|
|
|
extern const char * const TYPE_EOBJECT_EDN_BUFFER_MANAGER = "BufferManager";
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @brief Check if the object has the specific type.
|
|
|
|
* @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it
|
|
|
|
* @param[in] objectType type of the object we want to check
|
|
|
|
* @return true if the object is compatible, otherwise false
|
|
|
|
*/
|
|
|
|
bool CheckObjectType(const char * const objectType)
|
|
|
|
{
|
|
|
|
if (NULL == objectType) {
|
|
|
|
EWOL_ERROR("check error : \"" << TYPE_EOBJECT_EDN_BUFFER_MANAGER << "\" != NULL(pointer) ");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (objectType == TYPE_EOBJECT_EDN_BUFFER_MANAGER) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if(true == ewol::EObject::CheckObjectType(objectType)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
EWOL_ERROR("check error : \"" << TYPE_EOBJECT_EDN_BUFFER_MANAGER << "\" != \"" << objectType << "\"");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the current Object type of the EObject
|
|
|
|
* @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it
|
|
|
|
* @param[in] objectType type description
|
|
|
|
* @return true if the object is compatible, otherwise false
|
|
|
|
*/
|
|
|
|
const char * const GetObjectType(void)
|
|
|
|
{
|
|
|
|
return TYPE_EOBJECT_EDN_BUFFER_MANAGER;
|
|
|
|
}
|
2012-02-20 20:30:26 +01:00
|
|
|
public:
|
2012-02-29 18:06:08 +01:00
|
|
|
/**
|
|
|
|
* @brief Receive a message from an other EObject with a specific eventId and data
|
|
|
|
* @param[in] CallerObject Pointer on the EObject that information came from
|
|
|
|
* @param[in] eventId Message registered by this class
|
|
|
|
* @param[in] data Data registered by this class
|
|
|
|
* @return ---
|
|
|
|
*/
|
|
|
|
virtual void OnReceiveMessage(ewol::EObject * CallerObject, const char * eventId, etk::UString data);
|
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
|
|
|
|
int32_t Open(etk::File &myFile);
|
|
|
|
bool Remove(int32_t BufferID);
|
|
|
|
public:
|
|
|
|
int32_t GetSelected(void) { return m_idSelected;};
|
|
|
|
//void SetSelected(int32_t id) {m_idSelected = id;};
|
|
|
|
Buffer * Get(int32_t BufferID);
|
|
|
|
bool Exist(int32_t BufferID);
|
|
|
|
bool Exist(etk::File &myFile);
|
|
|
|
int32_t GetId(etk::File &myFile);
|
|
|
|
// 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:
|
|
|
|
|
|
|
|
etk::VectorType<Buffer*> listBuffer; //!< element List of the char Elements
|
|
|
|
|
|
|
|
void RemoveAll(void); //!< remove all buffer
|
|
|
|
int32_t m_idSelected;
|
|
|
|
Buffer * BufferNotExiste; //!< When an error arrive in get buffer we return the Error buffer (not writable)
|
|
|
|
};
|
|
|
|
|
2012-03-14 09:26:14 +01:00
|
|
|
#define EDN_CAST_BUFFER_MANAGER(curentPointer) EWOL_CAST(TYPE_EOBJECT_EDN_BUFFER_MANAGER,classBufferManager,curentPointer)
|
2012-02-20 20:30:26 +01:00
|
|
|
|
2011-07-20 10:33:24 +02:00
|
|
|
|
|
|
|
// Constructeur
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
*
|
|
|
|
* @param[in,out] ---
|
|
|
|
*
|
|
|
|
* @return ---
|
|
|
|
*
|
|
|
|
*/
|
2012-02-20 20:30:26 +01:00
|
|
|
classBufferManager::classBufferManager(void)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
|
|
|
// nothing to do ...
|
|
|
|
BufferNotExiste = new BufferEmpty();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
*
|
|
|
|
* @param[in,out] ---
|
|
|
|
*
|
|
|
|
* @return ---
|
|
|
|
*
|
|
|
|
*/
|
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();");
|
2011-08-03 14:39:39 +02:00
|
|
|
listBuffer.Clear();
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_INFO("~classBufferManager::delete(BufferNotExiste);");
|
2011-07-20 10:33:24 +02:00
|
|
|
delete(BufferNotExiste);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-29 18:06:08 +01:00
|
|
|
/**
|
|
|
|
* @brief Receive a message from an other EObject with a specific eventId and data
|
|
|
|
* @param[in] CallerObject Pointer on the EObject that information came from
|
|
|
|
* @param[in] eventId Message registered by this class
|
|
|
|
* @param[in] data Data registered by this class
|
|
|
|
* @return ---
|
|
|
|
*/
|
|
|
|
void classBufferManager::OnReceiveMessage(ewol::EObject * CallerObject, const char * eventId, etk::UString data)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
2012-02-29 18:06:08 +01:00
|
|
|
ewol::EObject::OnReceiveMessage(CallerObject, eventId, data);
|
|
|
|
|
|
|
|
if (eventId == ednMsgBufferId) {
|
2012-02-14 19:29:53 +01:00
|
|
|
// select a new buffer ID :
|
2012-02-29 18:06:08 +01:00
|
|
|
if (data == "") {
|
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;
|
2012-02-29 18:06:08 +01:00
|
|
|
sscanf(data.Utf8Data(), "%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
|
|
|
}
|
|
|
|
}
|
2012-02-29 18:06:08 +01:00
|
|
|
} else if (eventId == 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
|
|
|
}
|
2012-02-29 18:06:08 +01:00
|
|
|
} else if (eventId == ednMsgOpenFile) {
|
|
|
|
if (data != "" ) {
|
2012-02-05 22:03:36 +01:00
|
|
|
etk::File myFile(data, etk::FILE_TYPE_DIRECT);
|
|
|
|
int32_t newOne = Open(myFile);
|
|
|
|
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-05 22:03:36 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-29 18:06:08 +01:00
|
|
|
} else if (eventId == ednMsgGuiSave) {
|
|
|
|
if (data == "") {
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_ERROR("Null data for close file ... ");
|
2012-02-09 17:20:52 +01:00
|
|
|
} else {
|
2012-02-29 18:06:08 +01:00
|
|
|
if (data == "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;
|
2012-02-29 18:06:08 +01:00
|
|
|
sscanf(data.Utf8Data(), "%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
|
|
|
}
|
|
|
|
}
|
2012-02-29 18:06:08 +01:00
|
|
|
} else if (eventId == ednMsgGuiClose) {
|
|
|
|
if (data == "") {
|
2012-04-23 10:15:43 +02:00
|
|
|
APPL_ERROR("Null data for close file ... ");
|
2012-02-08 18:05:19 +01:00
|
|
|
} else {
|
2012-02-29 18:06:08 +01:00
|
|
|
if (data == "All") {
|
2012-02-08 18:05:19 +01:00
|
|
|
|
2012-02-14 19:29:53 +01:00
|
|
|
} else {
|
|
|
|
int32_t closeID = -1;
|
2012-02-29 18:06:08 +01:00
|
|
|
if (data == "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 ...
|
2012-02-29 18:06:08 +01:00
|
|
|
sscanf(data.Utf8Data(), "%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) {
|
|
|
|
for(int32_t ii=closeID+1; ii < listBuffer.Size(); ii++) {
|
|
|
|
if (true == Exist(ii) ) {
|
|
|
|
destBuffer = ii;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// set it to the currect display
|
2012-02-29 18:06:08 +01:00
|
|
|
SendMultiCast(ednMsgBufferId, destBuffer);
|
2012-02-14 19:29:53 +01:00
|
|
|
m_idSelected = destBuffer;
|
|
|
|
}
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
2012-02-29 18:06:08 +01:00
|
|
|
} else if (eventId == ednMsgCodeViewSelectedId) {
|
2012-02-09 17:20:52 +01:00
|
|
|
//Change the selected buffer
|
2012-02-29 18:06:08 +01:00
|
|
|
if (data == "") {
|
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;
|
2012-02-29 18:06:08 +01:00
|
|
|
sscanf(data.Utf8Data(), "%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;
|
2011-08-03 14:39:39 +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
|
|
|
|
Buffer *myBuffer = new BufferText();
|
|
|
|
// Add at the list of element
|
2011-08-03 14:39:39 +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-02-20 20:30:26 +01:00
|
|
|
int32_t classBufferManager::Open(etk::File &myFile)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
2011-08-05 14:31:47 +02:00
|
|
|
// TODO : Check here if the file is already open ==> and display it if needed
|
2011-07-20 10:33:24 +02:00
|
|
|
// allocate a new Buffer
|
2011-08-05 14:31:47 +02:00
|
|
|
Buffer *myBuffer = new BufferText(myFile);
|
2011-07-20 10:33:24 +02:00
|
|
|
// Add at the list of element
|
2011-08-03 14:39:39 +02:00
|
|
|
listBuffer.PushBack(myBuffer);
|
2012-02-05 22:03:36 +01:00
|
|
|
return listBuffer.Size() - 1;
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-20 20:30:26 +01:00
|
|
|
Buffer * classBufferManager::Get(int32_t BufferID)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
|
|
|
// possible special case : -1;
|
|
|
|
if (-1 >= BufferID) {
|
|
|
|
return BufferNotExiste;
|
|
|
|
}
|
|
|
|
// check if the Buffer existed
|
2011-08-03 14:39:39 +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-04-23 10:15:43 +02:00
|
|
|
APPL_ERROR("call an non existing Buffer number too hight : " << BufferID << " > " << listBuffer.Size());
|
2011-07-20 10:33:24 +02:00
|
|
|
}
|
|
|
|
return BufferNotExiste;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2011-08-03 14:39:39 +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-02-20 20:30:26 +01:00
|
|
|
bool classBufferManager::Exist(etk::File &myFile )
|
2011-08-05 14:31:47 +02:00
|
|
|
{
|
|
|
|
if (-1 == GetId(myFile)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-20 20:30:26 +01:00
|
|
|
int32_t classBufferManager::GetId(etk::File &myFile)
|
2011-07-20 10:33:24 +02:00
|
|
|
{
|
|
|
|
int32_t iii;
|
|
|
|
// check if the Buffer existed
|
2011-08-03 14:39:39 +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
|
|
|
{
|
2011-08-03 14:39:39 +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
|
|
|
|
for (int32_t iii=0; iii<listBuffer.Size(); iii++) {
|
|
|
|
// 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
|
2011-08-03 14:39:39 +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-04-23 10:15:43 +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;
|
2011-08-03 14:39:39 +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)
|
|
|
|
{
|
|
|
|
if (NULL == localManager) {
|
|
|
|
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-02-29 18:06:08 +01:00
|
|
|
ewol::EObjectManager::MarkToRemoved(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();
|
|
|
|
}
|
|
|
|
|
|
|
|
Buffer * BufferManager::Get(int32_t BufferID)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BufferManager::Exist(etk::File &myFile)
|
|
|
|
{
|
|
|
|
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-02-20 20:30:26 +01:00
|
|
|
int32_t BufferManager::GetId(etk::File &myFile)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|