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

KDE's Doxygen guidelines are available online.