• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • part
kateautoindent.h
1 /* This file is part of the KDE libraries
2  Copyright (C) 2003 Jesse Yurkovich <yurkjes@iit.edu>
3  Copyright (C) 2004 >Anders Lund <anders@alweb.dk> (KateVarIndent class)
4  Copyright (C) 2005 Dominik Haumann <dhdev@gmx.de> (basic support for config page)
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef __KATE_AUTO_INDENT_H__
22 #define __KATE_AUTO_INDENT_H__
23 
24 #include <tqobject.h>
25 
26 #include "katecursor.h"
27 #include "kateconfig.h"
28 #include "katejscript.h"
29 class KateDocument;
30 
44 class IndenterConfigPage : public TQWidget
45 {
46  Q_OBJECT
47 
48  public:
54  IndenterConfigPage ( TQWidget *parent=0, const char *name=0 ) : TQWidget(parent, name) {}
55  virtual ~IndenterConfigPage () {}
56 
57  public slots:
62  virtual void apply () = 0;
63 };
64 
70 class KateAutoIndent : public TQObject
71 {
72  Q_OBJECT
73 
77  public:
84  static KateAutoIndent *createIndenter (KateDocument *doc, uint mode);
85 
90  static TQStringList listModes ();
91 
97  static TQString modeName (uint mode);
98 
104  static TQString modeDescription (uint mode);
105 
111  static uint modeNumber (const TQString &name);
112 
118  static bool hasConfigPage (uint mode);
119 
124  static IndenterConfigPage* configPage(TQWidget *parent, uint mode);
125 
126  public:
131  KateAutoIndent (KateDocument *doc);
132 
136  virtual ~KateAutoIndent ();
137 
138  public slots:
142  virtual void updateConfig () {};
143 
144  public:
149  virtual bool canProcessNewLine () const { return false; }
150 
157  virtual void processNewline (KateDocCursor &cur, bool needContinue) { Q_UNUSED(cur); Q_UNUSED(needContinue); }
158 
163  virtual void processChar (TQChar c) { Q_UNUSED(c); }
164 
168  virtual void processLine (KateDocCursor &/*line*/) { }
169 
173  virtual void processSection (const KateDocCursor &/*begin*/, const KateDocCursor &/*end*/) { }
174 
179  virtual bool canProcessLine() const { return false; }
180 
185  virtual uint modeNumber () const { return KateDocumentConfig::imNone; };
186 
187  protected:
188  KateDocument *doc;
189 };
190 
195 class KateViewIndentationAction : public KActionMenu
196 {
197  Q_OBJECT
198 
199  public:
200  KateViewIndentationAction(KateDocument *_doc, const TQString& text, TQObject* parent = 0, const char* name = 0);
201 
202  ~KateViewIndentationAction(){;};
203 
204  private:
205  KateDocument* doc;
206 
207  public slots:
208  void slotAboutToShow();
209 
210  private slots:
211  void setMode (int mode);
212 };
213 
217 class KateNormalIndent : public KateAutoIndent
218 {
219  Q_OBJECT
220 
221 public:
226  KateNormalIndent (KateDocument *doc);
227 
231  virtual ~KateNormalIndent ();
232 
233 public slots:
237  virtual void updateConfig ();
238 
239 public:
244  virtual bool canProcessNewLine () const { return true; }
245 
252  virtual void processNewline (KateDocCursor &cur, bool needContinue);
253 
258  virtual void processChar (TQChar c) { Q_UNUSED(c); }
259 
263  virtual void processLine (KateDocCursor &/*line*/) { }
264 
268  virtual void processSection (const KateDocCursor &/*begin*/, const KateDocCursor &/*end*/) { }
269 
274  virtual bool canProcessLine() const { return false; }
275 
280  virtual uint modeNumber () const { return KateDocumentConfig::imNormal; };
281 
282 protected:
283 
295  bool isBalanced (KateDocCursor &begin, const KateDocCursor &end, TQChar open, TQChar close, uint &pos) const;
296 
306  bool skipBlanks (KateDocCursor &cur, KateDocCursor &max, bool newline) const;
307 
313  uint measureIndent (KateDocCursor &cur) const;
314 
321  TQString tabString(uint length) const;
322 
323  uint tabWidth;
324  uint indentWidth;
325 
326 public:
327  // Attributes that we should skip over or otherwise know about
328  uchar commentAttrib;
329  uchar doxyCommentAttrib;
330  uchar regionAttrib;
331  uchar symbolAttrib;
332  uchar alertAttrib;
333  uchar tagAttrib;
334  uchar wordAttrib;
335  uchar keywordAttrib;
336  uchar normalAttrib;
337  uchar extensionAttrib;
338  uchar preprocessorAttrib;
339  uchar stringAttrib;
340  uchar charAttrib;
341 
342 protected:
343  bool useSpaces;
344  bool mixedIndent;
345  bool keepProfile;
346 };
347 
348 class KateCSmartIndent : public KateNormalIndent
349 {
350  Q_OBJECT
351 
352  public:
353  KateCSmartIndent (KateDocument *doc);
354  ~KateCSmartIndent ();
355 
356  virtual void processNewline (KateDocCursor &cur, bool needContinue);
357  virtual void processChar (TQChar c);
358 
359  virtual void processLine (KateDocCursor &line);
360  virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
361 
362  virtual bool canProcessLine() const { return true; }
363 
364  virtual uint modeNumber () const { return KateDocumentConfig::imCStyle; };
365 
366  private:
367  uint calcIndent (KateDocCursor &begin, bool needContinue);
368  uint calcContinue (KateDocCursor &begin, KateDocCursor &end);
369  uint findOpeningBrace (KateDocCursor &start);
370  uint findOpeningParen (KateDocCursor &start);
371  uint findOpeningComment (KateDocCursor &start);
372  bool firstOpeningBrace (KateDocCursor &start);
373  bool handleDoxygen (KateDocCursor &begin);
374 
375  bool allowSemi;
376  bool processingBlock;
377 };
378 
379 class KatePythonIndent : public KateNormalIndent
380 {
381  Q_OBJECT
382 
383  public:
384  KatePythonIndent (KateDocument *doc);
385  ~KatePythonIndent ();
386 
387  virtual void processNewline (KateDocCursor &cur, bool needContinue);
388 
389  virtual uint modeNumber () const { return KateDocumentConfig::imPythonStyle; };
390 
391  private:
392  int calcExtra (int &prevBlock, int &pos, KateDocCursor &end);
393  void traverseString( const TQChar &stringChar, KateDocCursor &cur, KateDocCursor &end );
394 
395  static TQRegExp endWithColon;
396  static TQRegExp stopStmt;
397  static TQRegExp blockBegin;
398 };
399 
400 class KateXmlIndent : public KateNormalIndent
401 {
402  Q_OBJECT
403 
404  public:
405  KateXmlIndent (KateDocument *doc);
406  ~KateXmlIndent ();
407 
408  virtual uint modeNumber () const { return KateDocumentConfig::imXmlStyle; }
409  virtual void processNewline (KateDocCursor &cur, bool needContinue);
410  virtual void processChar (TQChar c);
411  virtual void processLine (KateDocCursor &line);
412  virtual bool canProcessLine() const { return true; }
413  virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
414 
415  private:
416  // sets the indentation of a single line based on previous line
417  // (returns indentation width)
418  uint processLine (uint line);
419 
420  // gets information about a line
421  void getLineInfo (uint line, uint &prevIndent, int &numTags,
422  uint &attrCol, bool &unclosedTag);
423 
424  // useful regular expressions
425  static const TQRegExp startsWithCloseTag;
426  static const TQRegExp unclosedDoctype;
427 };
428 
429 class KateCSAndSIndent : public KateNormalIndent
430 {
431  Q_OBJECT
432 
433  public:
434  KateCSAndSIndent (KateDocument *doc);
435  ~KateCSAndSIndent ();
436 
437  virtual void processNewline (KateDocCursor &begin, bool needContinue);
438  virtual void processChar (TQChar c);
439 
440  virtual void processLine (KateDocCursor &line);
441  virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
442 
443  virtual bool canProcessLine() const { return true; }
444 
445  virtual uint modeNumber () const { return KateDocumentConfig::imCSAndS; };
446 
447  private:
448  void updateIndentString();
449 
450  bool inForStatement( int line );
451  int lastNonCommentChar( const KateDocCursor &line );
452  bool startsWithLabel( int line );
453  bool inStatement( const KateDocCursor &begin );
454  TQString continuationIndent( const KateDocCursor &begin );
455 
456  TQString calcIndent (const KateDocCursor &begin);
457  TQString calcIndentAfterKeyword(const KateDocCursor &indentCursor, const KateDocCursor &keywordCursor, int keywordPos, bool blockKeyword);
458  TQString calcIndentInBracket(const KateDocCursor &indentCursor, const KateDocCursor &bracketCursor, int bracketPos);
459  TQString calcIndentInBrace(const KateDocCursor &indentCursor, const KateDocCursor &braceCursor, int bracePos);
460 
461  bool handleDoxygen (KateDocCursor &begin);
462  TQString findOpeningCommentIndentation (const KateDocCursor &start);
463 
464  TQString indentString;
465 };
466 
492 class KateVarIndent : public KateNormalIndent
493 {
494  Q_OBJECT
495 
496  public:
500  enum pairs {
501  Parens=1,
502  Braces=2,
503  Brackets=4,
504  AngleBrackets=8
505  };
506 
507  KateVarIndent( KateDocument *doc );
508  virtual ~KateVarIndent();
509 
510  virtual void processNewline (KateDocCursor &cur, bool needContinue);
511  virtual void processChar (TQChar c);
512 
513  virtual void processLine (KateDocCursor &line);
514  virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
515 
516  virtual bool canProcessLine() const { return true; }
517 
518  virtual uint modeNumber () const { return KateDocumentConfig::imVarIndent; };
519 
520  private slots:
521  void slotVariableChanged(const TQString&, const TQString&);
522 
523  private:
532  int coupleBalance( int line, const TQChar &open, const TQChar &close ) const;
533 
538  bool hasRelevantOpening( const KateDocCursor &end ) const;
539 
540  class KateVarIndentPrivate *d;
541 };
542 
543 class KateScriptIndent : public KateNormalIndent
544 {
545  Q_OBJECT
546 
547  public:
548  KateScriptIndent( KateDocument *doc );
549  ~KateScriptIndent();
550 
551  virtual void processNewline( KateDocCursor &cur, bool needContinue );
552  virtual void processChar( TQChar c );
553 
554  virtual void processLine (KateDocCursor &line);
555 // virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
556 
557  virtual bool canProcessLine() const { return true; }
558 
559  virtual uint modeNumber () const { return KateDocumentConfig::imScriptIndent; };
560  private:
561  KateIndentScript m_script;
562 };
563 
564 class ScriptIndentConfigPage : public IndenterConfigPage
565 {
566  Q_OBJECT
567 
568  public:
569  ScriptIndentConfigPage ( TQWidget *parent=0, const char *name=0 );
570  virtual ~ScriptIndentConfigPage ();
571 
572  public slots:
576  virtual void apply ();
577 };
578 
579 #endif
580 
581 // 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

kate

Skip menu "kate"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kate by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |