1 | /* |
2 | SPDX-FileCopyrightText: 2002 John Firebaugh <jfirebaugh@kde.org> |
3 | SPDX-FileCopyrightText: 2001 Christoph Cullmann <cullmann@kde.org> |
4 | SPDX-FileCopyrightText: 2001-2010 Joseph Wenninger <jowenn@kde.org> |
5 | SPDX-FileCopyrightText: 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de> |
6 | |
7 | SPDX-License-Identifier: LGPL-2.0-or-later |
8 | */ |
9 | |
10 | #ifndef kate_view_h |
11 | #define kate_view_h |
12 | |
13 | #include <ktexteditor/linerange.h> |
14 | #include <ktexteditor/mainwindow.h> |
15 | #include <ktexteditor/view.h> |
16 | |
17 | #include <QJsonDocument> |
18 | #include <QPointer> |
19 | #include <QTimer> |
20 | |
21 | #include <array> |
22 | |
23 | #include "katetextfolding.h" |
24 | #include "katetextrange.h" |
25 | |
26 | namespace KTextEditor |
27 | { |
28 | class AnnotationModel; |
29 | class Message; |
30 | class InlineNoteProvider; |
31 | class DocumentPrivate; |
32 | } |
33 | |
34 | namespace Kate |
35 | { |
36 | class TextCursor; |
37 | } |
38 | class KateBookmarks; |
39 | class KateRendererConfig; |
40 | class KateViewConfig; |
41 | class KateRenderer; |
42 | class KateSpellCheckDialog; |
43 | class KateCompletionWidget; |
44 | class KateViewInternal; |
45 | class KateViewBar; |
46 | class KateTextPreview; |
47 | class KateGotoBar; |
48 | class KateDictionaryBar; |
49 | class ; |
50 | class KateMessageWidget; |
51 | class KateIconBorder; |
52 | class KateStatusBar; |
53 | class KateViewEncodingAction; |
54 | class ; |
55 | class KateAbstractInputMode; |
56 | class ; |
57 | class KateMessageLayout; |
58 | class KateInlineNoteData; |
59 | class MulticursorTest; |
60 | |
61 | class KToggleAction; |
62 | class KSelectAction; |
63 | |
64 | class QAction; |
65 | class QTextLayout; |
66 | class QSpacerItem; |
67 | class ; |
68 | class QActionGroup; |
69 | |
70 | namespace KTextEditor |
71 | { |
72 | // |
73 | // Kate KTextEditor::View class ;) |
74 | // |
75 | class KTEXTEDITOR_EXPORT ViewPrivate final : public KTextEditor::View |
76 | { |
77 | Q_OBJECT |
78 | |
79 | friend class KTextEditor::View; |
80 | friend class ::KateViewInternal; |
81 | friend class ::KateIconBorder; |
82 | friend class ::KateTextPreview; |
83 | friend MulticursorTest; |
84 | |
85 | public: |
86 | ViewPrivate(KTextEditor::DocumentPrivate *doc, QWidget *parent, KTextEditor::MainWindow *mainWindow = nullptr); |
87 | ~ViewPrivate() override; |
88 | |
89 | /** |
90 | * Get the view's main window, if any |
91 | * \return the view's main window |
92 | */ |
93 | KTextEditor::MainWindow *mainWindow() const override |
94 | { |
95 | return m_mainWindow; |
96 | } |
97 | |
98 | KTextEditor::Document *document() const override; |
99 | |
100 | ViewMode viewMode() const override; |
101 | QString viewModeHuman() const override; |
102 | InputMode viewInputMode() const override; |
103 | QString viewInputModeHuman() const override; |
104 | |
105 | void setViewInputMode(InputMode mode) override |
106 | { |
107 | setInputMode(mode); |
108 | } |
109 | |
110 | void setInputMode(InputMode mode, const bool rememberInConfig = true); |
111 | |
112 | public: |
113 | KateViewInternal *getViewInternal() |
114 | { |
115 | return m_viewInternal; |
116 | } |
117 | |
118 | // |
119 | // KTextEditor::ClipboardInterface |
120 | // |
121 | public Q_SLOTS: |
122 | void paste(const QString *textToPaste = nullptr); |
123 | void cut(); |
124 | void copy(); |
125 | void screenshot(); |
126 | |
127 | private Q_SLOTS: |
128 | /** |
129 | * Paste the global mouse selection. Support for Selection is provided only |
130 | * on systems with a global mouse selection (e.g. X11). |
131 | */ |
132 | void pasteSelection(); |
133 | |
134 | /** |
135 | * Insert contents of selected file into the currently open file |
136 | */ |
137 | void pasteFromFile(); |
138 | |
139 | /** |
140 | * Copy current selected stuff and paste previous content of clipboard as one operation. |
141 | */ |
142 | void swapWithClipboard(); |
143 | |
144 | /** |
145 | * Wrap lines touched by the selection with respect of existing paragraphs. |
146 | * Work is done by KTextEditor::DocumentPrivate::wrapParagraph |
147 | */ |
148 | void applyWordWrap(); |
149 | |
150 | /** |
151 | * Copy the current file name and line number |
152 | */ |
153 | void copyFileLocation() const; |
154 | |
155 | // |
156 | // KTextEditor::PopupMenuInterface |
157 | // |
158 | public: |
159 | void (QMenu *) override; |
160 | QMenu *() const override; |
161 | QMenu *(QMenu * = nullptr) const override; |
162 | |
163 | private Q_SLOTS: |
164 | void (); |
165 | void (); |
166 | |
167 | private: |
168 | QPointer<QMenu> ; |
169 | |
170 | // |
171 | // KTextEditor::ViewCursorInterface |
172 | // |
173 | public: |
174 | bool setCursorPosition(KTextEditor::Cursor position) override; |
175 | |
176 | KTextEditor::Cursor cursorPosition() const override; |
177 | |
178 | KTextEditor::Cursor cursorPositionVirtual() const override; |
179 | |
180 | QPoint cursorToCoordinate(KTextEditor::Cursor cursor) const override; |
181 | |
182 | KTextEditor::Cursor coordinatesToCursor(const QPoint &coord) const override; |
183 | |
184 | QPoint cursorPositionCoordinates() const override; |
185 | |
186 | bool setCursorPositionVisual(const KTextEditor::Cursor position); |
187 | |
188 | QScrollBar *verticalScrollBar() const override; |
189 | QScrollBar *horizontalScrollBar() const override; |
190 | |
191 | /** |
192 | * Return the virtual cursor column, each tab is expanded into the |
193 | * document's tabWidth characters. If word wrap is off, the cursor may be |
194 | * behind the line's length. |
195 | */ |
196 | int virtualCursorColumn() const; |
197 | |
198 | bool mouseTrackingEnabled() const override; |
199 | bool setMouseTrackingEnabled(bool enable) override; |
200 | |
201 | /* |
202 | * multicursor stuff |
203 | */ |
204 | |
205 | // Helper structs to work with multicursors |
206 | struct PlainSecondaryCursor { |
207 | KTextEditor::Cursor pos; |
208 | KTextEditor::Range range; |
209 | friend bool operator<(const PlainSecondaryCursor &l, const PlainSecondaryCursor &r) |
210 | { |
211 | return l.pos < r.pos; |
212 | } |
213 | }; |
214 | struct SecondaryCursor { |
215 | std::unique_ptr<Kate::TextCursor> pos; |
216 | std::unique_ptr<Kate::TextRange> range; |
217 | KTextEditor::Cursor anchor = KTextEditor::Cursor::invalid(); |
218 | |
219 | KTextEditor::Cursor cursor() const |
220 | { |
221 | return pos->toCursor(); |
222 | } |
223 | |
224 | friend bool operator<(const SecondaryCursor &l, const SecondaryCursor &r) |
225 | { |
226 | return l.cursor() < r.cursor(); |
227 | } |
228 | |
229 | friend bool operator<(const SecondaryCursor &l, KTextEditor::Cursor r) |
230 | { |
231 | return l.cursor() < r; |
232 | } |
233 | |
234 | friend bool operator==(const SecondaryCursor &l, const SecondaryCursor &r) |
235 | { |
236 | return l.cursor() == r.cursor() && l.selectionRange() == r.selectionRange(); |
237 | } |
238 | |
239 | KTextEditor::Range selectionRange() const |
240 | { |
241 | return range ? range->toRange() : KTextEditor::Range::invalid(); |
242 | } |
243 | |
244 | void clearSelection() |
245 | { |
246 | range.reset(); |
247 | anchor = KTextEditor::Cursor::invalid(); |
248 | } |
249 | }; |
250 | |
251 | // Just a helper to control the states in which we disallow multicursor |
252 | bool isMulticursorNotAllowed() const; |
253 | |
254 | // Adds a secondary cursor |
255 | void addSecondaryCursor(KTextEditor::Cursor cursor); |
256 | void setSecondaryCursors(const QList<KTextEditor::Cursor> &positions); |
257 | |
258 | const std::vector<SecondaryCursor> &secondaryCursors() const; |
259 | QList<PlainSecondaryCursor> plainSecondaryCursors() const; |
260 | void addSecondaryCursorsWithSelection(const QList<PlainSecondaryCursor> &cursorsWithSelection); |
261 | |
262 | void clearSecondaryCursors(); |
263 | void clearSecondarySelections(); |
264 | |
265 | // Check all the cursors, and remove cursors which have the same positions |
266 | // if @p matchLine is true, cursors whose line are same will be considered equal |
267 | void ensureUniqueCursors(bool matchLine = false); |
268 | |
269 | // For multicursor external api |
270 | QList<KTextEditor::Cursor> cursors() const; |
271 | QList<KTextEditor::Range> selectionRanges() const; |
272 | |
273 | void setCursors(const QList<KTextEditor::Cursor> &cursorPositions); |
274 | void setSelections(const QList<KTextEditor::Range> &selectionRanges); |
275 | |
276 | // Returns true if primary or secondary cursors have selection |
277 | bool hasSelections() const; |
278 | |
279 | private: |
280 | KTEXTEDITOR_NO_EXPORT |
281 | bool removeSecondaryCursors(const std::vector<KTextEditor::Cursor> &cursorToRemove, bool removeIfOverlapsSelection = false); |
282 | KTEXTEDITOR_NO_EXPORT |
283 | Kate::TextRange *newSecondarySelectionRange(KTextEditor::Range); |
284 | KTEXTEDITOR_NO_EXPORT |
285 | void sortCursors(); |
286 | KTEXTEDITOR_NO_EXPORT |
287 | void paintCursors(); |
288 | |
289 | std::vector<SecondaryCursor> m_secondaryCursors; |
290 | bool m_skipCurrentSelection = false; |
291 | |
292 | void addSecondaryCursorDown(); |
293 | // exported for multicursortest |
294 | void addSecondaryCursorUp(); |
295 | // exported for multicursortest |
296 | |
297 | private: |
298 | KTEXTEDITOR_NO_EXPORT |
299 | void notifyMousePositionChanged(const KTextEditor::Cursor newPosition); |
300 | |
301 | // Internal |
302 | public: |
303 | bool setCursorPositionInternal(const KTextEditor::Cursor position, uint tabwidth = 1, bool calledExternally = false); |
304 | |
305 | // |
306 | // KTextEditor::ConfigInterface |
307 | // |
308 | public: |
309 | QStringList configKeys() const override; |
310 | QVariant configValue(const QString &key) override; |
311 | void setConfigValue(const QString &key, const QVariant &value) override; |
312 | |
313 | public: |
314 | /** |
315 | * Try to fold an unfolded range starting at @p line |
316 | * @return the new folded range on success, otherwise an unvalid range |
317 | */ |
318 | KTextEditor::Range foldLine(int line); |
319 | |
320 | /** |
321 | * Try to unfold a folded range starting at @p line |
322 | * @return true when a range was unfolded, otherwise false |
323 | */ |
324 | bool unfoldLine(int line); |
325 | |
326 | /** |
327 | * Try to toggle the folding state of a range starting at line @p line |
328 | * @return true when the line was toggled, false when not |
329 | */ |
330 | bool toggleFoldingOfLine(int line); |
331 | |
332 | /** |
333 | * Try to change all the foldings inside a folding range starting at @p line |
334 | * but not the range itself starting there. |
335 | * However, should the range itself be folded, will only the range unfolded |
336 | * and the containing ranges kept untouched. |
337 | * Should the range not contain other ranges will the range itself folded, |
338 | * @return true when any range was folded or unfolded, otherwise false |
339 | */ |
340 | bool toggleFoldingsInRange(int line); |
341 | |
342 | // Code Completion Interface |
343 | public: |
344 | bool isCompletionActive() const override; |
345 | void startCompletion(KTextEditor::Range word, KTextEditor::CodeCompletionModel *model) override; |
346 | void startCompletion(const Range &word, |
347 | const QList<KTextEditor::CodeCompletionModel *> &models = QList<KTextEditor::CodeCompletionModel *>(), |
348 | KTextEditor::CodeCompletionModel::InvocationType invocationType = KTextEditor::CodeCompletionModel::ManualInvocation) override; |
349 | void abortCompletion() override; |
350 | void forceCompletion() override; |
351 | void registerCompletionModel(KTextEditor::CodeCompletionModel *model) override; |
352 | void unregisterCompletionModel(KTextEditor::CodeCompletionModel *model) override; |
353 | bool isCompletionModelRegistered(KTextEditor::CodeCompletionModel *model) const; |
354 | QList<KTextEditor::CodeCompletionModel *> codeCompletionModels() const override; |
355 | bool isAutomaticInvocationEnabled() const override; |
356 | void setAutomaticInvocationEnabled(bool enabled = true) override; |
357 | |
358 | Q_SIGNALS: |
359 | void completionExecuted(KTextEditor::View *view, KTextEditor::Cursor position, KTextEditor::CodeCompletionModel *model, const QModelIndex &); |
360 | void completionAborted(KTextEditor::View *view); |
361 | |
362 | public Q_SLOTS: |
363 | void userInvokedCompletion(); |
364 | |
365 | public: |
366 | KateCompletionWidget *completionWidget() const; |
367 | mutable KateCompletionWidget *m_completionWidget; |
368 | void sendCompletionExecuted(const KTextEditor::Cursor position, KTextEditor::CodeCompletionModel *model, const QModelIndex &index); |
369 | void sendCompletionAborted(); |
370 | |
371 | // |
372 | // KTextEditor::TextHintInterface |
373 | // |
374 | public: |
375 | void registerTextHintProvider(KTextEditor::TextHintProvider *provider) override; |
376 | void unregisterTextHintProvider(KTextEditor::TextHintProvider *provider) override; |
377 | void setTextHintDelay(int delay) override; |
378 | int textHintDelay() const override; |
379 | |
380 | public: |
381 | bool dynWordWrap() const |
382 | { |
383 | return m_hasWrap; |
384 | } |
385 | |
386 | // |
387 | // Inline Notes Interface |
388 | // |
389 | public: |
390 | void registerInlineNoteProvider(KTextEditor::InlineNoteProvider *provider) override; |
391 | void unregisterInlineNoteProvider(KTextEditor::InlineNoteProvider *provider) override; |
392 | QRect inlineNoteRect(const KateInlineNoteData ¬e) const; |
393 | |
394 | QVarLengthArray<KateInlineNoteData, 8> inlineNotes(int line) const; |
395 | |
396 | private: |
397 | std::vector<KTextEditor::InlineNoteProvider *> m_inlineNoteProviders; |
398 | |
399 | private Q_SLOTS: |
400 | void inlineNotesReset(); |
401 | void inlineNotesLineChanged(int line); |
402 | |
403 | // |
404 | // KTextEditor::SelectionInterface stuff |
405 | // |
406 | public Q_SLOTS: |
407 | bool setSelection(KTextEditor::Range selection) override; |
408 | |
409 | bool removeSelection() override |
410 | { |
411 | return clearSelection(); |
412 | } |
413 | |
414 | bool removeSelectionText() override |
415 | { |
416 | return removeSelectedText(); |
417 | } |
418 | |
419 | bool setBlockSelection(bool on) override; |
420 | bool toggleBlockSelection(); |
421 | |
422 | bool clearSelection(); |
423 | bool clearSelection(bool redraw, bool finishedChangingSelection = true); |
424 | |
425 | bool removeSelectedText(); |
426 | |
427 | bool selectAll(); |
428 | |
429 | public: |
430 | bool selection() const override; |
431 | QString selectionText() const override; |
432 | bool blockSelection() const override; |
433 | KTextEditor::Range selectionRange() const override; |
434 | |
435 | static void blockFix(KTextEditor::Range &range); |
436 | |
437 | // |
438 | // Arbitrary Syntax HL + Action extensions |
439 | // |
440 | public: |
441 | // Action association extension |
442 | void deactivateEditActions(); |
443 | void activateEditActions(); |
444 | |
445 | // |
446 | // internal helper stuff, for katerenderer and so on |
447 | // |
448 | public: |
449 | // should cursor be wrapped ? take config + blockselection state in account |
450 | bool wrapCursor() const; |
451 | |
452 | // some internal functions to get selection state of a line/col |
453 | bool cursorSelected(const KTextEditor::Cursor cursor); |
454 | bool lineSelected(int line); |
455 | bool lineEndSelected(const KTextEditor::Cursor lineEndPos); |
456 | bool lineHasSelected(int line); |
457 | bool lineIsSelection(int line); |
458 | |
459 | void ensureCursorColumnValid(); |
460 | |
461 | void tagSelection(KTextEditor::Range oldSelection); |
462 | |
463 | void selectWord(const KTextEditor::Cursor cursor); |
464 | void selectLine(const KTextEditor::Cursor cursor); |
465 | |
466 | // BEGIN EDIT STUFF |
467 | public: |
468 | void editStart(); |
469 | void editEnd(int editTagLineStart, int editTagLineEnd, bool tagFrom); |
470 | |
471 | void editSetCursor(const KTextEditor::Cursor cursor); |
472 | // END |
473 | |
474 | // BEGIN TAG & CLEAR |
475 | public: |
476 | bool tagLine(const KTextEditor::Cursor virtualCursor); |
477 | |
478 | bool tagRange(KTextEditor::Range range, bool realLines = false); |
479 | bool tagLines(KTextEditor::LineRange lineRange, bool realLines = false); |
480 | bool tagLines(KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors = false); |
481 | bool tagLines(KTextEditor::Range range, bool realRange = false); |
482 | |
483 | void tagAll(); |
484 | |
485 | void clear(); |
486 | |
487 | void repaintText(bool paintOnlyDirty = false); |
488 | |
489 | void updateView(bool changed = false); |
490 | // END |
491 | |
492 | // |
493 | // KTextEditor::AnnotationView |
494 | // |
495 | public: |
496 | void setAnnotationModel(KTextEditor::AnnotationModel *model) override; |
497 | KTextEditor::AnnotationModel *annotationModel() const override; |
498 | void setAnnotationBorderVisible(bool visible) override; |
499 | bool isAnnotationBorderVisible() const override; |
500 | void setAnnotationItemDelegate(KTextEditor::AbstractAnnotationItemDelegate *delegate) override; |
501 | KTextEditor::AbstractAnnotationItemDelegate *annotationItemDelegate() const override; |
502 | void setAnnotationUniformItemSizes(bool enable) override; |
503 | bool uniformAnnotationItemSizes() const override; |
504 | |
505 | Q_SIGNALS: |
506 | void navigateLeft(); |
507 | void navigateRight(); |
508 | void navigateUp(); |
509 | void navigateDown(); |
510 | void navigateAccept(); |
511 | void navigateBack(); |
512 | |
513 | private: |
514 | KTextEditor::AnnotationModel *m_annotationModel; |
515 | |
516 | // |
517 | // KTextEditor::View |
518 | // |
519 | public: |
520 | void emitNavigateLeft() |
521 | { |
522 | Q_EMIT navigateLeft(); |
523 | } |
524 | void emitNavigateRight() |
525 | { |
526 | Q_EMIT navigateRight(); |
527 | } |
528 | void emitNavigateUp() |
529 | { |
530 | Q_EMIT navigateUp(); |
531 | } |
532 | void emitNavigateDown() |
533 | { |
534 | Q_EMIT navigateDown(); |
535 | } |
536 | void emitNavigateAccept() |
537 | { |
538 | Q_EMIT navigateAccept(); |
539 | } |
540 | void emitNavigateBack() |
541 | { |
542 | Q_EMIT navigateBack(); |
543 | } |
544 | /** |
545 | Return values for "save" related commands. |
546 | */ |
547 | bool isOverwriteMode() const; |
548 | |
549 | bool isLineRTL(int line) const; |
550 | |
551 | const QTextLayout *textLayout(const KTextEditor::Cursor pos) const; |
552 | |
553 | public Q_SLOTS: |
554 | void indent(); |
555 | void unIndent(); |
556 | void cleanIndent(); |
557 | void formatIndent(); |
558 | void align(); // alias of formatIndent, for backward compatibility |
559 | void alignOn(); |
560 | void (); |
561 | void (); |
562 | void (); |
563 | void killLine(); |
564 | |
565 | /** |
566 | * Sets the cursor to the previous editing position in this document |
567 | */ |
568 | void goToPreviousEditingPosition(); |
569 | |
570 | /** |
571 | * Sets the cursor to the next editing position in this document. |
572 | */ |
573 | void goToNextEditingPosition(); |
574 | |
575 | /** |
576 | * Uppercases selected text, or an alphabetic character next to the cursor. |
577 | */ |
578 | void uppercase(); |
579 | |
580 | /** |
581 | * Lowercases selected text, or an alphabetic character next to the cursor. |
582 | */ |
583 | void lowercase(); |
584 | |
585 | /** |
586 | * Capitalizes the selection (makes each word start with an uppercase) or |
587 | * the word under the cursor. |
588 | */ |
589 | void capitalize(); |
590 | |
591 | /** |
592 | * Joins lines touched by the selection. |
593 | */ |
594 | void joinLines(); |
595 | |
596 | /** |
597 | * Performs a line break (insert a new line char) at current cursor position |
598 | * and indent the new line. |
599 | * |
600 | * Most work is done by @c KTextEditor::DocumentPrivate::newLine and |
601 | * @c KateAutoIndent::userTypedChar |
602 | * @see KTextEditor::DocumentPrivate::newLine, KateAutoIndent |
603 | */ |
604 | void keyReturn(); |
605 | |
606 | /** |
607 | * Performs a line break (insert a new line char) at current cursor position |
608 | * but keep all leading non word char as indent for the new line. |
609 | */ |
610 | void smartNewline(); |
611 | |
612 | /** |
613 | * Inserts a new line character at the current cursor position, with |
614 | * the newly inserted line having no indentation regardless of indentation |
615 | * settings. Useful e.g. for inserting a new, empty, line to separate |
616 | * blocks of code inside a function. |
617 | */ |
618 | void noIndentNewline(); |
619 | |
620 | void newLineAbove(); |
621 | |
622 | void newLineBelow(); |
623 | |
624 | /** |
625 | * Insert a tabulator char at current cursor position. |
626 | */ |
627 | void backspace(); |
628 | |
629 | /** |
630 | * Remove the word left from the current cursor position including all leading |
631 | * space. |
632 | * @see KateViewInternal::wordPrev |
633 | */ |
634 | void deleteWordLeft(bool subword = false); |
635 | |
636 | /** |
637 | * Remove the current selection. When nothing is selected the char right |
638 | * from the current cursor position is removed. |
639 | * @see KTextEditor::DocumentPrivate::del |
640 | */ |
641 | void keyDelete(); |
642 | |
643 | /** |
644 | * When the char right from the current cursor position is a space is all |
645 | * space to the right removed. Otherwise is the word to the right including |
646 | * all trialling space removed. |
647 | * @see KateViewInternal::wordNext |
648 | */ |
649 | void deleteWordRight(bool subword = false); |
650 | |
651 | /** |
652 | * Transpose the characters left and right from the current cursor position |
653 | * and move the cursor one position to the right. If the char right to the |
654 | * current cursor position is a new line char, nothing is done. |
655 | * @see KTextEditor::DocumentPrivate::transpose |
656 | */ |
657 | void transpose(); |
658 | |
659 | /** |
660 | * Transpose the word at the current cursor position with the word to the right (or to the left for RTL layouts). |
661 | * If the word is the last in the line, try swapping with the previous word instead. |
662 | * If the word is the only one in the line, no swapping is done. |
663 | * @see KTextEditor::DocumentPrivate::swapTextRanges |
664 | */ |
665 | void transposeWord(); |
666 | void cursorLeft(); |
667 | void shiftCursorLeft(); |
668 | void cursorRight(); |
669 | void shiftCursorRight(); |
670 | void wordLeft(bool subword = false); |
671 | void shiftWordLeft(bool subword = false); |
672 | void wordRight(bool subword = false); |
673 | void shiftWordRight(bool subword = false); |
674 | void markSelection(); |
675 | void home(); |
676 | void shiftHome(); |
677 | void end(); |
678 | void shiftEnd(); |
679 | void up(); |
680 | void shiftUp(); |
681 | void down(); |
682 | void shiftDown(); |
683 | void scrollUp(); |
684 | void scrollDown(); |
685 | void topOfView(); |
686 | void shiftTopOfView(); |
687 | void bottomOfView(); |
688 | void shiftBottomOfView(); |
689 | void pageUp(); |
690 | void shiftPageUp(); |
691 | void pageDown(); |
692 | void shiftPageDown(); |
693 | void top(); |
694 | void shiftTop(); |
695 | void bottom(); |
696 | void shiftBottom(); |
697 | void toMatchingBracket(); |
698 | void shiftToMatchingBracket(); |
699 | void toPrevModifiedLine(); |
700 | void toNextModifiedLine(); |
701 | /** |
702 | * Insert a tabulator char at current cursor position. |
703 | */ |
704 | void insertTab(); |
705 | |
706 | void gotoLine(); |
707 | |
708 | // config file / session management functions |
709 | public: |
710 | /** |
711 | * Read session settings from the given \p config. |
712 | * |
713 | * Known flags: |
714 | * "SkipUrl" => don't save/restore the file |
715 | * "SkipMode" => don't save/restore the mode |
716 | * "SkipHighlighting" => don't save/restore the highlighting |
717 | * "SkipEncoding" => don't save/restore the encoding |
718 | * |
719 | * \param config read the session settings from this KConfigGroup |
720 | * \param flags additional flags |
721 | * \see writeSessionConfig() |
722 | */ |
723 | void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override; |
724 | |
725 | /** |
726 | * Write session settings to the \p config. |
727 | * See readSessionConfig() for more details. |
728 | * |
729 | * \param config write the session settings to this KConfigGroup |
730 | * \param flags additional flags |
731 | * \see readSessionConfig() |
732 | */ |
733 | void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override; |
734 | |
735 | public Q_SLOTS: |
736 | void setEol(int eol); |
737 | void setAddBom(bool enabled); |
738 | void find(); |
739 | void findSelectedForwards(); |
740 | void findSelectedBackwards(); |
741 | void findNextOccurunceAndSelect(); |
742 | void findAllOccuruncesAndSelect(); |
743 | void skipCurrentOccurunceSelection(); |
744 | void replace(); |
745 | void findNext(); |
746 | void findPrevious(); |
747 | void showSearchWrappedHint(bool isReverseSearch); |
748 | void createMultiCursorsFromSelection(); |
749 | void removeCursorsFromEmptyLines(); |
750 | |
751 | void setFoldingMarkersOn(bool enable); // Not in KTextEditor::View, but should be |
752 | void setIconBorder(bool enable); |
753 | void setLineNumbersOn(bool enable); |
754 | void setScrollBarMarks(bool enable); |
755 | void setScrollBarMiniMap(bool enable); |
756 | void setScrollBarMiniMapAll(bool enable); |
757 | void setScrollBarMiniMapWidth(int width); |
758 | void toggleFoldingMarkers(); |
759 | void toggleIconBorder(); |
760 | void toggleLineNumbersOn(); |
761 | void toggleScrollBarMarks(); |
762 | void toggleScrollBarMiniMap(); |
763 | void toggleScrollBarMiniMapAll(); |
764 | void toggleShowSpaces(); |
765 | void toggleDynWordWrap(); |
766 | void setDynWrapIndicators(int mode); |
767 | |
768 | public: |
769 | int getEol() const; |
770 | QMenu *(); |
771 | |
772 | public: |
773 | KateRenderer *renderer(); |
774 | KateRendererConfig *rendererConfig(); |
775 | |
776 | bool iconBorder(); |
777 | bool lineNumbersOn(); |
778 | bool scrollBarMarks(); |
779 | bool scrollBarMiniMap(); |
780 | bool scrollBarMiniMapAll(); |
781 | int dynWrapIndicators(); |
782 | bool foldingMarkersOn(); |
783 | bool forceRTLDirection() const; |
784 | |
785 | private Q_SLOTS: |
786 | /** |
787 | * used to update actions after selection changed |
788 | */ |
789 | void slotSelectionChanged(); |
790 | |
791 | void toggleInputMode(); |
792 | void cycleInputMode(); |
793 | |
794 | public: |
795 | /** |
796 | * accessor to katedocument pointer |
797 | * @return pointer to document |
798 | */ |
799 | KTextEditor::DocumentPrivate *doc() |
800 | { |
801 | return m_doc; |
802 | } |
803 | const KTextEditor::DocumentPrivate *doc() const |
804 | { |
805 | return m_doc; |
806 | } |
807 | |
808 | public Q_SLOTS: |
809 | void slotUpdateUndo(); |
810 | void toggleInsert(); |
811 | void reloadFile(); |
812 | void toggleWWMarker(); |
813 | void toggleNPSpaces(); |
814 | void toggleWordCount(bool on); |
815 | void toggleWriteLock(); |
816 | void switchToCmdLine(); |
817 | void slotReadWriteChanged(); |
818 | void toggleCamelCaseCursor(); |
819 | |
820 | Q_SIGNALS: |
821 | void dropEventPass(QDropEvent *); |
822 | |
823 | public: |
824 | /** |
825 | * Folding handler for this view. |
826 | * @return folding handler |
827 | */ |
828 | Kate::TextFolding &textFolding() |
829 | { |
830 | return m_textFolding; |
831 | } |
832 | |
833 | public: |
834 | void slotTextInserted(KTextEditor::View *view, const KTextEditor::Cursor position, const QString &text); |
835 | |
836 | void exportHtmlToFile(const QString &file); |
837 | |
838 | private Q_SLOTS: |
839 | void slotDocumentReloaded(); |
840 | void slotDocumentAboutToReload(); |
841 | void slotGotFocus(); |
842 | void slotLostFocus(); |
843 | void slotSaveCanceled(const QString &error); |
844 | void slotConfigDialog(); |
845 | void exportHtmlToClipboard(); |
846 | void exportHtmlToFile(); |
847 | |
848 | public Q_SLOTS: |
849 | void slotFoldToplevelNodes(); |
850 | void slotExpandToplevelNodes(); |
851 | void slotToggleFolding(); |
852 | void slotToggleFoldingsInRange(); |
853 | |
854 | private: |
855 | KTEXTEDITOR_NO_EXPORT |
856 | void setupLayout(); |
857 | KTEXTEDITOR_NO_EXPORT |
858 | void setupConnections(); |
859 | KTEXTEDITOR_NO_EXPORT |
860 | void setupActions(); |
861 | KTEXTEDITOR_NO_EXPORT |
862 | void setupEditActions(); |
863 | KTEXTEDITOR_NO_EXPORT |
864 | void setupCodeFolding(); |
865 | KTEXTEDITOR_NO_EXPORT |
866 | void setupSpeechActions(); |
867 | |
868 | std::vector<QAction *> m_editActions; |
869 | QAction *m_editUndo; |
870 | QAction *m_editRedo; |
871 | bool m_gotoBottomAfterReload; |
872 | bool m_markedSelection; |
873 | KToggleAction *m_toggleFoldingMarkers; |
874 | KToggleAction *m_toggleIconBar; |
875 | KToggleAction *m_toggleLineNumbers; |
876 | KToggleAction *m_toggleScrollBarMarks; |
877 | KToggleAction *m_toggleScrollBarMiniMap; |
878 | KToggleAction *m_toggleScrollBarMiniMapAll; |
879 | KToggleAction *m_toggleShowSpace; |
880 | KToggleAction *m_toggleDynWrap; |
881 | KSelectAction *m_setDynWrapIndicators; |
882 | KToggleAction *m_toggleWWMarker; |
883 | KToggleAction *m_toggleNPSpaces; |
884 | KToggleAction *m_toggleWordCount; |
885 | QAction *m_switchCmdLine; |
886 | KToggleAction *m_viInputModeAction; |
887 | |
888 | KSelectAction *m_setEndOfLine; |
889 | KToggleAction *m_addBom; |
890 | |
891 | QAction *m_cut; |
892 | QAction *m_copy; |
893 | QAction *m_copyHtmlAction; |
894 | QAction *m_paste; |
895 | QAction *m_clipboardHistory; |
896 | // always nullptr if paste selection isn't supported |
897 | QAction *m_pasteSelection = nullptr; |
898 | QAction *m_swapWithClipboard; |
899 | QAction *m_selectAll; |
900 | QAction *m_deSelect; |
901 | QAction *m_screenshotSelection = nullptr; |
902 | |
903 | QActionGroup *m_inputModeActions; |
904 | |
905 | KToggleAction *m_toggleBlockSelection; |
906 | KToggleAction *m_toggleInsert; |
907 | KToggleAction *m_toggleWriteLock; |
908 | KToggleAction *m_forceRTLDirection; |
909 | |
910 | bool m_hasWrap; |
911 | bool m_forceRTL = false; |
912 | bool m_accessibilityEnabled = false; |
913 | |
914 | KTextEditor::DocumentPrivate *const m_doc; |
915 | Kate::TextFolding m_textFolding; |
916 | KateViewConfig *const m_config; |
917 | KateRenderer *const m_renderer; |
918 | KateViewInternal *const m_viewInternal; |
919 | KateSpellCheckDialog *m_spell; |
920 | KateBookmarks *const m_bookmarks; |
921 | |
922 | //* margins |
923 | QSpacerItem *m_topSpacer; |
924 | QSpacerItem *m_leftSpacer; |
925 | QSpacerItem *m_rightSpacer; |
926 | QSpacerItem *m_bottomSpacer; |
927 | |
928 | private Q_SLOTS: |
929 | void slotHlChanged(); |
930 | |
931 | /** |
932 | * Configuration |
933 | */ |
934 | public: |
935 | inline KateViewConfig *config() |
936 | { |
937 | return m_config; |
938 | } |
939 | |
940 | void updateConfig(); |
941 | |
942 | void updateDocumentConfig(); |
943 | |
944 | void updateRendererConfig(); |
945 | |
946 | private Q_SLOTS: |
947 | void updateFoldingConfig(); |
948 | |
949 | private: |
950 | bool m_startingUp; |
951 | bool m_updatingDocumentConfig; |
952 | |
953 | // stores the current selection |
954 | Kate::TextRange m_selection; |
955 | |
956 | // do we select normal or blockwise ? |
957 | bool blockSelect; |
958 | |
959 | // templates |
960 | public: |
961 | bool insertTemplateInternal(const KTextEditor::Cursor insertPosition, const QString &templateString, const QString &script = QString()); |
962 | |
963 | bool evaluateScriptInternal(const QString &script, QVariant *result = nullptr); |
964 | |
965 | /** |
966 | * Accessors to the bars... |
967 | */ |
968 | public: |
969 | KateViewBar *bottomViewBar() const; |
970 | KateDictionaryBar *dictionaryBar(); |
971 | |
972 | private: |
973 | KTEXTEDITOR_NO_EXPORT |
974 | KateGotoBar *gotoBar(); |
975 | |
976 | /** |
977 | * viewbar + its widgets |
978 | * they are created on demand... |
979 | */ |
980 | private: |
981 | // created in constructor of the view |
982 | KateViewBar *m_bottomViewBar; |
983 | |
984 | // created on demand..., only access them through the above accessors.... |
985 | KateGotoBar *m_gotoBar; |
986 | KateDictionaryBar *m_dictionaryBar; |
987 | |
988 | // input modes |
989 | public: |
990 | KateAbstractInputMode *currentInputMode() const; |
991 | |
992 | public: |
993 | KTextEditor::Range visibleRange(); |
994 | |
995 | protected: |
996 | bool event(QEvent *e) override; |
997 | |
998 | KToggleAction *m_toggleOnTheFlySpellCheck; |
999 | KateSpellingMenu *; |
1000 | |
1001 | protected Q_SLOTS: |
1002 | void toggleOnTheFlySpellCheck(bool b); |
1003 | |
1004 | public Q_SLOTS: |
1005 | void changeDictionary(); |
1006 | void reflectOnTheFlySpellCheckStatus(bool enabled); |
1007 | |
1008 | public: |
1009 | KateSpellingMenu *(); |
1010 | |
1011 | private: |
1012 | bool ; |
1013 | |
1014 | private Q_SLOTS: |
1015 | /** |
1016 | * save folding state before document reload |
1017 | */ |
1018 | void saveFoldingState(); |
1019 | |
1020 | /** |
1021 | * restore folding state after document reload |
1022 | */ |
1023 | void applyFoldingState(); |
1024 | |
1025 | public: |
1026 | /** |
1027 | * Clear any saved folding state |
1028 | */ |
1029 | void clearFoldingState(); |
1030 | |
1031 | private: |
1032 | KTEXTEDITOR_NO_EXPORT |
1033 | void clearHighlights(); |
1034 | KTEXTEDITOR_NO_EXPORT |
1035 | void createHighlights(); |
1036 | |
1037 | private: |
1038 | KTEXTEDITOR_NO_EXPORT |
1039 | void selectionChangedForHighlights(); |
1040 | |
1041 | /** |
1042 | * saved folding state |
1043 | */ |
1044 | QJsonDocument m_savedFoldingState; |
1045 | |
1046 | QString m_currentTextForHighlights; |
1047 | |
1048 | std::vector<std::unique_ptr<KTextEditor::MovingRange>> m_rangesForHighlights; |
1049 | |
1050 | public: |
1051 | /** |
1052 | * Attribute of a range changed or range with attribute changed in given line range. |
1053 | * @param lineRange line range that the change spans |
1054 | * @param needsRepaint do we need to trigger repaints? e.g. if ranges with attributes change |
1055 | */ |
1056 | void (KTextEditor::LineRange lineRange, bool needsRepaint, Kate::TextRange *deleteRange); |
1057 | |
1058 | private Q_SLOTS: |
1059 | /** |
1060 | * Delayed update for view after text ranges changed |
1061 | */ |
1062 | void slotDelayedUpdateOfView(); |
1063 | |
1064 | Q_SIGNALS: |
1065 | /** |
1066 | * Delayed update for view after text ranges changed |
1067 | */ |
1068 | void delayedUpdateOfView(); |
1069 | |
1070 | /** |
1071 | * Emitted whenever the caret enter or leave a range. |
1072 | * ATM only used by KateStatusBar to update the dict button |
1073 | */ |
1074 | void caretChangedRange(KTextEditor::View *); |
1075 | |
1076 | public: |
1077 | /** |
1078 | * set of ranges which had the mouse inside last time, used for rendering |
1079 | * @return set of ranges which had the mouse inside last time checked |
1080 | */ |
1081 | const QSet<Kate::TextRange *> *rangesMouseIn() const |
1082 | { |
1083 | return &m_rangesMouseIn; |
1084 | } |
1085 | |
1086 | /** |
1087 | * set of ranges which had the caret inside last time, used for rendering |
1088 | * @return set of ranges which had the caret inside last time checked |
1089 | */ |
1090 | const QSet<Kate::TextRange *> *rangesCaretIn() const |
1091 | { |
1092 | return &m_rangesCaretIn; |
1093 | } |
1094 | |
1095 | /** |
1096 | * check if ranges changed for mouse in and caret in |
1097 | * @param activationType type of activation to check |
1098 | */ |
1099 | void updateRangesIn(KTextEditor::Attribute::ActivationType activationType); |
1100 | |
1101 | // |
1102 | // helpers for delayed view update after ranges changes |
1103 | // |
1104 | private: |
1105 | /** |
1106 | * delayed update timer |
1107 | */ |
1108 | QTimer m_delayedUpdateTimer; |
1109 | |
1110 | /** |
1111 | * line range to update |
1112 | */ |
1113 | KTextEditor::LineRange m_lineToUpdateRange; |
1114 | |
1115 | /** |
1116 | * set of ranges which had the mouse inside last time |
1117 | */ |
1118 | QSet<Kate::TextRange *> m_rangesMouseIn; |
1119 | |
1120 | /** |
1121 | * set of ranges which had the caret inside last time |
1122 | */ |
1123 | QSet<Kate::TextRange *> m_rangesCaretIn; |
1124 | |
1125 | // |
1126 | // forward impl for KTextEditor::MessageInterface |
1127 | // |
1128 | public: |
1129 | /** |
1130 | * Used by Document::postMessage(). |
1131 | */ |
1132 | void postMessage(KTextEditor::Message *message, QList<std::shared_ptr<QAction>> actions); |
1133 | |
1134 | private: |
1135 | /** |
1136 | * Message widgets showing KTextEditor::Messages. |
1137 | * The index of the array maps to the enum KTextEditor::Message::MessagePosition. |
1138 | */ |
1139 | std::array<KateMessageWidget *, 5> m_messageWidgets{._M_elems: {nullptr}}; |
1140 | /** Layout for floating notifications */ |
1141 | KateMessageLayout *m_notificationLayout = nullptr; |
1142 | |
1143 | // for unit test 'tests/messagetest.cpp' |
1144 | public: |
1145 | KateMessageWidget *messageWidget(); |
1146 | |
1147 | private: |
1148 | /** |
1149 | * The main window responsible for this view, if any |
1150 | */ |
1151 | QPointer<KTextEditor::MainWindow> m_mainWindow; |
1152 | |
1153 | // |
1154 | // KTextEditor::PrintInterface |
1155 | // |
1156 | public Q_SLOTS: |
1157 | bool print() override; |
1158 | void printPreview() override; |
1159 | |
1160 | public: |
1161 | /** |
1162 | * Get the view status bar |
1163 | * @return status bar, in enabled |
1164 | */ |
1165 | KateStatusBar *statusBar() const |
1166 | { |
1167 | return m_statusBar; |
1168 | } |
1169 | |
1170 | /** |
1171 | * Toogle status bar, e.g. create or remove it |
1172 | */ |
1173 | void toggleStatusBar(); |
1174 | |
1175 | /** |
1176 | * Get the encoding menu |
1177 | * @return the encoding menu |
1178 | */ |
1179 | KateViewEncodingAction *encodingAction() const |
1180 | { |
1181 | return m_encodingAction; |
1182 | } |
1183 | |
1184 | /** |
1185 | * Get the mode menu |
1186 | * @return the mode menu |
1187 | */ |
1188 | KateModeMenu *modeAction() const |
1189 | { |
1190 | return m_modeAction; |
1191 | } |
1192 | |
1193 | private: |
1194 | /** |
1195 | * the status bar of this view |
1196 | */ |
1197 | KateStatusBar *m_statusBar; |
1198 | |
1199 | /** |
1200 | * the encoding selection menu, used by view + status bar |
1201 | */ |
1202 | KateViewEncodingAction *m_encodingAction; |
1203 | |
1204 | /** |
1205 | * the mode selection menu, used by view |
1206 | */ |
1207 | KateModeMenu *m_modeAction; |
1208 | |
1209 | /** |
1210 | * is automatic invocation of completion disabled temporarily? |
1211 | */ |
1212 | bool m_temporaryAutomaticInvocationDisabled; |
1213 | |
1214 | public: |
1215 | /** |
1216 | * Returns the attribute for the default style \p defaultStyle. |
1217 | */ |
1218 | Attribute::Ptr defaultStyleAttribute(KSyntaxHighlighting::Theme::TextStyle defaultStyle) const override; |
1219 | |
1220 | /** |
1221 | * Get the list of AttributeBlocks for a given \p line in the document. |
1222 | * |
1223 | * \return list of AttributeBlocks for given \p line. |
1224 | */ |
1225 | QList<KTextEditor::AttributeBlock> lineAttributes(int line) override; |
1226 | |
1227 | private: |
1228 | // remember folding state to prevent refolding the first line if it was manually unfolded, |
1229 | // e.g. when saving a file or changing other config vars |
1230 | bool m_autoFoldedFirstLine; |
1231 | |
1232 | public: |
1233 | void setScrollPositionInternal(KTextEditor::Cursor cursor); |
1234 | |
1235 | void setHorizontalScrollPositionInternal(int x); |
1236 | |
1237 | KTextEditor::Cursor maxScrollPositionInternal() const; |
1238 | |
1239 | int firstDisplayedLineInternal(LineType lineType) const; |
1240 | |
1241 | int lastDisplayedLineInternal(LineType lineType) const; |
1242 | |
1243 | QRect textAreaRectInternal() const; |
1244 | |
1245 | private: |
1246 | /** |
1247 | * script action menu, stored in scoped pointer to ensure |
1248 | * destruction before other QObject auto-cleanup as it |
1249 | * manage sub objects on its own that have this view as parent |
1250 | */ |
1251 | std::unique_ptr<KateScriptActionMenu> ; |
1252 | |
1253 | // for showSearchWrappedHint() |
1254 | QPointer<KTextEditor::Message> m_wrappedMessage; |
1255 | bool m_isLastSearchReversed = false; |
1256 | }; |
1257 | |
1258 | } |
1259 | |
1260 | #endif |
1261 | |