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