diff --git a/lutin_edn.py b/lutin_edn.py index 50d173e..50316d2 100644 --- a/lutin_edn.py +++ b/lutin_edn.py @@ -1,7 +1,7 @@ #!/usr/bin/python import lutin.module as module import lutin.tools as tools -import lutin.debug as debug +import realog.debug as debug import os def get_type(): diff --git a/sources/appl/Buffer.cpp b/sources/appl/Buffer.cpp index 361c245..d7cc813 100644 --- a/sources/appl/Buffer.cpp +++ b/sources/appl/Buffer.cpp @@ -5,6 +5,9 @@ */ #include #include +#include +#include + #include #include #include @@ -108,6 +111,7 @@ appl::Buffer::Iterator appl::Buffer::selectStop() { } appl::Buffer::Buffer() : + signalFileIsModify(this, "file-is-modify", ""), signalIsModify(this, "is-modify", ""), signalIsSave(this, "is-save", ""), signalSelectChange(this, "select-change", ""), @@ -146,6 +150,7 @@ bool appl::Buffer::loadFile(const etk::Path& _name) { countNumberofLine(); tryFindHighlightType(); m_isModify = false; + m_fileIsModify = false; return true; } return false; @@ -165,6 +170,31 @@ void appl::Buffer::setFileName(const etk::Path& _name) { bool appl::Buffer::storeFile() { if (m_data.dumpIn(m_fileName) == true) { APPL_INFO("saving file : " << m_fileName); + etk::String extention = m_fileName.getExtention(); + if (etk::isIn(extention, {"cpp", "hpp", "h", "hpp"}) { + etk::Path clangFile = etk::path::findInParent(m_fileName, ".clang-format"); + if (etk::path::isFile(clangFile) == true) { + etk::String output = etk::exec("clang-format " + m_fileName.getAbsolute());// + " -assume-filename=" + clangFile.getAbsolute() + " + etk::String tmp = m_data.getString(); + /* + APPL_WARNING(" input = '" << tmp << "'"); + APPL_ERROR(" output = '" << output << "'"); + */ + if (tmp != output) { + /* + etk::io::File file(m_fileName + "_tmp"); + file.open(etk::io::OpenMode::Write); + file.write(&tmp[0], 1, tmp.size()); + file.close(); + */ + APPL_ERROR(" ==> data is differents"); + m_fileIsModify = true; + setModification(true); + signalFileIsModify(); + return true; + } + } + } setModification(false); return true; } diff --git a/sources/appl/Buffer.hpp b/sources/appl/Buffer.hpp index e592618..310ed2f 100644 --- a/sources/appl/Buffer.hpp +++ b/sources/appl/Buffer.hpp @@ -287,6 +287,7 @@ namespace appl { friend class Buffer; }; public: // signals + esignal::Signal<> signalFileIsModify; esignal::Signal<> signalIsModify; esignal::Signal<> signalIsSave; esignal::Signal<> signalSelectChange; @@ -297,6 +298,15 @@ namespace appl { public: DECLARE_FACTORY(Buffer); virtual ~Buffer(); + private: + bool m_fileIsModify = false; //!< The file has been modify and the buffer is not synchronous + public: + /** + * @brief get the curent filename of the Buffer + */ + bool getFileModify() const { + return m_fileIsModify; + } private: bool m_hasFileName; //!< When new file, the buffer has no name ==> but it might be reference with a single name ... etk::Path m_fileName; //!< name of the file (with his path)