• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • 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 class KateCodeFoldingTree;
00030 namespace KTextEditor { class Cursor; }
00031 class KateBuffer;
00032 
00033 class QString;
00034 //END
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;                // 0 -> toplevel / invalid
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 *findNodeStartingAt(unsigned int line);
00136     KateCodeFoldingNode *rootNode () { return &m_root; }
00137 
00138     unsigned int getRealLine         (unsigned int virtualLine);
00139     unsigned int getVirtualLine      (unsigned int realLine);
00140     unsigned int getHiddenLinesCount (unsigned int docLine);
00141 
00142     bool isTopLevel (unsigned int line);
00143 
00144     void lineHasBeenInserted (unsigned int line);
00145     void lineHasBeenRemoved  (unsigned int line);
00146     void debugDump ();
00147     void getLineInfo (KateLineInfo *info,unsigned int line);
00148 
00149     unsigned int getStartLine (KateCodeFoldingNode *node);
00150 
00151     void fixRoot (int endLRel);
00152     void clear ();
00153 
00154     KateCodeFoldingNode *findNodeForPosition(unsigned int line, unsigned int column);
00155   private:
00156 
00157     KateCodeFoldingNode m_root;
00158 
00159     KateBuffer *m_buffer;
00160 
00161     QHash<int,unsigned int> lineMapping;
00162     QSet<int>         dontIgnoreUnchangedLines;
00163 
00164     QList<KateCodeFoldingNode*> markedForDeleting;
00165     QList<KateCodeFoldingNode*> nodesForLine;
00166     QList<KateHiddenLineBlock>   hiddenLines;
00167 
00168     unsigned int hiddenLinesCountCache;
00169     bool         something_changed;
00170     bool         hiddenLinesCountCacheValid;
00171 
00172     static bool trueVal;
00173 
00174     KateCodeFoldingNode *findNodeForLineDescending (KateCodeFoldingNode *, unsigned int, unsigned int, bool oneStepOnly=false);
00175 
00176     bool correctEndings (signed char data, KateCodeFoldingNode *node, unsigned int line, unsigned int endCol, int insertPos);
00177 
00178     void dumpNode    (KateCodeFoldingNode *node, const QString &prefix);
00179     void addOpening  (KateCodeFoldingNode *node, signed char nType,QVector<int>* list, unsigned int line,unsigned int charPos);
00180     void addOpening_further_iterations (KateCodeFoldingNode *node,signed char nType, QVector<int>*
00181                                         list,unsigned int line,int current,unsigned int startLine,unsigned int charPos);
00182 
00183     void incrementBy1 (KateCodeFoldingNode *node, KateCodeFoldingNode *after);
00184     void decrementBy1 (KateCodeFoldingNode *node, KateCodeFoldingNode *after);
00185 
00186     void cleanupUnneededNodes (unsigned int line);
00187 
00191     bool removeEnding (KateCodeFoldingNode *node,unsigned int line);
00192 
00196     bool removeOpening (KateCodeFoldingNode *node,unsigned int line);
00197 
00198     void findAndMarkAllNodesforRemovalOpenedOrClosedAt (unsigned int line);
00199     void findAllNodesOpenedOrClosedAt (unsigned int line);
00200 
00201     void addNodeToFoundList  (KateCodeFoldingNode *node,unsigned int line,int childpos);
00202     void addNodeToRemoveList (KateCodeFoldingNode *node,unsigned int line);
00203     void addHiddenLineBlock  (KateCodeFoldingNode *node,unsigned int line);
00204 
00205     bool existsOpeningAtLineAfter(unsigned int line, KateCodeFoldingNode *node);
00206 
00207     void dontDeleteEnding  (KateCodeFoldingNode*);
00208     void dontDeleteOpening (KateCodeFoldingNode*);
00209 
00210     void updateHiddenSubNodes (KateCodeFoldingNode *node);
00211     void moveSubNodesUp (KateCodeFoldingNode *node);
00212 
00213 //     void removeParentReferencesFromChilds(KateCodeFoldingNode* node);
00214 
00215   public Q_SLOTS:
00216     void updateLine (unsigned int line,QVector<int>* regionChanges, bool *updated, bool changed,bool colschanged);
00217     void toggleRegionVisibility (unsigned int);
00218     void collapseToplevelNodes ();
00219     void expandToplevelNodes (int numLines);
00220     int collapseOne (int realLine);
00221     void expandOne  (int realLine, int numLines);
00225     void ensureVisible( uint line );
00226 
00227   private:
00228     bool m_clearCache;
00229   Q_SIGNALS:
00230     void regionVisibilityChangedAt  (unsigned int,bool clearCache);
00231     void regionBeginEndAddedRemoved (unsigned int);
00232 };
00233 
00234 #endif
00235 
00236 // 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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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