KTextEditor

katedocument.h
1 /* SPDX-License-Identifier: LGPL-2.0-or-later
2 
3  Copyright (C) 2001-2004 Christoph Cullmann <[email protected]>
4  Copyright (C) 2001 Joseph Wenninger <[email protected]>
5  Copyright (C) 1999 Jochen Wilhelmy <[email protected]>
6  Copyright (C) 2006 Hamish Rodda <[email protected]>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #ifndef _KATE_DOCUMENT_H_
25 #define _KATE_DOCUMENT_H_
26 
27 #include <QPointer>
28 #include <QStack>
29 #include <QTimer>
30 
31 #include <KJob>
32 
33 #include <ktexteditor/annotationinterface.h>
34 #include <ktexteditor/configinterface.h>
35 #include <ktexteditor/document.h>
36 #include <ktexteditor/inlinenoteinterface.h>
37 #include <ktexteditor/mainwindow.h>
38 #include <ktexteditor/markinterface.h>
39 #include <ktexteditor/message.h>
40 #include <ktexteditor/modificationinterface.h>
41 #include <ktexteditor/movinginterface.h>
42 
43 #include "katetextline.h"
44 #include <ktexteditor_export.h>
45 
47 namespace KTextEditor
48 {
49 class Plugin;
50 class Attribute;
51 class TemplateScript;
52 }
53 
54 namespace KIO
55 {
56 class TransferJob;
57 }
58 
59 namespace Kate
60 {
61 class SwapFile;
62 }
63 
64 class KateBuffer;
65 namespace KTextEditor
66 {
67 class ViewPrivate;
68 }
69 class KateDocumentConfig;
70 class KateHighlighting;
71 class KateUndoManager;
72 class KateOnTheFlyChecker;
73 class KateDocumentTest;
74 
75 class KateAutoIndent;
76 class KateModOnHdPrompt;
77 class KToggleAction;
78 
85 class KTEXTEDITOR_EXPORT KTextEditor::DocumentPrivate : public KTextEditor::Document,
92 {
93  Q_OBJECT
94  Q_INTERFACES(KTextEditor::MarkInterface)
95  Q_INTERFACES(KTextEditor::MarkInterfaceV2)
98  Q_INTERFACES(KTextEditor::ConfigInterface)
99  Q_INTERFACES(KTextEditor::MovingInterface)
100 
101  friend class KTextEditor::Document;
102  friend class ::KateDocumentTest;
103  friend class ::KateBuffer;
104 
105 public:
106  explicit DocumentPrivate(bool bSingleViewMode = false, bool bReadOnly = false, QWidget *parentWidget = nullptr, QObject * = nullptr);
107  ~DocumentPrivate() override;
108 
109  using ReadWritePart::closeUrl;
110  bool closeUrl() override;
111 
112  bool openUrl(const QUrl &url) override;
113 
114  KTextEditor::Range rangeOnLine(KTextEditor::Range range, int line) const;
115 
116 private:
117  void showAndSetOpeningErrorAccess();
118  /*
119  * Overload this to have on-demand view creation
120  */
121 public:
125  QWidget *widget() override;
126 
127 public:
128  bool readOnly() const
129  {
130  return m_bReadOnly;
131  }
132  bool singleViewMode() const
133  {
134  return m_bSingleViewMode;
135  }
136 
137 private:
138  // only to make part work, don't change it !
139  const bool m_bSingleViewMode;
140  const bool m_bReadOnly;
141 
142  //
143  // KTextEditor::Document stuff
144  //
145 public:
146  KTextEditor::View *createView(QWidget *parent, KTextEditor::MainWindow *mainWindow = nullptr) override;
147 
148  QList<KTextEditor::View *> views() const override
149  {
150  return m_viewsCache;
151  }
152 
153  virtual KTextEditor::View *activeView() const
154  {
155  return m_activeView;
156  }
157 
158 private:
160  KTextEditor::View *m_activeView = nullptr;
161 
162  //
163  // KTextEditor::EditInterface stuff
164  //
165 public Q_SLOTS:
166  bool setText(const QString &) override;
167  bool setText(const QStringList &text) override;
168  bool clear() override;
169 
170  bool insertText(const KTextEditor::Cursor &position, const QString &s, bool block = false) override;
171  bool insertText(const KTextEditor::Cursor &position, const QStringList &text, bool block = false) override;
172 
173  bool insertLine(int line, const QString &s) override;
174  bool insertLines(int line, const QStringList &s) override;
175 
176  bool removeText(const KTextEditor::Range &range, bool block = false) override;
177  bool removeLine(int line) override;
178 
179  bool replaceText(const KTextEditor::Range &range, const QString &s, bool block = false) override;
180 
181  // unhide method...
182  bool replaceText(const KTextEditor::Range &r, const QStringList &l, bool b) override
183  {
184  return KTextEditor::Document::replaceText(r, l, b);
185  }
186 
187 public:
188  bool isEditingTransactionRunning() const override;
189  QString text(const KTextEditor::Range &range, bool blockwise = false) const override;
190  QStringList textLines(const KTextEditor::Range &range, bool block = false) const override;
191  QString text() const override;
192  QString line(int line) const override;
193  QChar characterAt(const KTextEditor::Cursor &position) const override;
194  QString wordAt(const KTextEditor::Cursor &cursor) const override;
195  KTextEditor::Range wordRangeAt(const KTextEditor::Cursor &cursor) const override;
196  bool isValidTextPosition(const KTextEditor::Cursor &cursor) const override;
197  int lines() const override;
198  bool isLineModified(int line) const override;
199  bool isLineSaved(int line) const override;
200  bool isLineTouched(int line) const override;
201  KTextEditor::Cursor documentEnd() const override;
202  int totalCharacters() const override;
203  int lineLength(int line) const override;
204 
205 Q_SIGNALS:
206  void charactersSemiInteractivelyInserted(const KTextEditor::Cursor &position, const QString &text);
207 
216  void textInserted(KTextEditor::Document *document, const KTextEditor::Range &range);
217 
226  void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range, const QString &oldText);
227 
228 public:
229  // BEGIN editStart/editEnd (start, end, undo, cursor update, view update)
234  bool editStart();
235 
239  void editBegin()
240  {
241  editStart();
242  }
243 
248  bool editEnd();
249 
250  void pushEditState();
251  void popEditState();
252 
253  virtual bool startEditing()
254  {
255  return editStart();
256  }
257  virtual bool finishEditing()
258  {
259  return editEnd();
260  }
261 
262  // END editStart/editEnd
263 
264  void inputMethodStart();
265  void inputMethodEnd();
266 
267  // BEGIN LINE BASED INSERT/REMOVE STUFF (editStart() and editEnd() included)
275  bool editInsertText(int line, int col, const QString &s);
276 
284  bool editRemoveText(int line, int col, int len);
285 
294  bool editMarkLineAutoWrapped(int line, bool autowrapped);
295 
306  bool editWrapLine(int line, int col, bool newLine = true, bool *newLineAdded = nullptr);
307 
315  bool editUnWrapLine(int line, bool removeLine = true, int length = 0);
316 
323  bool editInsertLine(int line, const QString &s);
324 
330  bool editRemoveLine(int line);
331 
332  bool editRemoveLines(int from, int to);
333 
340  bool wrapText(int startLine, int endLine);
341 
353  bool wrapParagraph(int first, int last);
354  // END LINE BASED INSERT/REMOVE STUFF
355 
356 Q_SIGNALS:
360  void editLineWrapped(int line, int col, int len);
361 
365  void editLineUnWrapped(int line, int col);
366 
367 public:
368  bool isEditRunning() const;
369 
370  void setUndoMergeAllEdits(bool merge);
371 
372  enum EditingPositionKind { Previous, Next };
373 
378  KTextEditor::Cursor lastEditingPosition(EditingPositionKind nextOrPrevious, KTextEditor::Cursor);
379 
380 private:
381  int editSessionNumber = 0;
382  QStack<int> editStateStack;
383  bool editIsRunning = false;
384  bool m_undoMergeAllEdits = false;
385  KTextEditor::Cursor m_editLastChangeStartCursor = KTextEditor::Cursor::invalid();
387  int m_editingStackPosition = -1;
388 
389  //
390  // KTextEditor::UndoInterface stuff
391  //
392 public Q_SLOTS:
393  void undo();
394  void redo();
395 
399  void clearEditingPosStack();
400 
406  void saveEditingPositions(const KTextEditor::Cursor &cursor);
407 
408 public:
409  uint undoCount() const;
410  uint redoCount() const;
411 
412  KateUndoManager *undoManager()
413  {
414  return m_undoManager;
415  }
416 
417 protected:
418  KateUndoManager *const m_undoManager;
419 
420 Q_SIGNALS:
421  void undoChanged();
422 
423 public:
424  QVector<KTextEditor::Range> searchText(const KTextEditor::Range &range, const QString &pattern, const KTextEditor::SearchOptions options) const;
425 
426 private:
430  QWidget *dialogParent();
431 
432  /*
433  * Access to the mode/highlighting subsystem
434  */
435 public:
439  KTextEditor::DefaultStyle defaultStyleAt(const KTextEditor::Cursor &position) const override;
440 
445  QString mode() const override;
446 
451  QString highlightingMode() const override;
452 
457  QStringList modes() const override;
458 
463  QStringList highlightingModes() const override;
464 
470  bool setMode(const QString &name) override;
471 
477  bool setHighlightingMode(const QString &name) override;
484  QString highlightingModeSection(int index) const override;
485 
492  QString modeSection(int index) const override;
493 
494  /*
495  * Helpers....
496  */
497 public:
498  void bufferHlChanged();
499 
504  void setDontChangeHlOnSave();
505 
509  void bomSetByUser();
510 
511 public:
525  void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override;
526 
535  void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override;
536 
537 Q_SIGNALS:
538  void configChanged();
539 
540  //
541  // KTextEditor::MarkInterface
542  //
543 public Q_SLOTS:
544  void setMark(int line, uint markType) override;
545  void clearMark(int line) override;
546 
547  void addMark(int line, uint markType) override;
548  void removeMark(int line, uint markType) override;
549 
550  void clearMarks() override;
551 
552  void requestMarkTooltip(int line, QPoint position);
553 
555  bool handleMarkClick(int line);
556 
558  bool handleMarkContextMenu(int line, QPoint position);
559 
560  void setMarkPixmap(MarkInterface::MarkTypes, const QPixmap &) override;
561 
562  void setMarkDescription(MarkInterface::MarkTypes, const QString &) override;
563 
564  void setEditableMarks(uint markMask) override;
565 
566 public:
567  uint mark(int line) override;
568  const QHash<int, KTextEditor::Mark *> &marks() override;
571  virtual QColor markColor(MarkInterface::MarkTypes) const;
572  uint editableMarks() const override;
573 
574 Q_SIGNALS:
575  void markToolTipRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint position, bool &handled);
576 
577  void markContextMenuRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint pos, bool &handled);
578 
579  void markClicked(KTextEditor::Document *document, KTextEditor::Mark mark, bool &handled);
580 
581  void marksChanged(KTextEditor::Document *) override;
582  void markChanged(KTextEditor::Document *, KTextEditor::Mark, KTextEditor::MarkInterface::MarkChangeAction) override;
583 
584 private:
586  QHash<int, QVariant> m_markIcons; // QPixmap or QIcon, KF6: remove QPixmap support
587  QHash<int, QString> m_markDescriptions;
588  uint m_editableMarks = markType01;
589 
590  //
591  // KTextEditor::MarkInterfaceV2
592  //
593 public Q_SLOTS:
594  void setMarkIcon(MarkInterface::MarkTypes markType, const QIcon &icon) override;
595 
596 public:
597  QIcon markIcon(MarkInterface::MarkTypes markType) const override;
598 
599  // KTextEditor::PrintInterface
600  //
601 public Q_SLOTS:
602  bool print() override;
603  void printPreview() override;
604 
605  //
606  // KTextEditor::DocumentInfoInterface ( ### unfinished )
607  //
608 public:
614  QString mimeType() override;
615 
616  //
617  // once was KTextEditor::VariableInterface
618  //
619 public:
629  virtual QString variable(const QString &name) const;
630 
641  virtual void setVariable(const QString &name, const QString &value);
642 
643 private:
644  QMap<QString, QString> m_storedVariables;
645 
646  //
647  // MovingInterface API
648  //
649 public:
657 
668 
673  qint64 revision() const override;
674 
679  qint64 lastSavedRevision() const override;
680 
686  void lockRevision(qint64 revision) override;
687 
692  void unlockRevision(qint64 revision) override;
693 
701  void transformCursor(KTextEditor::Cursor &cursor, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1) override;
702 
711  void transformCursor(int &line, int &column, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1) override;
712 
721  void transformRange(KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors, KTextEditor::MovingRange::EmptyBehavior emptyBehavior, qint64 fromRevision, qint64 toRevision = -1) override;
722 
723  //
724  // MovingInterface Signals
725  //
726 Q_SIGNALS:
732 
739 
740  //
741  // Annotation Interface
742  //
743 public:
744  void setAnnotationModel(KTextEditor::AnnotationModel *model) override;
746 
747 Q_SIGNALS:
748  void annotationModelChanged(KTextEditor::AnnotationModel *, KTextEditor::AnnotationModel *);
749 
750 private:
751  KTextEditor::AnnotationModel *m_annotationModel = nullptr;
752 
753  //
754  // KParts::ReadWrite stuff
755  //
756 public:
762  bool openFile() override;
763 
769  bool saveFile() override;
770 
771  void setReadWrite(bool rw = true) override;
772 
773  void setModified(bool m) override;
774 
775  bool isAutoReload();
776  KToggleAction *autoReloadToggleAction()
777  {
778  return m_autoReloadMode;
779  };
780  void delayAutoReload();
781 
782 private Q_SLOTS:
783  void autoReloadToggled(bool b);
784 
785 private:
786  void activateDirWatch(const QString &useFileName = QString());
787  void deactivateDirWatch();
788 
789  QString m_dirWatchFile;
790 
795  bool createBackupFile();
796 
797 public:
805  void typeChars(KTextEditor::ViewPrivate *view, QString chars);
806 
810  inline int lastLine() const
811  {
812  return lines() - 1;
813  }
814 
815  // Repaint all of all of the views
816  void repaintViews(bool paintOnlyDirty = true);
817 
818  KateHighlighting *highlight() const;
819 
820 public Q_SLOTS:
821  void tagLines(int start, int end);
822 
823 private Q_SLOTS:
824  void internalHlChanged();
825 
826 public:
827  void addView(KTextEditor::View *);
835  void setActiveView(KTextEditor::View *);
836 
837  bool ownedView(KTextEditor::ViewPrivate *);
838 
839  int toVirtualColumn(int line, int column) const;
840  int toVirtualColumn(const KTextEditor::Cursor &) const;
841  int fromVirtualColumn(int line, int column) const;
842  int fromVirtualColumn(const KTextEditor::Cursor &) const;
843 
844  enum NewLineIndent { Indent, NoIndent };
845 
846  void newLine(KTextEditor::ViewPrivate *view, NewLineIndent indent = NewLineIndent::Indent); // Changes input
847  void backspace(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &);
848  void del(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &);
849  void transpose(const KTextEditor::Cursor &);
850  void paste(KTextEditor::ViewPrivate *view, const QString &text);
851 
852 public:
853  void indent(KTextEditor::Range range, int change);
854  void comment(KTextEditor::ViewPrivate *view, uint line, uint column, int change);
855  void align(KTextEditor::ViewPrivate *view, const KTextEditor::Range &range);
856  void insertTab(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &);
857 
858  enum TextTransform { Uppercase, Lowercase, Capitalize };
859 
867  void transform(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &, TextTransform);
871  void joinLines(uint first, uint last);
872 
873 private:
874  bool removeStringFromBeginning(int line, const QString &str);
875  bool removeStringFromEnd(int line, const QString &str);
876 
882  QString eventuallyReplaceTabs(const KTextEditor::Cursor &cursorPos, const QString &str) const;
883 
893  bool nextNonSpaceCharPos(int &line, int &col);
894 
902  bool previousNonSpaceCharPos(int &line, int &col);
903 
908  void addStartLineCommentToSingleLine(int line, int attrib = 0);
913  bool removeStartLineCommentFromSingleLine(int line, int attrib = 0);
914 
918  void addStartStopCommentToSingleLine(int line, int attrib = 0);
922  bool removeStartStopCommentFromSingleLine(int line, int attrib = 0);
926  bool removeStartStopCommentFromRegion(const KTextEditor::Cursor &start, const KTextEditor::Cursor &end, int attrib = 0);
927 
932  void addStartStopCommentToSelection(KTextEditor::ViewPrivate *view, int attrib = 0);
936  void addStartLineCommentToSelection(KTextEditor::ViewPrivate *view, int attrib = 0);
937 
944  bool removeStartStopCommentFromSelection(KTextEditor::ViewPrivate *view, int attrib = 0);
948  bool removeStartLineCommentFromSelection(KTextEditor::ViewPrivate *view, int attrib = 0);
949 
950 public:
951  KTextEditor::Range findMatchingBracket(const KTextEditor::Cursor &start, int maxLines);
952 
953 public:
954  QString documentName() const override
955  {
956  return m_docName;
957  }
958 
959 private:
960  void updateDocName();
961 
962 public:
967  {
968  return m_modOnHd;
969  }
970 
971  void setModifiedOnDisk(ModifiedOnDiskReason reason) override;
972 
973  void setModifiedOnDiskWarning(bool on) override;
974 
975 public Q_SLOTS:
980  virtual void slotModifiedOnDisk(KTextEditor::View *v = nullptr);
981 
985  bool documentReload() override;
986 
987  bool documentSave() override;
988  bool documentSaveAs() override;
989  bool documentSaveAsWithEncoding(const QString &encoding);
990  bool documentSaveCopyAs();
991 
992  bool save() override;
993 
994 public:
995  bool saveAs(const QUrl &url) override;
996 
997 Q_SIGNALS:
1005 
1006 private:
1007  // helper to handle the embedded notification for externally modified files
1008  QPointer<KateModOnHdPrompt> m_modOnHdHandler;
1009 
1010 private Q_SLOTS:
1011  void onModOnHdSaveAs();
1012  void onModOnHdClose();
1013  void onModOnHdReload();
1014  void onModOnHdAutoReload();
1015  void onModOnHdIgnore();
1016 
1017 public:
1018  bool setEncoding(const QString &e) override;
1019  QString encoding() const override;
1020 
1021 public Q_SLOTS:
1022  void setWordWrap(bool on);
1023  void setWordWrapAt(uint col);
1024 
1025 public:
1026  bool wordWrap() const;
1027  uint wordWrapAt() const;
1028 
1029 public Q_SLOTS:
1030  void setPageUpDownMovesCursor(bool on);
1031 
1032 public:
1033  bool pageUpDownMovesCursor() const;
1034 
1035  // code folding
1036 public:
1042 
1045 
1046 Q_SIGNALS:
1047  void aboutToRemoveText(const KTextEditor::Range &);
1048 
1049 private Q_SLOTS:
1050  void slotModOnHdDirty(const QString &path);
1051  void slotModOnHdCreated(const QString &path);
1052  void slotModOnHdDeleted(const QString &path);
1053  void slotDelayedHandleModOnHd();
1054 
1055 private:
1062  bool createDigest();
1063 
1067  QString reasonedMOHString() const;
1068 
1072  void removeTrailingSpaces();
1073 
1074 public:
1079  QByteArray checksum() const override;
1080 
1084  bool updateFileType(const QString &newType, bool user = false);
1085 
1086  QString fileType() const
1087  {
1088  return m_fileType;
1089  }
1090 
1097  {
1098  return *m_buffer;
1099  }
1100 
1106  {
1107  m_indenterSetByUser = true;
1108  }
1109 
1114  {
1115  m_userSetEncodingForNextReload = true;
1116  }
1117 
1118  //
1119  // REALLY internal data ;)
1120  //
1121 private:
1122  // text buffer
1123  KateBuffer *const m_buffer;
1124 
1125  // indenter
1126  KateAutoIndent *const m_indenter;
1127 
1128  bool m_hlSetByUser = false;
1129  bool m_bomSetByUser = false;
1130  bool m_indenterSetByUser = false;
1131  bool m_userSetEncodingForNextReload = false;
1132 
1133  bool m_modOnHd = false;
1134  KToggleAction *m_autoReloadMode;
1135  QTimer m_autoReloadThrottle;
1136  ModifiedOnDiskReason m_modOnHdReason = OnDiskUnmodified;
1137  ModifiedOnDiskReason m_prevModOnHdReason = OnDiskUnmodified;
1138 
1139  QString m_docName;
1140  int m_docNameNumber = 0;
1141 
1142  // file type !!!
1143  QString m_fileType;
1144  bool m_fileTypeSetByUser = false;
1145 
1149  bool m_reloading = false;
1150 
1151 public Q_SLOTS:
1152  void slotQueryClose_save(bool *handled, bool *abortClosing);
1153 
1154 public:
1155  bool queryClose() override;
1156 
1160 public:
1161  KateDocumentConfig *config()
1162  {
1163  return m_config;
1164  }
1165  KateDocumentConfig *config() const
1166  {
1167  return m_config;
1168  }
1169 
1170  void updateConfig();
1171 
1172 private:
1173  void makeAttribs(bool needInvalidate = true);
1174 
1175  KateDocumentConfig *const m_config;
1176 
1181 private:
1185  void readDirConfig();
1186 
1191  void readVariables(bool onlyViewAndRenderer = false);
1192 
1197  void readVariableLine(const QString &t, bool onlyViewAndRenderer = false);
1201  void setViewVariable(const QString &var, const QString &val);
1207  static bool checkBoolValue(QString value, bool *result);
1213  static bool checkIntValue(const QString &value, int *result);
1218  static bool checkColorValue(const QString &value, QColor &col);
1219 
1220  bool m_fileChangedDialogsActivated = false;
1221 
1222  //
1223  // KTextEditor::ConfigInterface
1224  //
1225 public:
1226  QStringList configKeys() const override;
1227  QVariant configValue(const QString &key) override;
1228  void setConfigValue(const QString &key, const QVariant &value) override;
1229 
1230  //
1231  // KTextEditor::RecoveryInterface
1232  //
1233 public:
1234  bool isDataRecoveryAvailable() const override;
1235  void recoverData() override;
1236  void discardDataRecovery() override;
1237 
1238  //
1239  // Highlighting information
1240  //
1241 public:
1242  QStringList embeddedHighlightingModes() const override;
1243  QString highlightingModeAt(const KTextEditor::Cursor &position) override;
1244  // TODO KDE5: move to View
1245  virtual KTextEditor::Attribute::Ptr attributeAt(const KTextEditor::Cursor &position);
1246 
1247  //
1248  // BEGIN: KTextEditor::MessageInterface
1249  //
1250 public:
1251  bool postMessage(KTextEditor::Message *message) override;
1252 
1253 public Q_SLOTS:
1254  void messageDestroyed(KTextEditor::Message *message);
1255 
1256 private:
1258  // END KTextEditor::MessageInterface
1259 
1260 public:
1261  QString defaultDictionary() const;
1262  QList<QPair<KTextEditor::MovingRange *, QString>> dictionaryRanges() const;
1263  bool isOnTheFlySpellCheckingEnabled() const;
1264 
1265  QString dictionaryForMisspelledRange(const KTextEditor::Range &range) const;
1266  void clearMisspellingForWord(const QString &word);
1267 
1268 public Q_SLOTS:
1269  void clearDictionaryRanges();
1270  void setDictionary(const QString &dict, const KTextEditor::Range &range, bool blockmode);
1271  void setDictionary(const QString &dict, const KTextEditor::Range &range);
1272  void setDefaultDictionary(const QString &dict);
1273  void onTheFlySpellCheckingEnabled(bool enable);
1274  void refreshOnTheFlyCheck(const KTextEditor::Range &range = KTextEditor::Range::invalid());
1275 
1276 Q_SIGNALS:
1277  void dictionaryRangesPresent(bool yesNo);
1278  void defaultDictionaryChanged(KTextEditor::DocumentPrivate *document);
1279 
1280 public:
1281  bool containsCharacterEncoding(const KTextEditor::Range &range);
1282 
1284 
1285  int computePositionWrtOffsets(const OffsetList &offsetList, int pos);
1286 
1291  QString decodeCharacters(const KTextEditor::Range &range, KTextEditor::DocumentPrivate::OffsetList &decToEncOffsetList, KTextEditor::DocumentPrivate::OffsetList &encToDecOffsetList);
1292  void replaceCharactersByEncoding(const KTextEditor::Range &range);
1293 
1294 protected:
1295  KateOnTheFlyChecker *m_onTheFlyChecker = nullptr;
1296  QString m_defaultDictionary;
1298 
1299  // from KTextEditor::MovingRangeFeedback
1300  void rangeInvalid(KTextEditor::MovingRange *movingRange) override;
1301  void rangeEmpty(KTextEditor::MovingRange *movingRange) override;
1302 
1303  void deleteDictionaryRange(KTextEditor::MovingRange *movingRange);
1304 
1305 private:
1306  Kate::SwapFile *m_swapfile;
1307 
1308 public:
1309  Kate::SwapFile *swapFile();
1310 
1311  // helpers for scripting and codefolding
1312  int defStyleNum(int line, int column);
1313  bool isComment(int line, int column);
1314 
1315 public:
1321  int findTouchedLine(int startLine, bool down);
1322 
1323 private Q_SLOTS:
1328  void slotStarted(KIO::Job *job);
1329  void slotCompleted();
1330  void slotCanceled();
1331 
1335  void slotTriggerLoadingMessage();
1336 
1340  void slotAbortLoading();
1341 
1342  void slotUrlChanged(const QUrl &url);
1343 
1344 private:
1348  enum DocumentStates {
1352  DocumentIdle,
1353 
1357  DocumentLoading,
1358 
1362  DocumentSaving,
1363 
1367  DocumentPreSavingAs,
1368 
1372  DocumentSavingAs
1373  };
1374 
1378  DocumentStates m_documentState = DocumentIdle;
1379 
1383  bool m_readWriteStateBeforeLoading = false;
1384 
1388  bool m_isUntitled = true;
1392  QPointer<KJob> m_loadingJob;
1393 
1397  QPointer<KTextEditor::Message> m_loadingMessage;
1398 
1402  bool m_openingError = false;
1403 
1407  QString m_openingErrorMessage;
1408 
1409 public:
1413  int lineLengthLimit() const;
1414 
1415 public Q_SLOTS:
1416  void openWithLineLengthLimitOverride();
1417 
1418 private:
1422  QTimer m_modOnHdTimer;
1423 
1424 private:
1428  QPointer<KateTemplateHandler> m_activeTemplateHandler;
1429 
1430 private:
1434  QSharedPointer<KTextEditor::MovingRange> m_currentAutobraceRange;
1438  QChar m_currentAutobraceClosingChar;
1439 
1440 private Q_SLOTS:
1441  void checkCursorForAutobrace(KTextEditor::View *view, const KTextEditor::Cursor &newPos);
1442 
1443 public:
1444  void setActiveTemplateHandler(KateTemplateHandler *handler);
1445 
1446 Q_SIGNALS:
1447  void loaded(KTextEditor::DocumentPrivate *document);
1448 
1449 private Q_SLOTS:
1453  void closeDocumentInApplication();
1454 
1455 private:
1456  // To calculate a QHash.keys() is quite expensive,
1457  // better keep a copy of that list updated when a view is added or removed.
1458  QList<KTextEditor::View *> m_viewsCache;
1459 };
1460 
1461 #endif
DefaultStyle
The following lists all valid default styles that are used for the syntax highlighting files in the i...
Definition: attribute.h:40
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:966
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:239
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:179
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:68
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:157
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:167
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:85
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:123
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:78
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:49
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:199
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:180
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:361
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:155
int lastLine() const
gets the last line number (lines() - 1)
Definition: katedocument.h:810
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:57
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:107
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:110
The KateBuffer class maintains a collections of lines.
Definition: katebuffer.h:44
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 Sat Jul 4 2020 22:58:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.