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
00027 #include "../interfaces/document.h"
00028
00029 #include <ktexteditor/configinterfaceextension.h>
00030 #include <ktexteditor/encodinginterface.h>
00031 #include <ktexteditor/sessionconfiginterface.h>
00032 #include <ktexteditor/editinterfaceext.h>
00033
00034 #include <dcopobject.h>
00035
00036 #include <qintdict.h>
00037 #include <qdatetime.h>
00038
00039 namespace KTextEditor { class Plugin; }
00040
00041 namespace KIO { class TransferJob; }
00042
00043 class KateUndoGroup;
00044 class KateCmd;
00045 class KateAttribute;
00046 class KateAutoIndent;
00047 class KateCodeFoldingTree;
00048 class KateBuffer;
00049 class KateView;
00050 class KateViewInternal;
00051 class LineRange;
00052 class KateArbitraryHighlight;
00053 class KateSuperRange;
00054 class KateLineInfo;
00055 class KateBrowserExtension;
00056 class KateDocumentConfig;
00057 class Highlight;
00058 class KatePartPluginItem;
00059 class KatePartPluginInfo;
00060
00061 class KSpell;
00062 class KTempFile;
00063
00064 class QTimer;
00065
00066
00067
00068
00069 class KateDocument : public Kate::Document,
00070 public KTextEditor::ConfigInterfaceExtension,
00071 public KTextEditor::EncodingInterface,
00072 public KTextEditor::SessionConfigInterface,
00073 public KTextEditor::EditInterfaceExt,
00074 public DCOPObject
00075 {
00076 K_DCOP
00077 Q_OBJECT
00078
00079 friend class KateViewInternal;
00080 friend class KateRenderer;
00081
00082 public:
00083 KateDocument (bool bSingleViewMode=false, bool bBrowserView=false, bool bReadOnly=false,
00084 QWidget *parentWidget = 0, const char *widgetName = 0, QObject * = 0, const char * = 0);
00085 ~KateDocument ();
00086
00087 bool closeURL();
00088
00089
00090
00091
00092 public:
00093 void unloadAllPlugins ();
00094
00095 void enableAllPluginsGUI (KateView *view);
00096 void disableAllPluginsGUI (KateView *view);
00097
00098 void loadPlugin (uint pluginIndex);
00099 void unloadPlugin (uint pluginIndex);
00100
00101 void enablePluginGUI (KTextEditor::Plugin *plugin, KateView *view);
00102 void enablePluginGUI (KTextEditor::Plugin *plugin);
00103
00104 void disablePluginGUI (KTextEditor::Plugin *plugin, KateView *view);
00105 void disablePluginGUI (KTextEditor::Plugin *plugin);
00106
00107 private:
00108 QMemArray<KTextEditor::Plugin *> m_plugins;
00109
00110 public:
00111 bool readOnly () const { return m_bReadOnly; }
00112 bool browserView () const { return m_bBrowserView; }
00113 bool singleViewMode () const { return m_bSingleViewMode; }
00114 KateBrowserExtension *browserExtension () { return m_extension; }
00115
00116 private:
00117
00118 bool m_bSingleViewMode;
00119 bool m_bBrowserView;
00120 bool m_bReadOnly;
00121 KateBrowserExtension *m_extension;
00122
00123
00124
00125
00126 public:
00127 KTextEditor::View *createView( QWidget *parent, const char *name );
00128 QPtrList<KTextEditor::View> views () const;
00129
00130 inline KateView *activeView () const { return m_activeView; }
00131
00132 private:
00133 QPtrList<KateView> m_views;
00134 QPtrList<KTextEditor::View> m_textEditViews;
00135 KateView *m_activeView;
00136
00137
00138
00139
00140 public slots:
00141 uint configPages () const;
00142 KTextEditor::ConfigPage *configPage (uint number = 0, QWidget *parent = 0, const char *name=0 );
00143 QString configPageName (uint number = 0) const;
00144 QString configPageFullName (uint number = 0) const;
00145 QPixmap configPagePixmap (uint number = 0, int size = KIcon::SizeSmall) const;
00146
00147
00148
00149
00150 public slots:
00151 QString text() const;
00152
00153 QString text ( uint startLine, uint startCol, uint endLine, uint endCol ) const;
00154 QString text ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise ) const;
00155
00156 QString textLine ( uint line ) const;
00157
00158 bool setText(const QString &);
00159 bool clear ();
00160
00161 bool insertText ( uint line, uint col, const QString &s );
00162 bool insertText ( uint line, uint col, const QString &s, bool blockwise );
00163
00164 bool removeText ( uint startLine, uint startCol, uint endLine, uint endCol );
00165 bool removeText ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise );
00166
00167 bool insertLine ( uint line, const QString &s );
00168 bool removeLine ( uint line );
00169
00170 uint numLines() const;
00171 uint numVisLines() const;
00172 uint length () const;
00173 int lineLength ( uint line ) const;
00174
00175 signals:
00176 void textChanged ();
00177 void charactersInteractivelyInserted(int ,int ,const QString&);
00178 void backspacePressed();
00179
00180 public:
00181
00182
00183
00184 void editBegin () { editStart(); }
00185 void editStart (bool withUndo = true);
00186 void editEnd ();
00187
00188
00189
00190
00191 bool editInsertText ( uint line, uint col, const QString &s );
00192 bool editRemoveText ( uint line, uint col, uint len );
00193
00194 bool editMarkLineAutoWrapped ( uint line, bool autowrapped );
00195
00196 bool editWrapLine ( uint line, uint col, bool newLine = true, bool *newLineAdded = 0 );
00197 bool editUnWrapLine ( uint line, bool removeLine = true, uint length = 0 );
00198
00199 bool editInsertLine ( uint line, const QString &s );
00200 bool editRemoveLine ( uint line );
00201
00202 bool wrapText (uint startLine, uint endLine);
00203
00204 signals:
00209 void editTextInserted ( uint line, uint col, uint len);
00210
00214 void editTextRemoved ( uint line, uint col, uint len);
00215
00219 void editLineWrapped ( uint line, uint col, uint len );
00220
00224 void editLineUnWrapped ( uint line, uint col );
00225
00229 void editLineInserted ( uint line );
00230
00234 void editLineRemoved ( uint line );
00235
00236 private:
00237 void undoStart();
00238 void undoEnd();
00239
00240 private slots:
00241 void undoCancel();
00242
00243 private:
00244 void editAddUndo (uint type, uint line, uint col, uint len, const QString &text);
00245 void editTagLine (uint line);
00246 void editRemoveTagLine (uint line);
00247 void editInsertTagLine (uint line);
00248
00249 uint editSessionNumber;
00250 bool editIsRunning;
00251 bool noViewUpdates;
00252 bool editWithUndo;
00253 uint editTagLineStart;
00254 uint editTagLineEnd;
00255 bool editTagFrom;
00256 KateUndoGroup* m_editCurrentUndo;
00257
00258
00259
00260
00261 public slots:
00262 bool setSelection ( const KateTextCursor & start,
00263 const KateTextCursor & end );
00264 bool setSelection ( uint startLine, uint startCol,
00265 uint endLine, uint endCol );
00266 bool clearSelection ();
00267 bool clearSelection (bool redraw, bool finishedChangingSelection = true);
00268
00269 bool hasSelection () const;
00270 QString selection () const ;
00271
00272 bool removeSelectedText ();
00273
00274 bool selectAll();
00275
00276
00277
00278
00279 int selStartLine() { return selectStart.line(); };
00280 int selStartCol() { return selectStart.col(); };
00281 int selEndLine() { return selectEnd.line(); };
00282 int selEndCol() { return selectEnd.col(); };
00283
00284 private:
00285
00286 bool lineColSelected (int line, int col);
00287 bool lineSelected (int line);
00288 bool lineEndSelected (int line, int endCol);
00289 bool lineHasSelected (int line);
00290 bool lineIsSelection (int line);
00291
00292 QPtrList<KateSuperCursor> m_superCursors;
00293
00294
00295 KateSuperCursor selectStart;
00296 KateSuperCursor selectEnd;
00297
00298 signals:
00299 void selectionChanged ();
00300
00301
00302
00303
00304 public slots:
00305 bool blockSelectionMode ();
00306 bool setBlockSelectionMode (bool on);
00307 bool toggleBlockSelectionMode ();
00308
00309 private:
00310
00311 bool blockSelect;
00312
00313
00314
00315
00316 public slots:
00317 void undo ();
00318 void redo ();
00319 void clearUndo ();
00320 void clearRedo ();
00321
00322 uint undoCount () const;
00323 uint redoCount () const;
00324
00325 uint undoSteps () const;
00326 void setUndoSteps ( uint steps );
00327
00328 private:
00329
00330
00331
00332 QPtrList<KateUndoGroup> undoItems;
00333 QPtrList<KateUndoGroup> redoItems;
00334 bool m_undoDontMerge;
00335 bool m_undoIgnoreCancel;
00336 QTimer* m_undoMergeTimer;
00337
00338
00339 KateUndoGroup* lastUndoGroupWhenSaved;
00340 bool docWasSavedWhenUndoWasEmpty;
00341
00342
00343 void updateModified();
00344
00345 signals:
00346 void undoChanged ();
00347
00348
00349
00350
00351 public slots:
00352 KTextEditor::Cursor *createCursor ();
00353 QPtrList<KTextEditor::Cursor> cursors () const;
00354
00355 private:
00356 QPtrList<KTextEditor::Cursor> myCursors;
00357
00358
00359
00360
00361 public slots:
00362 bool searchText (unsigned int startLine, unsigned int startCol,
00363 const QString &text, unsigned int *foundAtLine, unsigned int *foundAtCol,
00364 unsigned int *matchLen, bool casesensitive = true, bool backwards = false);
00365 bool searchText (unsigned int startLine, unsigned int startCol,
00366 const QRegExp ®exp, unsigned int *foundAtLine, unsigned int *foundAtCol,
00367 unsigned int *matchLen, bool backwards = false);
00368
00369
00370
00371
00372 public slots:
00373 uint hlMode ();
00374 bool setHlMode (uint mode);
00375 uint hlModeCount ();
00376 QString hlModeName (uint mode);
00377 QString hlModeSectionName (uint mode);
00378
00379 private:
00380 bool internalSetHlMode (uint mode);
00381 void setDontChangeHlOnSave();
00382
00383 signals:
00384 void hlChanged ();
00385
00386
00387
00388
00389 public:
00390 KateArbitraryHighlight* arbitraryHL() const { return m_arbitraryHL; };
00391
00392 private slots:
00393 void tagArbitraryLines(KateView* view, KateSuperRange* range);
00394
00395
00396
00397
00398 public slots:
00399 void readConfig ();
00400 void writeConfig ();
00401 void readConfig (KConfig *);
00402 void writeConfig (KConfig *);
00403 void readSessionConfig (KConfig *);
00404 void writeSessionConfig (KConfig *);
00405 void configDialog ();
00406
00407
00408
00409
00410 public slots:
00411 uint mark( uint line );
00412
00413 void setMark( uint line, uint markType );
00414 void clearMark( uint line );
00415
00416 void addMark( uint line, uint markType );
00417 void removeMark( uint line, uint markType );
00418
00419 QPtrList<KTextEditor::Mark> marks();
00420 void clearMarks();
00421
00422 void setPixmap( MarkInterface::MarkTypes, const QPixmap& );
00423 void setDescription( MarkInterface::MarkTypes, const QString& );
00424 QString markDescription( MarkInterface::MarkTypes );
00425 QPixmap *markPixmap( MarkInterface::MarkTypes );
00426 QColor markColor( MarkInterface::MarkTypes );
00427
00428 void setMarksUserChangable( uint markMask );
00429 uint editableMarks();
00430
00431 signals:
00432 void marksChanged();
00433 void markChanged( KTextEditor::Mark, KTextEditor::MarkInterfaceExtension::MarkChangeAction );
00434
00435 private:
00436 QIntDict<KTextEditor::Mark> m_marks;
00437 QIntDict<QPixmap> m_markPixmaps;
00438 QIntDict<QString> m_markDescriptions;
00439 uint m_editableMarks;
00440
00441
00442
00443
00444 public slots:
00445 bool printDialog ();
00446 bool print ();
00447
00448
00449
00450
00451
00452 public:
00453 bool openURL( const KURL &url );
00454
00455
00456
00457
00458 bool save();
00459
00460 bool openFile (KIO::Job * job);
00461 bool openFile ();
00462
00463 bool saveFile ();
00464
00465 void setReadWrite ( bool rw = true );
00466
00467 void setModified( bool m );
00468
00469 private slots:
00470 void slotDataKate ( KIO::Job* kio_job, const QByteArray &data );
00471 void slotFinishedKate ( KIO::Job * job );
00472
00473 private:
00474 void abortLoadKate();
00475
00476 void activateDirWatch ();
00477 void deactivateDirWatch ();
00478
00479 QString m_dirWatchFile;
00480
00481
00482
00483
00484 public:
00485 Kate::ConfigPage *colorConfigPage (QWidget *);
00486 Kate::ConfigPage *fontConfigPage (QWidget *);
00487 Kate::ConfigPage *indentConfigPage (QWidget *);
00488 Kate::ConfigPage *selectConfigPage (QWidget *);
00489 Kate::ConfigPage *editConfigPage (QWidget *);
00490 Kate::ConfigPage *keysConfigPage (QWidget *);
00491 Kate::ConfigPage *hlConfigPage (QWidget *);
00492 Kate::ConfigPage *viewDefaultsConfigPage (QWidget *);
00493 Kate::ConfigPage *saveConfigPage( QWidget * );
00494
00495 Kate::ActionMenu *hlActionMenu (const QString& text, QObject* parent = 0, const char* name = 0);
00496 Kate::ActionMenu *exportActionMenu (const QString& text, QObject* parent = 0, const char* name = 0);
00497
00498 public:
00502 bool typeChars ( KateView *type, const QString &chars );
00503
00507 uint lastLine() const { return numLines()-1;}
00508
00509 TextLine::Ptr kateTextLine(uint i);
00510 TextLine::Ptr plainKateTextLine(uint i);
00511
00512 uint configFlags ();
00513 void setConfigFlags (uint flags);
00514
00518 void tagSelection(const KateTextCursor &oldSelectStart, const KateTextCursor &oldSelectEnd);
00519
00520
00521 void repaintViews(bool paintOnlyDirty = true);
00522
00523 Highlight *highlight () { return m_highlight; }
00524
00525 public slots:
00526 void tagLines(int start, int end);
00527 void tagLines(KateTextCursor start, KateTextCursor end);
00528
00529
00530 public slots:
00531 void exportAs(const QString&);
00532
00533 private:
00534 bool exportDocumentToHTML (QTextStream *outputStream,const QString &name);
00535 QString HTMLEncode (QChar theChar);
00536
00537 signals:
00538 void modifiedChanged ();
00539 void preHighlightChanged(uint);
00540
00541 private slots:
00542 void internalHlChanged();
00543
00544 public:
00545 void addView(KTextEditor::View *);
00546 void removeView(KTextEditor::View *);
00547
00548 void addSuperCursor(class KateSuperCursor *, bool privateC);
00549 void removeSuperCursor(class KateSuperCursor *, bool privateC);
00550
00551 bool ownedView(KateView *);
00552 bool isLastView(int numViews);
00553
00554 uint currentColumn( const KateTextCursor& );
00555 void newLine( KateTextCursor&, KateViewInternal * );
00556 void backspace( const KateTextCursor& );
00557 void del( const KateTextCursor& );
00558 void transpose( const KateTextCursor& );
00559 void cut();
00560 void copy();
00561 void paste ( KateView* view );
00562
00563 void selectWord( const KateTextCursor& cursor );
00564 void selectLine( const KateTextCursor& cursor );
00565 void selectLength( const KateTextCursor& cursor, int length );
00566
00567 public:
00568 void insertIndentChars ( KateView *view );
00569
00570 void indent ( KateView *view, uint line, int change );
00571 void comment ( KateView *view, uint line, int change );
00572
00573 enum TextTransform { Uppercase, Lowercase, Capitalize };
00574
00582 void transform ( KateView *view, const KateTextCursor &, TextTransform );
00586 void joinLines( uint first, uint last );
00587
00588 private:
00589 void optimizeLeadingSpace( uint line, int flags, int change );
00590 void replaceWithOptimizedSpace( uint line, uint upto_column, uint space, int flags );
00591
00592 bool removeStringFromBegining(int line, QString &str);
00593 bool removeStringFromEnd(int line, QString &str);
00594
00604 bool nextNonSpaceCharPos(int &line, int &col);
00605
00613 bool previousNonSpaceCharPos(int &line, int &col);
00614
00615 void addStartLineCommentToSingleLine(int line);
00616 bool removeStartLineCommentFromSingleLine(int line);
00617
00618 void addStartStopCommentToSingleLine(int line);
00619 bool removeStartStopCommentFromSingleLine(int line);
00620
00621 void addStartStopCommentToSelection();
00622 void addStartLineCommentToSelection();
00623
00624 bool removeStartStopCommentFromSelection();
00625 bool removeStartLineCommentFromSelection();
00626
00627 public:
00628 QString getWord( const KateTextCursor& cursor );
00629
00630 public:
00631 void tagAll();
00632 void updateViews();
00633
00634 void newBracketMark( const KateTextCursor& start, KateTextRange& bm );
00635 bool findMatchingBracket( KateTextCursor& start, KateTextCursor& end );
00636
00637 private:
00638 void guiActivateEvent( KParts::GUIActivateEvent *ev );
00639
00640 private slots:
00641 void slotBufferChanged();
00642
00643 public:
00649 void isModOnHD(bool forceReload=false);
00650
00651 QString docName () {return m_docName;};
00652
00653 void setDocName (QString docName);
00654
00655 void lineInfo (KateLineInfo *info, unsigned int line);
00656
00657 KateCodeFoldingTree *foldingTree ();
00658
00659 public slots:
00663 void reloadFile();
00664
00665 public slots:
00666 void setEncoding (const QString &e);
00667 QString encoding() const;
00668
00669 public slots:
00670 void setWordWrap (bool on);
00671 bool wordWrap ();
00672
00673 void setWordWrapAt (uint col);
00674 uint wordWrapAt ();
00675
00676 public slots:
00677 void setPageUpDownMovesCursor(bool on);
00678 bool pageUpDownMovesCursor();
00679
00680 signals:
00681 void modStateChanged (Kate::Document *doc);
00682 void nameChanged (Kate::Document *doc);
00683
00684 public slots:
00685
00686 void flush ();
00687
00688 signals:
00693 void fileNameChanged ();
00694
00695 public slots:
00696 void applyWordWrap ();
00697
00698 public:
00699
00700
00701 public:
00702 unsigned int getRealLine(unsigned int virtualLine);
00703 unsigned int getVirtualLine(unsigned int realLine);
00704 unsigned int visibleLines ();
00705
00706 signals:
00707 void codeFoldingUpdated();
00708
00709 public slots:
00710 void dumpRegionTree();
00711
00712 private slots:
00713 void slotModOnHdDirty (const QString &path);
00714 void slotModOnHdCreated (const QString &path);
00715 void slotModOnHdDeleted (const QString &path);
00716
00717 private:
00725 bool createDigest( QCString &result );
00726
00727 public:
00728
00729 bool wrapCursor ();
00730
00731 public:
00732 void updateFileType (int newType, bool user = false);
00733
00734 int fileType () const { return m_fileType; };
00735
00736
00737
00738
00739 private:
00740
00741 KateBuffer *buffer;
00742
00743 Highlight *m_highlight;
00744
00745 KateArbitraryHighlight* m_arbitraryHL;
00746
00747 KateAutoIndent *m_indenter;
00748
00749 bool hlSetByUser;
00750
00751 bool m_modOnHd;
00752 unsigned char m_modOnHdReason;
00753 QCString m_digest;
00754
00755 QString m_docName;
00756 int m_docNameNumber;
00757
00758
00759 int m_fileType;
00760 bool m_fileTypeSetByUser;
00761
00762 public slots:
00763 void spellcheck();
00764 void ready(KSpell *);
00765 void misspelling( const QString&, const QStringList&, unsigned int );
00766 void corrected ( const QString&, const QString&, unsigned int);
00767 void spellResult( const QString& );
00768 void spellCleanDone();
00769
00770
00771 void slotQueryClose_save(bool *handled, bool* abortClosing);
00772
00773 private:
00774 void makeAttribs ();
00775
00776 void locatePosition( uint pos, uint& line, uint& col );
00777 KSpell* m_kspell;
00778 int m_mispellCount;
00779 int m_replaceCount;
00780 bool m_reloading;
00781
00782 public:
00783 static bool checkOverwrite( KURL u );
00784
00785 static void setDefaultEncoding (const QString &encoding);
00786
00790 public:
00791 inline KateDocumentConfig *config () { return m_config; };
00792
00793 void updateConfig ();
00794
00795 private:
00796 KateDocumentConfig *m_config;
00797
00802 private:
00807 void readVariables(bool onlyViewAndRenderer = false);
00808
00813 void readVariableLine( QString t, bool onlyViewAndRenderer = false );
00817 void setViewVariable( QString var, QString val );
00823 static bool checkBoolValue( QString value, bool *result );
00829 static bool checkIntValue( QString value, int *result );
00830
00831
00832
00833
00834 static bool checkColorValue( QString value, QColor &col );
00835
00836 static QRegExp kvLine;
00837 static QRegExp kvVar;
00838
00839 KIO::TransferJob *m_job;
00840 KTempFile *m_tempFile;
00841
00842
00843
00844
00845 public:
00846 void setIMSelectionValue( uint imStartLine, uint imStart, uint imEnd,
00847 uint imSelStart, uint imSelEnd, bool m_imComposeEvent );
00848 void getIMSelectionValue( uint *imStartLine, uint *imStart, uint *imEnd,
00849 uint *imSelStart, uint *imSelEnd );
00850
00851 private:
00852 uint m_imStartLine;
00853 uint m_imStart;
00854 uint m_imEnd;
00855 uint m_imSelStart;
00856 uint m_imSelEnd;
00857 bool m_imComposeEvent;
00858
00859 k_dcop:
00860 uint documentNumber () const;
00861 };
00862
00863 #endif
00864
00865
00866