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   public:
00452     bool openURL( const KURL &url );
00453 
00454     
00455 
00456 
00457     bool save();
00458 
00459     bool openFile (KIO::Job * job);
00460     bool openFile ();
00461 
00462     bool saveFile ();
00463 
00464     void setReadWrite ( bool rw = true );
00465 
00466     void setModified( bool m );
00467 
00468   private slots:
00469     void slotDataKate ( KIO::Job* kio_job, const QByteArray &data );
00470     void slotFinishedKate ( KIO::Job * job );
00471 
00472   private:
00473     void abortLoadKate();
00474 
00475   
00476   
00477   
00478   public:
00479     Kate::ConfigPage *colorConfigPage (QWidget *);
00480     Kate::ConfigPage *fontConfigPage (QWidget *);
00481     Kate::ConfigPage *indentConfigPage (QWidget *);
00482     Kate::ConfigPage *selectConfigPage (QWidget *);
00483     Kate::ConfigPage *editConfigPage (QWidget *);
00484     Kate::ConfigPage *keysConfigPage (QWidget *);
00485     Kate::ConfigPage *hlConfigPage (QWidget *);
00486     Kate::ConfigPage *viewDefaultsConfigPage (QWidget *);
00487     Kate::ConfigPage *saveConfigPage( QWidget * );
00488 
00489     Kate::ActionMenu *hlActionMenu (const QString& text, QObject* parent = 0, const char* name = 0);
00490     Kate::ActionMenu *exportActionMenu (const QString& text, QObject* parent = 0, const char* name = 0);
00491 
00492   public:
00496     bool typeChars ( KateView *type, const QString &chars );
00497 
00501     uint lastLine() const { return numLines()-1;}
00502 
00503     TextLine::Ptr kateTextLine(uint i);
00504     TextLine::Ptr plainKateTextLine(uint i);
00505 
00506     uint configFlags ();
00507     void setConfigFlags (uint flags);
00508 
00512     void tagSelection(const KateTextCursor &oldSelectStart, const KateTextCursor &oldSelectEnd);
00513 
00514     
00515     void repaintViews(bool paintOnlyDirty = true);
00516 
00517     Highlight *highlight () { return m_highlight; }
00518 
00519   public slots:    
00520     void tagLines(int start, int end);
00521     void tagLines(KateTextCursor start, KateTextCursor end);
00522 
00523   
00524   public slots:
00525      void exportAs(const QString&);
00526 
00527   private: 
00528     bool exportDocumentToHTML (QTextStream *outputStream,const QString &name);
00529     QString HTMLEncode (QChar theChar);
00530 
00531   signals:
00532     void modifiedChanged ();
00533     void preHighlightChanged(uint);
00534 
00535   private slots:
00536     void internalHlChanged();
00537 
00538   public:
00539     void addView(KTextEditor::View *);
00540     void removeView(KTextEditor::View *);
00541 
00542     void addSuperCursor(class KateSuperCursor *, bool privateC);
00543     void removeSuperCursor(class KateSuperCursor *, bool privateC);
00544 
00545     bool ownedView(KateView *);
00546     bool isLastView(int numViews);
00547 
00548     uint currentColumn( const KateTextCursor& );
00549     void newLine(             KateTextCursor&, KateViewInternal * ); 
00550     void backspace(     const KateTextCursor& );
00551     void del(           const KateTextCursor& );
00552     void transpose(     const KateTextCursor& );
00553     void cut();
00554     void copy();
00555     void paste ( KateView* view );
00556 
00557     void selectWord(   const KateTextCursor& cursor );
00558     void selectLine(   const KateTextCursor& cursor );
00559     void selectLength( const KateTextCursor& cursor, int length );
00560 
00561   public:
00562     void insertIndentChars ( KateView *view );
00563 
00564     void indent ( KateView *view, uint line, int change );
00565     void comment ( KateView *view, uint line, int change );
00566 
00567     enum TextTransform { Uppercase, Lowercase, Capitalize };
00568 
00576     void transform ( KateView *view, const KateTextCursor &, TextTransform );
00580     void joinLines( uint first, uint last );
00581 
00582   private:
00583     void optimizeLeadingSpace( uint line, int flags, int change );
00584     void replaceWithOptimizedSpace( uint line, uint upto_column, uint space, int flags );
00585 
00586     bool removeStringFromBegining(int line, QString &str);
00587     bool removeStringFromEnd(int line, QString &str);
00588 
00598     bool nextNonSpaceCharPos(int &line, int &col);
00599     
00607     bool previousNonSpaceCharPos(int &line, int &col);
00608 
00609     void addStartLineCommentToSingleLine(int line);
00610     bool removeStartLineCommentFromSingleLine(int line);
00611 
00612     void addStartStopCommentToSingleLine(int line);
00613     bool removeStartStopCommentFromSingleLine(int line);
00614 
00615     void addStartStopCommentToSelection();
00616     void addStartLineCommentToSelection();
00617 
00618     bool removeStartStopCommentFromSelection();
00619     bool removeStartLineCommentFromSelection();
00620 
00621   public:
00622     QString getWord( const KateTextCursor& cursor );
00623 
00624   public:
00625     void tagAll();
00626     void updateViews();
00627 
00628     void newBracketMark( const KateTextCursor& start, KateTextRange& bm );
00629     bool findMatchingBracket( KateTextCursor& start, KateTextCursor& end );
00630 
00631   private:
00632     void guiActivateEvent( KParts::GUIActivateEvent *ev );
00633 
00634   private slots:
00635     void slotBufferChanged();
00636 
00637   public:
00643     void isModOnHD(bool forceReload=false);
00644 
00645     QString docName () {return m_docName;};
00646 
00647     void setDocName (QString docName);
00648 
00649     void lineInfo (KateLineInfo *info, unsigned int line);
00650 
00651     KateCodeFoldingTree *foldingTree ();
00652 
00653   public slots:
00657     void reloadFile();
00658 
00659   public slots:
00660     void setEncoding (const QString &e);
00661     QString encoding() const;
00662 
00663   public slots:
00664     void setWordWrap (bool on);
00665     bool wordWrap ();
00666 
00667     void setWordWrapAt (uint col);
00668     uint wordWrapAt ();
00669 
00670   public slots:
00671     void setPageUpDownMovesCursor(bool on);
00672     bool pageUpDownMovesCursor();
00673 
00674   signals:
00675     void modStateChanged (Kate::Document *doc);
00676     void nameChanged (Kate::Document *doc);
00677 
00678   public slots:
00679     
00680     void flush ();
00681 
00682   signals:
00687     void fileNameChanged ();
00688 
00689   public slots:
00690      void applyWordWrap ();
00691 
00692   public:
00693 
00694  
00695   public:
00696     unsigned int getRealLine(unsigned int virtualLine);
00697     unsigned int getVirtualLine(unsigned int realLine);
00698     unsigned int visibleLines ();
00699 
00700   signals:
00701     void codeFoldingUpdated();
00702 
00703   public slots:
00704     void dumpRegionTree();
00705 
00706   private slots:
00707     void slotModOnHdDirty (const QString &path);
00708     void slotModOnHdCreated (const QString &path);
00709     void slotModOnHdDeleted (const QString &path);
00710 
00711   public:
00712     
00713     bool wrapCursor ();
00714 
00715   public:
00716     void updateFileType (int newType, bool user = false);
00717 
00718     int fileType () const { return m_fileType; };
00719 
00720   
00721   
00722   
00723   private:
00724     
00725     KateBuffer *buffer;
00726 
00727     Highlight *m_highlight;
00728 
00729     KateArbitraryHighlight* m_arbitraryHL;
00730 
00731     KateAutoIndent *m_indenter;
00732 
00733     bool hlSetByUser;
00734 
00735     bool m_modOnHd;
00736     unsigned char m_modOnHdReason;
00737 
00738     QString m_docName;
00739     int m_docNameNumber;
00740 
00741     
00742     int m_fileType;
00743     bool m_fileTypeSetByUser;
00744 
00745   public slots:
00746     void spellcheck();
00747     void ready(KSpell *);
00748     void misspelling( const QString&, const QStringList&, unsigned int );
00749     void corrected  ( const QString&, const QString&, unsigned int);
00750     void spellResult( const QString& );
00751     void spellCleanDone();
00752   
00753   
00754     void slotQueryClose_save(bool *handled, bool* abortClosing);
00755 
00756   private:
00757     void makeAttribs ();
00758 
00759     void locatePosition( uint pos, uint& line, uint& col );
00760     KSpell*         m_kspell;
00761     int             m_mispellCount;
00762     int             m_replaceCount;
00763     bool            m_reloading;
00764 
00765   public:
00766     static bool checkOverwrite( KURL u );
00767 
00768     static void setDefaultEncoding (const QString &encoding);
00769 
00773   public:
00774     inline KateDocumentConfig *config () { return m_config; };
00775 
00776     void updateConfig ();
00777 
00778   private:
00779     KateDocumentConfig *m_config;
00780 
00785   private:
00790     void readVariables(bool onlyViewAndRenderer = false);
00791 
00796     void readVariableLine( QString t, bool onlyViewAndRenderer = false );
00800     void setViewVariable( QString var, QString val );
00806     static bool checkBoolValue( QString value, bool *result );
00812     static bool checkIntValue( QString value, int *result );
00813     
00814 
00815 
00816 
00817     static bool checkColorValue( QString value, QColor &col );
00818 
00819     static QRegExp kvLine;
00820     static QRegExp kvVar;
00821 
00822     KIO::TransferJob *m_job;
00823     KTempFile *m_tempFile;
00824     
00825   
00826   
00827   
00828   public:
00829     void setIMSelectionValue( uint imStartLine, uint imStart, uint imEnd,
00830                               uint imSelStart, uint imSelEnd, bool m_imComposeEvent );
00831     void getIMSelectionValue( uint *imStartLine, uint *imStart, uint *imEnd,
00832                               uint *imSelStart, uint *imSelEnd );
00833 
00834   private:
00835     uint m_imStartLine;
00836     uint m_imStart;
00837     uint m_imEnd;
00838     uint m_imSelStart;
00839     uint m_imSelEnd;
00840     bool m_imComposeEvent;
00841 
00842   k_dcop:
00843     uint documentNumber () const;
00844 };
00845 
00846 #endif
00847 
00848 
00849