00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#ifndef _KATE_DOCUMENT_H_
00022
#define _KATE_DOCUMENT_H_
00023
00024
#include "katesupercursor.h"
00025
#include "katetextline.h"
00026
#include "kateundo.h"
00027
00028
#include "../interfaces/document.h"
00029
00030
#include <ktexteditor/configinterfaceextension.h>
00031
#include <ktexteditor/encodinginterface.h>
00032
#include <ktexteditor/sessionconfiginterface.h>
00033
#include <ktexteditor/editinterfaceext.h>
00034
00035
#include <dcopobject.h>
00036
00037
#include <kmimetype.h>
00038
#include <klocale.h>
00039
00040
#include <qintdict.h>
00041
#include <qmap.h>
00042
#include <qdatetime.h>
00043
00044
namespace KTextEditor {
class Plugin; }
00045
00046
namespace KIO {
class TransferJob; }
00047
00048
class KateUndoGroup;
00049
class KateCmd;
00050
class KateAttribute;
00051
class KateAutoIndent;
00052
class KateCodeFoldingTree;
00053
class KateBuffer;
00054
class KateView;
00055
class KateViewInternal;
00056
class KateArbitraryHighlight;
00057
class KateSuperRange;
00058
class KateLineInfo;
00059
class KateBrowserExtension;
00060
class KateDocumentConfig;
00061
class KateHighlighting;
00062
class KatePartPluginItem;
00063
class KatePartPluginInfo;
00064
00065
class KSpell;
00066
class KTempFile;
00067
00068
class QTimer;
00069
00070
00071
00072
00073
class KateDocument :
public Kate::Document,
00074
public Kate::DocumentExt,
00075
public KTextEditor::ConfigInterfaceExtension,
00076
public KTextEditor::EncodingInterface,
00077
public KTextEditor::SessionConfigInterface,
00078
public KTextEditor::EditInterfaceExt,
00079
public DCOPObject
00080 {
00081 K_DCOP
00082 Q_OBJECT
00083
00084
friend class KateViewInternal;
00085
friend class KateRenderer;
00086
00087
public:
00088 KateDocument (
bool bSingleViewMode=
false,
bool bBrowserView=
false,
bool bReadOnly=
false,
00089
QWidget *parentWidget = 0,
const char *widgetName = 0,
QObject * = 0,
const char * = 0);
00090 ~KateDocument ();
00091
00092
bool closeURL();
00093
00094
00095
00096
00097
public:
00098
void unloadAllPlugins ();
00099
00100
void enableAllPluginsGUI (KateView *view);
00101
void disableAllPluginsGUI (KateView *view);
00102
00103
void loadPlugin (uint pluginIndex);
00104
void unloadPlugin (uint pluginIndex);
00105
00106
void enablePluginGUI (KTextEditor::Plugin *plugin, KateView *view);
00107
void enablePluginGUI (KTextEditor::Plugin *plugin);
00108
00109
void disablePluginGUI (KTextEditor::Plugin *plugin, KateView *view);
00110
void disablePluginGUI (KTextEditor::Plugin *plugin);
00111
00112
private:
00113
QMemArray<KTextEditor::Plugin *> m_plugins;
00114
00115
public:
00116
bool readOnly ()
const {
return m_bReadOnly; }
00117
bool browserView ()
const {
return m_bBrowserView; }
00118
bool singleViewMode ()
const {
return m_bSingleViewMode; }
00119
KateBrowserExtension *browserExtension () {
return m_extension; }
00120
00121
private:
00122
00123
bool m_bSingleViewMode;
00124
bool m_bBrowserView;
00125
bool m_bReadOnly;
00126
KateBrowserExtension *m_extension;
00127
00128
00129
00130
00131
public:
00132 KTextEditor::View *createView(
QWidget *parent,
const char *name );
00133
QPtrList<KTextEditor::View> views () const;
00134
00135 inline KateView *activeView ()
const {
return m_activeView; }
00136
00137
private:
00138
QPtrList<KateView> m_views;
00139
QPtrList<KTextEditor::View> m_textEditViews;
00140 KateView *m_activeView;
00141
00142
00143
00144
00145
public slots:
00146 uint configPages () const;
00147 KTextEditor::ConfigPage *configPage (uint number = 0,
QWidget *parent = 0, const
char *name=0 );
00148
QString configPageName (uint number = 0) const;
00149
QString configPageFullName (uint number = 0) const;
00150
QPixmap configPagePixmap (uint number = 0,
int size =
KIcon::SizeSmall) const;
00151
00152
00153
00154
00155 public slots:
00156
QString text() const;
00157
00158
QString text ( uint startLine, uint startCol, uint endLine, uint endCol ) const;
00159
QString text ( uint startLine, uint startCol, uint endLine, uint endCol,
bool blockwise ) const;
00160
00161
QString textLine ( uint line ) const;
00162
00163
bool setText(const
QString &);
00164
bool clear ();
00165
00166
bool insertText ( uint line, uint col, const QString &s );
00167
bool insertText ( uint line, uint col, const QString &s,
bool blockwise );
00168
00169
bool removeText ( uint startLine, uint startCol, uint endLine, uint endCol );
00170
bool removeText ( uint startLine, uint startCol, uint endLine, uint endCol,
bool blockwise );
00171
00172
bool insertLine ( uint line, const QString &s );
00173
bool removeLine ( uint line );
00174
00175 uint numLines() const;
00176 uint numVisLines() const;
00177 uint length () const;
00178
int lineLength ( uint line ) const;
00179
00180 signals:
00181
void textChanged ();
00182
void charactersInteractivelyInserted(
int ,
int ,const QString&);
00183
void backspacePressed();
00184
00185 public:
00186
00187
00188
00189
void editBegin () { editStart(); }
00190
void editStart (
bool withUndo =
true);
00191
void editEnd ();
00192
00193
00194
00195
00196
bool editInsertText ( uint line, uint col,
const QString &s );
00197
bool editRemoveText ( uint line, uint col, uint len );
00198
00199
bool editMarkLineAutoWrapped ( uint line,
bool autowrapped );
00200
00201
bool editWrapLine ( uint line, uint col,
bool newLine =
true,
bool *newLineAdded = 0 );
00202
bool editUnWrapLine ( uint line,
bool removeLine =
true, uint length = 0 );
00203
00204
bool editInsertLine ( uint line,
const QString &s );
00205
bool editRemoveLine ( uint line );
00206
00207
bool wrapText (uint startLine, uint endLine);
00208
00209 signals:
00214
void editTextInserted ( uint line, uint col, uint len);
00215
00219
void editTextRemoved ( uint line, uint col, uint len);
00220
00224
void editLineWrapped ( uint line, uint col, uint len );
00225
00229
void editLineUnWrapped ( uint line, uint col );
00230
00234
void editLineInserted ( uint line );
00235
00239
void editLineRemoved ( uint line );
00240
00241
private:
00242
void undoStart();
00243
void undoEnd();
00244
00245
private slots:
00246
void undoCancel();
00247
00248
private:
00249
void editAddUndo (KateUndoGroup::UndoType type, uint line, uint col, uint len,
const QString &text);
00250
void editTagLine (uint line);
00251
void editRemoveTagLine (uint line);
00252
void editInsertTagLine (uint line);
00253
00254 uint editSessionNumber;
00255
bool editIsRunning;
00256
bool noViewUpdates;
00257
bool editWithUndo;
00258 uint editTagLineStart;
00259 uint editTagLineEnd;
00260
bool editTagFrom;
00261
KateUndoGroup* m_editCurrentUndo;
00262
00263
00264
00265
00266
public slots:
00267
bool setSelection (
const KateTextCursor & start,
00268
const KateTextCursor & end );
00269
bool setSelection ( uint startLine, uint startCol,
00270 uint endLine, uint endCol );
00271
bool clearSelection ();
00272
bool clearSelection (
bool redraw,
bool finishedChangingSelection =
true);
00273
00274
bool hasSelection () const;
00275
QString selection () const ;
00276
00277
bool removeSelectedText ();
00278
00279
bool selectAll();
00280
00281
00282
00283
00284
int selStartLine() {
return selectStart.line(); };
00285
int selStartCol() {
return selectStart.col(); };
00286
int selEndLine() {
return selectEnd.line(); };
00287
int selEndCol() {
return selectEnd.col(); };
00288
00289
private:
00290
00291
bool lineColSelected (
int line,
int col);
00292
bool lineSelected (
int line);
00293
bool lineEndSelected (
int line,
int endCol);
00294
bool lineHasSelected (
int line);
00295
bool lineIsSelection (
int line);
00296
00297
QPtrList<KateSuperCursor> m_superCursors;
00298
00299
00300
KateSuperCursor selectStart;
00301
KateSuperCursor selectEnd;
00302
00303 signals:
00304
void selectionChanged ();
00305
00306
00307
00308
00309
public slots:
00310
bool blockSelectionMode ();
00311
bool setBlockSelectionMode (
bool on);
00312
bool toggleBlockSelectionMode ();
00313
00314
private:
00315
00316
bool blockSelect;
00317
00318
00319
00320
00321
public slots:
00322
void undo ();
00323
void redo ();
00324
void clearUndo ();
00325
void clearRedo ();
00326
00327 uint undoCount () const;
00328 uint redoCount () const;
00329
00330 uint undoSteps () const;
00331
void setUndoSteps ( uint steps );
00332
00333 private:
00334
00335
00336
00337
QPtrList<
KateUndoGroup> undoItems;
00338
QPtrList<
KateUndoGroup> redoItems;
00339
bool m_undoDontMerge;
00340
bool m_undoIgnoreCancel;
00341
QTimer* m_undoMergeTimer;
00342
00343
00344
KateUndoGroup* lastUndoGroupWhenSaved;
00345
bool docWasSavedWhenUndoWasEmpty;
00346
00347
00348
void updateModified();
00349
00350 signals:
00351
void undoChanged ();
00352
00353
00354
00355
00356 public slots:
00357 KTextEditor::Cursor *createCursor ();
00358
QPtrList<KTextEditor::Cursor> cursors () const;
00359
00360 private:
00361
QPtrList<KTextEditor::Cursor> myCursors;
00362
00363
00364
00365
00366 public slots:
00367
bool searchText (
unsigned int startLine,
unsigned int startCol,
00368 const
QString &text,
unsigned int *foundAtLine,
unsigned int *foundAtCol,
00369
unsigned int *matchLen,
bool casesensitive = true,
bool backwards = false);
00370
bool searchText (
unsigned int startLine,
unsigned int startCol,
00371 const
QRegExp ®exp,
unsigned int *foundAtLine,
unsigned int *foundAtCol,
00372
unsigned int *matchLen,
bool backwards = false);
00373
00374
00375
00376
00377 public slots:
00378 uint hlMode ();
00379
bool setHlMode (uint mode);
00380 uint hlModeCount ();
00381
QString hlModeName (uint mode);
00382
QString hlModeSectionName (uint mode);
00383
00384 private:
00385
bool internalSetHlMode (uint mode);
00386
void setDontChangeHlOnSave();
00387
00388 signals:
00389
void hlChanged ();
00390
00391
00392
00393
00394 public:
00395
KateArbitraryHighlight* arbitraryHL()
const {
return m_arbitraryHL; };
00396
00397
private slots:
00398
void tagArbitraryLines(KateView* view,
KateSuperRange* range);
00399
00400
00401
00402
00403
public slots:
00404
void readConfig ();
00405
void writeConfig ();
00406
void readConfig (
KConfig *);
00407
void writeConfig (
KConfig *);
00408
void readSessionConfig (
KConfig *);
00409
void writeSessionConfig (
KConfig *);
00410
void configDialog ();
00411
00412
00413
00414
00415
public slots:
00416 uint mark( uint line );
00417
00418
void setMark( uint line, uint markType );
00419
void clearMark( uint line );
00420
00421
void addMark( uint line, uint markType );
00422
void removeMark( uint line, uint markType );
00423
00424
QPtrList<KTextEditor::Mark> marks();
00425
void clearMarks();
00426
00427
void setPixmap( MarkInterface::MarkTypes,
const QPixmap& );
00428
void setDescription( MarkInterface::MarkTypes,
const QString& );
00429
QString markDescription( MarkInterface::MarkTypes );
00430
QPixmap *markPixmap( MarkInterface::MarkTypes );
00431
QColor markColor( MarkInterface::MarkTypes );
00432
00433
void setMarksUserChangable( uint markMask );
00434 uint editableMarks();
00435
00436 signals:
00437
void marksChanged();
00438
void markChanged( KTextEditor::Mark, KTextEditor::MarkInterfaceExtension::MarkChangeAction );
00439
00440
private:
00441
QIntDict<KTextEditor::Mark> m_marks;
00442
QIntDict<QPixmap> m_markPixmaps;
00443
QIntDict<QString> m_markDescriptions;
00444 uint m_editableMarks;
00445
00446
00447
00448
00449
public slots:
00450
bool printDialog ();
00451
bool print ();
00452
00453
00454
00455
00456
public:
00466
QString mimeType();
00467
00475
long fileSize();
00476
00484
QString niceFileSize();
00485
00494
KMimeType::Ptr mimeTypeForContent();
00495
00496
00497
00498
00499
public:
00500
QString variable(
const QString &name )
const;
00501
00502 signals:
00503
void variableChanged(
const QString &,
const QString & );
00504
00505
private:
00506
QMap<QString, QString> m_storedVariables;
00507
00508
00509
00510
00511
public:
00512
bool openURL(
const KURL &url );
00513
00514
00515
00516
00517
bool save();
00518
00519
bool openFile (
KIO::Job * job);
00520
bool openFile ();
00521
00522
bool saveFile ();
00523
00524
void setReadWrite (
bool rw =
true );
00525
00526
void setModified(
bool m );
00527
00528
private slots:
00529
void slotDataKate (
KIO::Job* kio_job,
const QByteArray &data );
00530
void slotFinishedKate (
KIO::Job * job );
00531
00532
private:
00533
void abortLoadKate();
00534
00535
void activateDirWatch ();
00536
void deactivateDirWatch ();
00537
00538
QString m_dirWatchFile;
00539
00540
00541
00542
00543
public:
00544 Kate::ConfigPage *colorConfigPage (
QWidget *);
00545 Kate::ConfigPage *fontConfigPage (
QWidget *);
00546 Kate::ConfigPage *indentConfigPage (
QWidget *);
00547 Kate::ConfigPage *selectConfigPage (
QWidget *);
00548 Kate::ConfigPage *editConfigPage (
QWidget *);
00549 Kate::ConfigPage *keysConfigPage (
QWidget *);
00550 Kate::ConfigPage *hlConfigPage (
QWidget *);
00551 Kate::ConfigPage *viewDefaultsConfigPage (
QWidget *);
00552 Kate::ConfigPage *saveConfigPage(
QWidget * );
00553
00554 Kate::ActionMenu *hlActionMenu (
const QString& text,
QObject* parent = 0,
const char* name = 0);
00555 Kate::ActionMenu *exportActionMenu (
const QString& text,
QObject* parent = 0,
const char* name = 0);
00556
00557
public:
00561
bool typeChars ( KateView *type,
const QString &chars );
00562
00566 uint lastLine()
const {
return numLines()-1;}
00567
00568
KateTextLine::Ptr kateTextLine(uint i);
00569
KateTextLine::Ptr plainKateTextLine(uint i);
00570
00571 uint configFlags ();
00572
void setConfigFlags (uint flags);
00573
00577
void tagSelection(
const KateTextCursor &oldSelectStart,
const KateTextCursor &oldSelectEnd);
00578
00579
00580
void repaintViews(
bool paintOnlyDirty =
true);
00581
00582 KateHighlighting *highlight () {
return m_highlight; }
00583
00584
public slots:
00585
void tagLines(
int start,
int end);
00586
void tagLines(
KateTextCursor start,
KateTextCursor end);
00587
00588
00589
public slots:
00590
void exportAs(
const QString&);
00591
00592
private:
00593
bool exportDocumentToHTML (
QTextStream *outputStream,
const QString &name);
00594
QString HTMLEncode (
QChar theChar);
00595
00596 signals:
00597
void modifiedChanged ();
00598
void preHighlightChanged(uint);
00599
00600
private slots:
00601
void internalHlChanged();
00602
00603
public:
00604
void addView(KTextEditor::View *);
00605
void removeView(KTextEditor::View *);
00606
00607
void addSuperCursor(
class KateSuperCursor *,
bool privateC);
00608
void removeSuperCursor(
class KateSuperCursor *,
bool privateC);
00609
00610
bool ownedView(KateView *);
00611
bool isLastView(
int numViews);
00612
00613 uint currentColumn(
const KateTextCursor& );
00614
void newLine(
KateTextCursor&, KateViewInternal * );
00615
void backspace(
const KateTextCursor& );
00616
void del(
const KateTextCursor& );
00617
void transpose(
const KateTextCursor& );
00618
void cut();
00619
void copy();
00620
void paste ( KateView* view );
00621
00622
void selectWord(
const KateTextCursor& cursor );
00623
void selectLine(
const KateTextCursor& cursor );
00624
void selectLength(
const KateTextCursor& cursor,
int length );
00625
00626
public:
00627
void insertIndentChars ( KateView *view );
00628
00629
void indent ( KateView *view, uint line,
int change );
00630
void comment ( KateView *view, uint line,
int change );
00631
void align ( uint line );
00632
00633
enum TextTransform { Uppercase, Lowercase, Capitalize };
00634
00642
void transform ( KateView *view,
const KateTextCursor &, TextTransform );
00646
void joinLines( uint first, uint last );
00647
00648
private:
00649
void optimizeLeadingSpace( uint line,
int flags,
int change );
00650
void replaceWithOptimizedSpace( uint line, uint upto_column, uint space,
int flags );
00651
00652
bool removeStringFromBegining(
int line,
QString &str);
00653
bool removeStringFromEnd(
int line,
QString &str);
00654
00664
bool nextNonSpaceCharPos(
int &line,
int &col);
00665
00673
bool previousNonSpaceCharPos(
int &line,
int &col);
00674
00679
void addStartLineCommentToSingleLine(
int line,
int attrib=0);
00684
bool removeStartLineCommentFromSingleLine(
int line,
int attrib=0);
00685
00689
void addStartStopCommentToSingleLine(
int line,
int attrib=0);
00693
bool removeStartStopCommentFromSingleLine(
int line,
int attrib=0);
00694
00699
void addStartStopCommentToSelection(
int attrib=0 );
00703
void addStartLineCommentToSelection(
int attrib=0 );
00704
00711
bool removeStartStopCommentFromSelection(
int attrib=0 );
00715
bool removeStartLineCommentFromSelection(
int attrib=0 );
00716
00717
public:
00718
QString getWord(
const KateTextCursor& cursor );
00719
00720
public:
00721
void tagAll();
00722
void updateViews();
00723
00724
void newBracketMark(
const KateTextCursor& start, KateTextRange& bm );
00725
bool findMatchingBracket(
KateTextCursor& start,
KateTextCursor& end );
00726
00727
private:
00728
void guiActivateEvent(
KParts::GUIActivateEvent *ev );
00729
00730
public:
00731
00732
QString docName () {
return m_docName;};
00733
00734
void setDocName (
QString docName);
00735
00736
void lineInfo (KateLineInfo *info,
unsigned int line);
00737
00738 KateCodeFoldingTree *foldingTree ();
00739
00740
public:
00746
bool isModifiedOnDisc() {
return m_modOnHd; };
00747
00749
void isModOnHD(
bool =
false ) {};
00750
00751
void setModifiedOnDisk(
int reason );
00752
00753
public slots:
00760
void slotModifiedOnDisk(
Kate::View *v=0 );
00761
00765
void reloadFile();
00766
00767
private:
00768
int m_isasking;
00769
00770
00771
public slots:
00772
void setEncoding (
const QString &e);
00773
QString encoding() const;
00774
00775 public slots:
00776
void setWordWrap (
bool on);
00777
bool wordWrap ();
00778
00779
void setWordWrapAt (uint col);
00780 uint wordWrapAt ();
00781
00782 public slots:
00783
void setPageUpDownMovesCursor(
bool on);
00784
bool pageUpDownMovesCursor();
00785
00786 signals:
00787
void modStateChanged (Kate::Document *doc);
00788
void nameChanged (Kate::Document *doc);
00789
00790 public slots:
00791
00792
void flush ();
00793
00794 signals:
00799
void fileNameChanged ();
00800
00801 public slots:
00802
void applyWordWrap ();
00803
00804 public:
00805
00806
00807 public:
00808
unsigned int getRealLine(
unsigned int virtualLine);
00809
unsigned int getVirtualLine(
unsigned int realLine);
00810
unsigned int visibleLines ();
00811
00812 signals:
00813
void codeFoldingUpdated();
00814
00815 public slots:
00816
void dumpRegionTree();
00817
00818 private slots:
00819
void slotModOnHdDirty (const
QString &path);
00820
void slotModOnHdCreated (const
QString &path);
00821
void slotModOnHdDeleted (const
QString &path);
00822
00823 private:
00833
bool createDigest (
QCString &result );
00834
00840 inline
QString reasonedMOHString()
const
00841
{
00842
QString reason;
00843
if ( m_modOnHdReason == 1 )
00844 reason = i18n(
"modified");
00845
else if ( m_modOnHdReason == 2 )
00846 reason = i18n(
"created");
00847
else if ( m_modOnHdReason == 3 )
00848 reason = i18n(
"deleted");
00849
00850
return i18n(
"The file '%1' was changed (%2) on disc by another program!").arg( url().prettyURL() ).arg( reason );
00851 }
00852
00861
void removeTrailingSpace( uint line );
00862
00863
public:
00864
00865
bool wrapCursor ();
00866
00867
public:
00868
void updateFileType (
int newType,
bool user =
false);
00869
00870
int fileType ()
const {
return m_fileType; };
00871
00872
00873
00874
00875
private:
00876
00877
KateBuffer *m_buffer;
00878
00879 KateHighlighting *m_highlight;
00880
00881
KateArbitraryHighlight* m_arbitraryHL;
00882
00883
KateAutoIndent *m_indenter;
00884
00885
bool hlSetByUser;
00886
00887
bool m_modOnHd;
00888
unsigned char m_modOnHdReason;
00889
QCString m_digest;
00890
00891
QString m_docName;
00892
int m_docNameNumber;
00893
00894
00895
int m_fileType;
00896
bool m_fileTypeSetByUser;
00897
00901
bool m_reloading;
00902
00903
public slots:
00904
void spellcheck();
00905
void ready(
KSpell *);
00906
void misspelling(
const QString&,
const QStringList&,
unsigned int );
00907
void corrected (
const QString&,
const QString&,
unsigned int);
00908
void spellResult(
const QString& );
00909
void spellCleanDone();
00910
00911
00912
void slotQueryClose_save(
bool *handled,
bool* abortClosing);
00913
00914
private:
00915
00916
00917
void locatePosition( uint pos, uint& line, uint& col );
00918
KSpell* m_kspell;
00919
00920
public:
00921
void makeAttribs ();
00922
00923
static bool checkOverwrite(
KURL u );
00924
00925
static void setDefaultEncoding (
const QString &encoding);
00926
00930
public:
00931
inline KateDocumentConfig *config () {
return m_config; };
00932
00933
void updateConfig ();
00934
00935
private:
00936 KateDocumentConfig *m_config;
00937
00942
private:
00947
void readVariables(
bool onlyViewAndRenderer =
false);
00948
00953
void readVariableLine(
QString t,
bool onlyViewAndRenderer =
false );
00957
void setViewVariable(
QString var,
QString val );
00963
static bool checkBoolValue(
QString value,
bool *result );
00969
static bool checkIntValue(
QString value,
int *result );
00970
00971
00972
00973
00974
static bool checkColorValue(
QString value,
QColor &col );
00975
00976
static QRegExp kvLine;
00977
static QRegExp kvVar;
00978
00979
KIO::TransferJob *m_job;
00980
KTempFile *m_tempFile;
00981
00982
00983
00984
00985
public:
00986
void setIMSelectionValue( uint imStartLine, uint imStart, uint imEnd,
00987 uint imSelStart, uint imSelEnd,
bool m_imComposeEvent );
00988
void getIMSelectionValue( uint *imStartLine, uint *imStart, uint *imEnd,
00989 uint *imSelStart, uint *imSelEnd );
00990
00991
private:
00992 uint m_imStartLine;
00993 uint m_imStart;
00994 uint m_imEnd;
00995 uint m_imSelStart;
00996 uint m_imSelEnd;
00997
bool m_imComposeEvent;
00998
00999 k_dcop:
01000 uint documentNumber () const;
01001 };
01002
01003 #endif
01004
01005
01006