diff --git a/sources/appl/Buffer.cpp b/sources/appl/Buffer.cpp index cd632d4..a0fdc0e 100644 --- a/sources/appl/Buffer.cpp +++ b/sources/appl/Buffer.cpp @@ -16,6 +16,7 @@ const char* const appl::Buffer::eventIsModify = "edn-is-modify"; const char* const appl::Buffer::eventIsSave = "edn-is-save"; const char* const appl::Buffer::eventSelectChange = "edn-select-change"; +const char* const appl::Buffer::eventChangeName = "edn-buffer-name-change"; appl::Buffer::Iterator& appl::Buffer::Iterator::operator++ (void) { m_value = etk::UChar::Null; @@ -109,13 +110,15 @@ appl::Buffer::Buffer(void) : m_cursorPos(0), m_cursorSelectPos(-1), m_cursorPreferredCol(-1), - m_nbLines(0), + m_nbLines(1), m_highlight(NULL) { static int32_t bufferBaseId = 0; m_fileName = "No Name " + std::to_string(bufferBaseId); + bufferBaseId++; addEventId(eventIsModify); addEventId(eventIsSave); addEventId(eventSelectChange); + addEventId(eventChangeName); } appl::Buffer::~Buffer(void) { @@ -151,6 +154,7 @@ void appl::Buffer::setFileName(const std::string& _name) { } m_fileName = _name; m_hasFileName = true; + generateEventId(eventChangeName); setModification(true); } @@ -178,6 +182,10 @@ void appl::Buffer::setModification(bool _status) { void appl::Buffer::countNumberofLine(void) { + if (m_data.size() == 0) { + m_nbLines = 1; + return; + } m_nbLines = 0; for (Iterator it = begin(); (bool)it == true; @@ -470,7 +478,11 @@ void appl::Buffer::copy(std::string& _data, const appl::Buffer::Iterator& _pos, } bool appl::Buffer::write(const std::string& _data, const appl::Buffer::Iterator& _pos) { - m_data.insert(_pos, (int8_t*)(_data.c_str()), _data.size()); + if ((esize_t)_pos <= 0) { + m_data.insert(0, (int8_t*)(_data.c_str()), _data.size()); + } else { + m_data.insert(_pos, (int8_t*)(_data.c_str()), _data.size()); + } regenerateHighLightAt(_pos, 0, _data.size()); m_selectMode = false; moveCursor((esize_t)_pos+_data.size()); diff --git a/sources/appl/Buffer.h b/sources/appl/Buffer.h index 66d87c4..2b32b90 100644 --- a/sources/appl/Buffer.h +++ b/sources/appl/Buffer.h @@ -264,6 +264,7 @@ namespace appl { static const char* const eventIsModify; static const char* const eventIsSave; static const char* const eventSelectChange; + static const char* const eventChangeName; public: Buffer(void); ~Buffer(void); diff --git a/sources/appl/BufferManager.cpp b/sources/appl/BufferManager.cpp index 4c60bf2..680ec4c 100644 --- a/sources/appl/BufferManager.cpp +++ b/sources/appl/BufferManager.cpp @@ -36,12 +36,23 @@ appl::BufferManager::~BufferManager(void) { m_list.clear(); } + +appl::Buffer* appl::BufferManager::createNewBuffer(void) { + appl::Buffer* tmp = new appl::Buffer(); + if (tmp == NULL) { + APPL_ERROR("Can not allocate the Buffer (empty)."); + return NULL; + } + m_list.push_back(tmp); + sendMultiCast(appl::MsgSelectNewFile, tmp->getFileName()); + return tmp; +} + appl::Buffer* appl::BufferManager::get(const std::string& _fileName, bool _createIfNeeded) { for (esize_t iii = 0; iii < m_list.size(); ++iii) { if (m_list[iii] == NULL) { continue; } - if (m_list[iii]->getFileName() == _fileName) { return m_list[iii]; } diff --git a/sources/appl/BufferManager.h b/sources/appl/BufferManager.h index a05799c..8f0ca01 100644 --- a/sources/appl/BufferManager.h +++ b/sources/appl/BufferManager.h @@ -55,6 +55,11 @@ namespace appl { appl::Buffer* get(esize_t _id) { return m_list[_id]; } + /** + * @brief Create a new buffer empty. + * @return Created buffer or NULL. + */ + appl::Buffer* createNewBuffer(void); private: appl::Buffer* m_bufferSelected; public: diff --git a/sources/appl/Gui/BufferView.cpp b/sources/appl/Gui/BufferView.cpp index bb6037e..a1ab199 100644 --- a/sources/appl/Gui/BufferView.cpp +++ b/sources/appl/Gui/BufferView.cpp @@ -46,6 +46,7 @@ BufferView::BufferView(void) { registerMultiCast(ednMsgBufferId); registerMultiCast(appl::MsgSelectNewFile); registerMultiCast(appl::MsgSelectChange); + registerMultiCast(appl::MsgNameChange); m_selectedID = -1; m_selectedIdRequested = -1; // load buffer manager: @@ -87,6 +88,7 @@ void BufferView::onReceiveMessage(const ewol::EMessage& _msg) { } buffer->registerOnEvent(this, appl::Buffer::eventIsSave); buffer->registerOnEvent(this, appl::Buffer::eventIsModify); + buffer->registerOnEvent(this, appl::Buffer::eventChangeName); appl::dataBufferStruct* tmp = new appl::dataBufferStruct(_msg.getData(), buffer); if (tmp == NULL) { APPL_ERROR("Allocation error of the tmp buffer list element"); @@ -96,6 +98,16 @@ void BufferView::onReceiveMessage(const ewol::EMessage& _msg) { markToRedraw(); return; } + if (_msg.getMessage() == appl::Buffer::eventChangeName) { + for (auto element : m_list) { + if (element == NULL) { + continue; + } + element->m_bufferName = element->m_buffer->getFileName(); + } + markToRedraw(); + return; + } if (_msg.getMessage() == appl::Buffer::eventIsSave) { markToRedraw(); return; diff --git a/sources/appl/Gui/MainWindows.cpp b/sources/appl/Gui/MainWindows.cpp index 06f77c1..62299d4 100644 --- a/sources/appl/Gui/MainWindows.cpp +++ b/sources/appl/Gui/MainWindows.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include namespace appl { @@ -269,6 +271,7 @@ MainWindows::MainWindows(void) { // Generic event ... registerMultiCast(ednMsgGuiSaveAs); registerMultiCast(ednMsgProperties); + registerMultiCast(ednMsgGuiNew); registerMultiCast(ednMsgGuiOpen); registerMultiCast(ednMsgGuiClose); // to update the title ... @@ -279,9 +282,7 @@ MainWindows::MainWindows(void) { MainWindows::~MainWindows(void) { - if (m_bufferManager != NULL) { - appl::BufferManager::release(m_bufferManager); - } + appl::BufferManager::release(m_bufferManager); } @@ -292,7 +293,7 @@ const char *const ednEventPopUpFileSaveAs = "edn-mainWindows-saveAsSelected"; void MainWindows::onReceiveMessage(const ewol::EMessage& _msg) { ewol::Windows::onReceiveMessage(_msg); - //APPL_INFO("Receive Event from the main windows ... : \"" << eventId << "\" == > data=\"" << data << "\"" ); + APPL_INFO("Receive Event from the main windows: " << _msg ); // open file Section ... if (_msg.getMessage() == ednMsgGuiOpen) { widget::FileChooser* tmpWidget = new widget::FileChooser(); @@ -315,131 +316,6 @@ void MainWindows::onReceiveMessage(const ewol::EMessage& _msg) { // apply widget pop-up ... popUpWidgetPush(tmpWidget); tmpWidget->registerOnEvent(this, widget::FileChooser::eventValidate, ednEventPopUpFileSelected); - } else if (_msg.getMessage() == ednEventPopUpFileSelected) { - APPL_DEBUG("Request opening the file : " << _msg.getData()); - if (m_bufferManager == NULL) { - APPL_ERROR("can not call unexistant buffer manager ... "); - return; - } - m_bufferManager->open(_msg.getData()); - } else if (_msg.getMessage() == ednMsgGuiSave) { - APPL_DEBUG("Request saving the file : " << _msg.getData()); - if (m_bufferManager == NULL) { - APPL_ERROR("can not call unexistant buffer manager ... "); - return; - } - if (to_lower(_msg.getData()) == "current") { - appl::Buffer* tmpBuffer = m_bufferManager->getBufferSelected(); - if (tmpBuffer == NULL) { - APPL_WARNING("No buffer selected !!! "); - createPopUpMessage(ewol::Windows::messageTypeError, "No buffer selected !!!"); - return; - } - // Note : for direct saving, we do not chack the saving status ==> all time saving ... - if (tmpBuffer->hasFileName() == false) { - saveAsPopUp(tmpBuffer); - return; - } - if (tmpBuffer->storeFile() == false) { - displayWarningMessage("We can not save the file :
" + tmpBuffer->getFileName() + ""); - APPL_ERROR("can not save the file !!! '" << tmpBuffer->getFileName() << "'"); - } - return; - } else if (to_lower(_msg.getData()) == "all") { - APPL_TODO("Need to save all the buffers ... "); - for (esize_t iii=0; iii < m_bufferManager->size(); ++iii) { - appl::Buffer* tmpBuffer = m_bufferManager->get(iii); - if (tmpBuffer == NULL) { - continue; - } - if (tmpBuffer->isModify() == false) { - continue; - } - if (tmpBuffer->hasFileName() == false) { - // TODO : Has no name ==> must generate a save AS !!! - APPL_TODO("Has no name ==> must generate a save AS"); - continue; - } - if (tmpBuffer->storeFile() == false) { - displayWarningMessage("We can not save the file :
" + tmpBuffer->getFileName() + ""); - APPL_ERROR("can not save the file !!! '" << tmpBuffer->getFileName() << "'"); - } - } - return; - } else { - APPL_ERROR("UNKNOW request : " << _msg); - } - } else if (_msg.getMessage() == ednMsgGuiSaveAs) { - if (_msg.getData() == "") { - APPL_ERROR("Null data for Save As file ... "); - } else { - m_currentSavingAsIdBuffer = -1; - if (_msg.getData() == "current") { - m_currentSavingAsIdBuffer = -1;//BufferManager::getSelected(); - } else { - sscanf(_msg.getData().c_str(), "%d", &m_currentSavingAsIdBuffer); - } - - /* - if (false == BufferManager::exist(m_currentSavingAsIdBuffer)) { - APPL_ERROR("Request saveAs on non existant Buffer ID=" << m_currentSavingAsIdBuffer); - } else { - BufferText* myBuffer = BufferManager::get(m_currentSavingAsIdBuffer); - widget::FileChooser* tmpWidget = new widget::FileChooser(); - if (NULL == tmpWidget) { - APPL_ERROR("Can not allocate widget == > display might be in error"); - } else { - tmpWidget->setTitle("Save files As..."); - tmpWidget->setValidateLabel("Save"); - std::string folder = "/home/"; - std::string fileName = ""; - if (true == myBuffer->haveName()) { - etk::FSNode tmpName = myBuffer->getFileName(); - folder = tmpName.getNameFolder(); - fileName = tmpName.getNameFile(); - } - tmpWidget->setFolder(folder); - tmpWidget->setFileName(fileName); - popUpWidgetPush(tmpWidget); - tmpWidget->registerOnEvent(this, ewolEventFileChooserValidate, ednEventPopUpFileSaveAs); - } - } - */ - } - } else if (_msg.getMessage() == ednEventPopUpFileSaveAs) { - // get the filename : - std::string tmpData = _msg.getData(); - APPL_DEBUG("Request Saving As file : " << tmpData); - /* - BufferManager::get(m_currentSavingAsIdBuffer)->setFileName(tmpData); - sendMultiCast(ednMsgGuiSave, m_currentSavingAsIdBuffer); - */ - } else if( _msg.getMessage() == ednMsgBufferState - || _msg.getMessage() == ednMsgBufferId) { - // the buffer change we need to update the widget string - /* - BufferText* tmpBuffer = BufferManager::get(BufferManager::getSelected()); - if (NULL != tmpBuffer) { - etk::FSNode compleateName = tmpBuffer->getFileName(); - bool isModify = tmpBuffer->isModify(); - std::string directName = compleateName.getName(); - if (true == isModify) { - directName += " *"; - } - if (NULL != m_widgetLabelFileName) { - m_widgetLabelFileName->setLabel(std::string("") + directName + ""); - } - std::string windowsTitle = "edn - "; - windowsTitle += directName; - setTitle(windowsTitle); - return; - } else { - m_widgetLabelFileName->setLabel(""); - setTitle("edn"); - } - */ - return; - // TODO : set the Title .... } else if (_msg.getMessage() == ednMsgProperties) { // Request the parameter GUI widget::Parameter* tmpWidget = new widget::Parameter(); @@ -462,14 +338,86 @@ void MainWindows::onReceiveMessage(const ewol::EMessage& _msg) { ewol::getContext().getResourcesManager().reLoadResources(); ewol::getContext().forceRedrawAll(); } else if (_msg.getMessage() == ednMsgGuiExit) { - // TODO ... - } else if (_msg.getMessage() == ednMsgGuiClose) { + // TODO : ... + } + // Note : Fore all next message we need to acces to the buffer manager ==> just check one time ... + if (m_bufferManager == NULL) { + APPL_ERROR("can not call unexistant buffer manager ... "); + return; + } + if (_msg.getMessage() == ednMsgGuiNew) { if (m_bufferManager == NULL) { APPL_ERROR("can not call unexistant buffer manager ... "); return; } + (void)m_bufferManager->createNewBuffer(); + } else if (_msg.getMessage() == ednEventPopUpFileSelected) { + APPL_DEBUG("Request opening the file : " << _msg.getData()); + m_bufferManager->open(_msg.getData()); + } else if (_msg.getMessage() == ednMsgGuiSave) { + APPL_DEBUG("Request saving the file : " << _msg.getData()); + if (to_lower(_msg.getData()) == "current") { + appl::WorkerSaveFile* tmpWorker = new appl::WorkerSaveFile(""); + #if 0 + appl::Buffer* tmpBuffer = m_bufferManager->getBufferSelected(); + if (tmpBuffer == NULL) { + APPL_WARNING("No buffer selected !!! "); + createPopUpMessage(ewol::Windows::messageTypeError, "No buffer selected !!!"); + return; + } + // Note : for direct saving, we do not chack the saving status ==> all time saving ... + if (tmpBuffer->hasFileName() == false) { + saveAsPopUp(tmpBuffer); + return; + } + if (tmpBuffer->storeFile() == false) { + displayWarningMessage("We can not save the file :
" + tmpBuffer->getFileName() + ""); + APPL_ERROR("can not save the file !!! '" << tmpBuffer->getFileName() << "'"); + } + #endif + return; + } else if (to_lower(_msg.getData()) == "all") { + appl::WorkerSaveAllFile* tmpWorker = new appl::WorkerSaveAllFile(); + #if 0 + APPL_TODO("Need to save all the buffers ... "); + for (esize_t iii=0; iii < m_bufferManager->size(); ++iii) { + appl::Buffer* tmpBuffer = m_bufferManager->get(iii); + if (tmpBuffer == NULL) { + continue; + } + if (tmpBuffer->isModify() == false) { + continue; + } + if (tmpBuffer->hasFileName() == false) { + // TODO : Has no name ==> must generate a save AS !!! + APPL_TODO("Has no name ==> must generate a save AS"); + continue; + } + if (tmpBuffer->storeFile() == false) { + displayWarningMessage("We can not save the file :
" + tmpBuffer->getFileName() + ""); + APPL_ERROR("can not save the file !!! '" << tmpBuffer->getFileName() << "'"); + } + } + #endif + return; + } else { + APPL_ERROR("UNKNOW request : " << _msg); + } + } else if (_msg.getMessage() == ednMsgGuiSaveAs) { + appl::WorkerSaveFile* tmpWorker = new appl::WorkerSaveFile("", true); + #if 0 + appl::Buffer* tmpBuffer = m_bufferManager->getBufferSelected(); + if (tmpBuffer == NULL) { + APPL_ERROR("Error to get the buffer ... " << _msg.getData()); + return; + } + saveAsPopUp(tmpBuffer); + #endif + } else if (_msg.getMessage() == ednMsgGuiClose) { // Get a ref on the buffer selected (if null, no buffer was selected ...) if (_msg.getData() == "current") { + appl::WorkerCloseFile* tmpWorker = new appl::WorkerCloseFile(""); + #if 0 appl::Buffer* tmpBuffer = m_bufferManager->getBufferSelected(); if (tmpBuffer == NULL) { APPL_ERROR("Error to get the buffer ... " << _msg.getData()); @@ -480,16 +428,16 @@ void MainWindows::onReceiveMessage(const ewol::EMessage& _msg) { } else { tmpBuffer->removeObject(); } + #endif } else { // ALL !!! + appl::WorkerCloseAllFile* tmpWorker = new appl::WorkerCloseAllFile(); + #if 0 // TODO : How to generate the save for all ... APPL_TODO("Close all the buffer."); + #endif } } else if (_msg.getMessage() == mainWindowsRequestSaveFile) { // return after a choice of close... - if (m_bufferManager == NULL) { - APPL_ERROR("can not call unexistant buffer manager ... "); - return; - } if (m_bufferManager->exist(_msg.getData()) == false) { APPL_ERROR("Try to save an non-existant file :" << _msg.getData()); return; @@ -503,14 +451,12 @@ void MainWindows::onReceiveMessage(const ewol::EMessage& _msg) { APPL_ERROR("Will never arrive"); saveAsPopUp(tmpBuffer); } else { - // TODO : Save the file ... + if (tmpBuffer->storeFile() == false) { + APPL_ERROR("Error when loading the file " << _msg.getData()); + displayErrorMessage("Error when loading the file
" + _msg.getData() + ""); + } } } else if (_msg.getMessage() == mainWindowsRequestSaveFileAs) { // return after a choice of close... - - if (m_bufferManager == NULL) { - APPL_ERROR("can not call unexistant buffer manager ... "); - return; - } if (m_bufferManager->exist(_msg.getData()) == false) { APPL_ERROR("Try to save an non-existant file :" << _msg.getData()); return; @@ -522,10 +468,6 @@ void MainWindows::onReceiveMessage(const ewol::EMessage& _msg) { } saveAsPopUp(tmpBuffer); } else if (_msg.getMessage() == mainWindowsRequestcloseFileNoCheck) { // return after a choice of close... - if (m_bufferManager == NULL) { - APPL_ERROR("can not call unexistant buffer manager ... "); - return; - } if (m_bufferManager->exist(_msg.getData()) == false) { APPL_ERROR("Try to save an non-existant file :" << _msg.getData()); return; @@ -546,24 +488,7 @@ void MainWindows::saveAsPopUp(appl::Buffer* _buffer) { APPL_ERROR("Call With NULL input..."); return; } - widget::FileChooser* tmpWidget = new widget::FileChooser(); - if (NULL == tmpWidget) { - APPL_ERROR("Can not allocate widget == > display might be in error"); - return; - } - tmpWidget->setTitle("Save files As..."); - tmpWidget->setValidateLabel("Save"); - std::string folder = "/home/"; - std::string fileName = ""; - /*if (true == _buffer->hasFileName()) */{ - etk::FSNode tmpName(_buffer->getFileName()); - folder = tmpName.getNameFolder(); - fileName = tmpName.getNameFile(); - } - tmpWidget->setFolder(folder); - tmpWidget->setFileName(fileName); - popUpWidgetPush(tmpWidget); - //tmpWidget->registerOnEvent(this, ewolEventFileChooserValidate, ednEventPopUpFileSaveAs); + appl::WorkerSaveFile* tmpObject = new appl::WorkerSaveFile(_buffer->getFileName()); } void MainWindows::closeNotSavedFile(appl::Buffer* _buffer) { diff --git a/sources/appl/Gui/MainWindows.h b/sources/appl/Gui/MainWindows.h index 0913015..005f8c0 100644 --- a/sources/appl/Gui/MainWindows.h +++ b/sources/appl/Gui/MainWindows.h @@ -38,7 +38,6 @@ class MainWindows : public ewol::Windows { */ void closeNotSavedFile(appl::Buffer* _buffer); public: // Derived function - virtual const char * const getObjectType(void) { return "MainWindows"; }; virtual void onReceiveMessage(const ewol::EMessage& _msg); virtual void onObjectRemove(ewol::EObject * _removeObject); }; diff --git a/sources/appl/Gui/Search.h b/sources/appl/Gui/Search.h index 2b4ce9a..c9853ab 100644 --- a/sources/appl/Gui/Search.h +++ b/sources/appl/Gui/Search.h @@ -24,7 +24,6 @@ class Search : public widget::Sizer Search(void); ~Search(void); public: // derived function - virtual const char * const getObjectType(void) { return "ApplSearch"; }; virtual void onReceiveMessage(const ewol::EMessage& _msg); virtual void onObjectRemove(ewol::EObject * _removeObject); }; diff --git a/sources/appl/Gui/TagFileList.h b/sources/appl/Gui/TagFileList.h index c9ff4c4..0f64e64 100644 --- a/sources/appl/Gui/TagFileList.h +++ b/sources/appl/Gui/TagFileList.h @@ -45,10 +45,6 @@ namespace appl { uint32_t getNuberOfRaw(void); bool getElement(int32_t _colomn, int32_t _raw, std::string& _myTextToWrite, etk::Color<>& _fg, etk::Color<>& _bg); bool onItemEvent(int32_t _IdInput, enum ewol::keyEvent::status _typeEvent, int32_t _colomn, int32_t _raw, float _x, float _y); - // derived function - const char * const getObjectType(void) { - return "appl::TagFileList"; - }; public: /** * @brief add a Ctags item on the curent list diff --git a/sources/appl/Gui/TagFileSelection.h b/sources/appl/Gui/TagFileSelection.h index 205f5f1..7ded5c5 100644 --- a/sources/appl/Gui/TagFileSelection.h +++ b/sources/appl/Gui/TagFileSelection.h @@ -31,7 +31,6 @@ namespace appl { */ void addCtagsNewItem(std::string file, int32_t line); public: // herited function - const char * const getObjectType(void) { return "EwolFileChooser"; }; void onReceiveMessage(const ewol::EMessage& _msg); void onObjectRemove(ewol::EObject * _removeObject); }; diff --git a/sources/appl/Gui/TextViewer.h b/sources/appl/Gui/TextViewer.h index 80cc5c0..e4264d2 100644 --- a/sources/appl/Gui/TextViewer.h +++ b/sources/appl/Gui/TextViewer.h @@ -54,7 +54,6 @@ namespace appl { protected: // derived function virtual void onDraw(void); public: // Derived function - const char * const getObjectType(void) { return "appl::TextViewer"; }; virtual bool calculateMinSize(void); virtual void onRegenerateDisplay(void); virtual void onReceiveMessage(const ewol::EMessage& _msg); diff --git a/sources/appl/Gui/WorkerCloseAllFile.cpp b/sources/appl/Gui/WorkerCloseAllFile.cpp new file mode 100644 index 0000000..e69de29 diff --git a/sources/appl/Gui/WorkerCloseAllFile.h b/sources/appl/Gui/WorkerCloseAllFile.h new file mode 100644 index 0000000..e69de29 diff --git a/sources/appl/Gui/WorkerCloseFile.cpp b/sources/appl/Gui/WorkerCloseFile.cpp new file mode 100644 index 0000000..89116a8 --- /dev/null +++ b/sources/appl/Gui/WorkerCloseFile.cpp @@ -0,0 +1,114 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license GPL v3 (see license file) + */ + +#include +#include +#include + +#undef __class__ +#define __class__ "WorkerCloseFile" + +static const char* s_saveAsValidate = "save-as-validate"; +static const char* s_saveValidate = "save-validate"; +static const char* s_closeValidate = "close-validate"; + +appl::WorkerCloseFile::WorkerCloseFile(const std::string& _bufferName) : + m_closeAfter(_close), + m_bufferName(_bufferName), + m_worker(NULL), + m_bufferManager(NULL) { + // load buffer manager: + m_bufferManager = appl::BufferManager::keep(); + + if (m_bufferManager == NULL) { + APPL_ERROR("can not call unexistant buffer manager ... "); + autoDestroy(); + return; + } + if (m_bufferManager->exist(m_bufferName) == false) { + APPL_ERROR("Try to close an non-existant file :" << m_bufferName); + autoDestroy(); + return; + } + appl::Buffer* tmpBuffer = m_bufferManager->get(m_bufferName); + if (tmpBuffer == NULL) { + APPL_ERROR("Error to get the buffer : " << m_bufferName); + autoDestroy(); + return; + } + if (tmpBuffer->isModify() == false) { + tmpBuffer->removeObject(); + // TODO : Send message ... + + autoDestroy(); + return; + } + + widget::StdPopUp* tmpPopUp = new widget::StdPopUp(); + if (tmpPopUp == NULL) { + APPL_ERROR("Can not create a simple pop-up"); + return; + } + tmpPopUp->setTitle("Close un-saved file:"); + tmpPopUp->setComment("The file named : \"" + tmpBuffer->getFileName() + "\" is curently modify.
If you don't saves these modifications,
they will be definitly lost..."); + ewol::Widget* bt = NULL; + if (tmpBuffer->hasFileName() == true) { + bt = tmpPopUp->addButton("Save", true); + if (bt != NULL) { + bt->registerOnEvent(this, widget::Button::eventPressed, s_saveValidate, tmpBuffer->getFileName()); + } + } + bt = tmpPopUp->addButton("Save As", true); + if (bt != NULL) { + bt->registerOnEvent(this, widget::Button::eventPressed, s_saveAsValidate, tmpBuffer->getFileName()); + } + bt = tmpPopUp->addButton("Close", true); + if (bt != NULL) { + bt->registerOnEvent(this, widget::Button::eventPressed, s_closeValidate, tmpBuffer->getFileName()); + } + tmpPopUp->addButton("Cancel", true); + tmpPopUp->setRemoveOnExternClick(true); + ewol::Windows* tmpWindows = ewol::getContext().getWindows(); + if (tmpWindows == NULL) { + APPL_ERROR("Error to get the windows."); + autoDestroy(); + return; + } + tmpWindows->popUpWidgetPush(tmpPopUp); +} + +appl::WorkerCloseFile::~WorkerCloseFile(void) { + appl::BufferManager::release(m_bufferManager); +} + +void appl::WorkerCloseFile::onReceiveMessage(const ewol::EMessage& _msg) { + if (m_bufferManager == NULL) { + // nothing to do in this case ==> can do nothing ... + return; + } + APPL_DEBUG("have message : " << _msg); + if (_msg.getMessage() == s_saveAsValidate) { + + } else if (_msg.getMessage() == s_saveValidate) { + + } else if (_msg.getMessage() == s_closeValidate) { + + } +} + +void appl::WorkerCloseFile::onObjectRemove(ewol::EObject* _removeObject) { + if (_removeObject == m_worker) { + m_worker = NULL; + APPL_VERBOSE("AutoRemove After closing sub widget ..."); + autoDestroy(); + } else if (_removeObject == m_bufferManager) { + m_bufferManager = NULL; + autoDestroy(); + } +} + diff --git a/sources/appl/Gui/WorkerCloseFile.h b/sources/appl/Gui/WorkerCloseFile.h new file mode 100644 index 0000000..da5fa3f --- /dev/null +++ b/sources/appl/Gui/WorkerCloseFile.h @@ -0,0 +1,32 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license GPL v3 (see license file) + */ + +#ifndef __WORKER_CLOSE_FILE_H__ +#define __WORKER_CLOSE_FILE_H__ + +#include +#include +#include + +namespace appl { + class WorkerCloseFile : public ewol::EObject { + public: + // note : if == "" ==> current ... + WorkerCloseFile(const std::string& _bufferName); + virtual ~WorkerCloseFile(void); + private: + std::string m_bufferName; + appl::WorkerSaveFile* m_worker; //! sub-worker element... + appl::BufferManager* m_bufferManager; //!< handle on the buffer manager + public: // derived function + virtual void onReceiveMessage(const ewol::EMessage& _msg); + virtual void onObjectRemove(ewol::EObject * _removeObject); + }; +}; + +#endif \ No newline at end of file diff --git a/sources/appl/Gui/WorkerSaveAllFile.cpp b/sources/appl/Gui/WorkerSaveAllFile.cpp new file mode 100644 index 0000000..eb29b18 --- /dev/null +++ b/sources/appl/Gui/WorkerSaveAllFile.cpp @@ -0,0 +1,96 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license GPL v3 (see license file) + */ + +#include +#include +#include + +#undef __class__ +#define __class__ "WorkerSaveFile" + +static const char* s_saveAsDone = "save-as-done"; + +appl::WorkerSaveAllFile::WorkerSaveAllFile(void) : + m_worker(NULL), + m_bufferManager(NULL) { + // load buffer manager: + m_bufferManager = appl::BufferManager::keep(); + + if (m_bufferManager == NULL) { + APPL_ERROR("can not call unexistant buffer manager ... "); + autoDestroy(); + return; + } + // List all current open file : + for (size_t iii=0; iiisize(); ++iii) { + appl::Buffer* tmpBuffer = m_bufferManager->get(iii); + if (tmpBuffer == NULL) { + continue; + } + if (tmpBuffer->isModify() == false) { + continue; + } + if (tmpBuffer->hasFileName() == false) { + m_bufferNameList.push_back(tmpBuffer->getFileName()); + } else { + tmpBuffer->storeFile(); + } + } + // checkif an element has something to do in the queue + if (m_bufferNameList.size() == 0) { + autoDestroy(); + return; + } + // create the worker : + m_worker = new appl::WorkerSaveFile(m_bufferNameList.front()); + // remove first element : + m_bufferNameList.pop_front(); + if (m_bufferNameList.size() == 0) { + autoDestroy(); + return; + } + m_worker->registerOnEvent(this, appl::WorkerSaveFile::eventSaveDone, s_saveAsDone); +} + +appl::WorkerSaveAllFile::~WorkerSaveAllFile(void) { + appl::BufferManager::release(m_bufferManager); +} + +void appl::WorkerSaveAllFile::onReceiveMessage(const ewol::EMessage& _msg) { + if (m_bufferManager == NULL) { + // nothing to do in this case ==> can do nothing ... + return; + } + if (_msg.getMessage() == s_saveAsDone) { + if (m_bufferNameList.size() == 0) { + autoDestroy(); + return; + } + // create the worker : + m_worker = new appl::WorkerSaveFile(m_bufferNameList.front()); + // remove first element : + m_bufferNameList.pop_front(); + if (m_bufferNameList.size() == 0) { + autoDestroy(); + return; + } + m_worker->registerOnEvent(this, appl::WorkerSaveFile::eventSaveDone, s_saveAsDone); + } +} + +void appl::WorkerSaveAllFile::onObjectRemove(ewol::EObject* _removeObject) { + if (_removeObject == m_worker) { + m_worker = NULL; + APPL_VERBOSE("AutoRemove After saving sub widget ..."); + autoDestroy(); + } else if (_removeObject == m_bufferManager) { + m_bufferManager = NULL; + autoDestroy(); + } +} + diff --git a/sources/appl/Gui/WorkerSaveAllFile.h b/sources/appl/Gui/WorkerSaveAllFile.h new file mode 100644 index 0000000..444848c --- /dev/null +++ b/sources/appl/Gui/WorkerSaveAllFile.h @@ -0,0 +1,30 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license GPL v3 (see license file) + */ + +#ifndef __WORKER_SAVE_ALL_FILE_H__ +#define __WORKER_SAVE_ALL_FILE_H__ + +#include +#include + +namespace appl { + class WorkerSaveAllFile : public ewol::EObject { + public: + WorkerSaveAllFile(void); + virtual ~WorkerSaveAllFile(void); + private: + std::vector m_bufferNameList; + appl::WorkerSaveFile* m_worker; //! pop-up element that is open... + appl::BufferManager* m_bufferManager; //!< handle on the buffer manager + public: // derived function + virtual void onReceiveMessage(const ewol::EMessage& _msg); + virtual void onObjectRemove(ewol::EObject * _removeObject); + }; +}; + +#endif diff --git a/sources/appl/Gui/WorkerSaveFile.cpp b/sources/appl/Gui/WorkerSaveFile.cpp new file mode 100644 index 0000000..a0b1d19 --- /dev/null +++ b/sources/appl/Gui/WorkerSaveFile.cpp @@ -0,0 +1,110 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license GPL v3 (see license file) + */ + +#include +#include +#include + +#undef __class__ +#define __class__ "WorkerSaveFile" + +static const char* appl::WorkerSaveFile::eventSaveDone = "save-file-done"; + +static const char* s_saveAsValidate = "save-as-validate"; + +appl::WorkerSaveFile::WorkerSaveFile(const std::string& _bufferName, bool _forceSaveAs) : + m_bufferName(_bufferName), + m_chooser(NULL), + m_bufferManager(NULL) { + addEventId(eventSaveDone); + // load buffer manager: + m_bufferManager = appl::BufferManager::keep(); + + if (m_bufferManager == NULL) { + APPL_ERROR("can not call unexistant buffer manager ... "); + autoDestroy(); + return; + } + // TODO : if "" ==> it is current buffer selected ... + if (m_bufferManager->exist(m_bufferName) == false) { + APPL_ERROR("Try to save an non-existant file :" << m_bufferName); + autoDestroy(); + return; + } + appl::Buffer* tmpBuffer = m_bufferManager->get(m_bufferName); + if (tmpBuffer == NULL) { + APPL_ERROR("Error to get the buffer : " << m_bufferName); + autoDestroy(); + return; + } + m_chooser = new widget::FileChooser(); + if (NULL == m_chooser) { + APPL_ERROR("Can not allocate widget == > display might be in error"); + autoDestroy(); + return; + } + m_chooser->setTitle("Save files As..."); + m_chooser->setValidateLabel("Save"); + etk::FSNode tmpName(m_bufferName); + m_chooser->setFolder(tmpName.getNameFolder()); + m_chooser->setFileName(tmpName.getNameFile()); + ewol::Windows* tmpWindows = ewol::getContext().getWindows(); + if (tmpWindows == NULL) { + APPL_ERROR("Error to get the windows."); + autoDestroy(); + return; + } + tmpWindows->popUpWidgetPush(m_chooser); + m_chooser->registerOnEvent(this, widget::FileChooser::eventValidate, s_saveAsValidate); +} + +appl::WorkerSaveFile::~WorkerSaveFile(void) { + appl::BufferManager::release(m_bufferManager); +} + +void appl::WorkerSaveFile::onReceiveMessage(const ewol::EMessage& _msg) { + if (m_bufferManager == NULL) { + // nothing to do in this case ==> can do nothing ... + return; + } + if (_msg.getMessage() == s_saveAsValidate) { + if (_msg.getData() == "") { + APPL_ERROR(" might be an error of the File chooser system..."); + return; + } + if (m_bufferManager->exist(m_bufferName) == false) { + APPL_ERROR("Try to save an non-existant file :" << m_bufferName); + return; + } + appl::Buffer* tmpBuffer = m_bufferManager->get(m_bufferName); + if (tmpBuffer == NULL) { + APPL_ERROR("Error to get the buffer : " << m_bufferName); + return; + } + tmpBuffer->setFileName(_msg.getData()); + if (tmpBuffer->storeFile() == false) { + ewol::Windows* tmpWindows = ewol::getContext().getWindows(); + if (tmpWindows == NULL) { + return; + } + tmpWindows->displayWarningMessage("We can not save the file :
" + tmpBuffer->getFileName() + ""); + } + } +} + +void appl::WorkerSaveFile::onObjectRemove(ewol::EObject* _removeObject) { + if (_removeObject == m_chooser) { + m_chooser = NULL; + APPL_VERBOSE("AutoRemove After closing sub widget ..."); + autoDestroy(); + } else if (_removeObject == m_bufferManager) { + m_bufferManager = NULL; + autoDestroy(); + } +} + diff --git a/sources/appl/Gui/WorkerSaveFile.h b/sources/appl/Gui/WorkerSaveFile.h new file mode 100644 index 0000000..dd68411 --- /dev/null +++ b/sources/appl/Gui/WorkerSaveFile.h @@ -0,0 +1,32 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license GPL v3 (see license file) + */ + +#ifndef __WORKER_SAVE_FILE_H__ +#define __WORKER_SAVE_FILE_H__ + +#include +#include + +namespace appl { + class WorkerSaveFile : public ewol::EObject { + public: + static const char* eventSaveDone; + public: + WorkerSaveFile(const std::string& _bufferName, bool _forceSaveAs=false); + virtual ~WorkerSaveFile(void); + private: + std::string m_bufferName; + widget::FileChooser* m_chooser; //! pop-up element that is open... + appl::BufferManager* m_bufferManager; //!< handle on the buffer manager + public: // derived function + virtual void onReceiveMessage(const ewol::EMessage& _msg); + virtual void onObjectRemove(ewol::EObject * _removeObject); + }; +}; + +#endif diff --git a/sources/appl/globalMsg.cpp b/sources/appl/globalMsg.cpp index fa9fd5b..5a719f5 100644 --- a/sources/appl/globalMsg.cpp +++ b/sources/appl/globalMsg.cpp @@ -60,5 +60,6 @@ extern const char* const ednMsgBufferColor = "edn-Msg-Buffer-Color"; extern const char* const appl::MsgSelectNewFile = "edn-msg-select-new-file"; extern const char* const appl::MsgSelectChange = "edn-msg-select-change"; +extern const char* const appl::MsgNameChange = "edn-msg-buffer-name-change"; diff --git a/sources/appl/globalMsg.h b/sources/appl/globalMsg.h index 145b92e..c18659d 100644 --- a/sources/appl/globalMsg.h +++ b/sources/appl/globalMsg.h @@ -60,6 +60,7 @@ namespace appl { extern const char* const MsgSelectNewFile; // data : "buffer/name" extern const char* const MsgSelectChange; // data : "" + extern const char* const MsgNameChange; // data : "" }; #endif diff --git a/sources/appl/init.cpp b/sources/appl/init.cpp index 66e81e8..a2c02ef 100644 --- a/sources/appl/init.cpp +++ b/sources/appl/init.cpp @@ -34,9 +34,6 @@ #include #include -char32_t mychar32; - - /** * @brief Main of the program (This can be set in every case, but it is not used in Andoid...). * @param std IO diff --git a/sources/lutin_edn.py b/sources/lutin_edn.py index 38ea78b..d982f4c 100755 --- a/sources/lutin_edn.py +++ b/sources/lutin_edn.py @@ -25,7 +25,11 @@ def Create(target): 'appl/Gui/Search.cpp', 'appl/Gui/SearchData.cpp', 'appl/Gui/TagFileSelection.cpp', - 'appl/Gui/TagFileList.cpp']) + 'appl/Gui/TagFileList.cpp', + 'appl/Gui/WorkerSaveFile.cpp', + 'appl/Gui/WorkerSaveAllFile.cpp', + 'appl/Gui/WorkerCloseFile.cpp', + 'appl/Gui/WorkerCloseAllFile.cpp']) # All needed for the buffer management : myModule.AddSrcFile([