Kate
katecodefolding.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _KATE_CODEFOLDING_H_
00020 #define _KATE_CODEFOLDING_H_
00021
00022
00023 #include <QtCore/QObject>
00024 #include <QtCore/QHash>
00025 #include <QtCore/QSet>
00026 #include <QtCore/QList>
00027 #include <QtCore/QVector>
00028
00029 class KateCodeFoldingTree;
00030 namespace KTextEditor { class Cursor; }
00031 class KateBuffer;
00032
00033 class QString;
00034
00035
00036 class KateHiddenLineBlock
00037 {
00038 public:
00039 unsigned int start;
00040 unsigned int length;
00041 };
00042
00043 class KateLineInfo
00044 {
00045 public:
00046 bool topLevel;
00047 bool startsVisibleBlock;
00048 bool startsInVisibleBlock;
00049 bool endsBlock;
00050 bool invalidBlockEnd;
00051 int depth;
00052 };
00053
00054 class KateCodeFoldingNode
00055 {
00056 friend class KateCodeFoldingTree;
00057
00058 public:
00059 KateCodeFoldingNode ();
00060 KateCodeFoldingNode (KateCodeFoldingNode *par, signed char typ, unsigned int sLRel);
00061
00062 ~KateCodeFoldingNode ();
00063
00064 inline int nodeType () { return type;}
00065
00066 inline bool isVisible () {return visible;}
00067
00068 inline KateCodeFoldingNode *getParentNode () {return parentNode;}
00069
00070 bool getBegin (KateCodeFoldingTree *tree, KTextEditor::Cursor* begin);
00071 bool getEnd (KateCodeFoldingTree *tree, KTextEditor::Cursor *end);
00072
00076 protected:
00077 inline bool noChildren () const { return m_children.isEmpty(); }
00078
00079 inline int childCount () const { return m_children.size(); }
00080
00081 inline KateCodeFoldingNode *child (uint index) const { return m_children[index]; }
00082
00083 inline int findChild (KateCodeFoldingNode *node, uint start = 0) const
00084 {
00085 for (int i=start; i < m_children.size(); ++i)
00086 if (m_children[i] == node)
00087 return i;
00088
00089 return -1;
00090 }
00091
00092 inline void appendChild (KateCodeFoldingNode *node) { m_children.append (node); }
00093
00094 void insertChild (uint index, KateCodeFoldingNode *node);
00095
00096 KateCodeFoldingNode *takeChild (uint index);
00097
00098 void clearChildren ();
00099
00100 int cmpPos(KateCodeFoldingTree *tree, uint line, uint col);
00101
00105 private:
00106 KateCodeFoldingNode *parentNode;
00107 unsigned int startLineRel;
00108 unsigned int endLineRel;
00109
00110 unsigned int startCol;
00111 unsigned int endCol;
00112
00113 bool startLineValid;
00114 bool endLineValid;
00115
00116 signed char type;
00117 bool visible;
00118 bool deleteOpening;
00119 bool deleteEnding;
00120
00121 QVector<KateCodeFoldingNode*> m_children;
00122 };
00123
00124 class KateCodeFoldingTree : public QObject
00125 {
00126 friend class KateCodeFoldingNode;
00127
00128 Q_OBJECT
00129
00130 public:
00131 KateCodeFoldingTree (KateBuffer *buffer);
00132 ~KateCodeFoldingTree ();
00133
00134 KateCodeFoldingNode *findNodeForLine (unsigned int line);
00135 KateCodeFoldingNode *rootNode () { return &m_root; }
00136
00137 unsigned int getRealLine (unsigned int virtualLine);
00138 unsigned int getVirtualLine (unsigned int realLine);
00139 unsigned int getHiddenLinesCount (unsigned int docLine);
00140
00141 bool isTopLevel (unsigned int line);
00142
00143 void lineHasBeenInserted (unsigned int line);
00144 void lineHasBeenRemoved (unsigned int line);
00145 void debugDump ();
00146 void getLineInfo (KateLineInfo *info,unsigned int line);
00147
00148 unsigned int getStartLine (KateCodeFoldingNode *node);
00149
00150 void fixRoot (int endLRel);
00151 void clear ();
00152
00153 KateCodeFoldingNode *findNodeForPosition(unsigned int line, unsigned int column);
00154 private:
00155
00156 KateCodeFoldingNode m_root;
00157
00158 KateBuffer *m_buffer;
00159
00160 QHash<int,unsigned int> lineMapping;
00161 QSet<int> dontIgnoreUnchangedLines;
00162
00163 QList<KateCodeFoldingNode*> markedForDeleting;
00164 QList<KateCodeFoldingNode*> nodesForLine;
00165 QList<KateHiddenLineBlock> hiddenLines;
00166
00167 unsigned int hiddenLinesCountCache;
00168 bool something_changed;
00169 bool hiddenLinesCountCacheValid;
00170
00171 static bool trueVal;
00172
00173 KateCodeFoldingNode *findNodeForLineDescending (KateCodeFoldingNode *, unsigned int, unsigned int, bool oneStepOnly=false);
00174
00175 bool correctEndings (signed char data, KateCodeFoldingNode *node, unsigned int line, unsigned int endCol, int insertPos);
00176
00177 void dumpNode (KateCodeFoldingNode *node, const QString &prefix);
00178 void addOpening (KateCodeFoldingNode *node, signed char nType,QVector<int>* list, unsigned int line,unsigned int charPos);
00179 void addOpening_further_iterations (KateCodeFoldingNode *node,signed char nType, QVector<int>*
00180 list,unsigned int line,int current,unsigned int startLine,unsigned int charPos);
00181
00182 void incrementBy1 (KateCodeFoldingNode *node, KateCodeFoldingNode *after);
00183 void decrementBy1 (KateCodeFoldingNode *node, KateCodeFoldingNode *after);
00184
00185 void cleanupUnneededNodes (unsigned int line);
00186
00190 bool removeEnding (KateCodeFoldingNode *node,unsigned int line);
00191
00195 bool removeOpening (KateCodeFoldingNode *node,unsigned int line);
00196
00197 void findAndMarkAllNodesforRemovalOpenedOrClosedAt (unsigned int line);
00198 void findAllNodesOpenedOrClosedAt (unsigned int line);
00199
00200 void addNodeToFoundList (KateCodeFoldingNode *node,unsigned int line,int childpos);
00201 void addNodeToRemoveList (KateCodeFoldingNode *node,unsigned int line);
00202 void addHiddenLineBlock (KateCodeFoldingNode *node,unsigned int line);
00203
00204 bool existsOpeningAtLineAfter(unsigned int line, KateCodeFoldingNode *node);
00205
00206 void dontDeleteEnding (KateCodeFoldingNode*);
00207 void dontDeleteOpening (KateCodeFoldingNode*);
00208
00209 void updateHiddenSubNodes (KateCodeFoldingNode *node);
00210 void moveSubNodesUp (KateCodeFoldingNode *node);
00211
00212 public Q_SLOTS:
00213 void updateLine (unsigned int line,QVector<int>* regionChanges, bool *updated, bool changed,bool colschanged);
00214 void toggleRegionVisibility (unsigned int);
00215 void collapseToplevelNodes ();
00216 void expandToplevelNodes (int numLines);
00217 int collapseOne (int realLine);
00218 void expandOne (int realLine, int numLines);
00222 void ensureVisible( uint line );
00223
00224 Q_SIGNALS:
00225 void regionVisibilityChangedAt (unsigned int);
00226 void regionBeginEndAddedRemoved (unsigned int);
00227 };
00228
00229 #endif
00230
00231