22 #ifndef _KATE_DOCUMENT_H_
23 #define _KATE_DOCUMENT_H_
25 #include <QtCore/QLinkedList>
26 #include <QtCore/QMap>
27 #include <QtCore/QDate>
28 #include <QtGui/QClipboard>
29 #include <QtCore/QStack>
31 #include <kmimetype.h>
33 #include <ktexteditor/document.h>
34 #include <ktexteditor/sessionconfiginterface.h>
35 #include <ktexteditor/searchinterface.h>
36 #include <ktexteditor/markinterface.h>
37 #include <ktexteditor/variableinterface.h>
38 #include <ktexteditor/modificationinterface.h>
39 #include <ktexteditor/configinterface.h>
40 #include <ktexteditor/annotationinterface.h>
41 #include <ktexteditor/highlightinterface.h>
42 #include <ktexteditor/movinginterface.h>
43 #include <ktexteditor/recoveryinterface.h>
44 #include <ktexteditor/messageinterface.h>
51 namespace KTextEditor {
57 namespace KIO {
class TransferJob; }
59 namespace Kate {
class SwapFile; }
75 public KTextEditor::SessionConfigInterface,
76 public KTextEditor::ParameterizedSessionConfigInterface,
77 public KTextEditor::SearchInterface,
78 public KTextEditor::MarkInterface,
79 public KTextEditor::VariableInterface,
80 public KTextEditor::ModificationInterface,
81 public KTextEditor::ConfigInterface,
82 public KTextEditor::AnnotationInterface,
83 public KTextEditor::HighlightInterface,
84 public KTextEditor::MovingInterface,
85 public KTextEditor::RecoveryInterface,
86 public KTextEditor::MessageInterface,
87 private KTextEditor::MovingRangeFeedback
90 Q_INTERFACES(KTextEditor::SessionConfigInterface)
91 Q_INTERFACES(KTextEditor::ParameterizedSessionConfigInterface)
92 Q_INTERFACES(KTextEditor::SearchInterface)
93 Q_INTERFACES(KTextEditor::MarkInterface)
94 Q_INTERFACES(KTextEditor::VariableInterface)
95 Q_INTERFACES(KTextEditor::ModificationInterface)
96 Q_INTERFACES(KTextEditor::AnnotationInterface)
97 Q_INTERFACES(KTextEditor::ConfigInterface)
98 Q_INTERFACES(KTextEditor::HighlightInterface)
99 Q_INTERFACES(KTextEditor::MovingInterface)
100 Q_INTERFACES(KTextEditor::RecoveryInterface)
101 Q_INTERFACES(KTextEditor::MessageInterface)
103 friend class KateDocumentTest;
107 explicit
KateDocument (
bool bSingleViewMode=false,
bool bBrowserView=false,
bool bReadOnly=false,
111 using ReadWritePart::closeUrl;
112 virtual
bool closeUrl();
114 virtual
bool openUrl( const KUrl &url );
116 virtual KTextEditor::Editor *editor ();
118 KTextEditor::Range rangeOnLine(KTextEditor::Range range,
int line) const;
121 void showAndSetOpeningErrorAccess();
133 void readWriteChanged (KTextEditor::Document *document);
138 bool readOnly ()
const {
return m_bReadOnly; }
141 static bool simpleMode ();
145 const bool m_bSingleViewMode;
146 const bool m_bBrowserView;
147 const bool m_bReadOnly;
153 virtual KTextEditor::View *createView(
QWidget *parent );
156 virtual KTextEditor::View*
activeView()
const {
return m_activeView; }
163 KTextEditor::View *m_activeView;
169 virtual bool setText(
const QString &);
171 virtual bool clear ();
173 virtual bool insertText (
const KTextEditor::Cursor &position,
const QString &s,
bool block =
false );
174 virtual bool insertText (
const KTextEditor::Cursor &position,
const QStringList &text,
bool block =
false );
176 virtual bool insertLine (
int line,
const QString &s );
177 virtual bool insertLines (
int line,
const QStringList &s );
179 virtual bool removeText (
const KTextEditor::Range &range,
bool block =
false );
180 virtual bool removeLine (
int line );
182 virtual bool replaceText (
const KTextEditor::Range &range,
const QString &s,
bool block =
false );
186 {
return KTextEditor::Document::replaceText (r, l, b); }
189 virtual QString text (
const KTextEditor::Range &range,
bool blockwise =
false )
const;
190 virtual QStringList textLines (
const KTextEditor::Range& range,
bool block =
false )
const;
192 virtual QString line(
int line)
const;
193 virtual QChar character(
const KTextEditor::Cursor& position)
const;
194 virtual int lines()
const;
195 virtual KTextEditor::Cursor documentEnd()
const;
196 virtual int totalCharacters()
const;
197 virtual int lineLength(
int line)
const;
200 void charactersSemiInteractivelyInserted(
const KTextEditor::Cursor& position,
const QString& text);
221 void pushEditState();
229 void inputMethodStart();
230 void inputMethodEnd();
240 bool editInsertText (
int line,
int col,
const QString &s );
248 bool editRemoveText (
int line,
int col,
int len );
258 bool editMarkLineAutoWrapped (
int line,
bool autowrapped );
270 bool editWrapLine (
int line,
int col,
bool newLine =
true,
bool *newLineAdded = 0 );
278 bool editUnWrapLine (
int line,
bool removeLine =
true,
int length = 0 );
286 bool editInsertLine (
int line,
const QString &s );
292 bool editRemoveLine (
int line );
294 bool editRemoveLines (
int from,
int to );
302 bool wrapText (
int startLine,
int endLine);
309 void editLineWrapped (
int line,
int col,
int len );
314 void editLineUnWrapped (
int line,
int col );
317 bool isEditRunning()
const;
319 void setUndoMergeAllEdits(
bool merge);
322 int editSessionNumber;
325 bool m_undoMergeAllEdits;
335 uint undoCount ()
const;
336 uint redoCount ()
const;
340 return m_undoManager;
354 const KTextEditor::Range & range,
356 const KTextEditor::Search::SearchOptions options);
358 virtual KTextEditor::Search::SearchOptions supportedSearchOptions()
const;
382 virtual QString highlightingMode()
const;
401 virtual bool setMode(
const QString &name);
408 virtual bool setHighlightingMode(
const QString &name);
415 virtual QString highlightingModeSection(
int index )
const;
423 virtual QString modeSection(
int index )
const;
429 void bufferHlChanged();
435 void setDontChangeHlOnSave();
446 virtual void readSessionConfig (
const KConfigGroup&);
447 virtual void writeSessionConfig (KConfigGroup&);
448 virtual void readParameterizedSessionConfig (
const KConfigGroup&,
unsigned long configParameters);
449 virtual void writeParameterizedSessionConfig (KConfigGroup&,
unsigned long configParameters);
452 void configChanged();
458 virtual void setMark(
int line, uint markType );
459 virtual void clearMark(
int line );
461 virtual void addMark(
int line, uint markType );
462 virtual void removeMark(
int line, uint markType );
464 virtual void clearMarks();
466 void requestMarkTooltip(
int line,
QPoint position );
469 bool handleMarkClick(
int line );
472 bool handleMarkContextMenu(
int line,
QPoint position );
474 virtual void setMarkPixmap( MarkInterface::MarkTypes,
const QPixmap& );
476 virtual void setMarkDescription( MarkInterface::MarkTypes,
const QString& );
478 virtual void setEditableMarks( uint markMask );
481 virtual uint mark(
int line );
483 virtual QPixmap markPixmap( MarkInterface::MarkTypes )
const;
484 virtual QString markDescription( MarkInterface::MarkTypes )
const;
485 virtual QColor markColor( MarkInterface::MarkTypes )
const;
486 virtual uint editableMarks()
const;
489 void markToolTipRequested( KTextEditor::Document* document,
KTextEditor::Mark mark,
QPoint position,
bool& handled );
491 void markContextMenuRequested( KTextEditor::Document* document,
KTextEditor::Mark mark,
QPoint pos,
bool& handled );
493 void markClicked( KTextEditor::Document* document,
KTextEditor::Mark mark,
bool& handled );
495 void marksChanged( KTextEditor::Document* );
496 void markChanged( KTextEditor::Document*,
KTextEditor::Mark, KTextEditor::MarkInterface::MarkChangeAction );
502 uint m_editableMarks;
509 Q_SCRIPTABLE
bool print ();
530 KMimeType::Ptr mimeTypeForContent();
541 void variableChanged( KTextEditor::Document*,
const QString &,
const QString & );
556 virtual KTextEditor::MovingCursor *newMovingCursor (
const KTextEditor::Cursor &position, KTextEditor::MovingCursor::InsertBehavior insertBehavior = KTextEditor::MovingCursor::MoveOnInsert);
565 virtual KTextEditor::MovingRange *newMovingRange (
const KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors = KTextEditor::MovingRange::DoNotExpand
566 , KTextEditor::MovingRange::EmptyBehavior emptyBehavior = KTextEditor::MovingRange::AllowEmpty);
572 virtual qint64 revision ()
const;
578 virtual qint64 lastSavedRevision ()
const;
585 virtual void lockRevision (qint64 revision);
591 virtual void unlockRevision (qint64 revision);
600 virtual void transformCursor (KTextEditor::Cursor &cursor, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1);
610 virtual void transformCursor (
int& line,
int& column, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1);
620 virtual void transformRange (KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, KTextEditor::MovingRange::EmptyBehavior emptyBehavior, qint64 fromRevision, qint64 toRevision = -1);
630 void aboutToDeleteMovingInterfaceContent (KTextEditor::Document *document);
637 void aboutToInvalidateMovingInterfaceContent (KTextEditor::Document *document);
644 virtual void setAnnotationModel( KTextEditor::AnnotationModel* model );
645 virtual KTextEditor::AnnotationModel* annotationModel()
const;
648 void annotationModelChanged( KTextEditor::AnnotationModel*, KTextEditor::AnnotationModel* );
651 KTextEditor::AnnotationModel* m_annotationModel;
662 virtual bool openFile ();
669 virtual bool saveFile ();
671 virtual void setReadWrite (
bool rw =
true );
673 virtual void setModified(
bool m );
677 void deactivateDirWatch ();
694 void repaintViews(
bool paintOnlyDirty =
true);
699 void tagLines(
int start,
int end);
702 void internalHlChanged();
705 void addView(KTextEditor::View *);
712 void removeView(KTextEditor::View *);
713 void setActiveView(KTextEditor::View*);
717 int toVirtualColumn(
int line,
int column )
const;
718 int toVirtualColumn(
const KTextEditor::Cursor& )
const;
719 int fromVirtualColumn(
int line,
int column )
const;
720 int fromVirtualColumn(
const KTextEditor::Cursor& )
const;
723 void backspace(
KateView *view,
const KTextEditor::Cursor& );
724 void del(
KateView *view,
const KTextEditor::Cursor& );
725 void transpose(
const KTextEditor::Cursor& );
729 void indent ( KTextEditor::Range range,
int change );
730 void comment (
KateView *view, uint line, uint column,
int change );
731 void align (
KateView *view,
const KTextEditor::Range &range );
732 void insertTab(
KateView *view,
const KTextEditor::Cursor& );
743 void transform (
KateView *view,
const KTextEditor::Cursor &, TextTransform );
747 void joinLines( uint first, uint last );
750 bool removeStringFromBeginning(
int line,
const QString &str);
751 bool removeStringFromEnd(
int line,
const QString &str);
762 bool nextNonSpaceCharPos(
int &line,
int &col);
771 bool previousNonSpaceCharPos(
int &line,
int &col);
777 void addStartLineCommentToSingleLine(
int line,
int attrib=0);
782 bool removeStartLineCommentFromSingleLine(
int line,
int attrib=0);
787 void addStartStopCommentToSingleLine(
int line,
int attrib=0);
791 bool removeStartStopCommentFromSingleLine(
int line,
int attrib=0);
795 bool removeStartStopCommentFromRegion(
const KTextEditor::Cursor &start,
const KTextEditor::Cursor &end,
int attrib=0);
801 void addStartStopCommentToSelection(
KateView *view,
int attrib=0 );
805 void addStartLineCommentToSelection(
KateView *view,
int attrib=0 );
813 bool removeStartStopCommentFromSelection(
KateView *view,
int attrib=0 );
817 bool removeStartLineCommentFromSelection(
KateView *view,
int attrib=0 );
821 QString getWord(
const KTextEditor::Cursor& cursor );
824 void newBracketMark(
const KTextEditor::Cursor& start, KTextEditor::Range& bm,
int maxLines = -1 );
825 bool findMatchingBracket( KTextEditor::Range& range,
int maxLines = -1 );
831 void updateDocName ();
839 virtual void setModifiedOnDisk( ModifiedOnDiskReason reason );
841 virtual void setModifiedOnDiskWarning (
bool on );
848 virtual void slotModifiedOnDisk( KTextEditor::View *v = 0 );
853 virtual bool documentReload ();
855 virtual bool documentSave ();
856 virtual bool documentSaveAs ();
860 virtual bool saveAs(
const KUrl &url );
869 void modifiedOnDisk (KTextEditor::Document *doc,
bool isModified, KTextEditor::ModificationInterface::ModifiedOnDiskReason reason);
872 void ignoreModifiedOnDiskOnce();
879 virtual bool setEncoding (
const QString &e);
880 virtual const QString &encoding()
const;
884 void setWordWrap (
bool on);
885 void setWordWrapAt (uint col);
888 bool wordWrap()
const;
889 uint wordWrapAt()
const;
892 void setPageUpDownMovesCursor(
bool on);
895 bool pageUpDownMovesCursor()
const;
903 void aboutToRemoveText(
const KTextEditor::Range&);
906 void slotModOnHdDirty (
const QString &path);
907 void slotModOnHdCreated (
const QString &path);
908 void slotModOnHdDeleted (
const QString &path);
918 bool createDigest ();
923 QString reasonedMOHString()
const;
928 void removeTrailingSpaces();
937 void updateFileType (
const QString &newType,
bool user =
false);
954 m_indenterSetByUser =
true;
962 m_userSetEncodingForNextReload =
true;
977 bool m_indenterSetByUser;
978 bool m_userSetEncodingForNextReload;
981 ModifiedOnDiskReason m_modOnHdReason;
988 bool m_fileTypeSetByUser;
996 void slotQueryClose_save(
bool *handled,
bool* abortClosing);
999 virtual bool queryClose();
1001 void makeAttribs (
bool needInvalidate =
true);
1003 static bool checkOverwrite( KUrl u,
QWidget *parent );
1012 void updateConfig ();
1025 void readDirConfig ();
1031 void readVariables(
bool onlyViewAndRenderer =
false);
1037 void readVariableLine(
QString t,
bool onlyViewAndRenderer =
false );
1047 static bool checkBoolValue(
QString value,
bool *result );
1053 static bool checkIntValue(
QString value,
int *result );
1064 static QRegExp kvLineWildcard;
1068 bool m_fileChangedDialogsActivated;
1076 virtual void setConfigValue(
const QString &key,
const QVariant &value);
1082 virtual bool isDataRecoveryAvailable()
const;
1083 virtual void recoverData();
1084 virtual void discardDataRecovery();
1090 virtual KTextEditor::Attribute::Ptr defaultStyle(
const KTextEditor::HighlightInterface::DefaultStyle ds)
const;
1092 virtual QStringList embeddedHighlightingModes()
const;
1093 virtual QString highlightingModeAt(
const KTextEditor::Cursor& position);
1095 virtual KTextEditor::Attribute::Ptr attributeAt(
const KTextEditor::Cursor & position);
1101 virtual bool postMessage(KTextEditor::Message* message);
1104 void messageDestroyed(KTextEditor::Message* message);
1111 QString defaultDictionary()
const;
1113 bool isOnTheFlySpellCheckingEnabled()
const;
1115 QString dictionaryForMisspelledRange(
const KTextEditor::Range& range)
const;
1116 void clearMisspellingForWord(
const QString& word);
1119 void clearDictionaryRanges();
1120 void setDictionary(
const QString& dict,
const KTextEditor::Range &range);
1121 void revertToDefaultDictionary(
const KTextEditor::Range &range);
1122 void setDefaultDictionary(
const QString& dict);
1123 void onTheFlySpellCheckingEnabled(
bool enable);
1124 void refreshOnTheFlyCheck(
const KTextEditor::Range &range = KTextEditor::Range::invalid());
1127 void dictionaryRangesPresent(
bool yesNo);
1131 bool containsCharacterEncoding(
const KTextEditor::Range& range);
1135 int computePositionWrtOffsets(
const OffsetList& offsetList,
int pos);
1141 QString decodeCharacters(
const KTextEditor::Range& range,
1144 void replaceCharactersByEncoding(
const KTextEditor::Range& range);
1154 void rangeInvalid(KTextEditor::MovingRange *movingRange);
1155 void rangeEmpty(KTextEditor::MovingRange *movingRange);
1157 void deleteDictionaryRange(KTextEditor::MovingRange *movingRange);
1166 int defStyleNum(
int line,
int column);
1167 bool isComment(
int line,
int column);
1170 int findModifiedLine(
int startLine,
bool down);
1177 void slotStarted(KIO::Job *job);
1178 void slotCompleted();
1179 void slotCanceled();
1184 void slotTriggerLoadingMessage ();
1189 void slotAbortLoading ();
1195 enum DocumentStates {
1214 DocumentPreSavingAs,
1225 DocumentStates m_documentState;
1230 bool m_readWriteStateBeforeLoading;
virtual const QString & documentName() const
KateBuffer & buffer()
Get access to buffer of this document.
KateDocumentConfig * config()
Configuration.
void editBegin()
Alias for editStart()
virtual KTextEditor::View * activeView() const
void rememberUserDidSetIndentationMode()
set indentation mode by user this will remember that a user did set it and will avoid reset on save ...
virtual bool startEditing()
#define KATEPART_TESTS_EXPORT
KateUndoManager implements a document's history.
KateUndoManager * undoManager()
void userSetEncodingForNextReload()
User did set encoding for next reload => enforce it!
int lastLine() const
gets the last line number (lines() - 1)
bool singleViewMode() const
virtual bool replaceText(const KTextEditor::Range &r, const QStringList &l, bool b)
Provides Auto-Indent functionality for katepart.
Class for tracking editing actions.
QString m_defaultDictionary
QList< QPair< KTextEditor::MovingRange *, QString > > m_dictionaryRanges
QList< QPair< int, int > > OffsetList
EncodedCharaterInsertionPolicy
virtual bool endEditing()
KateUndoManager *const m_undoManager
KateOnTheFlyChecker * m_onTheFlyChecker
KateDocumentConfig * config() const
The KateBuffer class maintains a collections of lines.