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 final : public KTextEditor::Document,
78 {
79  Q_OBJECT
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  void setMetaData(const KPluginMetaData &metaData);
103 
104 private:
105  void showAndSetOpeningErrorAccess();
106  /*
107  * Overload this to have on-demand view creation
108  */
109 public:
110  /**
111  * @return The widget defined by this part, set by setWidget().
112  */
113  QWidget *widget() override;
114 
115 public:
116  bool readOnly() const
117  {
118  return m_bReadOnly;
119  }
120  bool singleViewMode() const
121  {
122  return m_bSingleViewMode;
123  }
124 
125 private:
126  // only to make part work, don't change it !
127  const bool m_bSingleViewMode;
128  const bool m_bReadOnly;
129 
130  //
131  // KTextEditor::Document stuff
132  //
133 public:
134  KTextEditor::View *createView(QWidget *parent, KTextEditor::MainWindow *mainWindow = nullptr) override;
135 
136  QList<KTextEditor::View *> views() const override
137  {
138  return m_viewsCache;
139  }
140 
141  virtual KTextEditor::View *activeView() const
142  {
143  return m_activeView;
144  }
145 
146 private:
148  KTextEditor::View *m_activeView = nullptr;
149 
150  //
151  // KTextEditor::EditInterface stuff
152  //
153 public Q_SLOTS:
154  bool setText(const QString &) override;
155  bool setText(const QStringList &text) override;
156  bool clear() override;
157 
158  bool insertText(const KTextEditor::Cursor &position, const QString &s, bool block = false) override;
159  bool insertText(const KTextEditor::Cursor &position, const QStringList &text, bool block = false) override;
160 
161  bool insertLine(int line, const QString &s) override;
162  bool insertLines(int line, const QStringList &s) override;
163 
164  bool removeText(const KTextEditor::Range &range, bool block = false) override;
165  bool removeLine(int line) override;
166 
167  bool replaceText(const KTextEditor::Range &range, const QString &s, bool block = false) override;
168 
169  // unhide method...
170  bool replaceText(const KTextEditor::Range &r, const QStringList &l, bool b) override
171  {
172  return KTextEditor::Document::replaceText(r, l, b);
173  }
174 
175 public:
176  bool isEditingTransactionRunning() const override;
177  QString text(const KTextEditor::Range &range, bool blockwise = false) const override;
178  QStringList textLines(const KTextEditor::Range &range, bool block = false) const override;
179  QString text() const override;
180  QString line(int line) const override;
181  QChar characterAt(const KTextEditor::Cursor &position) const override;
182  QString wordAt(const KTextEditor::Cursor &cursor) const override;
183  KTextEditor::Range wordRangeAt(const KTextEditor::Cursor &cursor) const override;
184  bool isValidTextPosition(const KTextEditor::Cursor &cursor) const override;
185  int lines() const override;
186  bool isLineModified(int line) const override;
187  bool isLineSaved(int line) const override;
188  bool isLineTouched(int line) const override;
189  KTextEditor::Cursor documentEnd() const override;
190  int totalCharacters() const override;
191  int lineLength(int line) const override;
192 
193 Q_SIGNALS:
194  void charactersSemiInteractivelyInserted(const KTextEditor::Cursor &position, const QString &text);
195 
196  /**
197  * The \p document emits this signal whenever text was inserted. The
198  * insertion occurred at range.start(), and new text now occupies up to
199  * range.end().
200  * \param document document which emitted this signal
201  * \param range range that the newly inserted text occupies
202  * \see insertText(), insertLine()
203  */
204  void textInsertedRange(KTextEditor::Document *document, const KTextEditor::Range &range);
205 
206  /**
207  * The \p document emits this signal whenever \p range was removed, i.e.
208  * text was removed.
209  * \param document document which emitted this signal
210  * \param range range that the removed text previously occupied
211  * \param oldText the text that has been removed
212  * \see removeText(), removeLine(), clear()
213  */
214  void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range, const QString &oldText);
215 
216 public:
217  // BEGIN editStart/editEnd (start, end, undo, cursor update, view update)
218  /**
219  * Enclose editor actions with @p editStart() and @p editEnd() to group
220  * them.
221  */
222  bool editStart();
223 
224  /**
225  * Alias for @p editStart()
226  */
227  void editBegin()
228  {
229  editStart();
230  }
231 
232  /**
233  * End a editor operation.
234  * @see editStart()
235  */
236  bool editEnd();
237 
238  void pushEditState();
239  void popEditState();
240 
241  virtual bool startEditing()
242  {
243  return editStart();
244  }
245  virtual bool finishEditing()
246  {
247  return editEnd();
248  }
249 
250  // END editStart/editEnd
251 
252  void inputMethodStart();
253  void inputMethodEnd();
254 
255  // BEGIN LINE BASED INSERT/REMOVE STUFF (editStart() and editEnd() included)
256  /**
257  * Add a string in the given line/column
258  * @param line line number
259  * @param col column
260  * @param s string to be inserted
261  * @return true on success
262  */
263  bool editInsertText(int line, int col, const QString &s);
264 
265  /**
266  * Remove a string in the given line/column
267  * @param line line number
268  * @param col column
269  * @param len length of text to be removed
270  * @return true on success
271  */
272  bool editRemoveText(int line, int col, int len);
273 
274  /**
275  * Mark @p line as @p autowrapped. This is necessary if static word warp is
276  * enabled, because we have to know whether to insert a new line or add the
277  * wrapped words to the following line.
278  * @param line line number
279  * @param autowrapped autowrapped?
280  * @return true on success
281  */
282  bool editMarkLineAutoWrapped(int line, bool autowrapped);
283 
284  /**
285  * Wrap @p line. If @p newLine is true, ignore the textline's flag
286  * KateTextLine::flagAutoWrapped and force a new line. Whether a new line
287  * was needed/added you can grab with @p newLineAdded.
288  * @param line line number
289  * @param col column
290  * @param newLine if true, force a new line
291  * @param newLineAdded return value is true, if new line was added (may be 0)
292  * @return true on success
293  */
294  bool editWrapLine(int line, int col, bool newLine = true, bool *newLineAdded = nullptr);
295 
296  /**
297  * Unwrap @p line. If @p removeLine is true, we force to join the lines. If
298  * @p removeLine is true, @p length is ignored (eg not needed).
299  * @param line line number
300  * @param removeLine if true, force to remove the next line
301  * @return true on success
302  */
303  bool editUnWrapLine(int line, bool removeLine = true, int length = 0);
304 
305  /**
306  * Insert a string at the given line.
307  * @param line line number
308  * @param s string to insert
309  * @return true on success
310  */
311  bool editInsertLine(int line, const QString &s);
312 
313  /**
314  * Remove a line
315  * @param line line number
316  * @return true on success
317  */
318  bool editRemoveLine(int line);
319 
320  bool editRemoveLines(int from, int to);
321 
322  /**
323  * Warp a line
324  * @param startLine line to begin wrapping
325  * @param endLine line to stop wrapping
326  * @return true on success
327  */
328  bool wrapText(int startLine, int endLine);
329 
330  /**
331  * Wrap lines touched by the selection with respect of existing paragraphs.
332  * To do so will the paragraph prior to the wrap joined as one single line
333  * which cause an almost perfect wrapped paragraph as long as there are no
334  * unneeded spaces exist or some formatting like this comment block.
335  * Without any selection the current line is wrapped.
336  * Empty lines around each paragraph are untouched.
337  * @param first line to begin wrapping
338  * @param last line to stop wrapping
339  * @return true on success
340  */
341  bool wrapParagraph(int first, int last);
342  // END LINE BASED INSERT/REMOVE STUFF
343 
344 Q_SIGNALS:
345  /**
346  * Emitted when text from @p line was wrapped at position pos onto line @p nextLine.
347  */
348  void editLineWrapped(int line, int col, int len);
349 
350  /**
351  * Emitted each time text from @p nextLine was upwrapped onto @p line.
352  */
353  void editLineUnWrapped(int line, int col);
354 
355 public:
356  bool isEditRunning() const;
357 
358  void setUndoMergeAllEdits(bool merge);
359 
360  enum EditingPositionKind { Previous, Next };
361 
362  /**
363  *Returns the next or previous position cursor in this document from the stack depending on the argument passed.
364  *@return cursor invalid if m_editingStack empty
365  */
366  KTextEditor::Cursor lastEditingPosition(EditingPositionKind nextOrPrevious, KTextEditor::Cursor);
367 
368 private:
369  int editSessionNumber = 0;
370  QStack<int> editStateStack;
371  bool editIsRunning = false;
372  bool m_undoMergeAllEdits = false;
373  KTextEditor::Cursor m_editLastChangeStartCursor = KTextEditor::Cursor::invalid();
375  int m_editingStackPosition = -1;
376 
377  //
378  // KTextEditor::UndoInterface stuff
379  //
380 public Q_SLOTS:
381  void undo();
382  void redo();
383 
384  /**
385  * Removes all the elements in m_editingStack of the respective document.
386  */
387  void clearEditingPosStack();
388 
389  /**
390  * Saves the editing positions into the stack.
391  * If the consecutive editings happens in the same line, then remove
392  * the previous and add the new one with updated column no.
393  */
394  void saveEditingPositions(const KTextEditor::Cursor cursor);
395 
396 public:
397  uint undoCount() const;
398  uint redoCount() const;
399 
400  KateUndoManager *undoManager()
401  {
402  return m_undoManager;
403  }
404 
405 protected:
406  KateUndoManager *const m_undoManager;
407 
408 Q_SIGNALS:
409  void undoChanged();
410 
411 public:
413 
414 private:
415  /**
416  * Return a widget suitable to be used as a dialog parent.
417  */
418  QWidget *dialogParent();
419 
420  /**
421  * Wrapper around QFileDialog::getSaveFileUrl, will use proper dialogParent
422  * and try it's best to find a good directory as start
423  * @param dialogTitle dialog title string
424  * @return url to save to or empty url if aborted
425  */
426  QUrl getSaveFileUrl(const QString &dialogTitle);
427 
428  /*
429  * Access to the mode/highlighting subsystem
430  */
431 public:
432  /**
433  * @copydoc KTextEditor::Document::defaultStyleAt()
434  */
435  KTextEditor::DefaultStyle defaultStyleAt(const KTextEditor::Cursor &position) const override;
436 
437  /**
438  * Return the name of the currently used mode
439  * \return name of the used mode
440  */
441  QString mode() const override;
442 
443  /**
444  * Return the name of the currently used mode
445  * \return name of the used mode
446  */
447  QString highlightingMode() const override;
448 
449  /**
450  * Return a list of the names of all possible modes
451  * \return list of mode names
452  */
453  QStringList modes() const override;
454 
455  /**
456  * Return a list of the names of all possible modes
457  * \return list of mode names
458  */
459  QStringList highlightingModes() const override;
460 
461  /**
462  * Set the current mode of the document by giving its name
463  * \param name name of the mode to use for this document
464  * \return \e true on success, otherwise \e false
465  */
466  bool setMode(const QString &name) override;
467 
468  /**
469  * Set the current mode of the document by giving its name
470  * \param name name of the mode to use for this document
471  * \return \e true on success, otherwise \e false
472  */
473  bool setHighlightingMode(const QString &name) override;
474  /**
475  * Returns the name of the section for a highlight given its @p index in the highlight
476  * list (as returned by highlightModes()).
477  * You can use this function to build a tree of the highlight names, organized in sections.
478  * \param index in the highlight list for which to find the section name.
479  */
480  QString highlightingModeSection(int index) const override;
481 
482  /**
483  * Returns the name of the section for a mode given its @p index in the highlight
484  * list (as returned by modes()).
485  * You can use this function to build a tree of the mode names, organized in sections.
486  * \param index index in the highlight list for which to find the section name.
487  */
488  QString modeSection(int index) const override;
489 
490  /*
491  * Helpers....
492  */
493 public:
494  void bufferHlChanged();
495 
496  /**
497  * allow to mark, that we changed hl on user wish and should not reset it
498  * atm used for the user visible menu to select highlightings
499  */
500  void setDontChangeHlOnSave();
501 
502  /**
503  * Set that the BOM marker is forced via the tool menu
504  */
505  void bomSetByUser();
506 
507 public:
508  /**
509  * Read session settings from the given \p config.
510  *
511  * Known flags:
512  * "SkipUrl" => don't save/restore the file
513  * "SkipMode" => don't save/restore the mode
514  * "SkipHighlighting" => don't save/restore the highlighting
515  * "SkipEncoding" => don't save/restore the encoding
516  *
517  * \param config read the session settings from this KConfigGroup
518  * \param flags additional flags
519  * \see writeSessionConfig()
520  */
521  void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override;
522 
523  /**
524  * Write session settings to the \p config.
525  * See readSessionConfig() for more details.
526  *
527  * \param config write the session settings to this KConfigGroup
528  * \param flags additional flags
529  * \see readSessionConfig()
530  */
531  void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override;
532 
533  //
534  // KTextEditor::MarkInterface
535  //
536 public Q_SLOTS:
537  void setMark(int line, uint markType) override;
538  void clearMark(int line) override;
539 
540  void addMark(int line, uint markType) override;
541  void removeMark(int line, uint markType) override;
542 
543  void clearMarks() override;
544 
545  void requestMarkTooltip(int line, QPoint position);
546 
547  /// Returns true if the click on the mark should not be further processed
548  bool handleMarkClick(int line);
549 
550  /// Returns true if the context-menu event should not further be processed
551  bool handleMarkContextMenu(int line, QPoint position);
552 
553  void setMarkPixmap(MarkInterface::MarkTypes, const QPixmap &) override;
554 
555  void setMarkDescription(MarkInterface::MarkTypes, const QString &) override;
556 
557  void setEditableMarks(uint markMask) override;
558 
559 public:
560  uint mark(int line) override;
561  const QHash<int, KTextEditor::Mark *> &marks() override;
564  virtual QColor markColor(MarkInterface::MarkTypes) const;
565  uint editableMarks() const override;
566 
567 Q_SIGNALS:
568  void markToolTipRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint position, bool &handled);
569 
570  void markContextMenuRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint pos, bool &handled);
571 
572  void markClicked(KTextEditor::Document *document, KTextEditor::Mark mark, bool &handled);
573 
574  void marksChanged(KTextEditor::Document *) override;
576 
577 private:
579  QHash<int, QVariant> m_markIcons; // QPixmap or QIcon, KF6: remove QPixmap support
580  QHash<int, QString> m_markDescriptions;
581  uint m_editableMarks = markType01;
582 
583  //
584  // KTextEditor::MarkInterfaceV2
585  //
586 public Q_SLOTS:
587  void setMarkIcon(MarkInterface::MarkTypes markType, const QIcon &icon) override;
588 
589 public:
590  QIcon markIcon(MarkInterface::MarkTypes markType) const override;
591 
592  // KTextEditor::PrintInterface
593  //
594 public Q_SLOTS:
595  bool print() override;
596  void printPreview() override;
597 
598  //
599  // KTextEditor::DocumentInfoInterface ( ### unfinished )
600  //
601 public:
602  /**
603  * Tries to detect mime-type based on file name and content of buffer.
604  *
605  * @return the name of the mimetype for the document.
606  */
607  QString mimeType() override;
608 
609  //
610  // once was KTextEditor::VariableInterface
611  //
612 public:
613  /**
614  * Returns the value for the variable @p name.
615  * If the Document does not have a variable called @p name,
616  * an empty QString() is returned.
617  *
618  * // TODO KF6: expose in KTextEditor::Document?
619  *
620  * @param name variable to query
621  * @return value of the variable @p name
622  * @see setVariable()
623  */
624  virtual QString variable(const QString &name) const;
625 
626  /**
627  * Set the variable @p name to @p value. Setting and changing a variable
628  * has immediate effect on the Document. For instance, setting the variable
629  * @e indent-mode to @e cstyle will immediately cause the Document to load
630  * the C Style indenter.
631  *
632  * // TODO KF6: expose in KTextEditor::Document?
633  *
634  * @param name the variable name
635  * @param value the value to be set
636  * @see variable()
637  */
638  virtual void setVariable(const QString &name, const QString &value);
639 
640 private:
641  std::map<QString, QString> m_storedVariables;
642 
643  //
644  // MovingInterface API
645  //
646 public:
647  /**
648  * Create a new moving cursor for this document.
649  * @param position position of the moving cursor to create
650  * @param insertBehavior insertion behavior
651  * @return new moving cursor for the document
652  */
655 
656  /**
657  * Create a new moving range for this document.
658  * @param range range of the moving range to create
659  * @param insertBehaviors insertion behaviors
660  * @param emptyBehavior behavior on becoming empty
661  * @return new moving range for the document
662  */
666 
667  /**
668  * Current revision
669  * @return current revision
670  */
671  qint64 revision() const override;
672 
673  /**
674  * Last revision the buffer got successful saved
675  * @return last revision buffer got saved, -1 if none
676  */
677  qint64 lastSavedRevision() const override;
678 
679  /**
680  * Lock a revision, this will keep it around until released again.
681  * But all revisions will always be cleared on buffer clear() (and therefor load())
682  * @param revision revision to lock
683  */
684  void lockRevision(qint64 revision) override;
685 
686  /**
687  * Release a revision.
688  * @param revision revision to release
689  */
690  void unlockRevision(qint64 revision) override;
691 
692  /**
693  * Transform a cursor from one revision to an other.
694  * @param cursor cursor to transform
695  * @param insertBehavior behavior of this cursor on insert of text at its position
696  * @param fromRevision from this revision we want to transform
697  * @param toRevision to this revision we want to transform, default of -1 is current revision
698  */
701  qint64 fromRevision,
702  qint64 toRevision = -1) override;
703 
704  /**
705  * Transform a cursor from one revision to an other.
706  * @param line line number of the cursor to transform
707  * @param column column number of the cursor to transform
708  * @param insertBehavior behavior of this cursor on insert of text at its position
709  * @param fromRevision from this revision we want to transform
710  * @param toRevision to this revision we want to transform, default of -1 is current revision
711  */
712  void
713  transformCursor(int &line, int &column, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision = -1) override;
714 
715  /**
716  * Transform a range from one revision to an other.
717  * @param range range to transform
718  * @param insertBehaviors behavior of this range on insert of text at its position
719  * @param emptyBehavior behavior on becoming empty
720  * @param fromRevision from this revision we want to transform
721  * @param toRevision to this revision we want to transform, default of -1 is current revision
722  */
726  qint64 fromRevision,
727  qint64 toRevision = -1) override;
728 
729  //
730  // MovingInterface Signals
731  //
732 Q_SIGNALS:
733  /**
734  * This signal is emitted before the cursors/ranges/revisions of a document are destroyed as the document is deleted.
735  * @param document the document which the interface belongs too which is in the process of being deleted
736  */
738 
739  /**
740  * 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
741  * load/reload). While this signal is emitted, still the old document content is around before the clear.
742  * @param document the document which the interface belongs too which will invalidate its data
743  */
745 
746  //
747  // Annotation Interface
748  //
749 public:
750  void setAnnotationModel(KTextEditor::AnnotationModel *model) override;
752 
753 Q_SIGNALS:
754  void annotationModelChanged(KTextEditor::AnnotationModel *, KTextEditor::AnnotationModel *);
755 
756 private:
757  KTextEditor::AnnotationModel *m_annotationModel = nullptr;
758 
759  //
760  // KParts::ReadWrite stuff
761  //
762 public:
763  /**
764  * open the file obtained by the kparts framework
765  * the framework abstracts the loading of remote files
766  * @return success
767  */
768  bool openFile() override;
769 
770  /**
771  * save the file obtained by the kparts framework
772  * the framework abstracts the uploading of remote files
773  * @return success
774  */
775  bool saveFile() override;
776 
777  void setReadWrite(bool rw = true) override;
778 
779  void setModified(bool m) override;
780 
781  bool isAutoReload();
782  KToggleAction *autoReloadToggleAction()
783  {
784  return m_autoReloadMode;
785  };
786  void delayAutoReload();
787 
788 private Q_SLOTS:
789  void autoReloadToggled(bool b);
790 
791 private:
792  void activateDirWatch(const QString &useFileName = QString());
793  void deactivateDirWatch();
794 
795  QString m_dirWatchFile;
796 
797  /**
798  * Make backup copy during saveFile, if configured that way.
799  * @return success? else saveFile should return false and not write the file
800  */
801  bool createBackupFile();
802 
803 public:
804  /**
805  * Type chars in a view.
806  * Characters are filtered in KateViewInternal::isAcceptableInput() before calling typeChars.
807  *
808  * @param view view that received the input
809  * @param chars characters to type
810  */
811  void typeChars(KTextEditor::ViewPrivate *view, QString chars);
812 
813  /**
814  * gets the last line number (lines() - 1)
815  */
816  inline int lastLine() const
817  {
818  return lines() - 1;
819  }
820 
821  // Repaint all of all of the views
822  void repaintViews(bool paintOnlyDirty = true);
823 
824  KateHighlighting *highlight() const;
825 
826 public Q_SLOTS:
827  void tagLines(KTextEditor::LineRange lineRange);
828  void tagLine(int line);
829 
830 private Q_SLOTS:
831  void internalHlChanged();
832 
833 public:
834  void addView(KTextEditor::View *);
835  /** removes the view from the list of views. The view is *not* deleted.
836  * That's your job. Or, easier, just delete the view in the first place.
837  * It will remove itself. TODO: this could be converted to a private slot
838  * connected to the view's destroyed() signal. It is not currently called
839  * anywhere except from the KTextEditor::ViewPrivate destructor.
840  */
842  void setActiveView(KTextEditor::View *);
843 
844  bool ownedView(KTextEditor::ViewPrivate *);
845 
846  int toVirtualColumn(int line, int column) const;
847  int toVirtualColumn(const KTextEditor::Cursor) const;
848  int fromVirtualColumn(int line, int column) const;
849  int fromVirtualColumn(const KTextEditor::Cursor) const;
850 
851  enum NewLineIndent { Indent, NoIndent };
852  enum NewLinePos { Normal, Above, Below };
853 
854  void newLine(KTextEditor::ViewPrivate *view, NewLineIndent indent = NewLineIndent::Indent, NewLinePos newLinePos = Normal); // Changes input
855  void backspace(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor);
856  void del(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor);
857  void transpose(const KTextEditor::Cursor);
858  void swapTextRanges(KTextEditor::Range firstWord, KTextEditor::Range secondWord);
859  bool multiPaste(KTextEditor::ViewPrivate *view, const QStringList &texts);
860  void paste(KTextEditor::ViewPrivate *view, const QString &text);
861 
862 public:
863  enum CommentType {
864  UnComment = -1,
865  ToggleComment = 0,
866  Comment = 1,
867  };
868 
869 private:
870  // Helper function for use with multiple cursors
871  KTextEditor::Cursor backspaceAtCursor(KTextEditor::ViewPrivate *v, KTextEditor::Cursor c);
872  void commentSelection(KTextEditor::Range selection, KTextEditor::Cursor c, bool blockSelect, CommentType changeType);
873  bool skipAutoBrace(QChar closingBracket, KTextEditor::Cursor pos);
874 
875 public:
876  void indent(KTextEditor::Range range, int change);
877  void comment(KTextEditor::ViewPrivate *view, uint line, uint column, CommentType change);
878  void align(KTextEditor::ViewPrivate *view, KTextEditor::Range range);
879  void alignOn(KTextEditor::Range range, const QString &pattern, bool blockwise);
880  void insertTab(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor);
881 
882  enum TextTransform { Uppercase, Lowercase, Capitalize };
883 
884  /**
885  Handling uppercase, lowercase and capitalize for the view.
886 
887  If there is a selection, that is transformed, otherwise for uppercase or
888  lowercase the character right of the cursor is transformed, for capitalize
889  the word under the cursor is transformed.
890  */
891  void transform(KTextEditor::ViewPrivate *view, KTextEditor::Cursor, TextTransform);
892  /**
893  Unwrap a range of lines.
894  */
895  void joinLines(uint first, uint last);
896 
897 private:
898  void transformCursorOrRange(KTextEditor::ViewPrivate *view, const KTextEditor::Cursor, KTextEditor::Range selection, TextTransform);
899 
900  bool removeStringFromBeginning(int line, const QString &str);
901  bool removeStringFromEnd(int line, const QString &str);
902 
903  /**
904  Expand tabs to spaces in typed text, if enabled.
905  @param cursorPos The current cursor position for the inserted characters.
906  @param str The typed characters to expand.
907  */
908  QString eventuallyReplaceTabs(const KTextEditor::Cursor cursorPos, const QString &str) const;
909 
910  /**
911  Find the position (line and col) of the next char
912  that is not a space. If found line and col point to the found character.
913  Otherwise they have both the value -1.
914  @param line Line of the character which is examined first.
915  @param col Column of the character which is examined first.
916  @return True if the specified or a following character is not a space
917  Otherwise false.
918  */
919  bool nextNonSpaceCharPos(int &line, int &col);
920 
921  /**
922  Find the position (line and col) of the previous char
923  that is not a space. If found line and col point to the found character.
924  Otherwise they have both the value -1.
925  @return True if the specified or a preceding character is not a space.
926  Otherwise false.
927  */
928  bool previousNonSpaceCharPos(int &line, int &col);
929 
930  /**
931  * Sets a comment marker as defined by the language providing the attribute
932  * @p attrib on the line @p line
933  */
934  void addStartLineCommentToSingleLine(int line, int attrib = 0);
935  /**
936  * Removes a comment marker as defined by the language providing the attribute
937  * @p attrib on the line @p line
938  */
939  bool removeStartLineCommentFromSingleLine(int line, int attrib = 0);
940 
941  /**
942  * @see addStartLineCommentToSingleLine.
943  */
944  void addStartStopCommentToSingleLine(int line, int attrib = 0);
945  /**
946  *@see removeStartLineCommentFromSingleLine.
947  */
948  bool removeStartStopCommentFromSingleLine(int line, int attrib = 0);
949  /**
950  *@see removeStartLineCommentFromSingleLine.
951  */
952  bool removeStartStopCommentFromRegion(const KTextEditor::Cursor start, const KTextEditor::Cursor end, int attrib = 0);
953 
954  /**
955  * Add a comment marker as defined by the language providing the attribute
956  * @p attrib to each line in the selection.
957  */
958  void addStartStopCommentToSelection(KTextEditor::Range, bool blockSelection, int attrib = 0);
959  /**
960  * @see addStartStopCommentToSelection.
961  */
962  void addStartLineCommentToSelection(KTextEditor::Range, int attrib = 0);
963 
964  /**
965  * Removes comment markers relevant to the language providing
966  * the attribute @p attrib from each line in the selection.
967  *
968  * @return whether the operation succeeded.
969  */
970  bool removeStartStopCommentFromSelection(KTextEditor::Range, int attrib = 0);
971  /**
972  * @see removeStartStopCommentFromSelection.
973  */
974  bool removeStartLineCommentFromSelection(KTextEditor::Range, int attrib, bool toggleComment);
975 
976 public:
977  KTextEditor::Range findMatchingBracket(const KTextEditor::Cursor start, int maxLines);
978 
979 public:
980  QString documentName() const override
981  {
982  return m_docName;
983  }
984 
985 private:
986  void updateDocName();
987  static void uniquifyDocNames(const std::vector<KTextEditor::DocumentPrivate *> &docs);
988 
989 public:
990  /**
991  * @return whether the document is modified on disk since last saved
992  */
994  {
995  return m_modOnHd;
996  }
997 
998  void setModifiedOnDisk(ModifiedOnDiskReason reason) override;
999 
1000  void setModifiedOnDiskWarning(bool on) override;
1001 
1002 public Q_SLOTS:
1003  /**
1004  * Ask the user what to do, if the file has been modified on disk.
1005  * Reimplemented from KTextEditor::Document.
1006  */
1007  virtual void slotModifiedOnDisk(KTextEditor::View *v = nullptr);
1008 
1009  /**
1010  * Reloads the current document from disk if possible
1011  */
1012  bool documentReload() override;
1013 
1014  bool documentSave() override;
1015  bool documentSaveAs() override;
1016  bool documentSaveAsWithEncoding(const QString &encoding);
1017  bool documentSaveCopyAs();
1018 
1019  bool save() override;
1020 
1021 public:
1022  bool saveAs(const QUrl &url) override;
1023 
1024 Q_SIGNALS:
1025  /**
1026  * Indicate this file is modified on disk
1027  * @param doc the KTextEditor::Document object that represents the file on disk
1028  * @param isModified indicates the file was modified rather than created or deleted
1029  * @param reason the reason we are emitting the signal.
1030  */
1032 
1033 private:
1034  // helper to handle the embedded notification for externally modified files
1035  QPointer<KateModOnHdPrompt> m_modOnHdHandler;
1036 
1037 private Q_SLOTS:
1038  void onModOnHdSaveAs();
1039  void onModOnHdClose();
1040  void onModOnHdReload();
1041  void onModOnHdAutoReload();
1042  void onModOnHdIgnore();
1043 
1044 public:
1045  bool setEncoding(const QString &e) override;
1046  QString encoding() const override;
1047 
1048 public Q_SLOTS:
1049  void setWordWrap(bool on);
1050  void setWordWrapAt(uint col);
1051 
1052 public:
1053  bool wordWrap() const;
1054  uint wordWrapAt() const;
1055 
1056 public Q_SLOTS:
1057  void setPageUpDownMovesCursor(bool on);
1058 
1059 public:
1060  bool pageUpDownMovesCursor() const;
1061 
1062  // code folding
1063 public:
1064  /**
1065  * Same as plainKateTextLine(), except that it is made sure
1066  * the line is highlighted.
1067  */
1069 
1070  //! @copydoc KateBuffer::plainLine()
1072 
1073 Q_SIGNALS:
1074  void aboutToRemoveText(KTextEditor::Range);
1075 
1076 private Q_SLOTS:
1077  void slotModOnHdDirty(const QString &path);
1078  void slotModOnHdCreated(const QString &path);
1079  void slotModOnHdDeleted(const QString &path);
1080  void slotDelayedHandleModOnHd();
1081 
1082 private:
1083  /**
1084  * Create a git compatible sha1 checksum of the file, if it is a local file.
1085  * The result can be accessed through KateBuffer::digest().
1086  *
1087  * @return whether the operation was attempted and succeeded.
1088  */
1089  bool createDigest();
1090 
1091  /**
1092  * create a string for the modonhd warnings, giving the reason.
1093  */
1094  QString reasonedMOHString() const;
1095 
1096  /**
1097  * Removes all trailing whitespace in the document and add new line at eof
1098  * if configured that way.
1099  */
1100  void removeTrailingSpacesAndAddNewLineAtEof();
1101 
1102 public:
1103  /**
1104  * Returns a git compatible sha1 checksum of this document on disk.
1105  * @return checksum for this document on disk
1106  */
1107  QByteArray checksum() const override;
1108 
1109  /**
1110  * @return false if @p newType is an invalid mode.
1111  */
1112  bool updateFileType(const QString &newType, bool user = false);
1113 
1114  QString fileType() const
1115  {
1116  return m_fileType;
1117  }
1118 
1119  /**
1120  * Get access to buffer of this document.
1121  * Is needed to create cursors and ranges for example.
1122  * @return document buffer
1123  */
1125  {
1126  return *m_buffer;
1127  }
1128 
1129  /**
1130  * set indentation mode by user
1131  * this will remember that a user did set it and will avoid reset on save
1132  */
1134  {
1135  m_indenterSetByUser = true;
1136  }
1137 
1138  /**
1139  * User did set encoding for next reload => enforce it!
1140  */
1142  {
1143  m_userSetEncodingForNextReload = true;
1144  }
1145 
1146  //
1147  // REALLY internal data ;)
1148  //
1149 private:
1150  // text buffer
1151  KateBuffer *const m_buffer;
1152 
1153  // indenter
1154  KateAutoIndent *const m_indenter;
1155 
1156  bool m_hlSetByUser = false;
1157  bool m_bomSetByUser = false;
1158  bool m_indenterSetByUser = false;
1159  bool m_userSetEncodingForNextReload = false;
1160 
1161  bool m_modOnHd = false;
1162  KToggleAction *m_autoReloadMode;
1163  QTimer m_autoReloadThrottle;
1164  ModifiedOnDiskReason m_modOnHdReason = OnDiskUnmodified;
1165  ModifiedOnDiskReason m_prevModOnHdReason = OnDiskUnmodified;
1166 
1167  QString m_docName;
1168  int m_docNameNumber = 0;
1169 
1170  // file type !!!
1171  QString m_fileType;
1172  bool m_fileTypeSetByUser = false;
1173 
1174  /**
1175  * document is still reloading a file
1176  */
1177  bool m_reloading = false;
1178 
1179 public Q_SLOTS:
1180  void slotQueryClose_save(bool *handled, bool *abortClosing);
1181 
1182 public:
1183  bool queryClose() override;
1184 
1185  /**
1186  * Configuration
1187  */
1188 public:
1189  KateDocumentConfig *config()
1190  {
1191  return m_config.get();
1192  }
1193  KateDocumentConfig *config() const
1194  {
1195  return m_config.get();
1196  }
1197 
1198  void updateConfig();
1199 
1200 private:
1201  void makeAttribs(bool needInvalidate = true);
1202 
1203  std::unique_ptr<KateDocumentConfig> const m_config;
1204 
1205  /**
1206  * Variable Reader
1207  * TODO add register functionality/ktexteditor interface
1208  */
1209 private:
1210  /**
1211  * read dir config file
1212  */
1213  void readDirConfig();
1214 
1215  /**
1216  Reads all the variables in the document.
1217  Called when opening/saving a document
1218  */
1219  void readVariables(bool onlyViewAndRenderer = false);
1220 
1221  /**
1222  Reads and applies the variables in a single line
1223  TODO registered variables gets saved in a [map]
1224  */
1225  void readVariableLine(const QString &t, bool onlyViewAndRenderer = false);
1226  /**
1227  Sets a view variable in all the views.
1228  */
1229  void setViewVariable(const QString &var, const QString &val);
1230  /**
1231  @return weather a string value could be converted
1232  to a bool value as supported.
1233  The value is put in *result.
1234  */
1235  static bool checkBoolValue(QString value, bool *result);
1236  /**
1237  @return weather a string value could be converted
1238  to a integer value.
1239  The value is put in *result.
1240  */
1241  static bool checkIntValue(const QString &value, int *result);
1242  /**
1243  Feeds value into @p col using QColor::setNamedColor() and returns
1244  whether the color is valid
1245  */
1246  static bool checkColorValue(const QString &value, QColor &col);
1247 
1248  bool m_fileChangedDialogsActivated = false;
1249 
1250  //
1251  // KTextEditor::ConfigInterface
1252  //
1253 public:
1254  QStringList configKeys() const override;
1255  QVariant configValue(const QString &key) override;
1256  void setConfigValue(const QString &key, const QVariant &value) override;
1257 
1258  //
1259  // KTextEditor::RecoveryInterface
1260  //
1261 public:
1262  bool isDataRecoveryAvailable() const override;
1263  void recoverData() override;
1264  void discardDataRecovery() override;
1265 
1266  //
1267  // Highlighting information
1268  //
1269 public:
1270  QStringList embeddedHighlightingModes() const override;
1271  QString highlightingModeAt(const KTextEditor::Cursor &position) override;
1272 
1273  //
1274  // BEGIN: KTextEditor::MessageInterface
1275  //
1276 public:
1277  bool postMessage(KTextEditor::Message *message) override;
1278 
1279 public Q_SLOTS:
1280  void messageDestroyed(KTextEditor::Message *message);
1281 
1282 private:
1284  // END KTextEditor::MessageInterface
1285 
1286 public:
1287  QString defaultDictionary() const;
1288  QList<QPair<KTextEditor::MovingRange *, QString>> dictionaryRanges() const;
1289  bool isOnTheFlySpellCheckingEnabled() const;
1290  KateOnTheFlyChecker *onTheFlySpellChecker() const
1291  {
1292  return m_onTheFlyChecker;
1293  }
1294 
1295  QString dictionaryForMisspelledRange(KTextEditor::Range range) const;
1296  void clearMisspellingForWord(const QString &word);
1297 
1298 public Q_SLOTS:
1299  void clearDictionaryRanges();
1300  void setDictionary(const QString &dict, KTextEditor::Range range, bool blockmode);
1301  void setDictionary(const QString &dict, KTextEditor::Range range);
1302  void setDefaultDictionary(const QString &dict);
1303  void onTheFlySpellCheckingEnabled(bool enable);
1304  void refreshOnTheFlyCheck(KTextEditor::Range range = KTextEditor::Range::invalid());
1305 
1306 Q_SIGNALS:
1307  void dictionaryRangesPresent(bool yesNo);
1308  void defaultDictionaryChanged(KTextEditor::DocumentPrivate *document);
1309 
1310 public:
1311  bool containsCharacterEncoding(KTextEditor::Range range);
1312 
1313  typedef QList<QPair<int, int>> OffsetList;
1314 
1315  static int computePositionWrtOffsets(const OffsetList &offsetList, int pos);
1316 
1317  /**
1318  * The first OffsetList is from decoded to encoded, and the second OffsetList from
1319  * encoded to decoded.
1320  **/
1322  KTextEditor::DocumentPrivate::OffsetList &decToEncOffsetList,
1323  KTextEditor::DocumentPrivate::OffsetList &encToDecOffsetList);
1324  void replaceCharactersByEncoding(KTextEditor::Range range);
1325 
1326 protected:
1327  KateOnTheFlyChecker *m_onTheFlyChecker = nullptr;
1328  QString m_defaultDictionary;
1330 
1331  // from KTextEditor::MovingRangeFeedback
1332  void rangeInvalid(KTextEditor::MovingRange *movingRange) override;
1333  void rangeEmpty(KTextEditor::MovingRange *movingRange) override;
1334 
1335  void deleteDictionaryRange(KTextEditor::MovingRange *movingRange);
1336 
1337 private:
1338  Kate::SwapFile *m_swapfile;
1339 
1340 public:
1341  Kate::SwapFile *swapFile();
1342 
1343  // helpers for scripting and codefolding
1344  int defStyleNum(int line, int column);
1345  bool isComment(int line, int column);
1346 
1347 public:
1348  /**
1349  * Find the next modified/saved line, starting at @p startLine. If @p down
1350  * is \e true, the search is performed downwards, otherwise upwards.
1351  * @return the touched line in the requested search direction, or -1 if not found
1352  */
1353  int findTouchedLine(int startLine, bool down);
1354 
1355 private Q_SLOTS:
1356  /**
1357  * watch for all started io jobs to remember if file is perhaps loading atm
1358  * @param job started job
1359  */
1360  void slotStarted(KIO::Job *job);
1361  void slotCompleted();
1362  void slotCanceled();
1363 
1364  /**
1365  * trigger display of loading message, after 1000 ms
1366  */
1367  void slotTriggerLoadingMessage();
1368 
1369  /**
1370  * Abort loading
1371  */
1372  void slotAbortLoading();
1373 
1374  void slotUrlChanged(const QUrl &url);
1375 
1376 private:
1377  /**
1378  * different possible states
1379  */
1380  enum DocumentStates {
1381  /**
1382  * Idle
1383  */
1384  DocumentIdle,
1385 
1386  /**
1387  * Loading
1388  */
1389  DocumentLoading,
1390 
1391  /**
1392  * Saving
1393  */
1394  DocumentSaving,
1395 
1396  /**
1397  * Pre Saving As, this is between ::saveAs is called and ::save
1398  */
1399  DocumentPreSavingAs,
1400 
1401  /**
1402  * Saving As
1403  */
1404  DocumentSavingAs
1405  };
1406 
1407  /**
1408  * current state
1409  */
1410  DocumentStates m_documentState = DocumentIdle;
1411 
1412  /**
1413  * read-write state before loading started
1414  */
1415  bool m_readWriteStateBeforeLoading = false;
1416 
1417  /**
1418  * if the document is untitled
1419  */
1420  bool m_isUntitled = true;
1421  /**
1422  * loading job, we want to cancel with cancel in the loading message
1423  */
1424  QPointer<KJob> m_loadingJob;
1425 
1426  /**
1427  * message to show during loading
1428  */
1429  QPointer<KTextEditor::Message> m_loadingMessage;
1430 
1431  /**
1432  * Was there any open error on last file loading?
1433  */
1434  bool m_openingError = false;
1435 
1436  /**
1437  * Last open file error message
1438  */
1439  QString m_openingErrorMessage;
1440 
1441 public:
1442  /**
1443  * reads the line length limit from config, if it is not overridden
1444  */
1445  int lineLengthLimit() const;
1446 
1447 public Q_SLOTS:
1448  void openWithLineLengthLimitOverride();
1449 
1450 private:
1451  /**
1452  * timer for delayed handling of mod on hd
1453  */
1454  QTimer m_modOnHdTimer;
1455 
1456 private:
1457  /**
1458  * currently active template handler; there can be only one
1459  */
1460  QPointer<KateTemplateHandler> m_activeTemplateHandler;
1461 
1462 private:
1463  /**
1464  * current autobrace range
1465  */
1466  std::unique_ptr<KTextEditor::MovingRange> m_currentAutobraceRange;
1467  /**
1468  * current autobrace closing character (e.g. ']')
1469  */
1470  QChar m_currentAutobraceClosingChar;
1471 
1472 private Q_SLOTS:
1473  void checkCursorForAutobrace(KTextEditor::View *view, const KTextEditor::Cursor newPos);
1474 
1475 public:
1476  void setActiveTemplateHandler(KateTemplateHandler *handler);
1477 
1478 Q_SIGNALS:
1479  void loaded(KTextEditor::DocumentPrivate *document);
1480 
1481 private:
1482  // To calculate a QHash.keys() is quite expensive,
1483  // better keep a copy of that list updated when a view is added or removed.
1484  QList<KTextEditor::View *> m_viewsCache;
1485 
1486  QTimer m_autoSaveTimer;
1487 };
1488 
1489 #endif
Mark extension interface for the Document.
virtual bool setText(const QString &text)=0
Set the given text as new document content.
qint64 lastSavedRevision() const override
Last revision the buffer got successful saved.
virtual void setMarkIcon(MarkTypes markType, const QIcon &icon)=0
Set the mark's icon to icon.
QIcon markIcon(MarkInterface::MarkTypes markType) const override
Get the mark's icon.
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.
QPixmap markPixmap(MarkInterface::MarkTypes) const override
Get the mark's pixmap.
virtual QStringList embeddedHighlightingModes() const =0
Get all available highlighting modes for the current document.
virtual void marksChanged(KTextEditor::Document *document)=0
The document emits this signal whenever a mark mask changed.
void typeChars(KTextEditor::ViewPrivate *view, QString chars)
Type chars in a view.
bool updateFileType(const QString &newType, bool user=false)
void saveEditingPositions(const KTextEditor::Cursor cursor)
Saves the editing positions into the stack.
QString decodeCharacters(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.
virtual bool postMessage(Message *message)=0
Post message to the Document and its Views.
bool editStart()
Enclose editor actions with editStart() and editEnd() to group them.
virtual QString highlightingModeAt(const Cursor &position)=0
Get the highlight mode used at a given position in the document.
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...
virtual QString wordAt(const KTextEditor::Cursor &cursor) const =0
Get the word at the text position cursor.
virtual bool insertLines(int line, const QStringList &text)=0
Insert line(s) at the given line number.
bool wrapParagraph(int first, int last)
Wrap lines touched by the selection with respect of existing paragraphs.
void editLineUnWrapped(int line, int col)
Emitted each time text from nextLine was upwrapped onto line.
KIOCORE_EXPORT DeleteJob * del(const QList< QUrl > &src, JobFlags flags=DefaultFlags)
virtual QStringList textLines(const Range &range, bool block=false) const =0
Get the document content within the given range.
KateBuffer & buffer()
Get access to buffer of this document.
virtual bool documentSaveAs()=0
Save the current file to another location.
void setDontChangeHlOnSave()
allow to mark, that we changed hl on user wish and should not reset it atm used for the user visible ...
Q_SLOTSQ_SLOTS
bool setHighlightingMode(const QString &name) override
Set the current mode of the document by giving its name.
Mark extension interface for the Document, version 2.
QWidget * widget() override
void rangeEmpty(KTextEditor::MovingRange *movingRange) override
The range is now empty (ie.
An model for providing line annotation information.
void setModifiedOnDiskWarning(bool on) override
Control, whether the editor should show a warning dialog whenever a file was modified on disk.
virtual int lines() const =0
Get the count of lines of the document.
DefaultStyle
The following lists all valid default styles that are used for the syntax highlighting files in the i...
Definition: attribute.h:28
void rangeInvalid(KTextEditor::MovingRange *movingRange) override
The range is now invalid (ie.
virtual bool isDataRecoveryAvailable() const =0
Returns whether a recovery is available for the current document.
Kate::TextLine plainKateTextLine(int i)
Return line lineno.
void markToolTipRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint position, bool &handled)
The document emits this signal whenever the mark is hovered using the mouse, and the receiver may sho...
QStringList highlightingModes() const override
Return a list of the names of all possible modes.
Q_SCRIPTABLE Q_NOREPLY void start()
constexpr static Cursor invalid() Q_DECL_NOEXCEPT
Returns an invalid cursor.
Definition: cursor.h:109
@ AllowEmpty
allow range to be empty
Definition: movingrange.h:167
virtual void setAnnotationModel(AnnotationModel *model)=0
Sets a new AnnotationModel for this document to provide annotation information for each line.
bool handleMarkContextMenu(int line, QPoint position)
Returns true if the context-menu event should not further be processed.
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 isModifiedOnDisc()
Definition: katedocument.h:993
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.
InsertBehavior
Insert behavior of this cursor, should it stay if text is insert at its position or should it move.
Definition: movingcursor.h:64
void setModifiedOnDisk(ModifiedOnDiskReason reason) override
Set the document's modified-on-disk state to reason.
An object representing lines from a start line to an end line.
Definition: linerange.h:37
void clearEditingPosStack()
Removes all the elements in m_editingStack of the respective document.
An object representing a section of text, from one Cursor to another.
virtual bool print()=0
Print the document.
virtual void setEditableMarks(uint markMask)=0
Set the mark mask the user is allowed to toggle to markMask.
const QList< QKeySequence > & undo()
bool editRemoveText(int line, int col, int len)
Remove a string in the given line/column.
virtual bool isLineTouched(int line) const =0
Check whether line was touched since the file was opened.
virtual bool insertText(const Cursor &position, const QString &text, bool block=false)=0
Insert text at position.
virtual void printPreview()=0
Shows the print preview dialog/.
bool editWrapLine(int line, int col, bool newLine=true, bool *newLineAdded=nullptr)
Wrap line.
virtual void setVariable(const QString &name, const QString &value)
Set the variable name to value.
void bomSetByUser()
Set that the BOM marker is forced via the tool menu.
bool documentReload() override
Reloads the current document from disk if possible.
Document interface for MovingCursors and MovingRanges.
QString highlightingMode() const override
Return the name of the currently used mode.
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.
bool handleMarkClick(int line)
Returns true if the click on the mark should not be further processed.
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.
bool isModified() const
void writeSessionConfig(KConfigGroup &config, const QSet< QString > &flags=QSet< QString >()) override
Write session settings to the config.
MarkTypes
Predefined mark types.
virtual void addMark(int line, uint markType)=0
Add marks of type markType to line.
void joinLines(uint first, uint last)
Unwrap a range of lines.
virtual Cursor documentEnd() const =0
End position of the document.
bool editMarkLineAutoWrapped(int line, bool autowrapped)
Mark line as autowrapped.
void aboutToDeleteMovingInterfaceContent(KTextEditor::Document *document)
This signal is emitted before the cursors/ranges/revisions of a document are destroyed as the documen...
void editBegin()
Alias for editStart()
Definition: katedocument.h:227
void unlockRevision(qint64 revision) override
Release a revision.
int findTouchedLine(int startLine, bool down)
Find the next modified/saved line, starting at startLine.
virtual int totalCharacters() const =0
Get the count of characters in the document.
uint mark(int line) override
Get all marks set on the line.
QStringList configKeys() const override
Get a list of all available keys.
This dialog will prompt the user for what do with a file that is modified on disk.
Definition: katedialogs.h:348
The Cursor represents a position in a Document.
Definition: cursor.h:71
virtual void setMarkDescription(MarkTypes mark, const QString &text)=0
Set the mark's description to text.
virtual bool queryClose()
Comment
void transformCursor(KTextEditor::Cursor &cursor, KTextEditor::MovingCursor::InsertBehavior insertBehavior, qint64 fromRevision, qint64 toRevision=-1) override
Transform a cursor from one revision to an other.
virtual bool saveAs(const QUrl &url)
virtual bool clear()=0
Remove the whole content of the document.
The KateBuffer class maintains a collections of lines.
Definition: katebuffer.h:30
virtual QString variable(const QString &name) const
Returns the value for the variable name.
virtual void setMarkPixmap(MarkTypes mark, const QPixmap &pixmap)=0
Set the mark's pixmap to pixmap.
void textInsertedRange(KTextEditor::Document *document, const KTextEditor::Range &range)
The document emits this signal whenever text was inserted.
Class for tracking editing actions.
Definition: kateswapfile.h:33
int lastLine() const
gets the last line number (lines() - 1)
Definition: katedocument.h:816
virtual int lineLength(int line) const =0
Get the length of a given line in characters.
void markContextMenuRequested(KTextEditor::Document *document, KTextEditor::Mark mark, QPoint pos, bool &handled)
The document emits this signal whenever the mark is right-clicked to show a context menu.
@ DoNotExpand
Don't expand to encapsulate new characters in either direction. This is the default.
Definition: movingrange.h:154
virtual QString line(int line) const =0
Get a single text line.
KateUndoManager implements a document's history.
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:146
virtual bool isLineModified(int line) const =0
Check whether line currently contains unsaved data.
virtual void recoverData()=0
If recover data is available, calling recoverData() will trigger the recovery of the data.
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.
virtual bool insertLine(int line, const QString &text)=0
Insert line(s) at the given line number.
bool wrapText(int startLine, int endLine)
Warp a line.
virtual void setReadWrite(bool readwrite=true)
QVariant configValue(const QString &key) override
Get a value for the key.
bool editInsertLine(int line, const QString &s)
Insert a string at the given line.
KTextEditor::DefaultStyle defaultStyleAt(const KTextEditor::Cursor &position) const override
Get the default style of the character located at position.
void markClicked(KTextEditor::Document *document, KTextEditor::Mark mark, bool &handled)
The document emits this signal whenever the mark is left-clicked.
ModifiedOnDiskReason
Reasons why a document is modified on disk.
bool closeUrl() override
bool saveFile() override
save the file obtained by the kparts framework the framework abstracts the uploading of remote files
bool editUnWrapLine(int line, bool removeLine=true, int length=0)
Unwrap line.
virtual QString documentName() const =0
Get this document's name.
void userSetEncodingForNextReload()
User did set encoding for next reload => enforce it!
virtual bool removeText(const Range &range, bool block=false)=0
Remove the text specified in range.
QByteArray checksum() const override
Returns a git compatible sha1 checksum of this document on disk.
virtual bool removeLine(int line)=0
Remove line from the document.
virtual bool openUrl(const QUrl &url)
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
Definition: katetextblock.h:22
QStringList modes() const override
Return a list of the names of all possible modes.
void setMetaData(const KPluginMetaData &metaData)
Q_SIGNALSQ_SIGNALS
A Document extension interface for handling Annotations.
void aboutToInvalidateMovingInterfaceContent(KTextEditor::Document *document)
This signal is emitted before the ranges of a document are invalidated and the revisions are deleted ...
uint editableMarks() const override
Get, which marks can be toggled by the user.
QString markDescription(MarkInterface::MarkTypes) const override
Get the mark's description to text.
Inserts a template and offers advanced snippet features, like navigation and mirroring.
KTextEditor::Cursor lastEditingPosition(EditingPositionKind nextOrPrevious, KTextEditor::Cursor)
Returns the next or previous position cursor in this document from the stack depending on the argumen...
External modification extension interface for the Document.
void setConfigValue(const QString &key, const QVariant &value) override
Set a the key's value to value.
virtual bool replaceText(const Range &range, const QString &text, bool block=false)
Replace text from range with specified text.
Definition: document.cpp:90
EmptyBehavior
Behavior of range if it becomes empty.
Definition: movingrange.h:166
Q_INTERFACES(...)
A class which provides notifications of state changes to a MovingRange.
virtual void clearMark(int line)=0
Clear all marks set in the line.
KPluginMetaData metaData() const
virtual bool documentSave()=0
Save the current file.
virtual QString encoding() const =0
Get the current chosen encoding.
void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range, const QString &oldText)
The document emits this signal whenever range was removed, i.e.
virtual QString text() const =0
Get the document content.
void readSessionConfig(const KConfigGroup &config, const QSet< QString > &flags=QSet< QString >()) override
Read session settings from the given config.
virtual void setMark(int line, uint markType)=0
Set the line's mark types to markType.
@ MoveOnInsert
move on insert
Definition: movingcursor.h:66
Provides Auto-Indent functionality for katepart.
Kate::TextLine kateTextLine(int i)
Same as plainKateTextLine(), except that it is made sure the line is highlighted.
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...
bool editInsertText(int line, int col, const QString &s)
Add a string in the given line/column.
A range that is bound to a specific Document, and maintains its position.
Definition: movingrange.h:144
KTextEditor::MovingCursor * newMovingCursor(const KTextEditor::Cursor &position, KTextEditor::MovingCursor::InsertBehavior insertBehavior=KTextEditor::MovingCursor::MoveOnInsert) override
Create a new moving cursor for this document.
virtual void slotModifiedOnDisk(KTextEditor::View *v=nullptr)
Ask the user what to do, if the file has been modified on disk.
virtual void removeMark(int line, uint markType)=0
Remove the mark mask of type markType from line.
virtual bool isEditingTransactionRunning() const =0
Check whether an editing transaction is currently running.
virtual bool setEncoding(const QString &encoding)=0
Set the encoding for this document.
virtual QChar characterAt(const Cursor &position) const =0
Get the character at text position cursor.
KateDocumentConfig * config()
Configuration.
qint64 revision() const override
Current revision.
bool openFile() override
open the file obtained by the kparts framework the framework abstracts the loading of remote files
virtual void discardDataRecovery()=0
If recover data is available, calling discardDataRecovery() will discard the recover data and the rec...
QString mimeType() override
Tries to detect mime-type based on file name and content of buffer.
virtual bool isValidTextPosition(const KTextEditor::Cursor &cursor) const =0
Get whether cursor is a valid text position.
virtual QList< View * > views() const =0
Returns the views pre-casted to KTextEditor::Views.
virtual void clearMarks()=0
Clear all marks in the entire document.
Mark class containing line and mark types.
Definition: markinterface.h:42
void transform(KTextEditor::ViewPrivate *view, KTextEditor::Cursor, TextTransform)
Handling uppercase, lowercase and capitalize for the view.
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.
This class holds a Message to display in Views.
Definition: message.h:93
virtual void markChanged(KTextEditor::Document *document, KTextEditor::Mark mark, KTextEditor::MarkInterface::MarkChangeAction action)=0
The document emits this signal whenever the mark changes.
KIOWIDGETS_EXPORT PasteJob * paste(const QMimeData *mimeData, const QUrl &destDir, JobFlags flags=DefaultFlags)
virtual bool save()
constexpr static Range invalid() Q_DECL_NOEXCEPT
Returns an invalid range.
int lineLengthLimit() const
reads the line length limit from config, if it is not overridden
QObject * parent() const const
A Cursor which is bound to a specific Document, and maintains its position.
Definition: movingcursor.h:54
QString message
bool editRemoveLine(int line)
Remove a line.
const QList< QKeySequence > & redo()
virtual KTextEditor::Range wordRangeAt(const KTextEditor::Cursor &cursor) const =0
Get the text range for the word located under the text position cursor.
void editLineWrapped(int line, int col, int len)
Emitted when text from line was wrapped at position pos onto line nextLine.
Config interface extension for the Document and View.
MarkChangeAction
Possible actions on a mark.
void lockRevision(qint64 revision) override
Lock a revision, this will keep it around until released again.
virtual AnnotationModel * annotationModel() const =0
returns the currently set AnnotationModel or 0 if there's none set
bool editEnd()
End a editor operation.
A KParts derived class representing a text document.
Definition: document.h:185
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed Aug 17 2022 03:54:01 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.