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 
65 /**
66  * @brief Backend of KTextEditor::Document related public KTextEditor interfaces.
67  *
68  * @warning This file is @e private API and not part of the public
69  * KTextEditor interfaces.
70  */
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:
108  /**
109  * @return The widget defined by this part, set by setWidget().
110  */
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 
194  /**
195  * The \p document emits this signal whenever text was inserted. The
196  * insertion occurred at range.start(), and new text now occupies up to
197  * range.end().
198  * \param document document which emitted this signal
199  * \param range range that the newly inserted text occupies
200  * \see insertText(), insertLine()
201  */
202  void textInsertedRange(KTextEditor::Document *document, const KTextEditor::Range &range);
203 
204  /**
205  * The \p document emits this signal whenever \p range was removed, i.e.
206  * text was removed.
207  * \param document document which emitted this signal
208  * \param range range that the removed text previously occupied
209  * \param oldText the text that has been removed
210  * \see removeText(), removeLine(), clear()
211  */
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)
216  /**
217  * Enclose editor actions with @p editStart() and @p editEnd() to group
218  * them.
219  */
220  bool editStart();
221 
222  /**
223  * Alias for @p editStart()
224  */
225  void editBegin()
226  {
227  editStart();
228  }
229 
230  /**
231  * End a editor operation.
232  * @see editStart()
233  */
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)
254  /**
255  * Add a string in the given line/column
256  * @param line line number
257  * @param col column
258  * @param s string to be inserted
259  * @return true on success
260  */
261  bool editInsertText(int line, int col, const QString &s);
262 
263  /**
264  * Remove a string in the given line/column
265  * @param line line number
266  * @param col column
267  * @param len length of text to be removed
268  * @return true on success
269  */
270  bool editRemoveText(int line, int col, int len);
271 
272  /**
273  * Mark @p line as @p autowrapped. This is necessary if static word warp is
274  * enabled, because we have to know whether to insert a new line or add the
275  * wrapped words to the following line.
276  * @param line line number
277  * @param autowrapped autowrapped?
278  * @return true on success
279  */
280  bool editMarkLineAutoWrapped(int line, bool autowrapped);
281 
282  /**
283  * Wrap @p line. If @p newLine is true, ignore the textline's flag
284  * KateTextLine::flagAutoWrapped and force a new line. Whether a new line
285  * was needed/added you can grab with @p newLineAdded.
286  * @param line line number
287  * @param col column
288  * @param newLine if true, force a new line
289  * @param newLineAdded return value is true, if new line was added (may be 0)
290  * @return true on success
291  */
292  bool editWrapLine(int line, int col, bool newLine = true, bool *newLineAdded = nullptr);
293 
294  /**
295  * Unwrap @p line. If @p removeLine is true, we force to join the lines. If
296  * @p removeLine is true, @p length is ignored (eg not needed).
297  * @param line line number
298  * @param removeLine if true, force to remove the next line
299  * @return true on success
300  */
301  bool editUnWrapLine(int line, bool removeLine = true, int length = 0);
302 
303  /**
304  * Insert a string at the given line.
305  * @param line line number
306  * @param s string to insert
307  * @return true on success
308  */
309  bool editInsertLine(int line, const QString &s);
310 
311  /**
312  * Remove a line
313  * @param line line number
314  * @return true on success
315  */
316  bool editRemoveLine(int line);
317 
318  bool editRemoveLines(int from, int to);
319 
320  /**
321  * Warp a line
322  * @param startLine line to begin wrapping
323  * @param endLine line to stop wrapping
324  * @return true on success
325  */
326  bool wrapText(int startLine, int endLine);
327 
328  /**
329  * Wrap lines touched by the selection with respect of existing paragraphs.
330  * To do so will the paragraph prior to the wrap joined as one single line
331  * which cause an almost perfect wrapped paragraph as long as there are no
332  * unneeded spaces exist or some formatting like this comment block.
333  * Without any selection the current line is wrapped.
334  * Empty lines around each paragraph are untouched.
335  * @param first line to begin wrapping
336  * @param last line to stop wrapping
337  * @return true on success
338  */
339  bool wrapParagraph(int first, int last);
340  // END LINE BASED INSERT/REMOVE STUFF
341 
342 Q_SIGNALS:
343  /**
344  * Emitted when text from @p line was wrapped at position pos onto line @p nextLine.
345  */
346  void editLineWrapped(int line, int col, int len);
347 
348  /**
349  * Emitted each time text from @p nextLine was upwrapped onto @p line.
350  */
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 
360  /**
361  *Returns the next or previous position cursor in this document from the stack depending on the argument passed.
362  *@return cursor invalid if m_editingStack empty
363  */
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 
382  /**
383  * Removes all the elements in m_editingStack of the respective document.
384  */
385  void clearEditingPosStack();
386 
387  /**
388  * Saves the editing positions into the stack.
389  * If the consecutive editings happens in the same line, then remove
390  * the previous and add the new one with updated column no.
391  */
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:
413  /**
414  * Return a widget suitable to be used as a dialog parent.
415  */
416  QWidget *dialogParent();
417 
418  /*
419  * Access to the mode/highlighting subsystem
420  */
421 public:
422  /**
423  * @copydoc KTextEditor::Document::defaultStyleAt()
424  */
425  KTextEditor::DefaultStyle defaultStyleAt(const KTextEditor::Cursor &position) const override;
426 
427  /**
428  * Return the name of the currently used mode
429  * \return name of the used mode
430  */
431  QString mode() const override;
432 
433  /**
434  * Return the name of the currently used mode
435  * \return name of the used mode
436  */
437  QString highlightingMode() const override;
438 
439  /**
440  * Return a list of the names of all possible modes
441  * \return list of mode names
442  */
443  QStringList modes() const override;
444 
445  /**
446  * Return a list of the names of all possible modes
447  * \return list of mode names
448  */
449  QStringList highlightingModes() const override;
450 
451  /**
452  * Set the current mode of the document by giving its name
453  * \param name name of the mode to use for this document
454  * \return \e true on success, otherwise \e false
455  */
456  bool setMode(const QString &name) override;
457 
458  /**
459  * Set the current mode of the document by giving its name
460  * \param name name of the mode to use for this document
461  * \return \e true on success, otherwise \e false
462  */
463  bool setHighlightingMode(const QString &name) override;
464  /**
465  * Returns the name of the section for a highlight given its @p index in the highlight
466  * list (as returned by highlightModes()).
467  * You can use this function to build a tree of the highlight names, organized in sections.
468  * \param index in the highlight list for which to find the section name.
469  */
470  QString highlightingModeSection(int index) const override;
471 
472  /**
473  * Returns the name of the section for a mode given its @p index in the highlight
474  * list (as returned by modes()).
475  * You can use this function to build a tree of the mode names, organized in sections.
476  * \param index index in the highlight list for which to find the section name.
477  */
478  QString modeSection(int index) const override;
479 
480  /*
481  * Helpers....
482  */
483 public:
484  void bufferHlChanged();
485 
486  /**
487  * allow to mark, that we changed hl on user wish and should not reset it
488  * atm used for the user visible menu to select highlightings
489  */
490  void setDontChangeHlOnSave();
491 
492  /**
493  * Set that the BOM marker is forced via the tool menu
494  */
495  void bomSetByUser();
496 
497 public:
498  /**
499  * Read session settings from the given \p config.
500  *
501  * Known flags:
502  * "SkipUrl" => don't save/restore the file
503  * "SkipMode" => don't save/restore the mode
504  * "SkipHighlighting" => don't save/restore the highlighting
505  * "SkipEncoding" => don't save/restore the encoding
506  *
507  * \param config read the session settings from this KConfigGroup
508  * \param flags additional flags
509  * \see writeSessionConfig()
510  */
511  void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override;
512 
513  /**
514  * Write session settings to the \p config.
515  * See readSessionConfig() for more details.
516  *
517  * \param config write the session settings to this KConfigGroup
518  * \param flags additional flags
519  * \see readSessionConfig()
520  */
521  void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override;
522 
523  //
524  // KTextEditor::MarkInterface
525  //
526 public Q_SLOTS:
527  void setMark(int line, uint markType) override;
528  void clearMark(int line) override;
529 
530  void addMark(int line, uint markType) override;
531  void removeMark(int line, uint markType) override;
532 
533  void clearMarks() override;
534 
535  void requestMarkTooltip(int line, QPoint position);
536 
537  /// Returns true if the click on the mark should not be further processed
538  bool handleMarkClick(int line);
539 
540  /// Returns true if the context-menu event should not further be processed
541  bool handleMarkContextMenu(int line, QPoint position);
542 
543  void setMarkPixmap(MarkInterface::MarkTypes, const QPixmap &) override;
544 
545  void setMarkDescription(MarkInterface::MarkTypes, const QString &) override;
546 
547  void setEditableMarks(uint markMask) override;
548 
549 public:
550  uint mark(int line) override;
551  const QHash<int, KTextEditor::Mark *> &marks() override;
554  virtual QColor markColor(MarkInterface::MarkTypes) const;
555  uint editableMarks() const override;
556 
557 Q_SIGNALS:
558  void markToolTipRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint position, bool &handled);
559 
560  void markContextMenuRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint pos, bool &handled);
561 
562  void markClicked(KTextEditor::Document *document, KTextEditor::Mark mark, bool &handled);
563 
564  void marksChanged(KTextEditor::Document *) override;
565  void markChanged(KTextEditor::Document *, KTextEditor::Mark, KTextEditor::MarkInterface::MarkChangeAction) override;
566 
567 private:
569  QHash<int, QVariant> m_markIcons; // QPixmap or QIcon, KF6: remove QPixmap support
570  QHash<int, QString> m_markDescriptions;
571  uint m_editableMarks = markType01;
572 
573  //
574  // KTextEditor::MarkInterfaceV2
575  //
576 public Q_SLOTS:
577  void setMarkIcon(MarkInterface::MarkTypes markType, const QIcon &icon) override;
578 
579 public:
580  QIcon markIcon(MarkInterface::MarkTypes markType) const override;
581 
582  // KTextEditor::PrintInterface
583  //
584 public Q_SLOTS:
585  bool print() override;
586  void printPreview() override;
587 
588  //
589  // KTextEditor::DocumentInfoInterface ( ### unfinished )
590  //
591 public:
592  /**
593  * Tries to detect mime-type based on file name and content of buffer.
594  *
595  * @return the name of the mimetype for the document.
596  */
597  QString mimeType() override;
598 
599  //
600  // once was KTextEditor::VariableInterface
601  //
602 public:
603  /**
604  * Returns the value for the variable @p name.
605  * If the Document does not have a variable called @p name,
606  * an empty QString() is returned.
607  *
608  * // TODO KF6: expose in KTextEditor::Document?
609  *
610  * @param name variable to query
611  * @return value of the variable @p name
612  * @see setVariable()
613  */
614  virtual QString variable(const QString &name) const;
615 
616  /**
617  * Set the variable @p name to @p value. Setting and changing a variable
618  * has immediate effect on the Document. For instance, setting the variable
619  * @e indent-mode to @e cstyle will immediately cause the Document to load
620  * the C Style indenter.
621  *
622  * // TODO KF6: expose in KTextEditor::Document?
623  *
624  * @param name the variable name
625  * @param value the value to be set
626  * @see variable()
627  */
628  virtual void setVariable(const QString &name, const QString &value);
629 
630 private:
631  std::map<QString, QString> m_storedVariables;
632 
633  //
634  // MovingInterface API
635  //
636 public:
637  /**
638  * Create a new moving cursor for this document.
639  * @param position position of the moving cursor to create
640  * @param insertBehavior insertion behavior
641  * @return new moving cursor for the document
642  */
645 
646  /**
647  * Create a new moving range for this document.
648  * @param range range of the moving range to create
649  * @param insertBehaviors insertion behaviors
650  * @param emptyBehavior behavior on becoming empty
651  * @return new moving range for the document
652  */
656 
657  /**
658  * Current revision
659  * @return current revision
660  */
661  qint64 revision() const override;
662 
663  /**
664  * Last revision the buffer got successful saved
665  * @return last revision buffer got saved, -1 if none
666  */
667  qint64 lastSavedRevision() const override;
668 
669  /**
670  * Lock a revision, this will keep it around until released again.
671  * But all revisions will always be cleared on buffer clear() (and therefor load())
672  * @param revision revision to lock
673  */
674  void lockRevision(qint64 revision) override;
675 
676  /**
677  * Release a revision.
678  * @param revision revision to release
679  */
680  void unlockRevision(qint64 revision) override;
681 
682  /**
683  * Transform a cursor from one revision to an other.
684  * @param cursor cursor to transform
685  * @param insertBehavior behavior of this cursor on insert of text at its position
686  * @param fromRevision from this revision we want to transform
687  * @param toRevision to this revision we want to transform, default of -1 is current revision
688  */
691  qint64 fromRevision,
692  qint64 toRevision = -1) override;
693 
694  /**
695  * Transform a cursor from one revision to an other.
696  * @param line line number of the cursor to transform
697  * @param column column number of the cursor to transform
698  * @param insertBehavior behavior of this cursor on insert of text at its position
699  * @param fromRevision from this revision we want to transform
700  * @param toRevision to this revision we want to transform, default of -1 is current revision
701  */
702  void
703  transformCursor(int &line, int &column, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1) override;
704 
705  /**
706  * Transform a range from one revision to an other.
707  * @param range range to transform
708  * @param insertBehaviors behavior of this range on insert of text at its position
709  * @param emptyBehavior behavior on becoming empty
710  * @param fromRevision from this revision we want to transform
711  * @param toRevision to this revision we want to transform, default of -1 is current revision
712  */
716  qint64 fromRevision,
717  qint64 toRevision = -1) override;
718 
719  //
720  // MovingInterface Signals
721  //
722 Q_SIGNALS:
723  /**
724  * This signal is emitted before the cursors/ranges/revisions of a document are destroyed as the document is deleted.
725  * @param document the document which the interface belongs too which is in the process of being deleted
726  */
728 
729  /**
730  * This signal is emitted before the ranges of a document are invalidated and the revisions are deleted as the document is cleared (for example on
731  * load/reload). While this signal is emitted, still the old document content is around before the clear.
732  * @param document the document which the interface belongs too which will invalidate its data
733  */
735 
736  //
737  // Annotation Interface
738  //
739 public:
740  void setAnnotationModel(KTextEditor::AnnotationModel *model) override;
742 
743 Q_SIGNALS:
744  void annotationModelChanged(KTextEditor::AnnotationModel *, KTextEditor::AnnotationModel *);
745 
746 private:
747  KTextEditor::AnnotationModel *m_annotationModel = nullptr;
748 
749  //
750  // KParts::ReadWrite stuff
751  //
752 public:
753  /**
754  * open the file obtained by the kparts framework
755  * the framework abstracts the loading of remote files
756  * @return success
757  */
758  bool openFile() override;
759 
760  /**
761  * save the file obtained by the kparts framework
762  * the framework abstracts the uploading of remote files
763  * @return success
764  */
765  bool saveFile() override;
766 
767  void setReadWrite(bool rw = true) override;
768 
769  void setModified(bool m) override;
770 
771  bool isAutoReload();
772  KToggleAction *autoReloadToggleAction()
773  {
774  return m_autoReloadMode;
775  };
776  void delayAutoReload();
777 
778 private Q_SLOTS:
779  void autoReloadToggled(bool b);
780 
781 private:
782  void activateDirWatch(const QString &useFileName = QString());
783  void deactivateDirWatch();
784 
785  QString m_dirWatchFile;
786 
787  /**
788  * Make backup copy during saveFile, if configured that way.
789  * @return success? else saveFile should return false and not write the file
790  */
791  bool createBackupFile();
792 
793 public:
794  /**
795  * Type chars in a view.
796  * Characters are filtered in KateViewInternal::isAcceptableInput() before calling typeChars.
797  *
798  * @param view view that received the input
799  * @param chars characters to type
800  */
801  void typeChars(KTextEditor::ViewPrivate *view, QString chars);
802 
803  /**
804  * gets the last line number (lines() - 1)
805  */
806  inline int lastLine() const
807  {
808  return lines() - 1;
809  }
810 
811  // Repaint all of all of the views
812  void repaintViews(bool paintOnlyDirty = true);
813 
814  KateHighlighting *highlight() const;
815 
816 public Q_SLOTS:
817  void tagLines(KTextEditor::LineRange lineRange);
818  void tagLine(int line);
819 
820 private Q_SLOTS:
821  void internalHlChanged();
822 
823 public:
824  void addView(KTextEditor::View *);
825  /** removes the view from the list of views. The view is *not* deleted.
826  * That's your job. Or, easier, just delete the view in the first place.
827  * It will remove itself. TODO: this could be converted to a private slot
828  * connected to the view's destroyed() signal. It is not currently called
829  * anywhere except from the KTextEditor::ViewPrivate destructor.
830  */
832  void setActiveView(KTextEditor::View *);
833 
834  bool ownedView(KTextEditor::ViewPrivate *);
835 
836  int toVirtualColumn(int line, int column) const;
837  int toVirtualColumn(const KTextEditor::Cursor &) const;
838  int fromVirtualColumn(int line, int column) const;
839  int fromVirtualColumn(const KTextEditor::Cursor &) const;
840 
841  enum NewLineIndent { Indent, NoIndent };
842 
843  void newLine(KTextEditor::ViewPrivate *view, NewLineIndent indent = NewLineIndent::Indent); // Changes input
844  void backspace(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &);
845  void del(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &);
846  void transpose(const KTextEditor::Cursor &);
847  void swapTextRanges(KTextEditor::Range firstWord, KTextEditor::Range secondWord);
848  void paste(KTextEditor::ViewPrivate *view, const QString &text);
849 
850 public:
851  void indent(KTextEditor::Range range, int change);
852  void comment(KTextEditor::ViewPrivate *view, uint line, uint column, int change);
853  void align(KTextEditor::ViewPrivate *view, const KTextEditor::Range &range);
854  void insertTab(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &);
855 
856  enum TextTransform { Uppercase, Lowercase, Capitalize };
857 
858  /**
859  Handling uppercase, lowercase and capitalize for the view.
860 
861  If there is a selection, that is transformed, otherwise for uppercase or
862  lowercase the character right of the cursor is transformed, for capitalize
863  the word under the cursor is transformed.
864  */
865  void transform(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor &, TextTransform);
866  /**
867  Unwrap a range of lines.
868  */
869  void joinLines(uint first, uint last);
870 
871 private:
872  bool removeStringFromBeginning(int line, const QString &str);
873  bool removeStringFromEnd(int line, const QString &str);
874 
875  /**
876  Expand tabs to spaces in typed text, if enabled.
877  @param cursorPos The current cursor position for the inserted characters.
878  @param str The typed characters to expand.
879  */
880  QString eventuallyReplaceTabs(const KTextEditor::Cursor &cursorPos, const QString &str) const;
881 
882  /**
883  Find the position (line and col) of the next char
884  that is not a space. If found line and col point to the found character.
885  Otherwise they have both the value -1.
886  @param line Line of the character which is examined first.
887  @param col Column of the character which is examined first.
888  @return True if the specified or a following character is not a space
889  Otherwise false.
890  */
891  bool nextNonSpaceCharPos(int &line, int &col);
892 
893  /**
894  Find the position (line and col) of the previous char
895  that is not a space. If found line and col point to the found character.
896  Otherwise they have both the value -1.
897  @return True if the specified or a preceding character is not a space.
898  Otherwise false.
899  */
900  bool previousNonSpaceCharPos(int &line, int &col);
901 
902  /**
903  * Sets a comment marker as defined by the language providing the attribute
904  * @p attrib on the line @p line
905  */
906  void addStartLineCommentToSingleLine(int line, int attrib = 0);
907  /**
908  * Removes a comment marker as defined by the language providing the attribute
909  * @p attrib on the line @p line
910  */
911  bool removeStartLineCommentFromSingleLine(int line, int attrib = 0);
912 
913  /**
914  * @see addStartLineCommentToSingleLine.
915  */
916  void addStartStopCommentToSingleLine(int line, int attrib = 0);
917  /**
918  *@see removeStartLineCommentFromSingleLine.
919  */
920  bool removeStartStopCommentFromSingleLine(int line, int attrib = 0);
921  /**
922  *@see removeStartLineCommentFromSingleLine.
923  */
924  bool removeStartStopCommentFromRegion(const KTextEditor::Cursor &start, const KTextEditor::Cursor &end, int attrib = 0);
925 
926  /**
927  * Add a comment marker as defined by the language providing the attribute
928  * @p attrib to each line in the selection.
929  */
930  void addStartStopCommentToSelection(KTextEditor::ViewPrivate *view, int attrib = 0);
931  /**
932  * @see addStartStopCommentToSelection.
933  */
934  void addStartLineCommentToSelection(KTextEditor::ViewPrivate *view, int attrib = 0);
935 
936  /**
937  * Removes comment markers relevant to the language providing
938  * the attribute @p attrib from each line in the selection.
939  *
940  * @return whether the operation succeeded.
941  */
942  bool removeStartStopCommentFromSelection(KTextEditor::ViewPrivate *view, int attrib = 0);
943  /**
944  * @see removeStartStopCommentFromSelection.
945  */
946  bool removeStartLineCommentFromSelection(KTextEditor::ViewPrivate *view, int attrib = 0);
947 
948 public:
949  KTextEditor::Range findMatchingBracket(const KTextEditor::Cursor &start, int maxLines);
950 
951 public:
952  QString documentName() const override
953  {
954  return m_docName;
955  }
956 
957 private:
958  void updateDocName();
959 
960 public:
961  /**
962  * @return whether the document is modified on disk since last saved
963  */
965  {
966  return m_modOnHd;
967  }
968 
969  void setModifiedOnDisk(ModifiedOnDiskReason reason) override;
970 
971  void setModifiedOnDiskWarning(bool on) override;
972 
973 public Q_SLOTS:
974  /**
975  * Ask the user what to do, if the file has been modified on disk.
976  * Reimplemented from KTextEditor::Document.
977  */
978  virtual void slotModifiedOnDisk(KTextEditor::View *v = nullptr);
979 
980  /**
981  * Reloads the current document from disk if possible
982  */
983  bool documentReload() override;
984 
985  bool documentSave() override;
986  bool documentSaveAs() override;
987  bool documentSaveAsWithEncoding(const QString &encoding);
988  bool documentSaveCopyAs();
989 
990  bool save() override;
991 
992 public:
993  bool saveAs(const QUrl &url) override;
994 
995 Q_SIGNALS:
996  /**
997  * Indicate this file is modified on disk
998  * @param doc the KTextEditor::Document object that represents the file on disk
999  * @param isModified indicates the file was modified rather than created or deleted
1000  * @param reason the reason we are emitting the signal.
1001  */
1003 
1004 private:
1005  // helper to handle the embedded notification for externally modified files
1006  QPointer<KateModOnHdPrompt> m_modOnHdHandler;
1007 
1008 private Q_SLOTS:
1009  void onModOnHdSaveAs();
1010  void onModOnHdClose();
1011  void onModOnHdReload();
1012  void onModOnHdAutoReload();
1013  void onModOnHdIgnore();
1014 
1015 public:
1016  bool setEncoding(const QString &e) override;
1017  QString encoding() const override;
1018 
1019 public Q_SLOTS:
1020  void setWordWrap(bool on);
1021  void setWordWrapAt(uint col);
1022 
1023 public:
1024  bool wordWrap() const;
1025  uint wordWrapAt() const;
1026 
1027 public Q_SLOTS:
1028  void setPageUpDownMovesCursor(bool on);
1029 
1030 public:
1031  bool pageUpDownMovesCursor() const;
1032 
1033  // code folding
1034 public:
1035  /**
1036  * Same as plainKateTextLine(), except that it is made sure
1037  * the line is highlighted.
1038  */
1040 
1041  //! @copydoc KateBuffer::plainLine()
1043 
1044 Q_SIGNALS:
1045  void aboutToRemoveText(const KTextEditor::Range &);
1046 
1047 private Q_SLOTS:
1048  void slotModOnHdDirty(const QString &path);
1049  void slotModOnHdCreated(const QString &path);
1050  void slotModOnHdDeleted(const QString &path);
1051  void slotDelayedHandleModOnHd();
1052 
1053 private:
1054  /**
1055  * Create a git compatible sha1 checksum of the file, if it is a local file.
1056  * The result can be accessed through KateBuffer::digest().
1057  *
1058  * @return whether the operation was attempted and succeeded.
1059  */
1060  bool createDigest();
1061 
1062  /**
1063  * create a string for the modonhd warnings, giving the reason.
1064  */
1065  QString reasonedMOHString() const;
1066 
1067  /**
1068  * Removes all trailing whitespace in the document.
1069  */
1070  void removeTrailingSpaces();
1071 
1072 public:
1073  /**
1074  * Returns a git compatible sha1 checksum of this document on disk.
1075  * @return checksum for this document on disk
1076  */
1077  QByteArray checksum() const override;
1078 
1079  /**
1080  * @return false if @p newType is an invalid mode.
1081  */
1082  bool updateFileType(const QString &newType, bool user = false);
1083 
1084  QString fileType() const
1085  {
1086  return m_fileType;
1087  }
1088 
1089  /**
1090  * Get access to buffer of this document.
1091  * Is needed to create cursors and ranges for example.
1092  * @return document buffer
1093  */
1095  {
1096  return *m_buffer;
1097  }
1098 
1099  /**
1100  * set indentation mode by user
1101  * this will remember that a user did set it and will avoid reset on save
1102  */
1104  {
1105  m_indenterSetByUser = true;
1106  }
1107 
1108  /**
1109  * User did set encoding for next reload => enforce it!
1110  */
1112  {
1113  m_userSetEncodingForNextReload = true;
1114  }
1115 
1116  //
1117  // REALLY internal data ;)
1118  //
1119 private:
1120  // text buffer
1121  KateBuffer *const m_buffer;
1122 
1123  // indenter
1124  KateAutoIndent *const m_indenter;
1125 
1126  bool m_hlSetByUser = false;
1127  bool m_bomSetByUser = false;
1128  bool m_indenterSetByUser = false;
1129  bool m_userSetEncodingForNextReload = false;
1130 
1131  bool m_modOnHd = false;
1132  KToggleAction *m_autoReloadMode;
1133  QTimer m_autoReloadThrottle;
1134  ModifiedOnDiskReason m_modOnHdReason = OnDiskUnmodified;
1135  ModifiedOnDiskReason m_prevModOnHdReason = OnDiskUnmodified;
1136 
1137  QString m_docName;
1138  int m_docNameNumber = 0;
1139 
1140  // file type !!!
1141  QString m_fileType;
1142  bool m_fileTypeSetByUser = false;
1143 
1144  /**
1145  * document is still reloading a file
1146  */
1147  bool m_reloading = false;
1148 
1149 public Q_SLOTS:
1150  void slotQueryClose_save(bool *handled, bool *abortClosing);
1151 
1152 public:
1153  bool queryClose() override;
1154 
1155  /**
1156  * Configuration
1157  */
1158 public:
1159  KateDocumentConfig *config()
1160  {
1161  return m_config.get();
1162  }
1163  KateDocumentConfig *config() const
1164  {
1165  return m_config.get();
1166  }
1167 
1168  void updateConfig();
1169 
1170 private:
1171  void makeAttribs(bool needInvalidate = true);
1172 
1173  std::unique_ptr<KateDocumentConfig> const m_config;
1174 
1175  /**
1176  * Variable Reader
1177  * TODO add register functionality/ktexteditor interface
1178  */
1179 private:
1180  /**
1181  * read dir config file
1182  */
1183  void readDirConfig();
1184 
1185  /**
1186  Reads all the variables in the document.
1187  Called when opening/saving a document
1188  */
1189  void readVariables(bool onlyViewAndRenderer = false);
1190 
1191  /**
1192  Reads and applies the variables in a single line
1193  TODO registered variables gets saved in a [map]
1194  */
1195  void readVariableLine(const QString &t, bool onlyViewAndRenderer = false);
1196  /**
1197  Sets a view variable in all the views.
1198  */
1199  void setViewVariable(const QString &var, const QString &val);
1200  /**
1201  @return weather a string value could be converted
1202  to a bool value as supported.
1203  The value is put in *result.
1204  */
1205  static bool checkBoolValue(QString value, bool *result);
1206  /**
1207  @return weather a string value could be converted
1208  to a integer value.
1209  The value is put in *result.
1210  */
1211  static bool checkIntValue(const QString &value, int *result);
1212  /**
1213  Feeds value into @p col using QColor::setNamedColor() and returns
1214  whether the color is valid
1215  */
1216  static bool checkColorValue(const QString &value, QColor &col);
1217 
1218  bool m_fileChangedDialogsActivated = false;
1219 
1220  //
1221  // KTextEditor::ConfigInterface
1222  //
1223 public:
1224  QStringList configKeys() const override;
1225  QVariant configValue(const QString &key) override;
1226  void setConfigValue(const QString &key, const QVariant &value) override;
1227 
1228  //
1229  // KTextEditor::RecoveryInterface
1230  //
1231 public:
1232  bool isDataRecoveryAvailable() const override;
1233  void recoverData() override;
1234  void discardDataRecovery() override;
1235 
1236  //
1237  // Highlighting information
1238  //
1239 public:
1240  QStringList embeddedHighlightingModes() const override;
1241  QString highlightingModeAt(const KTextEditor::Cursor &position) override;
1242 
1243  //
1244  // BEGIN: KTextEditor::MessageInterface
1245  //
1246 public:
1247  bool postMessage(KTextEditor::Message *message) override;
1248 
1249 public Q_SLOTS:
1250  void messageDestroyed(KTextEditor::Message *message);
1251 
1252 private:
1254  // END KTextEditor::MessageInterface
1255 
1256 public:
1257  QString defaultDictionary() const;
1258  QList<QPair<KTextEditor::MovingRange *, QString>> dictionaryRanges() const;
1259  bool isOnTheFlySpellCheckingEnabled() const;
1260 
1261  QString dictionaryForMisspelledRange(const KTextEditor::Range &range) const;
1262  void clearMisspellingForWord(const QString &word);
1263 
1264 public Q_SLOTS:
1265  void clearDictionaryRanges();
1266  void setDictionary(const QString &dict, const KTextEditor::Range &range, bool blockmode);
1267  void setDictionary(const QString &dict, const KTextEditor::Range &range);
1268  void setDefaultDictionary(const QString &dict);
1269  void onTheFlySpellCheckingEnabled(bool enable);
1270  void refreshOnTheFlyCheck(const KTextEditor::Range &range = KTextEditor::Range::invalid());
1271 
1272 Q_SIGNALS:
1273  void dictionaryRangesPresent(bool yesNo);
1274  void defaultDictionaryChanged(KTextEditor::DocumentPrivate *document);
1275 
1276 public:
1277  bool containsCharacterEncoding(const KTextEditor::Range &range);
1278 
1280 
1281  int computePositionWrtOffsets(const OffsetList &offsetList, int pos);
1282 
1283  /**
1284  * The first OffsetList is from decoded to encoded, and the second OffsetList from
1285  * encoded to decoded.
1286  **/
1288  KTextEditor::DocumentPrivate::OffsetList &decToEncOffsetList,
1289  KTextEditor::DocumentPrivate::OffsetList &encToDecOffsetList);
1290  void replaceCharactersByEncoding(const KTextEditor::Range &range);
1291 
1292 protected:
1293  KateOnTheFlyChecker *m_onTheFlyChecker = nullptr;
1294  QString m_defaultDictionary;
1296 
1297  // from KTextEditor::MovingRangeFeedback
1298  void rangeInvalid(KTextEditor::MovingRange *movingRange) override;
1299  void rangeEmpty(KTextEditor::MovingRange *movingRange) override;
1300 
1301  void deleteDictionaryRange(KTextEditor::MovingRange *movingRange);
1302 
1303 private:
1304  Kate::SwapFile *m_swapfile;
1305 
1306 public:
1307  Kate::SwapFile *swapFile();
1308 
1309  // helpers for scripting and codefolding
1310  int defStyleNum(int line, int column);
1311  bool isComment(int line, int column);
1312 
1313 public:
1314  /**
1315  * Find the next modified/saved line, starting at @p startLine. If @p down
1316  * is \e true, the search is performed downwards, otherwise upwards.
1317  * @return the touched line in the requested search direction, or -1 if not found
1318  */
1319  int findTouchedLine(int startLine, bool down);
1320 
1321 private Q_SLOTS:
1322  /**
1323  * watch for all started io jobs to remember if file is perhaps loading atm
1324  * @param job started job
1325  */
1326  void slotStarted(KIO::Job *job);
1327  void slotCompleted();
1328  void slotCanceled();
1329 
1330  /**
1331  * trigger display of loading message, after 1000 ms
1332  */
1333  void slotTriggerLoadingMessage();
1334 
1335  /**
1336  * Abort loading
1337  */
1338  void slotAbortLoading();
1339 
1340  void slotUrlChanged(const QUrl &url);
1341 
1342 private:
1343  /**
1344  * different possible states
1345  */
1346  enum DocumentStates {
1347  /**
1348  * Idle
1349  */
1350  DocumentIdle,
1351 
1352  /**
1353  * Loading
1354  */
1355  DocumentLoading,
1356 
1357  /**
1358  * Saving
1359  */
1360  DocumentSaving,
1361 
1362  /**
1363  * Pre Saving As, this is between ::saveAs is called and ::save
1364  */
1365  DocumentPreSavingAs,
1366 
1367  /**
1368  * Saving As
1369  */
1370  DocumentSavingAs
1371  };
1372 
1373  /**
1374  * current state
1375  */
1376  DocumentStates m_documentState = DocumentIdle;
1377 
1378  /**
1379  * read-write state before loading started
1380  */
1381  bool m_readWriteStateBeforeLoading = false;
1382 
1383  /**
1384  * if the document is untitled
1385  */
1386  bool m_isUntitled = true;
1387  /**
1388  * loading job, we want to cancel with cancel in the loading message
1389  */
1390  QPointer<KJob> m_loadingJob;
1391 
1392  /**
1393  * message to show during loading
1394  */
1395  QPointer<KTextEditor::Message> m_loadingMessage;
1396 
1397  /**
1398  * Was there any open error on last file loading?
1399  */
1400  bool m_openingError = false;
1401 
1402  /**
1403  * Last open file error message
1404  */
1405  QString m_openingErrorMessage;
1406 
1407 public:
1408  /**
1409  * reads the line length limit from config, if it is not overridden
1410  */
1411  int lineLengthLimit() const;
1412 
1413 public Q_SLOTS:
1414  void openWithLineLengthLimitOverride();
1415 
1416 private:
1417  /**
1418  * timer for delayed handling of mod on hd
1419  */
1420  QTimer m_modOnHdTimer;
1421 
1422 private:
1423  /**
1424  * currently active template handler; there can be only one
1425  */
1426  QPointer<KateTemplateHandler> m_activeTemplateHandler;
1427 
1428 private:
1429  /**
1430  * current autobrace range
1431  */
1432  std::unique_ptr<KTextEditor::MovingRange> m_currentAutobraceRange;
1433  /**
1434  * current autobrace closing character (e.g. ']')
1435  */
1436  QChar m_currentAutobraceClosingChar;
1437 
1438 private Q_SLOTS:
1439  void checkCursorForAutobrace(KTextEditor::View *view, const KTextEditor::Cursor &newPos);
1440 
1441 public:
1442  void setActiveTemplateHandler(KateTemplateHandler *handler);
1443 
1444 Q_SIGNALS:
1445  void loaded(KTextEditor::DocumentPrivate *document);
1446 
1447 private:
1448  // To calculate a QHash.keys() is quite expensive,
1449  // better keep a copy of that list updated when a view is added or removed.
1450  QList<KTextEditor::View *> m_viewsCache;
1451 };
1452 
1453 #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:964
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 setModifiedOnDisk(ModifiedOnDiskReason reason) override
Set the document&#39;s modified-on-disk state to reason.
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:166
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.
virtual bool clear()=0
Remove the whole content of the document.
void textInsertedRange(KTextEditor::Document *document, const KTextEditor::Range &range)
The document emits this signal whenever text was inserted.
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:144
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:154
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!
An object representing lines from a start line to an end line.
Definition: linerange.h:37
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:167
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...
Definition: katetextblock.h:20
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:146
int lastLine() const
gets the last line number (lines() - 1)
Definition: katedocument.h:806
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:90
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-2021 The KDE developers.
Generated on Thu Jun 24 2021 22:57:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.