[DEV] many small correction

This commit is contained in:
Edouard DUPIN 2013-11-21 21:56:22 +01:00
parent 069c457407
commit e15cb8e4b6
6 changed files with 52 additions and 28 deletions

View File

@ -20,6 +20,10 @@ const char* const appl::Buffer::eventChangeName = "edn-buffer-name-change";
appl::Buffer::Iterator& appl::Buffer::Iterator::operator++ (void) { appl::Buffer::Iterator& appl::Buffer::Iterator::operator++ (void) {
m_value = etk::UChar::Null; m_value = etk::UChar::Null;
if (m_current<0) {
m_current = 0;
return *this;
}
if ( m_data != NULL if ( m_data != NULL
&& m_current < m_data->m_data.size() ) { && m_current < m_data->m_data.size() ) {
int8_t nbChar = etk::UChar::theoricUTF8Len(m_data->m_data[m_current]); int8_t nbChar = etk::UChar::theoricUTF8Len(m_data->m_data[m_current]);
@ -47,6 +51,8 @@ appl::Buffer::Iterator& appl::Buffer::Iterator::operator-- (void) {
m_current = -1; m_current = -1;
} }
return *this; return *this;
} else {
m_current = -1;
} }
return *this; return *this;
} }
@ -91,6 +97,9 @@ appl::Buffer::Iterator appl::Buffer::end(void) {
} }
appl::Buffer::Iterator appl::Buffer::cursor(void) { appl::Buffer::Iterator appl::Buffer::cursor(void) {
if (m_cursorPos<= 0) {
return begin();
}
return position( m_cursorPos ); return position( m_cursorPos );
} }
@ -107,7 +116,7 @@ appl::Buffer::Buffer(void) :
m_hasFileName(false), m_hasFileName(false),
m_fileName(""), m_fileName(""),
m_isModify(false), m_isModify(false),
m_cursorPos(0), m_cursorPos(-1),
m_cursorSelectPos(-1), m_cursorSelectPos(-1),
m_cursorPreferredCol(-1), m_cursorPreferredCol(-1),
m_nbLines(1), m_nbLines(1),
@ -133,6 +142,7 @@ bool appl::Buffer::loadFile(const std::string& _name) {
m_fileName = _name; m_fileName = _name;
m_hasFileName = true; m_hasFileName = true;
m_isModify = true; m_isModify = true;
m_cursorPos = 0;
setHighlightType(""); setHighlightType("");
etk::FSNode file(m_fileName); etk::FSNode file(m_fileName);
if (file.exist() == false) { if (file.exist() == false) {
@ -181,12 +191,8 @@ void appl::Buffer::setModification(bool _status) {
} }
} }
// TODO : Naming error
void appl::Buffer::countNumberofLine(void) { void appl::Buffer::countNumberofLine(void) {
if (m_data.size() == 0) {
m_nbLines = 1;
return;
}
m_nbLines = 0; m_nbLines = 0;
for (Iterator it = begin(); for (Iterator it = begin();
(bool)it == true; (bool)it == true;
@ -195,6 +201,9 @@ void appl::Buffer::countNumberofLine(void) {
++m_nbLines; ++m_nbLines;
} }
} }
if (m_nbLines == 0) {
m_nbLines = 1;
}
} }
@ -203,7 +212,8 @@ appl::Buffer::Iterator appl::Buffer::getStartLine(const appl::Buffer::Iterator&
if (false == searchBack(_pos, etk::UChar::Return, startPos)) { if (false == searchBack(_pos, etk::UChar::Return, startPos)) {
return begin(); return begin();
} }
return startPos; // note search will return the position of \n ==> the lione start just after ...
return startPos+1;
} }
appl::Buffer::Iterator appl::Buffer::getEndLine(const appl::Buffer::Iterator& _pos) { appl::Buffer::Iterator appl::Buffer::getEndLine(const appl::Buffer::Iterator& _pos) {
@ -211,6 +221,7 @@ appl::Buffer::Iterator appl::Buffer::getEndLine(const appl::Buffer::Iterator& _p
if (false == search(_pos, etk::UChar::Return, endPos)) { if (false == search(_pos, etk::UChar::Return, endPos)) {
endPos = end(); endPos = end();
} }
// Note the line end at the \n
return endPos; return endPos;
} }
@ -412,7 +423,7 @@ appl::Buffer::Iterator appl::Buffer::countForwardNLines(const appl::Buffer::Iter
char32_t value; char32_t value;
int32_t lineCount = 0; int32_t lineCount = 0;
//APPL_INFO("startPos=" << startPos << " nLines=" << nLines); //APPL_INFO("startPos=" << startPos << " nLines=" << nLines);
for (Iterator it = ++position(_startPos); for (Iterator it = position(_startPos);
(bool)it == true; (bool)it == true;
++it) { ++it) {
value = *it; value = *it;
@ -433,7 +444,7 @@ appl::Buffer::Iterator appl::Buffer::countBackwardNLines(const appl::Buffer::Ite
char32_t value; char32_t value;
int32_t lineCount = 0; int32_t lineCount = 0;
for (Iterator it = --position(_startPos); for (Iterator it = --position(_startPos);
it != begin(); (bool)it == true;
--it) { --it) {
value = *it; value = *it;
if (value == etk::UChar::Return) { if (value == etk::UChar::Return) {

View File

@ -323,7 +323,7 @@ namespace appl {
return m_data; return m_data;
}; };
protected: protected:
esize_t m_cursorPos; //!< cursor position. int64_t m_cursorPos; //!< cursor position.
public: public:
void moveCursor(esize_t _pos); void moveCursor(esize_t _pos);
protected: protected:
@ -353,14 +353,14 @@ namespace appl {
* @brief Get the Start position of the selection. * @brief Get the Start position of the selection.
* @return position of the start selection. * @return position of the start selection.
*/ */
esize_t getStartSelectionPos(void) { int64_t getStartSelectionPos(void) {
return etk_min(m_cursorPos, m_cursorSelectPos); return etk_min(m_cursorPos, m_cursorSelectPos);
} }
/** /**
* @brief Get the Stop position of the selection. * @brief Get the Stop position of the selection.
* @return position of the stop selection. * @return position of the stop selection.
*/ */
esize_t getStopSelectionPos(void) { int64_t getStopSelectionPos(void) {
return etk_max(m_cursorPos, m_cursorSelectPos); return etk_max(m_cursorPos, m_cursorSelectPos);
} }
protected: protected:

View File

@ -238,9 +238,9 @@ MainWindows::MainWindows(void) {
(void)myMenu->addSpacer(); (void)myMenu->addSpacer();
(void)myMenu->add(idMenugDisplay, "Reload openGl Shader", "", ednMsgGuiReloadShader); (void)myMenu->add(idMenugDisplay, "Reload openGl Shader", "", ednMsgGuiReloadShader);
m_widgetLabelFileName = new widget::Label("<left>FileName</left>"); m_widgetLabelFileName = new widget::Label("FileName");
m_widgetLabelFileName->setExpand(bvec2(true,false)); m_widgetLabelFileName->setExpand(bvec2(true,false));
m_widgetLabelFileName->setFill(bvec2(false,true));; m_widgetLabelFileName->setFill(bvec2(true,false));;
mySizerHori->subWidgetAdd(m_widgetLabelFileName); mySizerHori->subWidgetAdd(m_widgetLabelFileName);
@ -279,6 +279,7 @@ MainWindows::MainWindows(void) {
registerMultiCast(ednMsgBufferId); registerMultiCast(ednMsgBufferId);
registerMultiCast(ednMsgGuiReloadShader); registerMultiCast(ednMsgGuiReloadShader);
registerMultiCast(appl::MsgNameGuiChangeColor); registerMultiCast(appl::MsgNameGuiChangeColor);
registerMultiCast(appl::MsgSelectNewFile);
} }
@ -350,11 +351,23 @@ void MainWindows::onReceiveMessage(const ewol::EMessage& _msg) {
APPL_ERROR("can not call unexistant buffer manager ... "); APPL_ERROR("can not call unexistant buffer manager ... ");
return; return;
} }
if (_msg.getMessage() == ednMsgGuiNew) { if (_msg.getMessage() == appl::MsgSelectNewFile) {
if (m_bufferManager == NULL) { // select a new Buffer ==> change title:
APPL_ERROR("can not call unexistant buffer manager ... "); appl::Buffer* tmpp = m_bufferManager->getBufferSelected();
return; if (tmpp == NULL) {
setTitle("Edn");
if (m_widgetLabelFileName != NULL) {
m_widgetLabelFileName->setLabel("");
}
} else {
setTitle(std::string("Edn : ") + (tmpp->isModify()==true?" *":"") + tmpp->getFileName());
if (m_widgetLabelFileName != NULL) {
m_widgetLabelFileName->setLabel(tmpp->getFileName() + (tmpp->isModify()==true?" *":""));
}
} }
} else if (_msg.getMessage() == ednMsgGuiNew) {
(void)m_bufferManager->createNewBuffer(); (void)m_bufferManager->createNewBuffer();
} else if (_msg.getMessage() == ednEventPopUpFileSelected) { } else if (_msg.getMessage() == ednEventPopUpFileSelected) {
APPL_DEBUG("Request opening the file : " << _msg.getData()); APPL_DEBUG("Request opening the file : " << _msg.getData());

View File

@ -696,7 +696,7 @@ void appl::TextViewer::updateScrolling(void) {
m_originScrooled.setY(realCursorPosition.y()-m_size.y()+lineSize*2.0f); m_originScrooled.setY(realCursorPosition.y()-m_size.y()+lineSize*2.0f);
} }
m_originScrooled.setMax(vec2(0,0)); m_originScrooled.setMax(vec2(0,0));
// TODO : Limit min position too ...
} }
bool appl::TextViewer::moveCursor(const appl::Buffer::Iterator& _pos) { bool appl::TextViewer::moveCursor(const appl::Buffer::Iterator& _pos) {
@ -790,6 +790,7 @@ void appl::TextViewer::moveCursorRight(appl::TextViewer::moveMode _mode) {
case moveLetter: case moveLetter:
it = m_buffer->cursor(); it = m_buffer->cursor();
++it; ++it;
APPL_ERROR("Cursor position : " << (esize_t)it);
moveCursor(it); moveCursor(it);
break; break;
case moveWord: case moveWord:
@ -813,6 +814,7 @@ void appl::TextViewer::moveCursorLeft(appl::TextViewer::moveMode _mode) {
case moveLetter: case moveLetter:
it = m_buffer->cursor();; it = m_buffer->cursor();;
--it; --it;
APPL_ERROR("Cursor position : " << (esize_t)it);
moveCursor(it); moveCursor(it);
break; break;
case moveWord: case moveWord:
@ -820,7 +822,7 @@ void appl::TextViewer::moveCursorLeft(appl::TextViewer::moveMode _mode) {
break; break;
case moveEnd: case moveEnd:
it = m_buffer->getStartLine(m_buffer->cursor()); it = m_buffer->getStartLine(m_buffer->cursor());
moveCursor(++it); moveCursor(it);
break; break;
} }
} }
@ -838,12 +840,11 @@ void appl::TextViewer::moveCursorUp(esize_t _nbLine) {
} }
// Decide what column to move to, if there's a preferred column use that // Decide what column to move to, if there's a preferred column use that
if (m_buffer->getFavoriteUpDownPos() < 0) { if (m_buffer->getFavoriteUpDownPos() < 0) {
// TODO : Remove this +1 !!! m_buffer->setFavoriteUpDownPos(getScreenSize(lineStartPos, m_buffer->cursor()));
m_buffer->setFavoriteUpDownPos(getScreenSize(lineStartPos+1, m_buffer->cursor()));
} }
EWOL_DEBUG("move_up : " << m_buffer->getFavoriteUpDownPos()); EWOL_DEBUG("move_up : " << m_buffer->getFavoriteUpDownPos());
// get the previous line // get the previous line
appl::Buffer::Iterator prevLineStartPos = m_buffer->countBackwardNLines(lineStartPos, _nbLine); appl::Buffer::Iterator prevLineStartPos = m_buffer->countBackwardNLines(lineStartPos-1, _nbLine);
//APPL_INFO("Move line UP result : prevLineStartPos=" << prevLineStartPos); //APPL_INFO("Move line UP result : prevLineStartPos=" << prevLineStartPos);
// get the display char position // get the display char position
appl::Buffer::Iterator newPos = getPosSize(prevLineStartPos, m_buffer->getFavoriteUpDownPos()); appl::Buffer::Iterator newPos = getPosSize(prevLineStartPos, m_buffer->getFavoriteUpDownPos());
@ -866,8 +867,7 @@ void appl::TextViewer::moveCursorDown(esize_t _nbLine) {
appl::Buffer::Iterator lineStartPos = m_buffer->getStartLine(m_buffer->cursor()); appl::Buffer::Iterator lineStartPos = m_buffer->getStartLine(m_buffer->cursor());
if (m_buffer->getFavoriteUpDownPos() < 0) { if (m_buffer->getFavoriteUpDownPos() < 0) {
// TODO : Remove this +1 !!! m_buffer->setFavoriteUpDownPos(getScreenSize(lineStartPos, m_buffer->cursor()));
m_buffer->setFavoriteUpDownPos(getScreenSize(lineStartPos+1, m_buffer->cursor()));
} }
EWOL_DEBUG("move down : " << m_buffer->getFavoriteUpDownPos()); EWOL_DEBUG("move down : " << m_buffer->getFavoriteUpDownPos());
// get the next line : // get the next line :

View File

@ -48,7 +48,7 @@ bool appl::TextPluginCopy::onReceiveMessage(appl::TextViewer& _textDrawer,
} }
} }
if (_msg.getMessage() == ednMsgGuiCut) { if (_msg.getMessage() == ednMsgGuiCut) {
_textDrawer.m_buffer->removeSelection(); _textDrawer.remove();
} }
return true; return true;
} else if (_msg.getMessage() == ednMsgGuiPaste) { } else if (_msg.getMessage() == ednMsgGuiPaste) {

View File

@ -40,7 +40,7 @@ bool appl::TextPluginMultiLineTab::onEventEntry(appl::TextViewer& _textDrawer,
appl::Buffer::Iterator itStart = _textDrawer.m_buffer->selectStart(); appl::Buffer::Iterator itStart = _textDrawer.m_buffer->selectStart();
appl::Buffer::Iterator itStop = _textDrawer.m_buffer->selectStop(); appl::Buffer::Iterator itStop = _textDrawer.m_buffer->selectStop();
// get the compleate section of the buffer : // get the compleate section of the buffer :
itStart = _textDrawer.m_buffer->getStartLine(itStart+1); itStart = _textDrawer.m_buffer->getStartLine(itStart);
itStop = _textDrawer.m_buffer->getEndLine(itStop); itStop = _textDrawer.m_buffer->getEndLine(itStop);
// copy the curent data in a classicle string: // copy the curent data in a classicle string:
std::string data; std::string data;
@ -91,6 +91,6 @@ bool appl::TextPluginMultiLineTab::onEventEntry(appl::TextViewer& _textDrawer,
} }
// Real replace of DATA : // Real replace of DATA :
_textDrawer.replace(data, itStart, itStop); _textDrawer.replace(data, itStart, itStop);
_textDrawer.m_buffer->setSelectionPos(itStart+1); _textDrawer.m_buffer->setSelectionPos(itStart);
return true; return true;
} }