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
00071 {
00075 public:
00082 static KateAutoIndent *createIndenter (KateDocument *doc, uint mode);
00083
00088 static QStringList listModes ();
00089
00095 static QString modeName (uint mode);
00096
00102 static QString modeDescription (uint mode);
00103
00109 static uint modeNumber (const QString &name);
00110
00116 static bool hasConfigPage (uint mode);
00117
00122 static IndenterConfigPage* configPage(QWidget *parent, uint mode);
00123
00124 public:
00129 KateAutoIndent (KateDocument *doc);
00130
00134 virtual ~KateAutoIndent ();
00135
00139 virtual void updateConfig () {};
00140
00145 virtual bool canProcessNewLine () const { return false; }
00146
00153 virtual void processNewline (KateDocCursor &cur, bool needContinue) { Q_UNUSED(cur); Q_UNUSED(needContinue); }
00154
00159 virtual void processChar (QChar c) { Q_UNUSED(c); }
00160
00164 virtual void processLine (KateDocCursor &) { }
00165
00169 virtual void processSection (const KateDocCursor &, const KateDocCursor &) { }
00170
00175 virtual bool canProcessLine() const { return false; }
00176
00181 virtual uint modeNumber () const { return KateDocumentConfig::imNone; };
00182
00183 protected:
00184 KateDocument *doc;
00185 };
00186
00191 class KateViewIndentationAction : public KActionMenu
00192 {
00193 Q_OBJECT
00194
00195 public:
00196 KateViewIndentationAction(KateDocument *_doc, const QString& text, QObject* parent = 0, const char* name = 0);
00197
00198 ~KateViewIndentationAction(){;};
00199
00200 private:
00201 KateDocument* doc;
00202
00203 public slots:
00204 void slotAboutToShow();
00205
00206 private slots:
00207 void setMode (int mode);
00208 };
00209
00213 class KateNormalIndent : public KateAutoIndent
00214 {
00215 public:
00220 KateNormalIndent (KateDocument *doc);
00221
00225 virtual ~KateNormalIndent ();
00226
00230 virtual void updateConfig ();
00231
00236 virtual bool canProcessNewLine () const { return true; }
00237
00244 virtual void processNewline (KateDocCursor &cur, bool needContinue);
00245
00250 virtual void processChar (QChar c) { Q_UNUSED(c); }
00251
00255 virtual void processLine (KateDocCursor &) { }
00256
00260 virtual void processSection (const KateDocCursor &, const KateDocCursor &) { }
00261
00266 virtual bool canProcessLine() const { return false; }
00267
00272 virtual uint modeNumber () const { return KateDocumentConfig::imNormal; };
00273
00274 protected:
00275
00287 bool isBalanced (KateDocCursor &begin, const KateDocCursor &end, QChar open, QChar close, uint &pos) const;
00288
00298 bool skipBlanks (KateDocCursor &cur, KateDocCursor &max, bool newline) const;
00299
00305 uint measureIndent (KateDocCursor &cur) const;
00306
00313 QString tabString(uint length) const;
00314
00315 uint tabWidth;
00316 uint indentWidth;
00317
00318
00319 uchar commentAttrib;
00320 uchar doxyCommentAttrib;
00321 uchar regionAttrib;
00322 uchar symbolAttrib;
00323 uchar alertAttrib;
00324 uchar tagAttrib;
00325 uchar wordAttrib;
00326 uchar keywordAttrib;
00327 uchar normalAttrib;
00328 uchar extensionAttrib;
00329
00330 bool useSpaces;
00331 bool mixedIndent;
00332 bool keepProfile;
00333 };
00334
00335 class KateCSmartIndent : public KateNormalIndent
00336 {
00337 public:
00338 KateCSmartIndent (KateDocument *doc);
00339 ~KateCSmartIndent ();
00340
00341 virtual void processNewline (KateDocCursor &begin, bool needContinue);
00342 virtual void processChar (QChar c);
00343
00344 virtual void processLine (KateDocCursor &line);
00345 virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00346
00347 virtual bool canProcessLine() const { return true; }
00348
00349 virtual uint modeNumber () const { return KateDocumentConfig::imCStyle; };
00350
00351 private:
00352 uint calcIndent (KateDocCursor &begin, bool needContinue);
00353 uint calcContinue (KateDocCursor &begin, KateDocCursor &end);
00354 uint findOpeningBrace (KateDocCursor &start);
00355 uint findOpeningParen (KateDocCursor &start);
00356 uint findOpeningComment (KateDocCursor &start);
00357 bool firstOpeningBrace (KateDocCursor &start);
00358 bool handleDoxygen (KateDocCursor &begin);
00359
00360 bool allowSemi;
00361 bool processingBlock;
00362 };
00363
00364 class KatePythonIndent : public KateNormalIndent
00365 {
00366 public:
00367 KatePythonIndent (KateDocument *doc);
00368 ~KatePythonIndent ();
00369
00370 virtual void processNewline (KateDocCursor &begin, bool needContinue);
00371
00372 virtual uint modeNumber () const { return KateDocumentConfig::imPythonStyle; };
00373
00374 private:
00375 int calcExtra (int &prevBlock, int &pos, KateDocCursor &end);
00376
00377 static QRegExp endWithColon;
00378 static QRegExp stopStmt;
00379 static QRegExp blockBegin;
00380 };
00381
00382 class KateXmlIndent : public KateNormalIndent
00383 {
00384 public:
00385 KateXmlIndent (KateDocument *doc);
00386 ~KateXmlIndent ();
00387
00388 virtual uint modeNumber () const { return KateDocumentConfig::imXmlStyle; }
00389 virtual void processNewline (KateDocCursor &begin, bool needContinue);
00390 virtual void processChar (QChar c);
00391 virtual void processLine (KateDocCursor &line);
00392 virtual bool canProcessLine() const { return true; }
00393 virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00394
00395 private:
00396
00397
00398 uint processLine (uint line);
00399
00400
00401 void getLineInfo (uint line, uint &prevIndent, int &numTags,
00402 uint &attrCol, bool &unclosedTag);
00403
00404
00405 static const QRegExp startsWithCloseTag;
00406 static const QRegExp unclosedDoctype;
00407 };
00408
00409 class KateCSAndSIndent : public KateNormalIndent
00410 {
00411 public:
00412 KateCSAndSIndent (KateDocument *doc);
00413 ~KateCSAndSIndent ();
00414
00415 virtual void processNewline (KateDocCursor &begin, bool needContinue);
00416 virtual void processChar (QChar c);
00417
00418 virtual void processLine (KateDocCursor &line);
00419 virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00420
00421 virtual bool canProcessLine() const { return true; }
00422
00423 virtual uint modeNumber () const { return KateDocumentConfig::imCSAndS; };
00424
00425 private:
00426 void updateIndentString();
00427
00428 bool inForStatement( int line );
00429 int lastNonCommentChar( const KateDocCursor &line );
00430 bool startsWithLabel( int line );
00431 bool inStatement( const KateDocCursor &begin );
00432 QString continuationIndent( const KateDocCursor &begin );
00433
00434 QString calcIndent (const KateDocCursor &begin);
00435 QString calcIndentAfterKeyword(const KateDocCursor &indentCursor, const KateDocCursor &keywordCursor, int keywordPos, bool blockKeyword);
00436 QString calcIndentInBracket(const KateDocCursor &indentCursor, const KateDocCursor &bracketCursor, int bracketPos);
00437 QString calcIndentInBrace(const KateDocCursor &indentCursor, const KateDocCursor &braceCursor, int bracePos);
00438
00439 bool handleDoxygen (KateDocCursor &begin);
00440 QString findOpeningCommentIndentation (const KateDocCursor &start);
00441
00442 QString indentString;
00443 };
00444
00470 class KateVarIndent : public QObject, public KateNormalIndent
00471 {
00472 Q_OBJECT
00473 public:
00477 enum pairs {
00478 Parens=1,
00479 Braces=2,
00480 Brackets=4,
00481 AngleBrackets=8
00482 };
00483
00484 KateVarIndent( KateDocument *doc );
00485 virtual ~KateVarIndent();
00486
00487 virtual void processNewline (KateDocCursor &cur, bool needContinue);
00488 virtual void processChar (QChar c);
00489
00490 virtual void processLine (KateDocCursor &line);
00491 virtual void processSection (const KateDocCursor &begin, const KateDocCursor &end);
00492
00493 virtual bool canProcessLine() const { return true; }
00494
00495 virtual uint modeNumber () const { return KateDocumentConfig::imVarIndent; };
00496
00497 private slots:
00498 void slotVariableChanged(const QString&, const QString&);
00499
00500 private:
00509 int coupleBalance( int line, const QChar &open, const QChar &close ) const;
00510
00515 bool hasRelevantOpening( const KateDocCursor &end ) const;
00516
00517 class KateVarIndentPrivate *d;
00518 };
00519
00520 class KateScriptIndent : public KateNormalIndent
00521 {
00522 public:
00523 KateScriptIndent( KateDocument *doc );
00524 ~KateScriptIndent();
00525
00526 virtual void processNewline( KateDocCursor &begin, bool needContinue );
00527 virtual void processChar( QChar c );
00528
00529 virtual void processLine (KateDocCursor &line);
00530
00531
00532 virtual bool canProcessLine() const { return true; }
00533
00534 virtual uint modeNumber () const { return KateDocumentConfig::imScriptIndent; };
00535 private:
00536 KateIndentScript m_script;
00537 };
00538
00539 class ScriptIndentConfigPage : public IndenterConfigPage
00540 {
00541 Q_OBJECT
00542
00543 public:
00544 ScriptIndentConfigPage ( QWidget *parent=0, const char *name=0 );
00545 virtual ~ScriptIndentConfigPage ();
00546
00547 public slots:
00551 virtual void apply ();
00552 };
00553
00554 #endif
00555
00556