KTextEditor

katedocument.h
1 /*
2  SPDX-FileCopyrightText: 2001-2004 Christoph Cullmann <[email protected]>
3  SPDX-FileCopyrightText: 2001 Joseph Wenninger <[email protected]>
4  SPDX-FileCopyrightText: 1999 Jochen Wilhelmy <[email protected]>
5  SPDX-FileCopyrightText: 2006 Hamish Rodda <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #ifndef _KATE_DOCUMENT_H_
11 #define _KATE_DOCUMENT_H_
12 
13 #include <QPointer>
14 #include <QStack>
15 #include <QTimer>
16 
17 #include <KJob>
18 
19 #include <ktexteditor/annotationinterface.h>
20 #include <ktexteditor/configinterface.h>
21 #include <ktexteditor/document.h>
22 #include <ktexteditor/inlinenoteinterface.h>
23 #include <ktexteditor/mainwindow.h>
24 #include <ktexteditor/markinterface.h>
25 #include <ktexteditor/message.h>
26 #include <ktexteditor/modificationinterface.h>
27 #include <ktexteditor/movinginterface.h>
28 
29 #include "katetextline.h"
30 #include <ktexteditor_export.h>
31 
33 namespace KTextEditor
34 {
35 class Plugin;
36 class Attribute;
37 class TemplateScript;
38 }
39 
40 namespace KIO
41 {
42 class TransferJob;
43 }
44 
45 namespace Kate
46 {
47 class SwapFile;
48 }
49 
50 class KateBuffer;
51 namespace KTextEditor
52 {
53 class ViewPrivate;
54 }
55 class KateDocumentConfig;
56 class KateHighlighting;
57 class KateUndoManager;
58 class KateOnTheFlyChecker;
59 class KateDocumentTest;
60 
61 class KateAutoIndent;
62 class KateModOnHdPrompt;
63 class KToggleAction;
64 
71 class KTEXTEDITOR_EXPORT KTextEditor::DocumentPrivate : public KTextEditor::Document,
78 {
79  Q_OBJECT
80  Q_INTERFACES(KTextEditor::MarkInterface)
81  Q_INTERFACES(KTextEditor::MarkInterfaceV2)
84  Q_INTERFACES(KTextEditor::ConfigInterface)
85  Q_INTERFACES(KTextEditor::MovingInterface)
86 
87  friend class KTextEditor::Document;
88  friend class ::KateDocumentTest;
89  friend class ::KateBuffer;
90 
91 public:
92  explicit DocumentPrivate(bool bSingleViewMode = false, bool bReadOnly = false, QWidget *parentWidget = nullptr, QObject * = nullptr);
93  ~DocumentPrivate() override;
94 
95  using ReadWritePart::closeUrl;
96  bool closeUrl() override;
97 
98  bool openUrl(const QUrl &url) override;
99 
100  KTextEditor::Range rangeOnLine(KTextEditor::Range range, int line) const;
101 
102 private:
103  void showAndSetOpeningErrorAccess();
104  /*
105  * Overload this to have on-demand view creation
106  */
107 public:
111  QWidget *widget() override;
112 
113 public:
114  bool readOnly() const
115  {
116  return m_bReadOnly;
117  }
118  bool singleViewMode() const
119  {
120  return m_bSingleViewMode;
121  }
122 
123 private:
124  // only to make part work, don't change it !
125  const bool m_bSingleViewMode;
126  const bool m_bReadOnly;
127 
128  //
129  // KTextEditor::Document stuff
130  //
131 public:
132  KTextEditor::View *createView(QWidget *parent, KTextEditor::MainWindow *mainWindow = nullptr) override;
133 
134  QList<KTextEditor::View *> views() const override
135  {
136  return m_viewsCache;
137  }
138 
139  virtual KTextEditor::View *activeView() const
140  {
141  return m_activeView;
142  }
143 
144 private:
146  KTextEditor::View *m_activeView = nullptr;
147 
148  //
149  // KTextEditor::EditInterface stuff
150  //
151 public Q_SLOTS:
152  bool setText(const QString &) override;
153  bool setText(const QStringList &text) override;
154  bool clear() override;
155 
156  bool insertText(const KTextEditor::Cursor &position, const QString &s, bool block = false) override;
157  bool insertText(const KTextEditor::Cursor &position, const QStringList &text, bool block = false) override;
158 
159  bool insertLine(int line, const QString &s) override;
160  bool insertLines(int line, const QStringList &s) override;
161 
162  bool removeText(const KTextEditor::Range &range, bool block = false) override;
163  bool removeLine(int line) override;
164 
165  bool replaceText(const KTextEditor::Range &range, const QString &s, bool block = false) override;
166 
167  // unhide method...
168  bool replaceText(const KTextEditor::Range &r, const QStringList &l, bool b) override
169  {
170  return KTextEditor::Document::replaceText(r, l, b);
171  }
172 
173 public:
174  bool isEditingTransactionRunning() const override;
175  QString text(const KTextEditor::Range &range, bool blockwise = false) const override;
176  QStringList textLines(const KTextEditor::Range &range, bool block = false) const override;
177  QString text() const override;
178  QString line(int line) const override;
179  QChar characterAt(const KTextEditor::Cursor &position) const override;
180  QString wordAt(const KTextEditor::Cursor &cursor) const override;
181  KTextEditor::Range wordRangeAt(const KTextEditor::Cursor &cursor) const override;
182  bool isValidTextPosition(const KTextEditor::Cursor &cursor) const override;
183  int lines() const override;
184  bool isLineModified(int line) const override;
185  bool isLineSaved(int line) const override;
186  bool isLineTouched(int line) const override;
187  KTextEditor::Cursor documentEnd() const override;
188  int totalCharacters() const override;
189  int lineLength(int line) const override;
190 
191 Q_SIGNALS:
192  void charactersSemiInteractivelyInserted(const KTextEditor::Cursor &position, const QString &text);
193 
202  void textInserted(KTextEditor::Document *document, const KTextEditor::Range &range);
203 
212  void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range, const QString &oldText);
213 
214 public:
215  // BEGIN editStart/editEnd (start, end, undo, cursor update, view update)
220  bool editStart();
221 
225  void editBegin()
226  {
227  editStart();
228  }
229 
234  bool editEnd();
235 
236  void pushEditState();
237  void popEditState();
238 
239  virtual bool startEditing()
240  {
241  return editStart();
242  }
243  virtual bool finishEditing()
244  {
245  return editEnd();
246  }
247 
248  // END editStart/editEnd
249 
250  void inputMethodStart();
251  void inputMethodEnd();
252 
253  // BEGIN LINE BASED INSERT/REMOVE STUFF (editStart() and editEnd() included)
261  bool editInsertText(int line, int col, const QString &s);
262 
270  bool editRemoveText(int line, int col, int len);
271 
280  bool editMarkLineAutoWrapped(int line, bool autowrapped);
281 
292  bool editWrapLine(int line, int col, bool newLine = true, bool *newLineAdded = nullptr);
293 
301  bool editUnWrapLine(int line, bool removeLine = true, int length = 0);
302 
309  bool editInsertLine(int line, const QString &s);
310 
316  bool editRemoveLine(int line);
317 
318  bool editRemoveLines(int from, int to);
319 
326  bool wrapText(int startLine, int endLine);
327 
339  bool wrapParagraph(int first, int last);
340  // END LINE BASED INSERT/REMOVE STUFF
341 
342 Q_SIGNALS:
346  void editLineWrapped(int line, int col, int len);
347 
351  void editLineUnWrapped(int line, int col);
352 
353 public:
354  bool isEditRunning() const;
355 
356  void setUndoMergeAllEdits(bool merge);
357 
358  enum EditingPositionKind { Previous, Next };
359 
364  KTextEditor::Cursor lastEditingPosition(EditingPositionKind nextOrPrevious, KTextEditor::Cursor);
365 
366 private:
367  int editSessionNumber = 0;
368  QStack<int> editStateStack;
369  bool editIsRunning = false;
370  bool m_undoMergeAllEdits = false;
371  KTextEditor::Cursor m_editLastChangeStartCursor = KTextEditor::Cursor::invalid();
373  int m_editingStackPosition = -1;
374 
375  //
376  // KTextEditor::UndoInterface stuff
377  //
378 public Q_SLOTS:
379  void undo();
380  void redo();
381 
385  void clearEditingPosStack();
386 
392  void saveEditingPositions(const KTextEditor::Cursor &cursor);
393 
394 public:
395  uint undoCount() const;
396  uint redoCount() const;
397 
398  KateUndoManager *undoManager()
399  {
400  return m_undoManager;
401  }
402 
403 protected:
404  KateUndoManager *const m_undoManager;
405 
406 Q_SIGNALS:
407  void undoChanged();
408 
409 public:
410  QVector<KTextEditor::Range> searchText(const KTextEditor::Range &range, const QString &pattern, const KTextEditor::SearchOptions options) const;
411 
412 private:
416  QWidget *dialogParent();
417 
418  /*
419  * Access to the mode/highlighting subsystem
420  */
421 public:
425  KTextEditor::DefaultStyle defaultStyleAt(const KTextEditor::Cursor &position) const override;
426 
431  QString mode() const override;
432 
437  QString highlightingMode() const override;
438 
443  QStringList modes() const override;
444 
449  QStringList highlightingModes() const override;
450 
456  bool setMode(const QString &name) override;
457 
463  bool setHighlightingMode(const QString &name) override;
470  QString highlightingModeSection(int index) const override;
471 
478  QString modeSection(int index) const override;
479 
480  /*
481  * Helpers....
482  */
483 public:
484  void bufferHlChanged();
485 
490  void setDontChangeHlOnSave();
491 
495  void bomSetByUser();
496 
497 public:
511  void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override;
512 
521  void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override;
522 
523 Q_SIGNALS:
524  void configChanged();
525 
526  //
527  // KTextEditor::MarkInterface
528  //
529 public Q_SLOTS:
530  void setMark(int line, uint markType) override;
531  void clearMark(int line) override;
532 
533  void addMark(int line, uint markType) override;
534  void removeMark(int line, uint markType) override;
535 
536  void clearMarks() override;
537 
538  void requestMarkTooltip(int line, QPoint position);
539 
541  bool handleMarkClick(int line);
542 
544  bool handleMarkContextMenu(int line, QPoint position);
545 
546  void setMarkPixmap(MarkInterface::MarkTypes, const QPixmap &) override;
547 
548  void setMarkDescription(MarkInterface::MarkTypes, const QString &) override;
549 
550  void setEditableMarks(uint markMask) override;
551 
552 public:
553  uint mark(int line) override;
554  const QHash<int, KTextEditor::Mark *> &marks() override;
557  virtual QColor markColor(MarkInterface::MarkTypes) const;
558  uint editableMarks() const override;
559 
560 Q_SIGNALS:
561  void markToolTipRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint position, bool &handled);
562 
563  void markContextMenuRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint pos, bool &handled);
564 
565  void markClicked(KTextEditor::Document *document, KTextEditor::Mark mark, bool &handled);
566 
567  void marksChanged(KTextEditor::Document *) override;
568  void markChanged(KTextEditor::Document *, KTextEditor::Mark, KTextEditor::MarkInterface::MarkChangeAction) override;
569 
570 private:
572  QHash<int, QVariant> m_markIcons; // QPixmap or QIcon, KF6: remove QPixmap support
573  QHash<int, QString> m_markDescriptions;
574  uint m_editableMarks = markType01;
575 
576  //
577  // KTextEditor::MarkInterfaceV2
578  //
579 public Q_SLOTS:
580  void setMarkIcon(MarkInterface::MarkTypes markType, const QIcon &icon) override;
581 
582 public:
583  QIcon markIcon(MarkInterface::MarkTypes markType) const override;
584 
585  // KTextEditor::PrintInterface
586  //
587 public Q_SLOTS:
588  bool print() override;
589  void printPreview() override;
590 
591  //
592  // KTextEditor::DocumentInfoInterface ( ### unfinished )
593  //
594 public:
600  QString mimeType() override;
601 
602  //
603  // once was KTextEditor::VariableInterface
604  //
605 public:
615  virtual QString variable(const QString &name) const;
616 
627  virtual void setVariable(const QString &name, const QString &value);
628 
629 private:
630  QMap<QString, QString> m_storedVariables;
631 
632  //
633  // MovingInterface API
634  //
635 public:
643 
654 
659  qint64 revision() const override;
660 
665  qint64 lastSavedRevision() const override;
666 
672  void lockRevision(qint64 revision) override;
673 
678  void unlockRevision(qint64 revision) override;
679 
687  void transformCursor(KTextEditor::Cursor &cursor, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1) override;
688 
697  void transformCursor(int &line, int &column, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1) override;
698 
707  void transformRange(KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, KTextEditor::MovingRange::EmptyBehavior emptyBehavior, qint64 fromRevision, qint64 toRevision = -1) override;
708 
709  //
710  // MovingInterface Signals
711  //
712 Q_SIGNALS:
718 
725 
726  //
727  // Annotation Interface
728  //
729 public:
730  void setAnnotationModel(KTextEditor::AnnotationModel *model) override;
732 
733 Q_SIGNALS:
734  void annotationModelChanged(KTextEditor::AnnotationModel *, KTextEditor::AnnotationModel *);
735 
736 private:
737  KTextEditor::AnnotationModel *m_annotationModel = nullptr;
738 
739  //
740  // KParts::ReadWrite stuff
741  //
742 public:
748  bool openFile() override;
749 
755  bool saveFile() override;
756 
757  void setReadWrite(bool rw = true) override;
758 
759  void setModified(bool m) override;
760 
761  bool isAutoReload();
762  KToggleAction *autoReloadToggleAction()
763  {
764  return m_autoReloadMode;
765  };
766  void delayAutoReload();
767 
768 private Q_SLOTS:
769  void autoReloadToggled(bool b);
770 
771 private:
772  void activateDirWatch(const QString &useFileName = QString());
773  void deactivateDirWatch();
774 
775  QString m_dirWatchFile;
776 
781  bool createBackupFile();
782 
783 public:
791  void typeChars(KTextEditor::ViewPrivate *view, QString chars);
792 
796  inline int lastLine() const
797  {
798  return lines() - 1;
799  }
800 
801  // Repaint all of all of the views
802  void repaintViews(bool paintOnlyDirty = true);
803 
804  KateHighlighting *highlight() const;
805 
806 public Q_SLOTS:
807  void tagLines(int start, int end);
808 
809 private Q_SLOTS:
810  void internalHlChanged();
811 
812 public:
813  void addView(KTextEditor::View *);
821  void setActiveView(KTextEditor::View *);
822 
823  bool ownedView(KTextEditor::ViewPrivate *);
824 
825  int toVirtualColumn(int line, int column) const;
826  int toVirtualColumn(const KTextEditor::Cursor &) const;
827  int fromVirtualColumn(int line, int column) const;
828  int fromVirtualColumn(const KTextEditor::Cursor &) const;
829 
830  enum NewLineIndent { Indent, NoIndent };
831 
832  void newLine(KTextEditor::ViewPrivate *view, NewLineIndent indent = NewLineIndent::Indent); // Changes input
833  void backspace(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &);
834  void del(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &);
835  void transpose(const KTextEditor::Cursor &);
836  void paste(KTextEditor::ViewPrivate *view, const QString &text);
837 
838 public:
839  void indent(KTextEditor::Range range, int change);
840  void comment(KTextEditor::ViewPrivate *view, uint line, uint column, int change);
841  void align(KTextEditor::ViewPrivate *view, const KTextEditor::Range &range);
842  void insertTab(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &);
843 
844  enum TextTransform { Uppercase, Lowercase, Capitalize };
845 
853  void transform(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &, TextTransform);
857  void joinLines(uint first, uint last);
858 
859 private:
860  bool removeStringFromBeginning(int line, const QString &str);
861  bool removeStringFromEnd(int line, const QString &str);
862 
868  QString eventuallyReplaceTabs(const KTextEditor::Cursor &cursorPos, const QString &str) const;
869 
879  bool nextNonSpaceCharPos(int &line, int &col);
880 
888  bool previousNonSpaceCharPos(int &line, int &col);
889 
894  void addStartLineCommentToSingleLine(int line, int attrib = 0);
899  bool removeStartLineCommentFromSingleLine(int line, int attrib = 0);
900 
904  void addStartStopCommentToSingleLine(int line, int attrib = 0);
908  bool removeStartStopCommentFromSingleLine(int line, int attrib = 0);
912  bool removeStartStopCommentFromRegion(const KTextEditor::Cursor &start, const KTextEditor::Cursor &end, int attrib = 0);
913 
918  void addStartStopCommentToSelection(KTextEditor::ViewPrivate *view, int attrib = 0);
922  void addStartLineCommentToSelection(KTextEditor::ViewPrivate *view, int attrib = 0);
923 
930  bool removeStartStopCommentFromSelection(KTextEditor::ViewPrivate *view, int attrib = 0);
934  bool removeStartLineCommentFromSelection(KTextEditor::ViewPrivate *view, int attrib = 0);
935 
936 public:
937  KTextEditor::Range findMatchingBracket(const KTextEditor::Cursor &start, int maxLines);
938 
939 public:
940  QString documentName() const override
941  {
942  return m_docName;
943  }
944 
945 private:
946  void updateDocName();
947 
948 public:
953  {
954  return m_modOnHd;
955  }
956 
957  void setModifiedOnDisk(ModifiedOnDiskReason reason) override;
958 
959  void setModifiedOnDiskWarning(bool on) override;
960 
961 public Q_SLOTS:
966  virtual void slotModifiedOnDisk(KTextEditor::View *v = nullptr);
967 
971  bool documentReload() override;
972 
973  bool documentSave() override;
974  bool documentSaveAs() override;
975  bool documentSaveAsWithEncoding(const QString &encoding);
976  bool documentSaveCopyAs();
977 
978  bool save() override;
979 
980 public:
981  bool saveAs(const QUrl &url) override;
982 
983 Q_SIGNALS:
991 
992 private:
993  // helper to handle the embedded notification for externally modified files
994  QPointer<KateModOnHdPrompt> m_modOnHdHandler;
995 
996 private Q_SLOTS:
997  void onModOnHdSaveAs();
998  void onModOnHdClose();
999  void onModOnHdReload();
1000  void onModOnHdAutoReload();
1001  void onModOnHdIgnore();
1002 
1003 public:
1004  bool setEncoding(const QString &e) override;
1005  QString encoding() const override;
1006 
1007 public Q_SLOTS:
1008  void setWordWrap(bool on);
1009  void setWordWrapAt(uint col);
1010 
1011 public:
1012  bool wordWrap() const;
1013  uint wordWrapAt() const;
1014 
1015 public Q_SLOTS:
1016  void setPageUpDownMovesCursor(bool on);
1017 
1018 public:
1019  bool pageUpDownMovesCursor() const;
1020 
1021  // code folding
1022 public:
1028 
1031 
1032 Q_SIGNALS:
1033  void aboutToRemoveText(const KTextEditor::Range &);
1034 
1035 private Q_SLOTS:
1036  void slotModOnHdDirty(const QString &path);
1037  void slotModOnHdCreated(const QString &path);
1038  void slotModOnHdDeleted(const QString &path);
1039  void slotDelayedHandleModOnHd();
1040 
1041 private:
1048  bool createDigest();
1049 
1053  QString reasonedMOHString() const;
1054 
1058  void removeTrailingSpaces();
1059 
1060 public:
1065  QByteArray checksum() const override;
1066 
1070  bool updateFileType(const QString &newType, bool user = false);
1071 
1072  QString fileType() const
1073  {
1074  return m_fileType;
1075  }
1076 
1083  {
1084  return *m_buffer;
1085  }
1086 
1092  {
1093  m_indenterSetByUser = true;
1094  }
1095 
1100  {
1101  m_userSetEncodingForNextReload = true;
1102  }
1103 
1104  //
1105  // REALLY internal data ;)
1106  //
1107 private:
1108  // text buffer
1109  KateBuffer *const m_buffer;
1110 
1111  // indenter
1112  KateAutoIndent *const m_indenter;
1113 
1114  bool m_hlSetByUser = false;
1115  bool m_bomSetByUser = false;
1116  bool m_indenterSetByUser = false;
1117  bool m_userSetEncodingForNextReload = false;
1118 
1119  bool m_modOnHd = false;
1120  KToggleAction *m_autoReloadMode;
1121  QTimer m_autoReloadThrottle;
1122  ModifiedOnDiskReason m_modOnHdReason = OnDiskUnmodified;
1123  ModifiedOnDiskReason m_prevModOnHdReason = OnDiskUnmodified;
1124 
1125  QString m_docName;
1126  int m_docNameNumber = 0;
1127 
1128  // file type !!!
1129  QString m_fileType;
1130  bool m_fileTypeSetByUser = false;
1131 
1135  bool m_reloading = false;
1136 
1137 public Q_SLOTS:
1138  void slotQueryClose_save(bool *handled, bool *abortClosing);
1139 
1140 public:
1141  bool queryClose() override;
1142 
1146 public:
1147  KateDocumentConfig *config()
1148  {
1149  return m_config;
1150  }
1151  KateDocumentConfig *config() const
1152  {
1153  return m_config;
1154  }
1155 
1156  void updateConfig();
1157 
1158 private:
1159  void makeAttribs(bool needInvalidate = true);
1160 
1161  KateDocumentConfig *const m_config;
1162 
1167 private:
1171  void readDirConfig();
1172 
1177  void readVariables(bool onlyViewAndRenderer = false);
1178 
1183  void readVariableLine(const QString &t, bool onlyViewAndRenderer = false);
1187  void setViewVariable(const QString &var, const QString &val);
1193  static bool checkBoolValue(QString value, bool *result);
1199  static bool checkIntValue(const QString &value, int *result);
1204  static bool checkColorValue(const QString &value, QColor &col);
1205 
1206  bool m_fileChangedDialogsActivated = false;
1207 
1208  //
1209  // KTextEditor::ConfigInterface
1210  //
1211 public:
1212  QStringList configKeys() const override;
1213  QVariant configValue(const QString &key) override;
1214  void setConfigValue(const QString &key, const QVariant &value) override;
1215 
1216  //
1217  // KTextEditor::RecoveryInterface
1218  //
1219 public:
1220  bool isDataRecoveryAvailable() const override;
1221  void recoverData() override;
1222  void discardDataRecovery() override;
1223 
1224  //
1225  // Highlighting information
1226  //
1227 public:
1228  QStringList embeddedHighlightingModes() const override;
1229  QString highlightingModeAt(const KTextEditor::Cursor &position) override;
1230 
1231  //
1232  // BEGIN: KTextEditor::MessageInterface
1233  //
1234 public:
1235  bool postMessage(KTextEditor::Message *message) override;
1236 
1237 public Q_SLOTS:
1238  void messageDestroyed(KTextEditor::Message *message);
1239 
1240 private:
1242  // END KTextEditor::MessageInterface
1243 
1244 public:
1245  QString defaultDictionary() const;
1246  QList<QPair<KTextEditor::MovingRange *, QString>> dictionaryRanges() const;
1247  bool isOnTheFlySpellCheckingEnabled() const;
1248 
1249  QString dictionaryForMisspelledRange(const KTextEditor::Range &range) const;
1250  void clearMisspellingForWord(const QString &word);
1251 
1252 public Q_SLOTS:
1253  void clearDictionaryRanges();
1254  void setDictionary(const QString &dict, const KTextEditor::Range &range, bool blockmode);
1255  void setDictionary(const QString &dict, const KTextEditor::Range &range);
1256  void setDefaultDictionary(const QString &dict);
1257  void onTheFlySpellCheckingEnabled(bool enable);
1258  void refreshOnTheFlyCheck(const KTextEditor::Range &range = KTextEditor::Range::invalid());
1259 
1260 Q_SIGNALS:
1261  void dictionaryRangesPresent(bool yesNo);
1262  void defaultDictionaryChanged(KTextEditor::DocumentPrivate *document);
1263 
1264 public:
1265  bool containsCharacterEncoding(const KTextEditor::Range &range);
1266 
1268 
1269  int computePositionWrtOffsets(const OffsetList &offsetList, int pos);
1270 
1275  QString decodeCharacters(const KTextEditor::Range &range, KTextEditor::DocumentPrivate::OffsetList &decToEncOffsetList, KTextEditor::DocumentPrivate::OffsetList &encToDecOffsetList);
1276  void replaceCharactersByEncoding(const KTextEditor::Range &range);
1277 
1278 protected:
1279  KateOnTheFlyChecker *m_onTheFlyChecker = nullptr;
1280  QString m_defaultDictionary;
1282 
1283  // from KTextEditor::MovingRangeFeedback
1284  void rangeInvalid(KTextEditor::MovingRange *movingRange) override;
1285  void rangeEmpty(KTextEditor::MovingRange *movingRange) override;
1286 
1287  void deleteDictionaryRange(KTextEditor::MovingRange *movingRange);
1288 
1289 private:
1290  Kate::SwapFile *m_swapfile;
1291 
1292 public:
1293  Kate::SwapFile *swapFile();
1294 
1295  // helpers for scripting and codefolding
1296  int defStyleNum(int line, int column);
1297  bool isComment(int line, int column);
1298 
1299 public:
1305  int findTouchedLine(int startLine, bool down);
1306 
1307 private Q_SLOTS:
1312  void slotStarted(KIO::Job *job);
1313  void slotCompleted();
1314  void slotCanceled();
1315 
1319  void slotTriggerLoadingMessage();
1320 
1324  void slotAbortLoading();
1325 
1326  void slotUrlChanged(const QUrl &url);
1327 
1328 private:
1332  enum DocumentStates {
1336  DocumentIdle,
1337 
1341  DocumentLoading,
1342 
1346  DocumentSaving,
1347 
1351  DocumentPreSavingAs,
1352 
1356  DocumentSavingAs
1357  };
1358 
1362  DocumentStates m_documentState = DocumentIdle;
1363 
1367  bool m_readWriteStateBeforeLoading = false;
1368 
1372  bool m_isUntitled = true;
1376  QPointer<KJob> m_loadingJob;
1377 
1381  QPointer<KTextEditor::Message> m_loadingMessage;
1382 
1386  bool m_openingError = false;
1387 
1391  QString m_openingErrorMessage;
1392 
1393 public:
1397  int lineLengthLimit() const;
1398 
1399 public Q_SLOTS:
1400  void openWithLineLengthLimitOverride();
1401 
1402 private:
1406  QTimer m_modOnHdTimer;
1407 
1408 private:
1412  QPointer<KateTemplateHandler> m_activeTemplateHandler;
1413 
1414 private:
1418  QSharedPointer<KTextEditor::MovingRange> m_currentAutobraceRange;
1422  QChar m_currentAutobraceClosingChar;
1423 
1424 private Q_SLOTS:
1425  void checkCursorForAutobrace(KTextEditor::View *view, const KTextEditor::Cursor &newPos);
1426 
1427 public:
1428  void setActiveTemplateHandler(KateTemplateHandler *handler);
1429 
1430 Q_SIGNALS:
1431  void loaded(KTextEditor::DocumentPrivate *document);
1432 
1433 private Q_SLOTS:
1437  void closeDocumentInApplication();
1438 
1439 private:
1440  // To calculate a QHash.keys() is quite expensive,
1441  // better keep a copy of that list updated when a view is added or removed.
1442  QList<KTextEditor::View *> m_viewsCache;
1443 };
1444 
1445 #endif
DefaultStyle
The following lists all valid default styles that are used for the syntax highlighting files in the i...
Definition: attribute.h:26
void rangeInvalid(KTextEditor::MovingRange *movingRange) override
The range is now invalid (ie.
Kate::TextLine kateTextLine(int i)
Same as plainKateTextLine(), except that it is made sure the line is highlighted. ...
virtual bool insertText(const Cursor &position, const QString &text, bool block=false)=0
Insert text at position.
bool editWrapLine(int line, int col, bool newLine=true, bool *newLineAdded=nullptr)
Wrap line.
Kate::TextLine plainKateTextLine(int i)
Return line lineno.
bool handleMarkContextMenu(int line, QPoint position)
Returns true if the context-menu event should not further be processed.
QString highlightingModeSection(int index) const override
Returns the name of the section for a highlight given its index in the highlight list (as returned by...
virtual void discardDataRecovery()=0
If recover data is available, calling discardDataRecovery() will discard the recover data and the rec...
bool isModifiedOnDisc()
Definition: katedocument.h:952
KTextEditor::MovingRange * newMovingRange(const KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors=KTextEditor::MovingRange::DoNotExpand, KTextEditor::MovingRange::EmptyBehavior emptyBehavior=KTextEditor::MovingRange::AllowEmpty) override
Create a new moving range for this document.
void editBegin()
Alias for editStart()
Definition: katedocument.h:225
virtual int lines() const =0
Get the count of lines of the document.
void aboutToDeleteMovingInterfaceContent(KTextEditor::Document *document)
This signal is emitted before the cursors/ranges/revisions of a document are destroyed as the documen...
void unlockRevision(qint64 revision) override
Release a revision.
virtual void setVariable(const QString &name, const QString &value)
Set the variable name to value.
bool documentReload() override
Reloads the current document from disk if possible.
void modifiedOnDisk(KTextEditor::Document *doc, bool isModified, KTextEditor::ModificationInterface::ModifiedOnDiskReason reason) override
Indicate this file is modified on disk.
bool setMode(const QString &name) override
Set the current mode of the document by giving its name.
virtual void printPreview()=0
Shows the print preview dialog/.
virtual bool openUrl(const QUrl &url)
bool handleMarkClick(int line)
Returns true if the click on the mark should not be further processed.
EmptyBehavior
Behavior of range if it becomes empty.
Definition: movingrange.h:165
virtual QString text() const =0
Get the document content.
QVector< KTextEditor::Range > searchText(const KTextEditor::Range &range, const QString &pattern, const SearchOptions options=Default) const
Searches the given input range for a text pattern.
virtual View * createView(QWidget *parent, KTextEditor::MainWindow *mainWindow=nullptr)=0
Create a new view attached to parent.
void removeView(KTextEditor::View *)
removes the view from the list of views.
void joinLines(uint first, uint last)
Unwrap a range of lines.
virtual bool save()
virtual bool isLineSaved(int line) const =0
Check whether line currently contains only saved text.
QString mode() const override
Return the name of the currently used mode.
virtual QList< View * > views() const =0
Returns the views pre-casted to KTextEditor::Views.
A Cursor which is bound to a specific Document, and maintains its position.
Definition: movingcursor.h:54
virtual bool postMessage(Message *message)=0
Post message to the Document and its Views.
Inserts a template and offers advanced snippet features, like navigation and mirroring.
virtual bool saveAs(const QUrl &url)
bool editRemoveLine(int line)
Remove a line.
Mark extension interface for the Document.
virtual bool isDataRecoveryAvailable() const =0
Returns whether a recovery is available for the current document.
void textInserted(KTextEditor::Document *document, const KTextEditor::Range &range)
The document emits this signal whenever text was inserted.
virtual bool clear()=0
Remove the whole content of the document.
virtual QStringList textLines(const Range &range, bool block=false) const =0
Get the document content within the given range.
void lockRevision(qint64 revision) override
Lock a revision, this will keep it around until released again.
A class which provides notifications of state changes to a MovingRange.
A range that is bound to a specific Document, and maintains its position.
Definition: movingrange.h:143
KateUndoManager implements a document&#39;s history.
Don&#39;t expand to encapsulate new characters in either direction. This is the default.
Definition: movingrange.h:153
KTextEditor::DefaultStyle defaultStyleAt(const KTextEditor::Cursor &position) const override
Get the default style of the character located at position.
bool setHighlightingMode(const QString &name) override
Set the current mode of the document by giving its name.
void setAnnotationModel(KTextEditor::AnnotationModel *model) override
Sets a new AnnotationModel for this document to provide annotation information for each line...
Q_SIGNALSQ_SIGNALS
QWidget * widget() override
virtual int lineLength(int line) const =0
Get the length of a given line in characters.
virtual bool queryClose()
virtual bool setText(const QString &text)=0
Set the given text as new document content.
The Cursor represents a position in a Document.
Definition: cursor.h:71
void typeChars(KTextEditor::ViewPrivate *view, QString chars)
Type chars in a view.
virtual bool insertLine(int line, const QString &text)=0
Insert line(s) at the given line number.
QStringList highlightingModes() const override
Return a list of the names of all possible modes.
bool updateFileType(const QString &newType, bool user=false)
virtual bool insertLines(int line, const QStringList &text)=0
Insert line(s) at the given line number.
QString markDescription(MarkInterface::MarkTypes) const override
Get the mark&#39;s description to text.
static constexpr Cursor invalid() Q_DECL_NOEXCEPT
Returns an invalid cursor.
Definition: cursor.h:109
bool editStart()
Enclose editor actions with editStart() and editEnd() to group them.
bool wrapParagraph(int first, int last)
Wrap lines touched by the selection with respect of existing paragraphs.
virtual QString encoding() const =0
Get the current chosen encoding.
KateBuffer & buffer()
Get access to buffer of this document.
void rememberUserDidSetIndentationMode()
set indentation mode by user this will remember that a user did set it and will avoid reset on save ...
const QHash< int, KTextEditor::Mark * > & marks() override
Get a hash holding all marks in the document.
External modification extension interface for the Document.
void rangeEmpty(KTextEditor::MovingRange *movingRange) override
The range is now empty (ie.
bool wrapText(int startLine, int endLine)
Warp a line.
QVariant configValue(const QString &key) override
Get a value for the key.
void clearEditingPosStack()
Removes all the elements in m_editingStack of the respective document.
InsertBehavior
Insert behavior of this cursor, should it stay if text is insert at its position or should it move...
Definition: movingcursor.h:64
KTextEditor::Cursor lastEditingPosition(EditingPositionKind nextOrPrevious, KTextEditor::Cursor)
Returns the next or previous position cursor in this document from the stack depending on the argumen...
MarkChangeAction
Possible actions on a mark.
Provides Auto-Indent functionality for katepart.
virtual QString line(int line) const =0
Get a single text line.
Class for tracking editing actions.
Definition: kateswapfile.h:35
virtual bool removeText(const Range &range, bool block=false)=0
Remove the text specified in range.
bool editUnWrapLine(int line, bool removeLine=true, int length=0)
Unwrap line.
bool closeUrl() override
A KParts derived class representing a text document.
Definition: document.h:185
void userSetEncodingForNextReload()
User did set encoding for next reload => enforce it!
Document interface for MovingCursors and MovingRanges.
qint64 lastSavedRevision() const override
Last revision the buffer got successful saved.
qint64 revision() const override
Current revision.
virtual bool removeLine(int line)=0
Remove line from the document.
virtual QString wordAt(const KTextEditor::Cursor &cursor) const =0
Get the word at the text position cursor.
QByteArray checksum() const override
Returns a git compatible sha1 checksum of this document on disk.
void saveEditingPositions(const KTextEditor::Cursor &cursor)
Saves the editing positions into the stack.
QString highlightingMode() const override
Return the name of the currently used mode.
allow range to be empty
Definition: movingrange.h:166
Config interface extension for the Document and View.
void readSessionConfig(const KConfigGroup &config, const QSet< QString > &flags=QSet< QString >()) override
Read session settings from the given config.
virtual QStringList embeddedHighlightingModes() const =0
Get all available highlighting modes for the current document.
virtual bool print()=0
Print the document.
bool editMarkLineAutoWrapped(int line, bool autowrapped)
Mark line as autowrapped.
void bomSetByUser()
Set that the BOM marker is forced via the tool menu.
KTextEditor::MovingCursor * newMovingCursor(const KTextEditor::Cursor &position, KTextEditor::MovingCursor::InsertBehavior insertBehavior=KTextEditor::MovingCursor::MoveOnInsert) override
Create a new moving cursor for this document.
void setConfigValue(const QString &key, const QVariant &value) override
Set a the key&#39;s value to value.
int findTouchedLine(int startLine, bool down)
Find the next modified/saved line, starting at startLine.
uint mark(int line) override
Get all marks set on the line.
virtual bool documentSave()=0
Save the current file.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
An model for providing line annotation information.
KateDocumentConfig * config()
Configuration.
virtual Cursor documentEnd() const =0
End position of the document.
void writeSessionConfig(KConfigGroup &config, const QSet< QString > &flags=QSet< QString >()) override
Write session settings to the config.
QString mimeType() override
Tries to detect mime-type based on file name and content of buffer.
An object representing a section of text, from one Cursor to another.
virtual void slotModifiedOnDisk(KTextEditor::View *v=nullptr)
Ask the user what to do, if the file has been modified on disk.
virtual QString documentName() const =0
Get this document&#39;s name.
virtual bool isLineTouched(int line) const =0
Check whether line was touched since the file was opened.
virtual bool setEncoding(const QString &encoding)=0
Set the encoding for this document.
ModifiedOnDiskReason
Reasons why a document is modified on disk.
Mark extension interface for the Document, version 2.
MarkTypes
Predefined mark types.
bool openFile() override
open the file obtained by the kparts framework the framework abstracts the loading of remote files ...
QString decodeCharacters(const KTextEditor::Range &range, KTextEditor::DocumentPrivate::OffsetList &decToEncOffsetList, KTextEditor::DocumentPrivate::OffsetList &encToDecOffsetList)
The first OffsetList is from decoded to encoded, and the second OffsetList from encoded to decoded...
void transformCursor(KTextEditor::Cursor &cursor, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision=-1) override
Transform a cursor from one revision to an other.
void editLineWrapped(int line, int col, int len)
Emitted when text from line was wrapped at position pos onto line nextLine.
int lineLengthLimit() const
reads the line length limit from config, if it is not overridden
bool editEnd()
End a editor operation.
QString modeSection(int index) const override
Returns the name of the section for a mode given its index in the highlight list (as returned by mode...
void transform(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &, TextTransform)
Handling uppercase, lowercase and capitalize for the view.
virtual void recoverData()=0
If recover data is available, calling recoverData() will trigger the recovery of the data...
virtual QString highlightingModeAt(const Cursor &position)=0
Get the highlight mode used at a given position in the document.
virtual bool isEditingTransactionRunning() const =0
Check whether an editing transaction is currently running.
virtual bool isValidTextPosition(const KTextEditor::Cursor &cursor) const =0
Get whether cursor is a valid text position.
KTextEditor::AnnotationModel * annotationModel() const override
returns the currently set AnnotationModel or 0 if there&#39;s none set
virtual void setReadWrite(bool readwrite=true)
static constexpr Range invalid() Q_DECL_NOEXCEPT
Returns an invalid range.
bool editInsertLine(int line, const QString &s)
Insert a string at the given line.
QIcon markIcon(MarkInterface::MarkTypes markType) const override
Get the mark&#39;s icon.
QStringList modes() const override
Return a list of the names of all possible modes.
QStringList configKeys() const override
Get a list of all available keys.
void setDontChangeHlOnSave()
allow to mark, that we changed hl on user wish and should not reset it atm used for the user visible ...
bool saveFile() override
save the file obtained by the kparts framework the framework abstracts the uploading of remote files ...
This dialog will prompt the user for what do with a file that is modified on disk.
Definition: katedialogs.h:345
virtual QString variable(const QString &name) const
Returns the value for the variable name.
QUrl url() const
void setModifiedOnDiskWarning(bool on) override
Control, whether the editor should show a warning dialog whenever a file was modified on disk...
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:143
int lastLine() const
gets the last line number (lines() - 1)
Definition: katedocument.h:796
Q_SLOTSQ_SLOTS
QObject * parent() const const
virtual KTextEditor::Range wordRangeAt(const KTextEditor::Cursor &cursor) const =0
Get the text range for the word located under the text position cursor.
virtual int totalCharacters() const =0
Get the count of characters in the document.
This class allows the application that embeds the KTextEditor component to allow it to access parts o...
Definition: mainwindow.h:43
virtual bool isLineModified(int line) const =0
Check whether line currently contains unsaved data.
void aboutToInvalidateMovingInterfaceContent(KTextEditor::Document *document)
This signal is emitted before the ranges of a document are invalidated and the revisions are deleted ...
void editLineUnWrapped(int line, int col)
Emitted each time text from nextLine was upwrapped onto line.
Mark class containing line and mark types.
Definition: message.h:93
bool editInsertText(int line, int col, const QString &s)
Add a string in the given line/column.
uint editableMarks() const override
Get, which marks can be toggled by the user.
virtual bool replaceText(const Range &range, const QString &text, bool block=false)
Replace text from range with specified text.
Definition: document.cpp:92
The KateBuffer class maintains a collections of lines.
Definition: katebuffer.h:30
QPixmap markPixmap(MarkInterface::MarkTypes) const override
Get the mark&#39;s pixmap.
bool isModified() const
virtual bool documentSaveAs()=0
Save the current file to another location.
virtual QChar characterAt(const Cursor &position) const =0
Get the character at text position cursor.
void transformRange(KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, KTextEditor::MovingRange::EmptyBehavior emptyBehavior, qint64 fromRevision, qint64 toRevision=-1) override
Transform a range from one revision to an other.
bool editRemoveText(int line, int col, int len)
Remove a string in the given line/column.
void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range, const QString &oldText)
The document emits this signal whenever range was removed, i.e.
A Document extension interface for handling Annotations.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Nov 30 2020 22:58:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.