00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __KATE_AUTO_INDENT_H__
00022 #define __KATE_AUTO_INDENT_H__
00023
00024 #include <qobject.h>
00025
00026 #include "katecursor.h"
00027 #include "kateconfig.h"
00028 #include "katejscript.h"
00029 class KateDocument;
00030
00044 class IndenterConfigPage : public QWidget
00045 {
00046 Q_OBJECT
00047
00048 public:
00054 IndenterConfigPage ( QWidget *parent=0, const char *name=0 ) : QWidget(parent, name) {}
00055 virtual ~IndenterConfigPage () {}
00056
00057 public slots:
00062 virtual void apply () = 0;
00063 };
00064
00070 class KateAutoIndent : public QObject
00071 {
00072 Q_OBJECT
00073
00077 public:
00084 static KateAutoIndent *createIndenter (KateDocument *doc, uint mode);
00085
00090 static QStringList listModes ();
00091
00097 static QString modeName (uint mode);
00098
00104 static QString modeDescription (uint mode);
00105
00111 static uint modeNumber (const QString &name);
00112
00118 static bool hasConfigPage (uint mode);
00119
00124 static IndenterConfigPage* configPage(QWidget *parent, uint mode);
00125
00126 public:
00131 KateAutoIndent (KateDocument *doc);
00132
00136 virtual ~KateAutoIndent ();
00137
00138 public slots:
00142 virtual void updateConfig () {};
00143
00144 public:
00149 virtual bool canProcessNewLine () const { return false; }
00150
00157 virtual void processNewline (KateDocCursor &cur, bool needContinue) { Q_UNUSED(cur); Q_UNUSED(needContinue); }
00158
00163 virtual void processChar (QChar c) { Q_UNUSED(c); }
00164
00168 virtual void processLine (KateDocCursor &) { }
00169
00173 virtual void processSection (const KateDocCursor &, const KateDocCursor &) { }
00174
00179 virtual bool canProcessLine() const { return false; }
00180
00185 virtual uint modeNumber () const { return KateDocumentConfig::imNone; };
00186
00187 protected:
00188 KateDocument *doc;
00189 };
00190
00195 class KateViewIndentationAction : public KActionMenu
00196 {
00197 Q_OBJECT
00198
00199 public:
00200 KateViewIndentationAction(KateDocument *_doc, const QString& text, QObject* parent = 0, const char* name = 0);
00201
00202 ~KateViewIndentationAction(){;};
00203
00204 private:
00205 KateDocument* doc;
00206
00207 public slots:
00208 void slotAboutToShow();
00209
00210 private slots:
00211 void setMode (int mode);
00212 };
00213
00217 class KateNormalIndent : public KateAutoIndent
00218 {
00219 Q_OBJECT
00220
00221 public:
00226 KateNormalIndent (KateDocument *doc);
00227
00231 virtual ~KateNormalIndent ();
00232
00233 public slots:
00237 virtual void updateConfig ();
00238
00239 public:
00244 virtual bool canProcessNewLine () const { return true; }
00245
00252 virtual void processNewline (KateDocCursor &cur, bool needContinue);
00253
00258 virtual void processChar (QChar c) { Q_UNUSED(c); }
00259
00263 virtual void processLine (KateDocCursor &) { }
00264
00268 virtual void processSection (const KateDocCursor &, const KateDocCursor &) { }
00269
00274 virtual bool canProcessLine() const { return false; }
00275
00280 virtual uint modeNumber () const { return KateDocumentConfig::imNormal; };
00281
00282 protected:
00283
00295 bool isBalanced (KateDocCursor &begin, const KateDocCursor &end, QChar open, QChar close, uint &pos) const;
00296
00306 bool skipBlanks (KateDocCursor &cur, KateDocCursor &max, bool newline) const;
00307
00313 uint measureIndent (KateDocCursor &cur) const;
00314
00321 QString tabString(uint length) const;
00322
00323 uint tabWidth;
00324 uint indentWidth;
00325
00326
00327 uchar commentAttrib;
00328 uchar doxyCommentAttrib;
00329 uchar regionAttrib;
00330 uchar symbolAttrib;
00331 uchar alertAttrib;
00332 uchar tagAttrib;
00333 uchar wordAttrib;
00334 uchar keywordAttrib;
00335 uchar normalAttrib;
00336 uchar extensionAttrib;
00337 uchar preprocessorAttrib;
00338
00339 bool useSpaces;
00340 bool mixedIndent;
00341 bool keepProfile;
00342 };
00343
00344 class KateCSmartIndent : public KateNormalIndent
00345 {
00346 Q_OBJECT
00347
00348 public:
00349 KateCSmartIndent (KateDocument *doc);
00350 ~KateCSmartIndent ();
00351
00352 virtual void processNewline (KateDocCursor &begin, bool needContinue);
00353 virtual void processChar (QChar c);
00354
00355 virtual void processLine (KateDocCursor &line);
00356 virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00357
00358 virtual bool canProcessLine() const { return true; }
00359
00360 virtual uint modeNumber () const { return KateDocumentConfig::imCStyle; };
00361
00362 private:
00363 uint calcIndent (KateDocCursor &begin, bool needContinue);
00364 uint calcContinue (KateDocCursor &begin, KateDocCursor &end);
00365 uint findOpeningBrace (KateDocCursor &start);
00366 uint findOpeningParen (KateDocCursor &start);
00367 uint findOpeningComment (KateDocCursor &start);
00368 bool firstOpeningBrace (KateDocCursor &start);
00369 bool handleDoxygen (KateDocCursor &begin);
00370
00371 bool allowSemi;
00372 bool processingBlock;
00373 };
00374
00375 class KatePythonIndent : public KateNormalIndent
00376 {
00377 Q_OBJECT
00378
00379 public:
00380 KatePythonIndent (KateDocument *doc);
00381 ~KatePythonIndent ();
00382
00383 virtual void processNewline (KateDocCursor &begin, bool needContinue);
00384
00385 virtual uint modeNumber () const { return KateDocumentConfig::imPythonStyle; };
00386
00387 private:
00388 int calcExtra (int &prevBlock, int &pos, KateDocCursor &end);
00389 void traverseString( const QChar &stringChar, KateDocCursor &cur, KateDocCursor &end );
00390
00391 static QRegExp endWithColon;
00392 static QRegExp stopStmt;
00393 static QRegExp blockBegin;
00394 };
00395
00396 class KateXmlIndent : public KateNormalIndent
00397 {
00398 Q_OBJECT
00399
00400 public:
00401 KateXmlIndent (KateDocument *doc);
00402 ~KateXmlIndent ();
00403
00404 virtual uint modeNumber () const { return KateDocumentConfig::imXmlStyle; }
00405 virtual void processNewline (KateDocCursor &begin, bool needContinue);
00406 virtual void processChar (QChar c);
00407 virtual void processLine (KateDocCursor &line);
00408 virtual bool canProcessLine() const { return true; }
00409 virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00410
00411 private:
00412
00413
00414 uint processLine (uint line);
00415
00416
00417 void getLineInfo (uint line, uint &prevIndent, int &numTags,
00418 uint &attrCol, bool &unclosedTag);
00419
00420
00421 static const QRegExp startsWithCloseTag;
00422 static const QRegExp unclosedDoctype;
00423 };
00424
00425 class KateCSAndSIndent : public KateNormalIndent
00426 {
00427 Q_OBJECT
00428
00429 public:
00430 KateCSAndSIndent (KateDocument *doc);
00431 ~KateCSAndSIndent ();
00432
00433 virtual void processNewline (KateDocCursor &begin, bool needContinue);
00434 virtual void processChar (QChar c);
00435
00436 virtual void processLine (KateDocCursor &line);
00437 virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00438
00439 virtual bool canProcessLine() const { return true; }
00440
00441 virtual uint modeNumber () const { return KateDocumentConfig::imCSAndS; };
00442
00443 private:
00444 void updateIndentString();
00445
00446 bool inForStatement( int line );
00447 int lastNonCommentChar( const KateDocCursor &line );
00448 bool startsWithLabel( int line );
00449 bool inStatement( const KateDocCursor &begin );
00450 QString continuationIndent( const KateDocCursor &begin );
00451
00452 QString calcIndent (const KateDocCursor &begin);
00453 QString calcIndentAfterKeyword(const KateDocCursor &indentCursor, const KateDocCursor &keywordCursor, int keywordPos, bool blockKeyword);
00454 QString calcIndentInBracket(const KateDocCursor &indentCursor, const KateDocCursor &bracketCursor, int bracketPos);
00455 QString calcIndentInBrace(const KateDocCursor &indentCursor, const KateDocCursor &braceCursor, int bracePos);
00456
00457 bool handleDoxygen (KateDocCursor &begin);
00458 QString findOpeningCommentIndentation (const KateDocCursor &start);
00459
00460 QString indentString;
00461 };
00462
00488 class KateVarIndent : public KateNormalIndent
00489 {
00490 Q_OBJECT
00491
00492 public:
00496 enum pairs {
00497 Parens=1,
00498 Braces=2,
00499 Brackets=4,
00500 AngleBrackets=8
00501 };
00502
00503 KateVarIndent( KateDocument *doc );
00504 virtual ~KateVarIndent();
00505
00506 virtual void processNewline (KateDocCursor &cur, bool needContinue);
00507 virtual void processChar (QChar c);
00508
00509 virtual void processLine (KateDocCursor &line);
00510 virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00511
00512 virtual bool canProcessLine() const { return true; }
00513
00514 virtual uint modeNumber () const { return KateDocumentConfig::imVarIndent; };
00515
00516 private slots:
00517 void slotVariableChanged(const QString&, const QString&);
00518
00519 private:
00528 int coupleBalance( int line, const QChar &open, const QChar &close ) const;
00529
00534 bool hasRelevantOpening( const KateDocCursor &end ) const;
00535
00536 class KateVarIndentPrivate *d;
00537 };
00538
00539 class KateScriptIndent : public KateNormalIndent
00540 {
00541 Q_OBJECT
00542
00543 public:
00544 KateScriptIndent( KateDocument *doc );
00545 ~KateScriptIndent();
00546
00547 virtual void processNewline( KateDocCursor &begin, bool needContinue );
00548 virtual void processChar( QChar c );
00549
00550 virtual void processLine (KateDocCursor &line);
00551
00552
00553 virtual bool canProcessLine() const { return true; }
00554
00555 virtual uint modeNumber () const { return KateDocumentConfig::imScriptIndent; };
00556 private:
00557 KateIndentScript m_script;
00558 };
00559
00560 class ScriptIndentConfigPage : public IndenterConfigPage
00561 {
00562 Q_OBJECT
00563
00564 public:
00565 ScriptIndentConfigPage ( QWidget *parent=0, const char *name=0 );
00566 virtual ~ScriptIndentConfigPage ();
00567
00568 public slots:
00572 virtual void apply ();
00573 };
00574
00575 #endif
00576
00577