katebuffer.h
/* This file is part of the KDE libraries
Copyright (c) 2000 Waldo Bastian <bastian@kde.org>
Copyright (C) 2002-2004 Christoph Cullmann <cullmann@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef __KATE_BUFFER_H__
#define __KATE_BUFFER_H__
#include "katetextline.h"
#include "katecodefoldinghelpers.h"
#include <kvmallocator.h>
#include <qptrlist.h>
#include <qobject.h>
#include <qtimer.h>
#include <qvaluevector.h>
class KateLineInfo;
class KateDocument;
class KateHighlighting;
class KateBufBlockList;
class KateBuffer;
class KateFileLoader;
class QTextCodec;
class KateBufBlock
{
friend class KateBufBlockList;
public:
KateBufBlock ( KateBuffer *parent, KateBufBlock *prev = 0, KateBufBlock *next = 0,
KateFileLoader *stream = 0 );
~KateBufBlock ();
private:
void fillBlock (KateFileLoader *stream);
public:
enum State
{
stateSwapped = 0,
stateClean = 1,
stateDirty = 2
};
State state () const { return m_state; }
public:
KateTextLine::Ptr line(uint i);
void insertLine(uint i, KateTextLine::Ptr line);
void removeLine(uint i);
void markDirty ();
public:
inline uint startLine () const { return m_startLine; };
inline void setStartLine (uint line) { m_startLine = line; }
inline uint endLine () const { return m_startLine + m_lines; }
inline uint lines () const { return m_lines; }
inline KateBufBlock *prev () { return m_prev; }
inline KateBufBlock *next () { return m_next; }
private:
void swapIn ();
void swapOut ();
private:
KateBufBlock::State m_state;
uint m_startLine;
uint m_lines;
KVMAllocator::Block *m_vmblock;
uint m_vmblockSize;
QValueVector<KateTextLine::Ptr> m_stringList;
KateBuffer* m_parent;
KateBufBlock *m_prev;
KateBufBlock *m_next;
private:
KateBufBlockList *list;
KateBufBlock *listPrev;
KateBufBlock *listNext;
};
class KateBufBlockList
{
public:
KateBufBlockList ();
public:
inline uint count() const { return m_count; }
inline KateBufBlock *first () { return m_first; };
inline KateBufBlock *last () { return m_last; };
inline bool isFirst (KateBufBlock *buf) { return m_first == buf; };
inline bool isLast (KateBufBlock *buf) { return m_last == buf; };
void append (KateBufBlock *buf);
inline static void remove (KateBufBlock *buf)
{
if (buf->list)
buf->list->removeInternal (buf);
}
private:
void removeInternal (KateBufBlock *buf);
private:
uint m_count;
KateBufBlock *m_first;
KateBufBlock *m_last;
};
class KateBuffer : public QObject
{
Q_OBJECT
friend class KateBufBlock;
public:
inline static uint maxLoadedBlocks () { return m_maxLoadedBlocks; }
static void setMaxLoadedBlocks (uint count);
private:
static uint m_maxLoadedBlocks;
public:
KateBuffer (KateDocument *doc);
~KateBuffer ();
public:
void editStart ();
void editEnd ();
inline bool editChanged () const { return editChangesDone; }
inline uint editTagStart () const { return editTagLineStart; }
inline uint editTagEnd () const { return editTagLineEnd; }
inline bool editTagFrom () const { return editTagLineFrom; }
private:
uint editSessionNumber;
bool editIsRunning;
uint editTagLineStart;
uint editTagLineEnd;
bool editTagLineFrom;
bool editChangesDone;
public:
void clear();
bool openFile (const QString &m_file);
bool loadingBorked () const { return m_loadingBorked; }
bool binary () const { return m_binary; }
bool canEncode ();
bool saveFile (const QString &m_file);
public:
inline KateTextLine::Ptr line(uint i)
{
KateBufBlock *buf = findBlock(i);
if (!buf)
return 0;
if (i < m_lineHighlighted)
return buf->line (i - buf->startLine());
return line_internal (buf, i);
}
private:
KateTextLine::Ptr line_internal (KateBufBlock *buf, uint i);
inline void addIndentBasedFoldingInformation(QMemArray<uint> &foldingList,bool addindent,uint deindent);
inline void updatePreviousNotEmptyLine(KateBufBlock *blk,uint current_line,bool addindent,uint deindent);
public:
inline KateTextLine::Ptr plainLine(uint i)
{
KateBufBlock *buf = findBlock(i);
if (!buf)
return 0;
return buf->line(i - buf->startLine());
}
inline uint count() const { return m_lines; }
private:
KateBufBlock *findBlock (uint i, uint *index = 0)
{
// out of range !
if (i >= m_lines)
return 0;
if ((m_blocks[m_lastFoundBlock]->startLine() <= i) && (m_blocks[m_lastFoundBlock]->endLine() > i))
{
if (index)
(*index) = m_lastFoundBlock;
return m_blocks[m_lastFoundBlock];
}
return findBlock_internal (i, index);
}
KateBufBlock *findBlock_internal (uint i, uint *index = 0);
public:
void changeLine(uint i);
void insertLine(uint i, KateTextLine::Ptr line);
void removeLine(uint i);
public:
inline uint countVisible () { return m_lines - m_regionTree.getHiddenLinesCount(m_lines); }
inline uint lineNumber (uint visibleLine) { return m_regionTree.getRealLine (visibleLine); }
inline uint lineVisibleNumber (uint line) { return m_regionTree.getVirtualLine (line); }
inline void lineInfo (KateLineInfo *info, unsigned int line) { m_regionTree.getLineInfo(info,line); }
inline uint tabWidth () const { return m_tabWidth; }
public:
void setTabWidth (uint w);
void setHighlight (uint hlMode);
KateHighlighting *highlight () { return m_highlight; };
void invalidateHighlighting();
KateCodeFoldingTree *foldingTree () { return &m_regionTree; };
public slots:
void codeFoldingColumnUpdate(unsigned int lineNr);
private:
bool doHighlight (KateBufBlock *buf, uint from, uint to, bool invalidate);
signals:
void codeFoldingUpdated();
void tagLines(int start, int end);
private:
KateDocument *m_doc;
uint m_lines;
QValueVector<KateBufBlock*> m_blocks;
uint m_lastInSyncBlock;
uint m_lastFoundBlock;
bool m_cacheReadError;
bool m_cacheWriteError;
bool m_loadingBorked;
bool m_binary;
private:
KateHighlighting *m_highlight;
KateCodeFoldingTree m_regionTree;
// for the scrapty indent sensitive langs
uint m_tabWidth;
uint m_lineHighlightedMax;
uint m_lineHighlighted;
uint m_maxDynamicContexts;
private:
KateBufBlockList m_loadedBlocks;
};
#endif
// kate: space-indent on; indent-width 2; replace-tabs on;
KSharedPtr
KateBufBlock::prev
KateBufBlock * prev()
prev block
Definition: katebuffer.h:153
KateBuffer::line
KateTextLine::Ptr line(uint i)
Return line i.
Definition: katebuffer.h:488
KateBuffer::editTagFrom
bool editTagFrom() const
line inserted/removed?
Definition: katebuffer.h:412
KateBuffer::editChanged
bool editChanged() const
were there changes in the current running editing session?
Definition: katebuffer.h:394
KateBufBlockList::last
KateBufBlock * last()
last block in this list or 0
Definition: katebuffer.h:273
KateBuffer::setMaxLoadedBlocks
static void setMaxLoadedBlocks(uint count)
modifier for max loaded blocks limit
Definition: katebuffer.cpp:79
KateBuffer::clear
void clear()
Clear the buffer.
Definition: katebuffer.cpp:431
KateBuffer::openFile
bool openFile(const QString &m_file)
Open a file, use the given filename.
Definition: katebuffer.cpp:458
KateBufBlock
The KateBufBlock class contains an amount of data representing a certain number of lines...
Definition: katebuffer.h:49
KateBuffer::saveFile
bool saveFile(const QString &m_file)
Save the buffer to a file, use the given filename + codec + end of line chars (internal use of qtexts...
Definition: katebuffer.cpp:564
KateBufBlock::State
State
state flags
Definition: katebuffer.h:80
KateBuffer::binary
bool binary() const
is this file a binary?
Definition: katebuffer.h:469
KateBufBlock::next
KateBufBlock * next()
next block
Definition: katebuffer.h:159
KateBufBlock::startLine
uint startLine() const
startLine
Definition: katebuffer.h:129
KateBufBlock::insertLine
void insertLine(uint i, KateTextLine::Ptr line)
insert line in front of line i marks the block dirty
Definition: katebuffer.cpp:1452
KateBufBlockList
list which allows O(1) inserts/removes will not delete the elements on remove will use the next/prevN...
Definition: katebuffer.h:248
KateBufBlock::KateBufBlock
KateBufBlock(KateBuffer *parent, KateBufBlock *prev=0, KateBufBlock *next=0, KateFileLoader *stream=0)
Create an empty block.
Definition: katebuffer.cpp:1273
KateBufBlockList::first
KateBufBlock * first()
first block in this list or 0
Definition: katebuffer.h:267
KateBufBlock::state
State state() const
returns the current state of this block
Definition: katebuffer.h:91
KateBufBlockList::isLast
bool isLast(KateBufBlock *buf)
is buf the last block?
Definition: katebuffer.h:287
KateBufBlock::markDirty
void markDirty()
mark this block as dirty, will invalidate the swap data insert/removeLine will mark the block dirty i...
Definition: katebuffer.cpp:1476
KateBuffer::editTagStart
uint editTagStart() const
dirty lines start
Definition: katebuffer.h:400
KateBuffer::editTagEnd
uint editTagEnd() const
dirty lines end
Definition: katebuffer.h:406
KateBuffer::editStart
void editStart()
start some editing action
Definition: katebuffer.cpp:363
KateBufBlock::setStartLine
void setStartLine(uint line)
update the first line, needed to keep it up to date
Definition: katebuffer.h:135
KateBufBlockList::append
void append(KateBufBlock *buf)
append a block to this list ! will remove it from the list it belonged before !
Definition: katebuffer.cpp:1589
KateBuffer::setHighlight
void setHighlight(uint hlMode)
Use highlight for highlighting.
Definition: katebuffer.cpp:856
KateBuffer::KateBuffer
KateBuffer(KateDocument *doc)
Create an empty buffer.
Definition: katebuffer.cpp:323
KateBufBlockList::count
uint count() const
count of blocks in this list
Definition: katebuffer.h:261
KateBufBlock::endLine
uint endLine() const
first line behind this block
Definition: katebuffer.h:141
KateBufBlockList::isFirst
bool isFirst(KateBufBlock *buf)
is buf the last block?
Definition: katebuffer.h:280
KateBuffer::loadingBorked
bool loadingBorked() const
was the last loading broken because of not enough tmp disk space ? (will be reseted on successful sav...
Definition: katebuffer.h:463
KateBuffer::editEnd
void editEnd()
finish some editing action
Definition: katebuffer.cpp:379
KateBuffer::plainLine
KateTextLine::Ptr plainLine(uint i)
Return line i without triggering highlighting.
Definition: katebuffer.h:512
KateBufBlock::lines
uint lines() const
lines in this block
Definition: katebuffer.h:147
KateBufBlock::removeLine
void removeLine(uint i)
remove line i marks the block dirty
Definition: katebuffer.cpp:1464
KateBuffer::canEncode
bool canEncode()
Can the current codec handle all chars.
Definition: katebuffer.cpp:540
KateBuffer::changeLine
void changeLine(uint i)
Mark line i as changed !
Definition: katebuffer.cpp:702
KateBufBlock::~KateBufBlock
~KateBufBlock()
destroy this block and take care of freeing all mem
Definition: katebuffer.cpp:1321
KateBuffer::invalidateHighlighting
void invalidateHighlighting()
Invalidate highlighting of whole buffer.
Definition: katebuffer.cpp:892
KateBuffer::~KateBuffer
~KateBuffer()
Goodbye buffer.
Definition: katebuffer.cpp:352
KateBuffer::tagLines
void tagLines(int start, int end)
Emitted when the highlighting of a certain range has changed.
KateBuffer::count
uint count() const
Return the total number of lines in the buffer.
Definition: katebuffer.h:524
KateBuffer::insertLine
void insertLine(uint i, KateTextLine::Ptr line)
Insert line in front of line i.
Definition: katebuffer.cpp:723
KateBuffer::maxLoadedBlocks
static uint maxLoadedBlocks()
maximal loaded block count
Definition: katebuffer.h:352
KateBufBlockList::KateBufBlockList
KateBufBlockList()
Default Constructor.
Definition: katebuffer.cpp:1582
KateBuffer::codeFoldingUpdated
void codeFoldingUpdated()
Emittend if codefolding returned with a changed list.
KateBufBlock::line
KateTextLine::Ptr line(uint i)
return line i The first line of this block is line 0.
Definition: katebuffer.cpp:1439
KateBuffer
The KateBuffer class maintains a collections of lines.
Definition: katebuffer.h:341
KateBuffer::removeLine
void removeLine(uint i)
Remove line i.
Definition: katebuffer.cpp:772

KDE Home | KDE Accessibility Home | Description of Access Keys