[DEBUG #1] Save file done
This commit is contained in:
parent
3574fd917c
commit
996fd58370
@ -20,10 +20,10 @@ appl::WorkerCloseAllFile::WorkerCloseAllFile() {
|
||||
}
|
||||
|
||||
void appl::WorkerCloseAllFile::init() {
|
||||
ewol::Object::init();
|
||||
ewol::object::Worker::init();
|
||||
if (m_bufferManager == nullptr) {
|
||||
APPL_ERROR("can not call unexistant buffer manager ... ");
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
// List all current open file :
|
||||
@ -41,7 +41,7 @@ void appl::WorkerCloseAllFile::init() {
|
||||
}
|
||||
// checkif an element has something to do in the queue
|
||||
if (m_bufferNameList.size() == 0) {
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
// create the worker :
|
||||
@ -49,14 +49,14 @@ void appl::WorkerCloseAllFile::init() {
|
||||
// remove first element :
|
||||
m_bufferNameList.erase(m_bufferNameList.begin());
|
||||
if (m_bufferNameList.size() == 0) {
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
m_worker->signalCloseDone.bind(shared_from_this(), &appl::WorkerCloseAllFile::onCallbackCloseDone);
|
||||
}
|
||||
|
||||
appl::WorkerCloseAllFile::~WorkerCloseAllFile() {
|
||||
|
||||
APPL_ERROR("Remove Worker");
|
||||
}
|
||||
|
||||
void appl::WorkerCloseAllFile::onCallbackCloseDone() {
|
||||
@ -65,7 +65,7 @@ void appl::WorkerCloseAllFile::onCallbackCloseDone() {
|
||||
return;
|
||||
}
|
||||
if (m_bufferNameList.size() == 0) {
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
// create the worker :
|
||||
@ -73,7 +73,7 @@ void appl::WorkerCloseAllFile::onCallbackCloseDone() {
|
||||
// remove first element :
|
||||
m_bufferNameList.erase(m_bufferNameList.begin());
|
||||
if (m_bufferNameList.size() == 0) {
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
m_worker->signalCloseDone.bind(shared_from_this(), &appl::WorkerCloseAllFile::onCallbackCloseDone);
|
||||
|
@ -9,11 +9,12 @@
|
||||
#ifndef __WORKER_CLOSE_ALL_FILE_H__
|
||||
#define __WORKER_CLOSE_ALL_FILE_H__
|
||||
|
||||
#include <ewol/object/Worker.h>
|
||||
#include <appl/BufferManager.h>
|
||||
#include <appl/Gui/WorkerCloseFile.h>
|
||||
|
||||
namespace appl {
|
||||
class WorkerCloseAllFile : public ewol::Object {
|
||||
class WorkerCloseAllFile : public ewol::object::Worker {
|
||||
protected:
|
||||
WorkerCloseAllFile();
|
||||
void init();
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
appl::WorkerCloseFile::WorkerCloseFile() :
|
||||
signalCloseDone(*this, "close-file-done"),
|
||||
signalAbort(*this, "close-file-abort"),
|
||||
m_buffer(nullptr),
|
||||
m_worker(nullptr),
|
||||
m_bufferManager(nullptr) {
|
||||
@ -25,11 +26,11 @@ appl::WorkerCloseFile::WorkerCloseFile() :
|
||||
}
|
||||
|
||||
void appl::WorkerCloseFile::init(const std::string& _bufferName) {
|
||||
ewol::Object::init();
|
||||
ewol::object::Worker::init();
|
||||
m_bufferName = _bufferName;
|
||||
if (m_bufferManager == nullptr) {
|
||||
APPL_ERROR("can not call unexistant buffer manager ... ");
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
if (m_bufferName == "") {
|
||||
@ -44,13 +45,13 @@ void appl::WorkerCloseFile::init(const std::string& _bufferName) {
|
||||
}
|
||||
if (m_bufferManager->exist(m_bufferName) == false) {
|
||||
APPL_ERROR("Try to close an non-existant file :" << m_bufferName);
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
m_buffer = m_bufferManager->get(m_bufferName);
|
||||
if (m_buffer == nullptr) {
|
||||
APPL_ERROR("Error to get the buffer : " << m_bufferName);
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
if (m_buffer->isModify() == false) {
|
||||
@ -81,21 +82,29 @@ void appl::WorkerCloseFile::init(const std::string& _bufferName) {
|
||||
if (bt != nullptr) {
|
||||
bt->signalPressed.bind(shared_from_this(), &appl::WorkerCloseFile::onCallbackClose);
|
||||
}
|
||||
tmpPopUp->addButton("Cancel", true);
|
||||
bt = tmpPopUp->addButton("Cancel", true);
|
||||
if (bt != nullptr) {
|
||||
bt->signalPressed.bind(shared_from_this(), &appl::WorkerCloseFile::onCallbackCancel);
|
||||
}
|
||||
tmpPopUp->setRemoveOnExternClick(true);
|
||||
std::shared_ptr<ewol::widget::Windows> tmpWindows = ewol::getContext().getWindows();
|
||||
if (tmpWindows == nullptr) {
|
||||
APPL_ERROR("Error to get the windows.");
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
tmpWindows->popUpWidgetPush(tmpPopUp);
|
||||
}
|
||||
|
||||
appl::WorkerCloseFile::~WorkerCloseFile() {
|
||||
|
||||
APPL_ERROR("Remove Worker");
|
||||
}
|
||||
|
||||
void appl::WorkerCloseFile::onCallbackCancel() {
|
||||
APPL_VERBOSE("Cancel signal ...");
|
||||
signalAbort.emit();
|
||||
destroy();
|
||||
}
|
||||
|
||||
void appl::WorkerCloseFile::onCallbackSaveAsValidate() {
|
||||
if (m_bufferManager == nullptr) {
|
||||
@ -105,17 +114,21 @@ void appl::WorkerCloseFile::onCallbackSaveAsValidate() {
|
||||
m_worker = appl::WorkerSaveFile::create(m_bufferName);
|
||||
if (m_worker != nullptr) {
|
||||
m_worker->signalSaveDone.bind(shared_from_this(), &appl::WorkerCloseFile::onCallbackClose);
|
||||
m_worker->signalAbort.bind(shared_from_this(), &appl::WorkerCloseFile::onCallbackCancel);
|
||||
}
|
||||
}
|
||||
|
||||
void appl::WorkerCloseFile::onCallbackSaveValidate() {
|
||||
if (m_bufferManager == nullptr) {
|
||||
// nothing to do in this case ==> can do nothing ...
|
||||
signalAbort.emit();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
if (m_buffer == nullptr) {
|
||||
APPL_ERROR("Error to get the buffer : oldName=" << m_bufferName);
|
||||
autoDestroy();
|
||||
signalAbort.emit();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
if (m_buffer->storeFile() == false) {
|
||||
@ -124,23 +137,29 @@ void appl::WorkerCloseFile::onCallbackSaveValidate() {
|
||||
return;
|
||||
}
|
||||
tmpWindows->displayWarningMessage("We can not save the file : <br/><i>" + m_buffer->getFileName() + "</i>");
|
||||
signalAbort.emit();
|
||||
} else {
|
||||
signalCloseDone.emit();
|
||||
}
|
||||
destroy();
|
||||
}
|
||||
|
||||
void appl::WorkerCloseFile::onCallbackClose() {
|
||||
if (m_bufferManager == nullptr) {
|
||||
// nothing to do in this case ==> can do nothing ...
|
||||
signalAbort.emit();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
if (m_buffer == nullptr) {
|
||||
APPL_ERROR("Error to get the buffer : " << m_bufferName);
|
||||
autoDestroy();
|
||||
signalAbort.emit();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
signalCloseDone.emit();
|
||||
m_buffer->destroy();
|
||||
m_buffer.reset();
|
||||
signalCloseDone.emit();
|
||||
destroy();
|
||||
}
|
||||
|
||||
|
@ -9,14 +9,16 @@
|
||||
#ifndef __WORKER_CLOSE_FILE_H__
|
||||
#define __WORKER_CLOSE_FILE_H__
|
||||
|
||||
#include <ewol/object/Worker.h>
|
||||
#include <ewol/widget/meta/FileChooser.h>
|
||||
#include <appl/BufferManager.h>
|
||||
#include <appl/Gui/WorkerSaveFile.h>
|
||||
|
||||
namespace appl {
|
||||
class WorkerCloseFile : public ewol::Object {
|
||||
class WorkerCloseFile : public ewol::object::Worker {
|
||||
public:
|
||||
ewol::object::Signal<void> signalCloseDone;
|
||||
ewol::object::Signal<void> signalAbort;
|
||||
protected:
|
||||
// note : if == "" ==> current ...
|
||||
WorkerCloseFile();
|
||||
@ -33,6 +35,7 @@ namespace appl {
|
||||
void onCallbackSaveAsValidate();
|
||||
void onCallbackSaveValidate();
|
||||
void onCallbackClose();
|
||||
void onCallbackCancel();
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -20,10 +20,10 @@ appl::WorkerSaveAllFile::WorkerSaveAllFile() {
|
||||
}
|
||||
|
||||
void appl::WorkerSaveAllFile::init() {
|
||||
ewol::Object::init();
|
||||
ewol::object::Worker::init();
|
||||
if (m_bufferManager == nullptr) {
|
||||
APPL_ERROR("can not call unexistant buffer manager ... ");
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
// List all current open file :
|
||||
@ -43,7 +43,7 @@ void appl::WorkerSaveAllFile::init() {
|
||||
}
|
||||
// checkif an element has something to do in the queue
|
||||
if (m_bufferNameList.size() == 0) {
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
// create the worker :
|
||||
@ -51,14 +51,14 @@ void appl::WorkerSaveAllFile::init() {
|
||||
// remove first element :
|
||||
m_bufferNameList.erase(m_bufferNameList.begin());
|
||||
if (m_bufferNameList.size() == 0) {
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
m_worker->signalSaveDone.bind(shared_from_this(), &appl::WorkerSaveAllFile::onCallbackSaveAsDone);
|
||||
}
|
||||
|
||||
appl::WorkerSaveAllFile::~WorkerSaveAllFile() {
|
||||
|
||||
APPL_ERROR("Remove Worker");
|
||||
}
|
||||
|
||||
void appl::WorkerSaveAllFile::onCallbackSaveAsDone() {
|
||||
@ -67,7 +67,7 @@ void appl::WorkerSaveAllFile::onCallbackSaveAsDone() {
|
||||
return;
|
||||
}
|
||||
if (m_bufferNameList.size() == 0) {
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
// create the worker :
|
||||
@ -75,7 +75,7 @@ void appl::WorkerSaveAllFile::onCallbackSaveAsDone() {
|
||||
// remove first element :
|
||||
m_bufferNameList.erase(m_bufferNameList.begin());
|
||||
if (m_bufferNameList.size() == 0) {
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
m_worker->signalSaveDone.bind(shared_from_this(), &appl::WorkerSaveAllFile::onCallbackSaveAsDone);
|
||||
|
@ -9,11 +9,12 @@
|
||||
#ifndef __WORKER_SAVE_ALL_FILE_H__
|
||||
#define __WORKER_SAVE_ALL_FILE_H__
|
||||
|
||||
#include <ewol/object/Worker.h>
|
||||
#include <appl/BufferManager.h>
|
||||
#include <appl/Gui/WorkerSaveFile.h>
|
||||
|
||||
namespace appl {
|
||||
class WorkerSaveAllFile : public ewol::Object {
|
||||
class WorkerSaveAllFile : public ewol::object::Worker {
|
||||
protected:
|
||||
WorkerSaveAllFile();
|
||||
void init();
|
||||
|
@ -15,18 +15,19 @@
|
||||
|
||||
|
||||
appl::WorkerSaveFile::WorkerSaveFile() :
|
||||
signalSaveDone(*this, "save-file-done") {
|
||||
signalSaveDone(*this, "save-file-done"),
|
||||
signalAbort(*this, "save-file-abort") {
|
||||
addObjectType("appl::WorkerSaveFile");
|
||||
// load buffer manager:
|
||||
m_bufferManager = appl::BufferManager::create();
|
||||
}
|
||||
|
||||
void appl::WorkerSaveFile::init(const std::string& _bufferName, bool _forceSaveAs) {
|
||||
ewol::Object::init();
|
||||
ewol::object::Worker::init();
|
||||
m_bufferName = _bufferName;
|
||||
if (m_bufferManager == nullptr) {
|
||||
APPL_ERROR("can not call unexistant buffer manager ... ");
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
if (m_bufferName == "") {
|
||||
@ -34,34 +35,34 @@ void appl::WorkerSaveFile::init(const std::string& _bufferName, bool _forceSaveA
|
||||
std::shared_ptr<appl::Buffer> tmpp = m_bufferManager->getBufferSelected();
|
||||
if (tmpp == nullptr) {
|
||||
APPL_ERROR("No selected buffer now ...");
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
m_bufferName = tmpp->getFileName();
|
||||
}
|
||||
if (m_bufferManager->exist(m_bufferName) == false) {
|
||||
APPL_ERROR("Try to save an non-existant file :" << m_bufferName);
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<appl::Buffer> tmpBuffer = m_bufferManager->get(m_bufferName);
|
||||
if (tmpBuffer == nullptr) {
|
||||
APPL_ERROR("Error to get the buffer : " << m_bufferName);
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
if (_forceSaveAs == false) {
|
||||
if (tmpBuffer->hasFileName() == true) {
|
||||
tmpBuffer->storeFile();
|
||||
signalSaveDone.emit();
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_chooser = ewol::widget::FileChooser::create();
|
||||
if (nullptr == m_chooser) {
|
||||
APPL_ERROR("Can not allocate widget == > display might be in error");
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
m_chooser->setTitle("Save files As...");
|
||||
@ -72,44 +73,56 @@ void appl::WorkerSaveFile::init(const std::string& _bufferName, bool _forceSaveA
|
||||
std::shared_ptr<ewol::widget::Windows> tmpWindows = ewol::getContext().getWindows();
|
||||
if (tmpWindows == nullptr) {
|
||||
APPL_ERROR("Error to get the windows.");
|
||||
autoDestroy();
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
tmpWindows->popUpWidgetPush(m_chooser);
|
||||
m_chooser->signalValidate.bind(shared_from_this(), &appl::WorkerSaveFile::onCallbackSaveAsValidate);
|
||||
m_chooser->signalCancel.bind(shared_from_this(), &appl::WorkerSaveFile::onCallbackCancel);
|
||||
}
|
||||
|
||||
appl::WorkerSaveFile::~WorkerSaveFile() {
|
||||
|
||||
APPL_ERROR("Remove Worker");
|
||||
}
|
||||
|
||||
void appl::WorkerSaveFile::onCallbackCancel() {
|
||||
signalAbort.emit();
|
||||
destroy();
|
||||
}
|
||||
|
||||
void appl::WorkerSaveFile::onCallbackSaveAsValidate(const std::string& _value) {
|
||||
if (m_bufferManager == nullptr) {
|
||||
// nothing to do in this case ==> can do nothing ...
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
if (_value == "") {
|
||||
APPL_ERROR(" might be an error of the File chooser system...");
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
if (m_bufferManager->exist(m_bufferName) == false) {
|
||||
APPL_ERROR("Try to save an non-existant file :" << m_bufferName);
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<appl::Buffer> tmpBuffer = m_bufferManager->get(m_bufferName);
|
||||
if (tmpBuffer == nullptr) {
|
||||
APPL_ERROR("Error to get the buffer : " << m_bufferName);
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
tmpBuffer->setFileName(_value);
|
||||
if (tmpBuffer->storeFile() == false) {
|
||||
std::shared_ptr<ewol::widget::Windows> tmpWindows = ewol::getContext().getWindows();
|
||||
if (tmpWindows == nullptr) {
|
||||
destroy();
|
||||
return;
|
||||
}
|
||||
tmpWindows->displayWarningMessage("We can not save the file : <br/><i>" + tmpBuffer->getFileName() + "</i>");
|
||||
} else {
|
||||
signalSaveDone.emit();
|
||||
}
|
||||
destroy();
|
||||
}
|
||||
|
||||
|
@ -10,12 +10,14 @@
|
||||
#define __WORKER_SAVE_FILE_H__
|
||||
|
||||
#include <ewol/widget/meta/FileChooser.h>
|
||||
#include <ewol/object/Worker.h>
|
||||
#include <appl/BufferManager.h>
|
||||
|
||||
namespace appl {
|
||||
class WorkerSaveFile : public ewol::Object {
|
||||
class WorkerSaveFile : public ewol::object::Worker {
|
||||
public:
|
||||
ewol::object::Signal<void> signalSaveDone;
|
||||
ewol::object::Signal<void> signalAbort;
|
||||
protected:
|
||||
WorkerSaveFile();
|
||||
void init(const std::string& _bufferName, bool _forceSaveAs=true);
|
||||
@ -28,6 +30,7 @@ namespace appl {
|
||||
std::shared_ptr<appl::BufferManager> m_bufferManager; //!< handle on the buffer manager
|
||||
public: // callback function
|
||||
void onCallbackSaveAsValidate(const std::string& _value);
|
||||
void onCallbackCancel();
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user