KTextEditor

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

KDE's Doxygen guidelines are available online.