diff --git a/sources/appl/Gui/MainWindows.cpp b/sources/appl/Gui/MainWindows.cpp index f8d1ce8..a6d2860 100644 --- a/sources/appl/Gui/MainWindows.cpp +++ b/sources/appl/Gui/MainWindows.cpp @@ -293,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: " << _msg ); + APPL_VERBOSE("Receive Event from the main windows: " << _msg ); // open file Section ... if (_msg.getMessage() == ednMsgGuiOpen) { widget::FileChooser* tmpWidget = new widget::FileChooser(); diff --git a/sources/appl/Gui/TextViewer.h b/sources/appl/Gui/TextViewer.h index 6740a1d..571984e 100644 --- a/sources/appl/Gui/TextViewer.h +++ b/sources/appl/Gui/TextViewer.h @@ -21,17 +21,7 @@ #include namespace appl { - class TextViewerPlugin; - class TextPluginCopy; - class TextPluginMultiLineTab; - class TextPluginAutoIndent; - class TextPluginHistory; class TextViewer : public widget::WidgetScrooled { - friend class appl::TextViewerPlugin; - friend class appl::TextPluginCopy; - friend class appl::TextPluginMultiLineTab; - friend class appl::TextPluginAutoIndent; - friend class appl::TextPluginHistory; private: appl::GlyphPainting* m_paintingProperties; //!< element painting property esize_t m_colorBackground; @@ -86,8 +76,68 @@ namespace appl { bool replace(const std::u32string& _data) { return replace(to_u8string(_data)); } + /** + * @brief Remove selected data ... + */ void remove(void); + /** + * @brief Remove selected data ... (No plugin call) + */ + void removeDirect(void) { + if (m_buffer==NULL) { + return; + } + m_buffer->removeSelection(); + } + /** + * @brief copy data in the _data ref value. + * @param[out] _data Output stream to copy. + * @return true of no error occured. + */ + bool copy(std::string& _data) { + if (m_buffer==NULL) { + return false; + } + return m_buffer->copy(_data); + } + /** + * @brief copy data in the _data ref value. + * @param[out] _data Output stream to copy. + * @param[in] _pos Position to add the data. + * @param[in] _posEnd End position to end replace the data. + */ + void copy(std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) { + if (m_buffer==NULL) { + return; + } + m_buffer->copy(_data, _pos, _posEnd); + } + /** + * @brief Write data at a specific position (No plugin call) + * @param[in] _data Data to insert in the buffer + * @param[in] _pos Position to add the data. + * @return true if the write is done corectly + */ + bool writeDirect(const std::string& _data, const appl::Buffer::Iterator& _pos) { + if (m_buffer==NULL) { + return false; + } + return m_buffer->write(_data, _pos); + } + /** + * @brief Write data at a specific position (No plugin call) + * @param[in] _data Data to insert in the buffer + * @param[in] _pos Position to add the data. + * @param[in] _posEnd End position to end replace the data. + * @return true if the write is done corectly + */ + bool replaceDirect(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) { + if (m_buffer==NULL) { + return false; + } + return m_buffer->replace(_data, _pos, _posEnd); + } appl::Buffer::Iterator getMousePosition(const vec2& _relativePos); void mouseEventDouble(void); @@ -163,7 +213,7 @@ namespace appl { * @param[in] _start Start position of the selection * @param[in] _stop Stop position of the selection (the curor is set at this position) */ - virtual void select(appl::Buffer::Iterator& _start, appl::Buffer::Iterator& _stop) { + virtual void select(const appl::Buffer::Iterator& _start, const appl::Buffer::Iterator& _stop) { if (m_buffer==NULL) { return; } @@ -216,6 +266,17 @@ namespace appl { } return ret; } + /** + * @brief Get an iterator an an specific position + * @param[in] _pos Requested position of the iterator. + * @return The Iterator + */ + appl::Buffer::Iterator position(int64_t _pos) { + if (m_buffer==NULL) { + return appl::Buffer::Iterator(); + } + return m_buffer->position(_pos); + } /** * @brief Get the cursor position. * @return The iterator on the cursor position diff --git a/sources/appl/TextPluginAutoIndent.cpp b/sources/appl/TextPluginAutoIndent.cpp index 4f0850b..f42a278 100644 --- a/sources/appl/TextPluginAutoIndent.cpp +++ b/sources/appl/TextPluginAutoIndent.cpp @@ -38,11 +38,11 @@ bool appl::TextPluginAutoIndent::onEventEntry(appl::TextViewer& _textDrawer, if (_event.getSpecialKey().isSetShift() == true) { return false; } - appl::Buffer::Iterator startLine = _textDrawer.m_buffer->cursor(); - if (_textDrawer.m_buffer->hasTextSelected() == true) { - startLine = _textDrawer.m_buffer->selectStart(); + appl::Buffer::Iterator startLine = _textDrawer.cursor(); + if (_textDrawer.hasTextSelected() == true) { + startLine = _textDrawer.selectStart(); } - startLine = _textDrawer.m_buffer->getStartLine(startLine); + startLine = _textDrawer.getStartLine(startLine); std::string data = "\n"; diff --git a/sources/appl/TextPluginCopy.cpp b/sources/appl/TextPluginCopy.cpp index 60c1ede..06c0b23 100644 --- a/sources/appl/TextPluginCopy.cpp +++ b/sources/appl/TextPluginCopy.cpp @@ -21,12 +21,12 @@ appl::TextPluginCopy::TextPluginCopy(void) { void appl::TextPluginCopy::onPluginEnable(appl::TextViewer& _textDrawer) { // add event : - _textDrawer.registerMultiCast(ednMsgGuiCopy); - _textDrawer.registerMultiCast(ednMsgGuiPaste); - _textDrawer.registerMultiCast(ednMsgGuiCut); - _textDrawer.shortCutAdd("ctrl+x", ednMsgGuiCut, "STD"); - _textDrawer.shortCutAdd("ctrl+c", ednMsgGuiCopy, "STD"); - _textDrawer.shortCutAdd("ctrl+v", ednMsgGuiPaste, "STD"); + _textDrawer.ext_registerMultiCast(ednMsgGuiCopy); + _textDrawer.ext_registerMultiCast(ednMsgGuiPaste); + _textDrawer.ext_registerMultiCast(ednMsgGuiCut); + _textDrawer.ext_shortCutAdd("ctrl+x", ednMsgGuiCut, "STD"); + _textDrawer.ext_shortCutAdd("ctrl+c", ednMsgGuiCopy, "STD"); + _textDrawer.ext_shortCutAdd("ctrl+v", ednMsgGuiPaste, "STD"); } void appl::TextPluginCopy::onPluginDisable(appl::TextViewer& _textDrawer) { @@ -40,9 +40,9 @@ bool appl::TextPluginCopy::onReceiveMessage(appl::TextViewer& _textDrawer, } if ( _msg.getMessage() == ednMsgGuiCopy || _msg.getMessage() == ednMsgGuiCut) { - if (_textDrawer.m_buffer != NULL) { + if (_textDrawer.hasBuffer() == true) { std::string value; - _textDrawer.m_buffer->copy(value); + _textDrawer.copy(value); if (value.size() != 0) { ewol::clipBoard::set(ewol::clipBoard::clipboardStd, value); } @@ -52,7 +52,7 @@ bool appl::TextPluginCopy::onReceiveMessage(appl::TextViewer& _textDrawer, } return true; } else if (_msg.getMessage() == ednMsgGuiPaste) { - if (_textDrawer.m_buffer != NULL) { + if (_textDrawer.hasBuffer() == true) { ewol::clipBoard::request(ewol::clipBoard::clipboardStd); } return true; diff --git a/sources/appl/TextPluginHistory.cpp b/sources/appl/TextPluginHistory.cpp index 53632ac..cec5d30 100644 --- a/sources/appl/TextPluginHistory.cpp +++ b/sources/appl/TextPluginHistory.cpp @@ -29,10 +29,10 @@ appl::TextPluginHistory::~TextPluginHistory(void) { void appl::TextPluginHistory::onPluginEnable(appl::TextViewer& _textDrawer) { // add event : - _textDrawer.registerMultiCast(ednMsgGuiRedo); - _textDrawer.registerMultiCast(ednMsgGuiUndo); - _textDrawer.shortCutAdd("ctrl+z", ednMsgGuiUndo); - _textDrawer.shortCutAdd("ctrl+shift+z", ednMsgGuiRedo); + _textDrawer.ext_registerMultiCast(ednMsgGuiRedo); + _textDrawer.ext_registerMultiCast(ednMsgGuiUndo); + _textDrawer.ext_shortCutAdd("ctrl+z", ednMsgGuiUndo); + _textDrawer.ext_shortCutAdd("ctrl+shift+z", ednMsgGuiRedo); } void appl::TextPluginHistory::onPluginDisable(appl::TextViewer& _textDrawer) { @@ -55,9 +55,9 @@ bool appl::TextPluginHistory::onReceiveMessage(appl::TextViewer& _textDrawer, appl::History *tmpElement = m_redo[m_redo.size()-1]; m_redo.pop_back(); m_undo.push_back(tmpElement); - _textDrawer.m_buffer->replace(tmpElement->m_addedText, - _textDrawer.m_buffer->position(tmpElement->m_posAdded), - _textDrawer.m_buffer->position(tmpElement->m_endPosRemoved) ); + _textDrawer.replaceDirect(tmpElement->m_addedText, + _textDrawer.position(tmpElement->m_posAdded), + _textDrawer.position(tmpElement->m_endPosRemoved) ); return true; } else if (_msg.getMessage() == ednMsgGuiUndo) { @@ -71,9 +71,9 @@ bool appl::TextPluginHistory::onReceiveMessage(appl::TextViewer& _textDrawer, appl::History *tmpElement = m_undo[m_undo.size()-1]; m_undo.pop_back(); m_redo.push_back(tmpElement); - _textDrawer.m_buffer->replace(tmpElement->m_removedText, - _textDrawer.m_buffer->position(tmpElement->m_posAdded), - _textDrawer.m_buffer->position(tmpElement->m_endPosAdded) ); + _textDrawer.replaceDirect(tmpElement->m_removedText, + _textDrawer.position(tmpElement->m_posAdded), + _textDrawer.position(tmpElement->m_endPosAdded) ); return true; } @@ -121,13 +121,13 @@ bool appl::TextPluginHistory::onWrite(appl::TextViewer& _textDrawer, tmpElement->m_posAdded = (int64_t)_pos; tmpElement->m_endPosRemoved = (int64_t)_pos; } - _textDrawer.m_buffer->write(_data, _pos); + _textDrawer.writeDirect(_data, _pos); if (tmpElement != NULL) { - tmpElement->m_endPosAdded = (int64_t)_textDrawer.m_buffer->cursor(); + tmpElement->m_endPosAdded = (int64_t)_textDrawer.cursor(); clearRedo(); m_undo.push_back(tmpElement); } - appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.m_buffer->cursor()); + appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor()); return true; } @@ -143,15 +143,15 @@ bool appl::TextPluginHistory::onReplace(appl::TextViewer& _textDrawer, tmpElement->m_posAdded = (int64_t)_pos; tmpElement->m_addedText = _data; tmpElement->m_endPosRemoved = (int64_t)_posEnd; - _textDrawer.m_buffer->copy(tmpElement->m_removedText, _pos, _posEnd); + _textDrawer.copy(tmpElement->m_removedText, _pos, _posEnd); } - _textDrawer.m_buffer->replace(_data, _pos, _posEnd); + _textDrawer.replaceDirect(_data, _pos, _posEnd); if (tmpElement != NULL) { - tmpElement->m_endPosAdded = (int64_t)_textDrawer.m_buffer->cursor(); + tmpElement->m_endPosAdded = (int64_t)_textDrawer.cursor(); clearRedo(); m_undo.push_back(tmpElement); } - appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.m_buffer->cursor()); + appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor()); return true; } @@ -167,12 +167,12 @@ bool appl::TextPluginHistory::onRemove(appl::TextViewer& _textDrawer, tmpElement->m_posAdded = (int64_t)_pos; tmpElement->m_endPosAdded = tmpElement->m_posAdded; tmpElement->m_endPosRemoved = (int64_t)_posEnd; - _textDrawer.m_buffer->copy(tmpElement->m_removedText, _pos, _posEnd); + _textDrawer.copy(tmpElement->m_removedText, _pos, _posEnd); clearRedo(); m_undo.push_back(tmpElement); } - _textDrawer.m_buffer->removeSelection(); - appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.m_buffer->cursor()); + _textDrawer.removeDirect(); + appl::textPluginManager::onCursorMove(_textDrawer, _textDrawer.cursor()); return true; } diff --git a/sources/appl/TextPluginMultiLineTab.cpp b/sources/appl/TextPluginMultiLineTab.cpp index 64f4877..729ccb8 100644 --- a/sources/appl/TextPluginMultiLineTab.cpp +++ b/sources/appl/TextPluginMultiLineTab.cpp @@ -34,17 +34,17 @@ bool appl::TextPluginMultiLineTab::onEventEntry(appl::TextViewer& _textDrawer, if (localValue != etk::UChar::Tabulation) { return false; } - if (_textDrawer.m_buffer->hasTextSelected() == false) { + if (_textDrawer.hasTextSelected() == false) { return false; } - appl::Buffer::Iterator itStart = _textDrawer.m_buffer->selectStart(); - appl::Buffer::Iterator itStop = _textDrawer.m_buffer->selectStop(); + appl::Buffer::Iterator itStart = _textDrawer.selectStart(); + appl::Buffer::Iterator itStop = _textDrawer.selectStop(); // get the compleate section of the buffer : - itStart = _textDrawer.m_buffer->getStartLine(itStart); - itStop = _textDrawer.m_buffer->getEndLine(itStop); + itStart = _textDrawer.getStartLine(itStart); + itStop = _textDrawer.getEndLine(itStop); // copy the curent data in a classicle string: std::string data; - _textDrawer.m_buffer->copy(data, itStart, itStop); + _textDrawer.copy(data, itStart, itStop); // TODO : Change this ... bool m_useTabs = true; int32_t m_tabDist = 4; @@ -91,6 +91,6 @@ bool appl::TextPluginMultiLineTab::onEventEntry(appl::TextViewer& _textDrawer, } // Real replace of DATA : _textDrawer.replace(data, itStart, itStop); - _textDrawer.m_buffer->setSelectionPos(itStart); + _textDrawer.select(itStart, itStart+data.size()); return true; } \ No newline at end of file