• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

Kate

katecodefolding.h

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #ifndef _KATE_CODEFOLDING_H_
00020 #define _KATE_CODEFOLDING_H_
00021 
00022 //BEGIN INCLUDES + FORWARDS
00023 #include <QtCore/QObject>
00024 #include <QtCore/QHash>
00025 #include <QtCore/QSet>
00026 #include <QtCore/QList>
00027 #include <QtCore/QVector>
00028 
00029 #include "katepartprivate_export.h"
00030 
00031 class KateCodeFoldingTree;
00032 namespace KTextEditor { class Cursor; }
00033 class KateBuffer;
00034 
00035 class QString;
00036 //END
00037 
00038 class KateHiddenLineBlock
00039 {
00040   public:
00041     unsigned int start;
00042     unsigned int length;
00043 };
00044 
00045 class KateLineInfo
00046 {
00047   public:
00048     bool topLevel;
00049     bool startsVisibleBlock;
00050     bool startsInVisibleBlock;
00051     bool endsBlock;
00052     bool invalidBlockEnd;
00053     int depth;
00054 };
00055 
00056 class KateCodeFoldingNode
00057 {
00058   friend class KateCodeFoldingTree;
00059 
00060   public:
00061     KateCodeFoldingNode ();
00062     KateCodeFoldingNode (KateCodeFoldingNode *par, signed char typ, unsigned int sLRel);
00063 
00064     ~KateCodeFoldingNode ();
00065 
00066     inline int nodeType () { return type;}
00067 
00068     inline bool isVisible () {return visible;}
00069 
00070     inline KateCodeFoldingNode *getParentNode () {return parentNode;}
00071 
00072     bool getBegin (KateCodeFoldingTree *tree, KTextEditor::Cursor* begin);
00073     bool getEnd (KateCodeFoldingTree *tree, KTextEditor::Cursor *end);
00074 
00078   protected:
00079     inline bool noChildren () const { return m_children.isEmpty(); }
00080 
00081     inline int childCount () const { return m_children.size(); }
00082 
00083     inline KateCodeFoldingNode *child (uint index) const { return m_children[index]; }
00084 
00085     inline int findChild (KateCodeFoldingNode *node, uint start = 0) const
00086     {
00087       for (int i=start; i < m_children.size(); ++i)
00088         if (m_children[i] == node)
00089           return i;
00090 
00091       return -1;
00092     }
00093 
00094     inline void appendChild (KateCodeFoldingNode *node) { m_children.append (node); }
00095 
00096     void insertChild (uint index, KateCodeFoldingNode *node);
00097 
00098     KateCodeFoldingNode *takeChild (uint index);
00099 
00100     void clearChildren ();
00101 
00102     int cmpPos(KateCodeFoldingTree *tree, uint line, uint col);
00103 
00104     void setAllowDestruction(bool allowDestruction) { this->allowDestruction = allowDestruction; }
00105     
00109   private:
00110     KateCodeFoldingNode                *parentNode;
00111     unsigned int startLineRel;
00112     unsigned int endLineRel;
00113 
00114     unsigned int startCol;
00115     unsigned int endCol;
00116 
00117     bool startLineValid;
00118     bool endLineValid;
00119 
00120     signed char type;                // 0 -> toplevel / invalid
00121     bool visible;
00122     bool deleteOpening;
00123     bool deleteEnding;
00124     bool allowDestruction;
00125     
00126     QVector<KateCodeFoldingNode*> m_children;
00127 };
00128 
00129 class KATEPART_TESTS_EXPORT KateCodeFoldingTree : public QObject
00130 {
00131   friend class KateCodeFoldingNode;
00132 
00133   Q_OBJECT
00134 
00135   public:
00136     KateCodeFoldingTree (KateBuffer *buffer);
00137     ~KateCodeFoldingTree ();
00138 
00139     KateCodeFoldingNode *findNodeForLine (unsigned int line);
00140     KateCodeFoldingNode *findNodeStartingAt(unsigned int line);
00141     KateCodeFoldingNode *rootNode () { return &m_root; }
00142 
00143     unsigned int getRealLine         (unsigned int virtualLine);
00144     unsigned int getVirtualLine      (unsigned int realLine);
00145     unsigned int getHiddenLinesCount (unsigned int docLine);
00146 
00147     bool isTopLevel (unsigned int line);
00148 
00149     void lineHasBeenInserted (unsigned int line);
00150     void lineHasBeenRemoved  (unsigned int line);
00151     void debugDump ();
00152     void getLineInfo (KateLineInfo *info,unsigned int line);
00153 
00154     unsigned int getStartLine (KateCodeFoldingNode *node);
00155 
00156     void fixRoot (int endLRel);
00157     void clear ();
00158 
00159     KateCodeFoldingNode *findNodeForPosition(unsigned int line, unsigned int column);
00160   private:
00161 
00162     KateCodeFoldingNode m_root;
00163 
00164     KateBuffer *const m_buffer;
00165 
00166     QHash<int,unsigned int> lineMapping;
00167     QSet<int>         dontIgnoreUnchangedLines;
00168 
00169     QList<KateCodeFoldingNode*> markedForDeleting;
00170     QList<KateCodeFoldingNode*> nodesForLine;
00171     QList<KateHiddenLineBlock>   hiddenLines;
00172 
00173     unsigned int hiddenLinesCountCache;
00174     bool         something_changed;
00175     bool         hiddenLinesCountCacheValid;
00176 
00177     static bool trueVal;
00178 
00179     KateCodeFoldingNode *findNodeForLineDescending (KateCodeFoldingNode *, unsigned int, unsigned int, bool oneStepOnly=false);
00180 
00181     bool correctEndings (signed char data, KateCodeFoldingNode *node, unsigned int line, unsigned int endCol, int insertPos);
00182 
00183     void dumpNode    (KateCodeFoldingNode *node, const QString &prefix);
00184     void addOpening  (KateCodeFoldingNode *node, signed char nType,QVector<int>* list, unsigned int line,unsigned int charPos);
00185     void addOpening_further_iterations (KateCodeFoldingNode *node,signed char nType, QVector<int>*
00186                                         list,unsigned int line,int current,unsigned int startLine,unsigned int charPos);
00187 
00188     void incrementBy1 (KateCodeFoldingNode *node, KateCodeFoldingNode *after);
00189     void decrementBy1 (KateCodeFoldingNode *node, KateCodeFoldingNode *after);
00190 
00191     void cleanupUnneededNodes (unsigned int line);
00192 
00196     bool removeEnding (KateCodeFoldingNode *node,unsigned int line);
00197 
00201     bool removeOpening (KateCodeFoldingNode *node,unsigned int line);
00202 
00203     void findAndMarkAllNodesforRemovalOpenedOrClosedAt (unsigned int line);
00204     void findAllNodesOpenedOrClosedAt (unsigned int line);
00205 
00206     void addNodeToFoundList  (KateCodeFoldingNode *node,unsigned int line,int childpos);
00207     void addNodeToRemoveList (KateCodeFoldingNode *node,unsigned int line);
00208     void addHiddenLineBlock  (KateCodeFoldingNode *node,unsigned int line);
00209 
00210     bool existsOpeningAtLineAfter(unsigned int line, KateCodeFoldingNode *node);
00211 
00212     void dontDeleteEnding  (KateCodeFoldingNode*);
00213     void dontDeleteOpening (KateCodeFoldingNode*);
00214 
00215     void updateHiddenSubNodes (KateCodeFoldingNode *node);
00216     void moveSubNodesUp (KateCodeFoldingNode *node);
00217 
00218 //     void removeParentReferencesFromChilds(KateCodeFoldingNode* node);
00219 
00220   public Q_SLOTS:
00221     void updateLine (unsigned int line,QVector<int>* regionChanges, bool *updated, bool changed,bool colschanged);
00222     void toggleRegionVisibility (unsigned int);
00223     void collapseToplevelNodes ();
00224     void expandToplevelNodes (int numLines);
00225     int collapseOne (int realLine);
00226     void expandOne  (int realLine, int numLines);
00230     void ensureVisible( uint line );
00231 
00232   private:
00233     bool m_clearCache;
00234   Q_SIGNALS:
00235     void regionVisibilityChangedAt  (unsigned int,bool clearCache);
00236     void regionBeginEndAddedRemoved (unsigned int);
00237 };
00238 
00239 #endif
00240 
00241 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal