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 #include "katebuffer.h"
00028 #include "katecodefoldinghelpers.h"
00029
00030 #include "../interfaces/document.h"
00031
00032 #include <ktexteditor/configinterfaceextension.h>
00033 #include <ktexteditor/encodinginterface.h>
00034 #include <ktexteditor/sessionconfiginterface.h>
00035 #include <ktexteditor/editinterfaceext.h>
00036 #include <ktexteditor/templateinterface.h>
00037
00038 #include <dcopobject.h>
00039
00040 #include <kmimetype.h>
00041 #include <klocale.h>
00042
00043 #include <qintdict.h>
00044 #include <qmap.h>
00045 #include <qdatetime.h>
00046
00047 namespace KTextEditor { class Plugin; }
00048
00049 namespace KIO { class TransferJob; }
00050
00051 class KateUndoGroup;
00052 class KateCmd;
00053 class KateAttribute;
00054 class KateAutoIndent;
00055 class KateCodeFoldingTree;
00056 class KateBuffer;
00057 class KateView;
00058 class KateViewInternal;
00059 class KateArbitraryHighlight;
00060 class KateSuperRange;
00061 class KateLineInfo;
00062 class KateBrowserExtension;
00063 class KateDocumentConfig;
00064 class KateHighlighting;
00065 class KatePartPluginItem;
00066 class KatePartPluginInfo;
00067
00068 class KTempFile;
00069
00070 class QTimer;
00071
00072 class KateKeyInterceptorFunctor;
00073
00074
00075
00076
00077 class KateDocument : public Kate::Document,
00078 public Kate::DocumentExt,
00079 public KTextEditor::ConfigInterfaceExtension,
00080 public KTextEditor::EncodingInterface,
00081 public KTextEditor::SessionConfigInterface,
00082 public KTextEditor::EditInterfaceExt,
00083 public KTextEditor::TemplateInterface,
00084 public DCOPObject
00085 {
00086 K_DCOP
00087 Q_OBJECT
00088
00089 friend class KateViewInternal;
00090 friend class KateRenderer;
00091
00092 public:
00093 KateDocument (bool bSingleViewMode=false, bool bBrowserView=false, bool bReadOnly=false,
00094 QWidget *parentWidget = 0, const char *widgetName = 0, QObject * = 0, const char * = 0);
00095 ~KateDocument ();
00096
00097 bool closeURL();
00098
00099
00100
00101
00102 public:
00103 void unloadAllPlugins ();
00104
00105 void enableAllPluginsGUI (KateView *view);
00106 void disableAllPluginsGUI (KateView *view);
00107
00108 void loadPlugin (uint pluginIndex);
00109 void unloadPlugin (uint pluginIndex);
00110
00111 void enablePluginGUI (KTextEditor::Plugin *plugin, KateView *view);
00112 void enablePluginGUI (KTextEditor::Plugin *plugin);
00113
00114 void disablePluginGUI (KTextEditor::Plugin *plugin, KateView *view);
00115 void disablePluginGUI (KTextEditor::Plugin *plugin);
00116
00117 private:
00118 QMemArray<KTextEditor::Plugin *> m_plugins;
00119
00120 public:
00121 bool readOnly () const { return m_bReadOnly; }
00122 bool browserView () const { return m_bBrowserView; }
00123 bool singleViewMode () const { return m_bSingleViewMode; }
00124 KateBrowserExtension *browserExtension () { return m_extension; }
00125
00126 private:
00127
00128 bool m_bSingleViewMode;
00129 bool m_bBrowserView;
00130 bool m_bReadOnly;
00131 KateBrowserExtension *m_extension;
00132
00133
00134
00135
00136 public:
00137 KTextEditor::View *createView( QWidget *parent, const char *name );
00138 QPtrList<KTextEditor::View> views () const;
00139
00140 inline KateView *activeView () const { return m_activeView; }
00141
00142 private:
00143 QPtrList<KateView> m_views;
00144 QPtrList<KTextEditor::View> m_textEditViews;
00145 KateView *m_activeView;
00146
00156 void setActiveView( KateView *view );
00157
00158
00159
00160
00161 public slots:
00162 uint configPages () const;
00163 KTextEditor::ConfigPage *configPage (uint number = 0, QWidget *parent = 0, const char *name=0 );
00164 QString configPageName (uint number = 0) const;
00165 QString configPageFullName (uint number = 0) const;
00166 QPixmap configPagePixmap (uint number = 0, int size = KIcon::SizeSmall) const;
00167
00168
00169
00170
00171 public slots:
00172 QString text() const;
00173
00174 QString text ( uint startLine, uint startCol, uint endLine, uint endCol ) const;
00175 QString text ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise ) const;
00176
00177 QString textLine ( uint line ) const;
00178
00179 bool setText(const QString &);
00180 bool clear ();
00181
00182 bool insertText ( uint line, uint col, const QString &s );
00183 bool insertText ( uint line, uint col, const QString &s, bool blockwise );
00184
00185 bool removeText ( uint startLine, uint startCol, uint endLine, uint endCol );
00186 bool removeText ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise );
00187
00188 bool insertLine ( uint line, const QString &s );
00189 bool removeLine ( uint line );
00190
00191 uint numLines() const;
00192 uint numVisLines() const;
00193 uint length () const;
00194 int lineLength ( uint line ) const;
00195
00196 signals:
00197 void textChanged ();
00198 void charactersInteractivelyInserted(int ,int ,const QString&);
00199 void charactersSemiInteractivelyInserted(int ,int ,const QString&);
00200 void backspacePressed();
00201
00202 public:
00203
00209 void editStart (bool withUndo = true);
00211 void editBegin () { editStart(); }
00216 void editEnd ();
00217 private:
00218 bool m_isInUndo;
00219
00220
00221
00222
00223 public:
00231 bool editInsertText ( uint line, uint col, const QString &s );
00239 bool editRemoveText ( uint line, uint col, uint len );
00240
00249 bool editMarkLineAutoWrapped ( uint line, bool autowrapped );
00250
00261 bool editWrapLine ( uint line, uint col, bool newLine = true, bool *newLineAdded = 0 );
00270 bool editUnWrapLine ( uint line, bool removeLine = true, uint length = 0 );
00271
00278 bool editInsertLine ( uint line, const QString &s );
00284 bool editRemoveLine ( uint line );
00285
00292 bool wrapText (uint startLine, uint endLine);
00293
00294
00295 signals:
00300 void editTextInserted ( uint line, uint col, uint len);
00301
00305 void editTextRemoved ( uint line, uint col, uint len);
00306
00310 void editLineWrapped ( uint line, uint col, uint len );
00311
00315 void editLineUnWrapped ( uint line, uint col );
00316
00320 void editLineInserted ( uint line );
00321
00325 void editLineRemoved ( uint line );
00326
00327 private:
00328 void undoStart();
00329 void undoEnd();
00330 void undoSafePoint();
00331
00332 private slots:
00333 void undoCancel();
00334
00335 private:
00336 void editAddUndo (KateUndoGroup::UndoType type, uint line, uint col, uint len, const QString &text);
00337
00338 uint editSessionNumber;
00339 bool editIsRunning;
00340 bool editWithUndo;
00341 bool m_undoComplexMerge;
00342 KateUndoGroup* m_editCurrentUndo;
00343
00344
00345
00346
00347 public slots:
00348 void undo ();
00349 void redo ();
00350 void clearUndo ();
00351 void clearRedo ();
00352
00353 uint undoCount () const;
00354 uint redoCount () const;
00355
00356 uint undoSteps () const;
00357 void setUndoSteps ( uint steps );
00358
00359 private:
00360 friend class KateTemplateHandler;
00361
00362 private:
00363 QPtrList<KateSuperCursor> m_superCursors;
00364
00365
00366
00367
00368 QPtrList<KateUndoGroup> undoItems;
00369 QPtrList<KateUndoGroup> redoItems;
00370 bool m_undoDontMerge;
00371 bool m_undoIgnoreCancel;
00372 QTimer* m_undoMergeTimer;
00373
00374
00375 KateUndoGroup* lastUndoGroupWhenSaved;
00376 KateUndoGroup* lastRedoGroupWhenSaved;
00377 bool docWasSavedWhenUndoWasEmpty;
00378 bool docWasSavedWhenRedoWasEmpty;
00379
00380
00381 void updateModified();
00382
00383 signals:
00384 void undoChanged ();
00385 void textInserted(int line,int column);
00386
00387
00388
00389
00390 public slots:
00391 KTextEditor::Cursor *createCursor ();
00392 QPtrList<KTextEditor::Cursor> cursors () const;
00393
00394 private:
00395 QPtrList<KTextEditor::Cursor> myCursors;
00396
00397
00398
00399
00400 public slots:
00401 bool searchText (unsigned int startLine, unsigned int startCol,
00402 const QString &text, unsigned int *foundAtLine, unsigned int *foundAtCol,
00403 unsigned int *matchLen, bool casesensitive = true, bool backwards = false);
00404 bool searchText (unsigned int startLine, unsigned int startCol,
00405 const QRegExp ®exp, unsigned int *foundAtLine, unsigned int *foundAtCol,
00406 unsigned int *matchLen, bool backwards = false);
00407
00408
00409
00410
00411 public slots:
00412 uint hlMode ();
00413 bool setHlMode (uint mode);
00414 uint hlModeCount ();
00415 QString hlModeName (uint mode);
00416 QString hlModeSectionName (uint mode);
00417
00418 public:
00419 void bufferHlChanged ();
00420
00421 private:
00422 void setDontChangeHlOnSave();
00423
00424 signals:
00425 void hlChanged ();
00426
00427
00428
00429
00430 public:
00431 KateArbitraryHighlight* arbitraryHL() const { return m_arbitraryHL; };
00432
00433 private slots:
00434 void tagArbitraryLines(KateView* view, KateSuperRange* range);
00435
00436
00437
00438
00439 public slots:
00440 void readConfig ();
00441 void writeConfig ();
00442 void readConfig (KConfig *);
00443 void writeConfig (KConfig *);
00444 void readSessionConfig (KConfig *);
00445 void writeSessionConfig (KConfig *);
00446 void configDialog ();
00447
00448
00449
00450
00451 public slots:
00452 uint mark( uint line );
00453
00454 void setMark( uint line, uint markType );
00455 void clearMark( uint line );
00456
00457 void addMark( uint line, uint markType );
00458 void removeMark( uint line, uint markType );
00459
00460 QPtrList<KTextEditor::Mark> marks();
00461 void clearMarks();
00462
00463 void setPixmap( MarkInterface::MarkTypes, const QPixmap& );
00464 void setDescription( MarkInterface::MarkTypes, const QString& );
00465 QString markDescription( MarkInterface::MarkTypes );
00466 QPixmap *markPixmap( MarkInterface::MarkTypes );
00467 QColor markColor( MarkInterface::MarkTypes );
00468
00469 void setMarksUserChangable( uint markMask );
00470 uint editableMarks();
00471
00472 signals:
00473 void marksChanged();
00474 void markChanged( KTextEditor::Mark, KTextEditor::MarkInterfaceExtension::MarkChangeAction );
00475
00476 private:
00477 QIntDict<KTextEditor::Mark> m_marks;
00478 QIntDict<QPixmap> m_markPixmaps;
00479 QIntDict<QString> m_markDescriptions;
00480 uint m_editableMarks;
00481
00482
00483
00484
00485 public slots:
00486 bool printDialog ();
00487 bool print ();
00488
00489
00490
00491
00492 public:
00502 QString mimeType();
00503
00511 long fileSize();
00512
00520 QString niceFileSize();
00521
00530 KMimeType::Ptr mimeTypeForContent();
00531
00532
00533
00534
00535 public:
00536 QString variable( const QString &name ) const;
00537
00538 signals:
00539 void variableChanged( const QString &, const QString & );
00540
00541 private:
00542 QMap<QString, QString> m_storedVariables;
00543
00544
00545
00546
00547 public:
00548 bool openURL( const KURL &url );
00549
00550
00551
00552
00553 bool save();
00554
00555
00556 bool saveAs( const KURL &url );
00557
00558 bool openFile (KIO::Job * job);
00559 bool openFile ();
00560
00561 bool saveFile ();
00562
00563 void setReadWrite ( bool readwrite = true );
00564
00565 void setModified( bool m );
00566
00567 private slots:
00568 void slotDataKate ( KIO::Job* kio_job, const QByteArray &data );
00569 void slotFinishedKate ( KIO::Job * job );
00570
00571 private:
00572 void abortLoadKate();
00573
00574 void activateDirWatch ();
00575 void deactivateDirWatch ();
00576
00577 QString m_dirWatchFile;
00578
00579
00580
00581
00582 public:
00583 Kate::ConfigPage *colorConfigPage (QWidget *) { return 0; }
00584 Kate::ConfigPage *fontConfigPage (QWidget *) { return 0; }
00585 Kate::ConfigPage *indentConfigPage (QWidget *) { return 0; }
00586 Kate::ConfigPage *selectConfigPage (QWidget *) { return 0; }
00587 Kate::ConfigPage *editConfigPage (QWidget *) { return 0; }
00588 Kate::ConfigPage *keysConfigPage (QWidget *) { return 0; }
00589 Kate::ConfigPage *hlConfigPage (QWidget *) { return 0; }
00590 Kate::ConfigPage *viewDefaultsConfigPage (QWidget *) { return 0; }
00591 Kate::ConfigPage *saveConfigPage( QWidget * ) { return 0; }
00592
00593 Kate::ActionMenu *hlActionMenu (const QString& , QObject* = 0, const char* = 0) { return 0; }
00594 Kate::ActionMenu *exportActionMenu (const QString& , QObject* = 0, const char* = 0) { return 0; }
00595
00596 public:
00600 bool typeChars ( KateView *type, const QString &chars );
00601
00605 inline uint lastLine() const { return numLines()-1; }
00606
00607 uint configFlags ();
00608 void setConfigFlags (uint flags);
00609
00610
00611 void repaintViews(bool paintOnlyDirty = true);
00612
00613 inline KateHighlighting *highlight () { return m_buffer->highlight(); }
00614
00615 inline KateHighlighting *highlight () const { return m_buffer->highlight(); }
00616
00617 public slots:
00618 void tagLines(int start, int end);
00619 void tagLines(KateTextCursor start, KateTextCursor end);
00620
00621
00622 public slots:
00623 void exportAs(const QString&) { };
00624
00625 signals:
00626 void modifiedChanged ();
00627 void preHighlightChanged(uint);
00628
00629 private slots:
00630 void internalHlChanged();
00631
00632 public:
00633 void addView(KTextEditor::View *);
00634 void removeView(KTextEditor::View *);
00635
00636 void addSuperCursor(class KateSuperCursor *, bool privateC);
00637 void removeSuperCursor(class KateSuperCursor *, bool privateC);
00638
00639 bool ownedView(KateView *);
00640 bool isLastView(int numViews);
00641
00642 uint currentColumn( const KateTextCursor& );
00643 void newLine( KateTextCursor&, KateViewInternal * );
00644 void backspace( KateView *view, const KateTextCursor& );
00645 void del( KateView *view, const KateTextCursor& );
00646 void transpose( const KateTextCursor& );
00647
00648 void paste ( KateView* view );
00649
00650 public:
00651 void insertIndentChars ( KateView *view );
00652
00653 void indent ( KateView *view, uint line, int change );
00654 void comment ( KateView *view, uint line, uint column, int change );
00655 void align ( KateView *view, uint line );
00656
00657 enum TextTransform { Uppercase, Lowercase, Capitalize };
00658
00666 void transform ( KateView *view, const KateTextCursor &, TextTransform );
00670 void joinLines( uint first, uint last );
00671
00672 private:
00673 void optimizeLeadingSpace( uint line, int flags, int change );
00674 void replaceWithOptimizedSpace( uint line, uint upto_column, uint space, int flags );
00675
00676 bool removeStringFromBegining(int line, QString &str);
00677 bool removeStringFromEnd(int line, QString &str);
00678
00688 bool nextNonSpaceCharPos(int &line, int &col);
00689
00697 bool previousNonSpaceCharPos(int &line, int &col);
00698
00703 void addStartLineCommentToSingleLine(int line, int attrib=0);
00708 bool removeStartLineCommentFromSingleLine(int line, int attrib=0);
00709
00713 void addStartStopCommentToSingleLine(int line, int attrib=0);
00717 bool removeStartStopCommentFromSingleLine(int line, int attrib=0);
00721 bool removeStartStopCommentFromRegion(const KateTextCursor &start, const KateTextCursor &end, int attrib=0);
00722
00727 void addStartStopCommentToSelection( KateView *view, int attrib=0 );
00731 void addStartLineCommentToSelection( KateView *view, int attrib=0 );
00732
00739 bool removeStartStopCommentFromSelection( KateView *view, int attrib=0 );
00743 bool removeStartLineCommentFromSelection( KateView *view, int attrib=0 );
00744
00745 public:
00746 QString getWord( const KateTextCursor& cursor );
00747
00748 public:
00749 void tagAll();
00750
00751 void newBracketMark( const KateTextCursor& start, KateBracketRange& bm, int maxLines = -1 );
00752 bool findMatchingBracket( KateTextCursor& start, KateTextCursor& end, int maxLines = -1 );
00753
00754 private:
00755 void guiActivateEvent( KParts::GUIActivateEvent *ev );
00756
00757 public:
00758
00759 QString docName () {return m_docName;};
00760
00761 void setDocName (QString docName);
00762
00763 void lineInfo (KateLineInfo *info, unsigned int line);
00764
00765 KateCodeFoldingTree *foldingTree ();
00766
00767 public:
00773 bool isModifiedOnDisc() { return m_modOnHd; };
00774
00776 void isModOnHD( bool =false ) {};
00777
00778 void setModifiedOnDisk( int reason );
00779
00780 public slots:
00787 void slotModifiedOnDisk( Kate::View *v=0 );
00788
00792 void reloadFile();
00793
00794 private:
00795 int m_isasking;
00796
00797
00798 public slots:
00799 void setEncoding (const QString &e);
00800 QString encoding() const;
00801
00802 public slots:
00803 void setWordWrap (bool on);
00804 bool wordWrap ();
00805
00806 void setWordWrapAt (uint col);
00807 uint wordWrapAt ();
00808
00809 public slots:
00810 void setPageUpDownMovesCursor(bool on);
00811 bool pageUpDownMovesCursor();
00812
00813 signals:
00814 void modStateChanged (Kate::Document *doc);
00815 void nameChanged (Kate::Document *doc);
00816
00817 public slots:
00818
00819 void flush ();
00820
00821 signals:
00826 void fileNameChanged ();
00827
00828 public slots:
00829 void applyWordWrap ();
00830
00831
00832 public:
00833 inline uint getRealLine(unsigned int virtualLine)
00834 {
00835 return m_buffer->lineNumber (virtualLine);
00836 }
00837
00838 inline uint getVirtualLine(unsigned int realLine)
00839 {
00840 return m_buffer->lineVisibleNumber (realLine);
00841 }
00842
00843 inline uint visibleLines ()
00844 {
00845 return m_buffer->countVisible ();
00846 }
00847
00848 inline KateTextLine::Ptr kateTextLine(uint i)
00849 {
00850 return m_buffer->line (i);
00851 }
00852
00853 inline KateTextLine::Ptr plainKateTextLine(uint i)
00854 {
00855 return m_buffer->plainLine (i);
00856 }
00857
00858 signals:
00859 void codeFoldingUpdated();
00860 void aboutToRemoveText(const KateTextRange&);
00861 void textRemoved();
00862
00863 private slots:
00864 void slotModOnHdDirty (const QString &path);
00865 void slotModOnHdCreated (const QString &path);
00866 void slotModOnHdDeleted (const QString &path);
00867
00868 private:
00878 bool createDigest ( QCString &result );
00879
00885 QString reasonedMOHString() const;
00886
00895 void removeTrailingSpace( uint line );
00896
00897 public:
00898 void updateFileType (int newType, bool user = false);
00899
00900 int fileType () const { return m_fileType; };
00901
00902
00903
00904
00905 private:
00906
00907 KateBuffer *m_buffer;
00908
00909 KateArbitraryHighlight* m_arbitraryHL;
00910
00911 KateAutoIndent *m_indenter;
00912
00913 bool hlSetByUser;
00914
00915 bool m_modOnHd;
00916 unsigned char m_modOnHdReason;
00917 QCString m_digest;
00918
00919 QString m_docName;
00920 int m_docNameNumber;
00921
00922
00923 int m_fileType;
00924 bool m_fileTypeSetByUser;
00925
00929 bool m_reloading;
00930 bool m_loading;
00931 bool m_encodingSticky;
00932
00933 public slots:
00934 void slotQueryClose_save(bool *handled, bool* abortClosing);
00935
00936 public:
00937 void makeAttribs (bool needInvalidate = true);
00938
00939 static bool checkOverwrite( KURL u );
00940
00941 static void setDefaultEncoding (const QString &encoding);
00942
00943 void setEncodingSticky( bool e ) { m_encodingSticky = e; }
00944
00948 public:
00949 inline KateDocumentConfig *config () { return m_config; };
00950
00951 void updateConfig ();
00952
00953 private:
00954 KateDocumentConfig *m_config;
00955
00960 private:
00964 void readDirConfig ();
00965
00970 void readVariables(bool onlyViewAndRenderer = false);
00971
00976 void readVariableLine( QString t, bool onlyViewAndRenderer = false );
00980 void setViewVariable( QString var, QString val );
00986 static bool checkBoolValue( QString value, bool *result );
00992 static bool checkIntValue( QString value, int *result );
00997 static bool checkColorValue( QString value, QColor &col );
00998
01002 static QRegExp kvLine;
01003 static QRegExp kvLineWildcard;
01004 static QRegExp kvLineMime;
01005 static QRegExp kvVar;
01006
01007 KIO::TransferJob *m_job;
01008 KTempFile *m_tempFile;
01009
01010
01011 public:
01012 bool setTabInterceptor(KateKeyInterceptorFunctor *interceptor);
01013 bool removeTabInterceptor(KateKeyInterceptorFunctor *interceptor);
01014 bool invokeTabInterceptor(KKey);
01015
01016 protected:
01017 virtual bool insertTemplateTextImplementation ( uint line, uint column, const QString &templateString, const QMap<QString,QString> &initialValues, QWidget *parentWindow=0 );
01018 KateKeyInterceptorFunctor *m_tabInterceptor;
01019
01020 protected slots:
01021 void testTemplateCode();
01022 void dumpRegionTree();
01023
01024
01025
01026
01027
01028
01029 public slots:
01030 bool setSelection ( uint startLine, uint startCol, uint endLine, uint endCol );
01031 bool clearSelection ();
01032 bool hasSelection () const;
01033 QString selection () const;
01034 bool removeSelectedText ();
01035 bool selectAll();
01036
01037
01038
01039
01040 int selStartLine();
01041 int selStartCol();
01042 int selEndLine();
01043 int selEndCol();
01044
01045
01046
01047 #undef signals
01048 #define signals public
01049 signals:
01050 #undef signals
01051 #define signals protected
01052 void selectionChanged ();
01053
01054
01055
01056
01057
01058 public slots:
01059 bool blockSelectionMode ();
01060 bool setBlockSelectionMode (bool on);
01061 bool toggleBlockSelectionMode ();
01062
01063 private:
01064
01065
01066 k_dcop:
01067 uint documentNumber () const;
01068 };
01069
01070 #endif
01071
01072
01073