Beispiel #1
0
void Document :: uncommentBlock()
{
   int selection = _selection;
   _selection = 0;

   if (selection < 0) {
      _caret.moveOn(selection);
      selection = -selection;
   }
   Point caret = _caret.getCaret();
   TextBookmark end = _caret;
   end.moveOn(selection);

   text_c line[3];
   while ((size_t)caret.y <= end.getRow()) {
      if (!_caret.moveTo(0, caret.y))
         return;

      _text->copyTo(_caret, line, 2);
      if (text_str(_T("//")).compare(line, 2)) {
         eraseChar(false);
         eraseChar(false);
      }
      caret.y++;
   }
}
Beispiel #2
0
bool Document :: findLine(text_t text, bool matchCase, bool wholeWord)
{
   TextBookmark bookmark = _caret;
   if (_text->findWord(bookmark, text, matchCase, wholeWord ? TERMINATORS : NULL)) {
      setCaret(bookmark.getCaret(false), false);
      setCaret(_caret.getColumn() + _ELENA_::getlength(text), _caret.getRow(), true);

      return true;
   }
   else return false;
}
Beispiel #3
0
int Document :: retrieveColumn(int row, int disp)
{
   TextBookmark bm = _caret;

   _text->validateBookmark(bm);

   bm.moveTo(0, row);
   bm.moveOn(disp);

   return bm.getColumn();
}
const _text_t* SourceDoc :: getCurrentLine(int disp, size_t& length)
{
   TextBookmark bm = _caret;
   bm.moveTo(0, _caret.getRow());
   if (disp == 0 || bm.moveOn(disp)) {
      return _text->getLine(bm, length);
   }
   else {
      length = 0;

      return NULL;
   }
}
_text_t SourceDoc :: getCurrentChar()
{
   size_t length = 0;
   const _text_t* line = NULL;

   TextBookmark bm = _caret;
   // return current or previous if EOL
   if (!bm.isEOL()) {
      line = _text->getLine(bm, length);
   }
   else {
      if (bm.moveOn(-1))
         line = _text->getLine(bm, length);
   }

   return (length > 0) ? line[0] : 0;
}
Beispiel #6
0
void Document :: tabbing(text_c space, size_t count, bool indent)
{
   _text->validateBookmark(_caret);

   if (_selection < 0) {
      _caret.moveOn(_selection);
      _selection = abs(_selection);
   }
   TextBookmark end = _caret;

   end.moveOn(_selection);

   // if only part of the line was selected just insert tab
   size_t lastRow = end.getRow();
   if (lastRow == _caret.getRow()) {
      if (indent)
         insertChar(space, count);
   }
   else {
      setCaret(0, _caret.getRow(), true);

      if (end.getColumn() == 0)
         lastRow--;

      TextBookmark start = _caret;
      while (start.getRow() <= lastRow) {
         if (indent) {
            for (size_t i = 0 ; i < count ; i++) {
               _text->insertChar(start, space);
               _selection++;
            }
         }
         else {
            size_t length;
            for (size_t i = 0 ; i < count ; i++) {
               text_t s = _text->getLine(start, length);
               if (length!=0 && (s[0]==' ' || s[0]=='\t')) {
                  bool tab = (s[0]=='\t');

                  _text->eraseChar(start);
                  _selection--;

                  if (tab)
                     break;
               }
               else break;
            }
         }
         if(!start.moveTo(0, start.getRow() + 1))
            break;
      }
   }
}
Beispiel #7
0
void Document :: commentBlock()
{
   int selection = _selection;
   _selection = 0;

   if (selection < 0) {
      _caret.moveOn(selection);
      selection = -selection;
   }
   Point caret = _caret.getCaret();
   TextBookmark end = _caret;
   end.moveOn(selection);

   while ((size_t)caret.y < end.getRow() || ((size_t)caret.y == end.getRow() && end.getColumn() > 0)) {
      if (!_caret.moveTo(0, caret.y))
         return;

      insertLine(_T("//"), 2);
      caret.y++;
   }
}
Beispiel #8
0
void Document :: duplicateLine()
{
   Point caret = _caret.getCaret(false);

   _caret.moveTo(0, caret.y);

   TextBookmark bm = _caret;
   bm.moveTo(_caret.getLength(), caret.y);

   size_t length = bm.getPosition() - _caret.getPosition();
   text_c* buffer = _ELENA_::StrFactory::allocate(length + 1, DEFAULT_TEXT);
   _text->copyTo(_caret, buffer, length);

   _caret.moveTo(0, caret.y + 1);
   _text->insertNewLine(_caret);
   _text->insertLine(_caret, buffer, length);

   _ELENA_::freestr(buffer);

   setCaret(caret.x, caret.y + 1, false);
}