~ubuntu-branches/ubuntu/quantal/kate/quantal-proposed

« back to all changes in this revision

Viewing changes to part/buffer/katetextbuffer.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-14 13:28:06 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20111214132806-aa2uf6ri5w2p8ak3
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
namespace Kate {
33
33
 
34
 
TextBuffer::TextBuffer (KTextEditor::Document *parent, int blockSize)
 
34
TextBuffer::TextBuffer (KateDocument *parent, int blockSize)
35
35
  : QObject (parent)
36
36
  , m_document (parent)
37
37
  , m_history (*this)
50
50
  , m_generateByteOrderMark (false)
51
51
  , m_endOfLineMode (eolUnix)
52
52
  , m_removeTrailingSpaces (false)
 
53
  , m_lineLengthLimit (1024)
53
54
{
54
55
  // minimal block size must be > 0
55
56
  Q_ASSERT (m_blockSize > 0);
166
167
  if (m_editingTransactions > 1)
167
168
    return false;
168
169
 
169
 
  // reset informations about edit...
 
170
  // reset information about edit...
170
171
  m_editingLastRevision = m_revision;
171
172
  m_editingLastLines = m_lines;
172
173
  m_editingMinimalLineChanged = -1;
323
324
  // only ranges on one line are supported
324
325
  Q_ASSERT (range.start().line() == range.end().line());
325
326
 
326
 
  // start colum <= end column and >= 0
 
327
  // start column <= end column and >= 0
327
328
  Q_ASSERT (range.start().column() <= range.end().column());
328
329
  Q_ASSERT (range.start().column() >= 0);
329
330
 
470
471
    m_blocks.at(i)->debugPrint (i);
471
472
}
472
473
 
473
 
bool TextBuffer::load (const QString &filename, bool &encodingErrors)
 
474
bool TextBuffer::load (const QString &filename, bool &encodingErrors, bool &tooLongLinesWrapped)
474
475
{
475
476
  // fallback codec must exist
476
477
  Q_ASSERT (m_fallbackTextCodec);
556
557
 
557
558
      // get unicode data for this line
558
559
      const QChar *unicodeData = file.unicode () + offset;
559
 
 
560
 
      // construct new text line with content from file
561
 
      TextLine textLine = TextLine (new TextLineData(QString (unicodeData, length)));
562
 
 
563
 
      // ensure blocks aren't too large
564
 
      if (m_blocks.last()->lines() >= m_blockSize)
565
 
        m_blocks.append (new TextBlock (this, m_blocks.last()->startLine() + m_blocks.last()->lines()));
566
 
 
567
 
      m_blocks.last()->appendLine (textLine);
568
 
      m_lines++;
 
560
      
 
561
      /**
 
562
       * split lines, if too large
 
563
       */
 
564
      do {
 
565
        /**
 
566
         * calculate line length
 
567
         */
 
568
        int lineLength = length;
 
569
        if ((m_lineLengthLimit > 0) && (lineLength > m_lineLengthLimit)) {
 
570
            /**
 
571
             * search for place to wrap
 
572
             */
 
573
            int spacePosition = m_lineLengthLimit-1;
 
574
            for (int testPosition = m_lineLengthLimit-1; (testPosition >= 0) && (testPosition >= (m_lineLengthLimit - (m_lineLengthLimit/10))); --testPosition) {
 
575
                /**
 
576
                 * wrap place found?
 
577
                 */
 
578
                if (unicodeData[testPosition].isSpace() || unicodeData[testPosition].isPunct()) {
 
579
                    spacePosition = testPosition;
 
580
                    break;
 
581
                }
 
582
            }
 
583
            
 
584
            /**
 
585
             * wrap the line
 
586
             */
 
587
            lineLength = spacePosition+1;
 
588
            length -= lineLength;
 
589
            tooLongLinesWrapped = true;
 
590
        } else {
 
591
            /**
 
592
             * be done after this round
 
593
             */
 
594
            length = 0;
 
595
        }
 
596
 
 
597
        /**
 
598
         * construct new text line with content from file
 
599
         * move data pointer
 
600
         */
 
601
        TextLine textLine = TextLine (new TextLineData(QString (unicodeData, lineLength)));
 
602
        unicodeData += lineLength;
 
603
 
 
604
        /**
 
605
         * ensure blocks aren't too large
 
606
         */
 
607
        if (m_blocks.last()->lines() >= m_blockSize)
 
608
            m_blocks.append (new TextBlock (this, m_blocks.last()->startLine() + m_blocks.last()->lines()));
 
609
 
 
610
        /**
 
611
         * append line to last block
 
612
         */
 
613
        m_blocks.last()->appendLine (textLine);
 
614
        ++m_lines;
 
615
      } while (length > 0);
569
616
    }
570
617
 
571
618
    // if no encoding error, break out of reading loop
706
753
  kDebug (13020) << "Saved file " << filename << "with codec" << m_textCodec->name()
707
754
    << (ok ? "without" : "with") << "errors";
708
755
 
 
756
  if (ok)
 
757
    markModifiedLinesAsSaved();
 
758
 
709
759
  // emit signal on success
710
760
  if (ok)
711
761
    emit saved (filename);
737
787
  }
738
788
}
739
789
 
 
790
void TextBuffer::markModifiedLinesAsSaved()
 
791
{
 
792
  foreach(TextBlock* block, m_blocks)
 
793
    block->markModifiedLinesAsSaved ();
 
794
}
 
795
 
740
796
QList<TextRange *> TextBuffer::rangesForLine (int line, KTextEditor::View *view, bool rangesWithAttributeOnly) const
741
797
{
742
798
  // get block, this will assert on invalid line