00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#ifndef __KATE_AUTO_INDENT_H__
00021
#define __KATE_AUTO_INDENT_H__
00022
00023
#include <qobject.h>
00024
00025
#include "katecursor.h"
00026
#include "kateconfig.h"
00027
00028
class KateDocument;
00029
00035 class KateAutoIndent
00036 {
00040
public:
00047
static KateAutoIndent *
createIndenter (KateDocument *doc, uint mode);
00048
00053
static QStringList listModes ();
00054
00060
static QString modeName (uint mode);
00061
00067
static QString modeDescription (uint mode);
00068
00074
static uint
modeNumber (
const QString &name);
00075
00076
public:
00081
KateAutoIndent (KateDocument *doc);
00082
00086
virtual ~KateAutoIndent ();
00087
00091 virtual void updateConfig () {};
00092
00097 virtual bool canProcessNewLine ()
const {
return false; }
00098
00105 virtual void processNewline (
KateDocCursor &,
bool ) {}
00106
00111 virtual void processChar (
QChar ) { }
00112
00116 virtual void processLine (
KateDocCursor &) { }
00117
00121 virtual void processSection (
KateDocCursor &,
KateDocCursor &) { }
00122
00127 virtual bool canProcessLine()
const {
return false; }
00128
00133 virtual uint
modeNumber ()
const {
return KateDocumentConfig::imNone; };
00134
00135
protected:
00136 KateDocument *doc;
00137 };
00138
00139
class KateViewIndentationAction :
public KActionMenu
00140 {
00141 Q_OBJECT
00142
00143
public:
00144 KateViewIndentationAction(KateDocument *_doc,
const QString& text,
QObject* parent = 0,
const char* name = 0);
00145
00146 ~KateViewIndentationAction(){;};
00147
00148
private:
00149 KateDocument* doc;
00150
00151
public slots:
00152
void slotAboutToShow();
00153
00154
private slots:
00155
void setMode (
int mode);
00156 };
00157
00161 class KateNormalIndent :
public KateAutoIndent
00162 {
00163
public:
00168
KateNormalIndent (KateDocument *doc);
00169
00173
virtual ~KateNormalIndent ();
00174
00178
virtual void updateConfig ();
00179
00184 virtual bool canProcessNewLine ()
const {
return true; }
00185
00192
virtual void processNewline (
KateDocCursor &cur,
bool needContinue);
00193
00198 virtual void processChar (
QChar ) { }
00199
00203 virtual void processLine (
KateDocCursor &) { }
00204
00208 virtual void processSection (
KateDocCursor &,
KateDocCursor &) { }
00209
00214 virtual bool canProcessLine()
const {
return false; }
00215
00220 virtual uint
modeNumber ()
const {
return KateDocumentConfig::imNormal; };
00221
00222
protected:
00223
00235
bool isBalanced (
KateDocCursor &begin,
const KateDocCursor &end,
QChar open,
QChar close, uint &pos)
const;
00236
00246
bool skipBlanks (
KateDocCursor &cur,
KateDocCursor &max,
bool newline)
const;
00247
00253 uint measureIndent (
KateDocCursor &cur)
const;
00254
00261
QString tabString(uint length)
const;
00262
00263 uint
tabWidth;
00264 uint
indentWidth;
00265
00266
00267 uchar commentAttrib;
00268 uchar doxyCommentAttrib;
00269 uchar regionAttrib;
00270 uchar symbolAttrib;
00271 uchar alertAttrib;
00272 uchar tagAttrib;
00273 uchar wordAttrib;
00274 uchar keywordAttrib;
00275 uchar normalAttrib;
00276 uchar extensionAttrib;
00277
00278 bool useSpaces;
00279 bool mixedIndent;
00280 bool keepProfile;
00281 };
00282
00283
class KateCSmartIndent :
public KateNormalIndent
00284 {
00285
public:
00286 KateCSmartIndent (KateDocument *doc);
00287 ~KateCSmartIndent ();
00288
00289
virtual void processNewline (
KateDocCursor &begin,
bool needContinue);
00290
virtual void processChar (
QChar c);
00291
00292
virtual void processLine (
KateDocCursor &line);
00293
virtual void processSection (
KateDocCursor &begin,
KateDocCursor &end);
00294
00295
virtual bool canProcessLine()
const {
return true; }
00296
00297
virtual uint
modeNumber ()
const {
return KateDocumentConfig::imCStyle; };
00298
00299
private:
00300 uint calcIndent (
KateDocCursor &begin,
bool needContinue);
00301 uint calcContinue (
KateDocCursor &begin,
KateDocCursor &end);
00302 uint findOpeningBrace (
KateDocCursor &start);
00303 uint findOpeningParen (
KateDocCursor &start);
00304 uint findOpeningComment (
KateDocCursor &start);
00305
bool firstOpeningBrace (
KateDocCursor &start);
00306
bool handleDoxygen (
KateDocCursor &begin);
00307
00308
bool allowSemi;
00309
bool processingBlock;
00310 };
00311
00312
class KatePythonIndent :
public KateNormalIndent
00313 {
00314
public:
00315 KatePythonIndent (KateDocument *doc);
00316 ~KatePythonIndent ();
00317
00318
virtual void processNewline (
KateDocCursor &begin,
bool needContinue);
00319
00320
virtual uint
modeNumber ()
const {
return KateDocumentConfig::imPythonStyle; };
00321
00322
private:
00323
int calcExtra (
int &prevBlock,
int &pos,
KateDocCursor &end);
00324
00325
static QRegExp endWithColon;
00326
static QRegExp stopStmt;
00327
static QRegExp blockBegin;
00328 };
00329
00330
class KateXmlIndent :
public KateNormalIndent
00331 {
00332
public:
00333 KateXmlIndent (KateDocument *doc);
00334 ~KateXmlIndent ();
00335
00336
virtual uint
modeNumber ()
const {
return KateDocumentConfig::imXmlStyle; }
00337
virtual void processNewline (
KateDocCursor &begin,
bool needContinue);
00338
virtual void processChar (
QChar c);
00339
virtual void processLine (
KateDocCursor &line);
00340
virtual bool canProcessLine()
const {
return true; }
00341
virtual void processSection (
KateDocCursor &begin,
KateDocCursor &end);
00342
00343
private:
00344
00345
00346 uint processLine (uint line);
00347
00348
00349
void getLineInfo (uint line, uint &prevIndent,
int &numTags,
00350 uint &attrCol,
bool &unclosedTag);
00351
00352
00353
static const QRegExp startsWithCloseTag;
00354
static const QRegExp unclosedDoctype;
00355 };
00356
00357
class KateCSAndSIndent :
public KateNormalIndent
00358 {
00359
public:
00360 KateCSAndSIndent (KateDocument *doc);
00361 ~KateCSAndSIndent ();
00362
00363
virtual void processNewline (
KateDocCursor &begin,
bool needContinue);
00364
virtual void processChar (
QChar c);
00365
00366
virtual void processLine (
KateDocCursor &line);
00367
virtual void processSection (
KateDocCursor &begin,
KateDocCursor &end);
00368
00369
virtual bool canProcessLine()
const {
return true; }
00370
00371
virtual uint
modeNumber ()
const {
return KateDocumentConfig::imCSAndS; };
00372
00373
private:
00374
void updateIndentString();
00375
00376
bool inForStatement(
int line );
00377
int lastNonCommentChar(
const KateDocCursor &line );
00378
bool startsWithLabel(
int line );
00379
bool inStatement(
const KateDocCursor &begin );
00380
QString continuationIndent(
const KateDocCursor &begin );
00381
00382
QString calcIndent (
const KateDocCursor &begin);
00383
QString calcIndentAfterKeyword(
const KateDocCursor &indentCursor,
const KateDocCursor &keywordCursor,
int keywordPos,
bool blockKeyword);
00384
QString calcIndentInBracket(
const KateDocCursor &indentCursor,
const KateDocCursor &bracketCursor,
int bracketPos);
00385
QString calcIndentInBrace(
const KateDocCursor &indentCursor,
const KateDocCursor &braceCursor,
int bracePos);
00386
00387
bool handleDoxygen (
KateDocCursor &begin);
00388
QString findOpeningCommentIndentation (
const KateDocCursor &start);
00389
00390
QString indentString;
00391 };
00392
00418 class KateVarIndent :
public QObject,
public KateNormalIndent
00419 {
00420 Q_OBJECT
00421
public:
00425 enum pairs {
00426 Parens=1,
00427 Braces=2,
00428 Brackets=4,
00429 AngleBrackets=8
00430 };
00431
00432
KateVarIndent( KateDocument *doc );
00433
virtual ~
KateVarIndent();
00434
00435
virtual void processNewline (
KateDocCursor &begin,
bool needContinue);
00436
virtual void processChar (
QChar c);
00437
00438
virtual void processLine (
KateDocCursor &line);
00439
virtual void processSection (
KateDocCursor &begin,
KateDocCursor &end);
00440
00441 virtual bool canProcessLine()
const {
return true; }
00442
00443 virtual uint
modeNumber ()
const {
return KateDocumentConfig::imVarIndent; };
00444
00445
private slots:
00446
void slotVariableChanged(
const QString&,
const QString&);
00447
00448
private:
00457
int coupleBalance(
int line,
const QChar &open,
const QChar &close )
const;
00458
00463
bool hasRelevantOpening(
const KateDocCursor &end )
const;
00464
00465
class KateVarIndentPrivate *d;
00466 };
00467
00468
#endif
00469
00470