File indexing completed on 2024-04-28 15:31:03

0001 /*
0002     SPDX-FileCopyrightText: 2002 John Firebaugh <jfirebaugh@kde.org>
0003     SPDX-FileCopyrightText: 2001 Christoph Cullmann <cullmann@kde.org>
0004     SPDX-FileCopyrightText: 2001-2010 Joseph Wenninger <jowenn@kde.org>
0005     SPDX-FileCopyrightText: 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef kate_view_h
0011 #define kate_view_h
0012 
0013 #include <ktexteditor/annotationinterface.h>
0014 #include <ktexteditor/codecompletioninterface.h>
0015 #include <ktexteditor/configinterface.h>
0016 #include <ktexteditor/inlinenoteinterface.h>
0017 #include <ktexteditor/linerange.h>
0018 #include <ktexteditor/mainwindow.h>
0019 #include <ktexteditor/texthintinterface.h>
0020 #include <ktexteditor/view.h>
0021 
0022 #include <QJsonDocument>
0023 #include <QMenu>
0024 #include <QModelIndex>
0025 #include <QPointer>
0026 #include <QScopedPointer>
0027 #include <QSpacerItem>
0028 #include <QTextLayout>
0029 #include <QTimer>
0030 
0031 #include <array>
0032 
0033 #include "katetextfolding.h"
0034 #include "katetextrange.h"
0035 
0036 namespace KTextEditor
0037 {
0038 class AnnotationModel;
0039 class Message;
0040 class InlineNoteProvider;
0041 class DocumentPrivate;
0042 }
0043 
0044 namespace Kate
0045 {
0046 class TextCursor;
0047 }
0048 class KateBookmarks;
0049 class KateViewConfig;
0050 class KateRenderer;
0051 class KateSpellCheckDialog;
0052 class KateCompletionWidget;
0053 class KateViewInternal;
0054 class KateViewBar;
0055 class KateTextPreview;
0056 class KateGotoBar;
0057 class KateDictionaryBar;
0058 class KateSpellingMenu;
0059 class KateMessageWidget;
0060 class KateIconBorder;
0061 class KateStatusBar;
0062 class KateViewEncodingAction;
0063 class KateModeMenu;
0064 class KateAbstractInputMode;
0065 class KateScriptActionMenu;
0066 class KateMessageLayout;
0067 class KateInlineNoteData;
0068 class MulticursorTest;
0069 
0070 class KToggleAction;
0071 class KSelectAction;
0072 
0073 class QAction;
0074 
0075 namespace KTextEditor
0076 {
0077 //
0078 // Kate KTextEditor::View class ;)
0079 //
0080 class KTEXTEDITOR_EXPORT ViewPrivate final : public KTextEditor::View,
0081                                              public KTextEditor::TextHintInterface,
0082                                              public KTextEditor::CodeCompletionInterfaceV2,
0083                                              public KTextEditor::ConfigInterface,
0084                                              public KTextEditor::InlineNoteInterface,
0085                                              public KTextEditor::AnnotationViewInterfaceV2
0086 {
0087     Q_OBJECT
0088     Q_INTERFACES(KTextEditor::TextHintInterface)
0089     Q_INTERFACES(KTextEditor::ConfigInterface)
0090     Q_INTERFACES(KTextEditor::CodeCompletionInterface)
0091     Q_INTERFACES(KTextEditor::CodeCompletionInterfaceV2)
0092     Q_INTERFACES(KTextEditor::AnnotationViewInterface)
0093     Q_INTERFACES(KTextEditor::AnnotationViewInterfaceV2)
0094     Q_INTERFACES(KTextEditor::InlineNoteInterface)
0095 
0096     friend class KTextEditor::View;
0097     friend class ::KateViewInternal;
0098     friend class ::KateIconBorder;
0099     friend class ::KateTextPreview;
0100     friend MulticursorTest;
0101 
0102 public:
0103     ViewPrivate(KTextEditor::DocumentPrivate *doc, QWidget *parent, KTextEditor::MainWindow *mainWindow = nullptr);
0104     ~ViewPrivate() override;
0105 
0106     /**
0107      * Get the view's main window, if any
0108      * \return the view's main window
0109      */
0110     KTextEditor::MainWindow *mainWindow() const override
0111     {
0112         return m_mainWindow;
0113     }
0114 
0115     KTextEditor::Document *document() const override;
0116 
0117     ViewMode viewMode() const override;
0118     QString viewModeHuman() const override;
0119     InputMode viewInputMode() const override;
0120     QString viewInputModeHuman() const override;
0121 
0122     void setInputMode(InputMode mode, const bool rememberInConfig = true);
0123 
0124 public:
0125     KateViewInternal *getViewInternal()
0126     {
0127         return m_viewInternal;
0128     }
0129 
0130     //
0131     // KTextEditor::ClipboardInterface
0132     //
0133 public Q_SLOTS:
0134     void paste(const QString *textToPaste = nullptr);
0135     void cut();
0136     void copy() const;
0137 
0138 private Q_SLOTS:
0139     /**
0140      * Paste the global mouse selection. Support for Selection is provided only
0141      * on systems with a global mouse selection (e.g. X11).
0142      */
0143     void pasteSelection();
0144 
0145     /**
0146      * Copy current selected stuff and paste previous content of clipboard as one operation.
0147      */
0148     void swapWithClipboard();
0149 
0150     /**
0151      * Wrap lines touched by the selection with respect of existing paragraphs.
0152      * Work is done by KTextEditor::DocumentPrivate::wrapParagraph
0153      */
0154     void applyWordWrap();
0155 
0156     //
0157     // KTextEditor::PopupMenuInterface
0158     //
0159 public:
0160     void setContextMenu(QMenu *menu) override;
0161     QMenu *contextMenu() const override;
0162     QMenu *defaultContextMenu(QMenu *menu = nullptr) const override;
0163 
0164 private Q_SLOTS:
0165     void aboutToShowContextMenu();
0166     void aboutToHideContextMenu();
0167 
0168 private:
0169     QPointer<QMenu> m_contextMenu;
0170 
0171     //
0172     // KTextEditor::ViewCursorInterface
0173     //
0174 public:
0175     bool setCursorPosition(KTextEditor::Cursor position) override;
0176 
0177     KTextEditor::Cursor cursorPosition() const override;
0178 
0179     KTextEditor::Cursor cursorPositionVirtual() const override;
0180 
0181     QPoint cursorToCoordinate(const KTextEditor::Cursor &cursor) const override;
0182 
0183     KTextEditor::Cursor coordinatesToCursor(const QPoint &coord) const override;
0184 
0185     QPoint cursorPositionCoordinates() const override;
0186 
0187     bool setCursorPositionVisual(const KTextEditor::Cursor position);
0188 
0189     /**
0190      * Return the virtual cursor column, each tab is expanded into the
0191      * document's tabWidth characters. If word wrap is off, the cursor may be
0192      * behind the line's length.
0193      */
0194     int virtualCursorColumn() const;
0195 
0196     bool mouseTrackingEnabled() const override;
0197     bool setMouseTrackingEnabled(bool enable) override;
0198 
0199     /*
0200      * multicursor stuff
0201      */
0202 
0203     // Helper structs to work with multicursors
0204     struct PlainSecondaryCursor {
0205         KTextEditor::Cursor pos;
0206         KTextEditor::Range range;
0207         friend bool operator<(const PlainSecondaryCursor &l, const PlainSecondaryCursor &r)
0208         {
0209             return l.pos < r.pos;
0210         }
0211     };
0212     struct SecondaryCursor {
0213         std::unique_ptr<Kate::TextCursor> pos;
0214         std::unique_ptr<Kate::TextRange> range;
0215         KTextEditor::Cursor anchor = KTextEditor::Cursor::invalid();
0216 
0217         KTextEditor::Cursor cursor() const
0218         {
0219             return pos->toCursor();
0220         }
0221 
0222         friend bool operator<(const SecondaryCursor &l, const SecondaryCursor &r)
0223         {
0224             return l.cursor() < r.cursor();
0225         }
0226 
0227         friend bool operator<(const SecondaryCursor &l, const KTextEditor::Cursor &r)
0228         {
0229             return l.cursor() < r;
0230         }
0231 
0232         friend bool operator==(const SecondaryCursor &l, const SecondaryCursor &r)
0233         {
0234             return l.cursor() == r.cursor();
0235         }
0236 
0237         void clearSelection()
0238         {
0239             range.reset();
0240             anchor = KTextEditor::Cursor::invalid();
0241         }
0242     };
0243 
0244     // Just a helper to control the states in which we disallow multicursor
0245     bool isMulticursorNotAllowed() const;
0246 
0247     // Adds a secondary cursor
0248     void addSecondaryCursor(const KTextEditor::Cursor &cursor);
0249     void setSecondaryCursors(const QVector<KTextEditor::Cursor> &positions);
0250 
0251     const std::vector<SecondaryCursor> &secondaryCursors() const;
0252     QVector<PlainSecondaryCursor> plainSecondaryCursors() const;
0253     void addSecondaryCursorsWithSelection(const QVector<PlainSecondaryCursor> &cursorsWithSelection);
0254 
0255     void clearSecondaryCursors();
0256     void clearSecondarySelections();
0257 
0258     // Check all the cursors, and remove cursors which have the same positions
0259     // if @p matchLine is true, cursors whose line are same will be considered equal
0260     void ensureUniqueCursors(bool matchLine = false);
0261 
0262     // For multicursor external api
0263     QVector<KTextEditor::Cursor> cursors() const;
0264     QVector<KTextEditor::Range> selectionRanges() const;
0265 
0266     void setCursors(const QVector<KTextEditor::Cursor> &cursorPositions);
0267     void setSelections(const QVector<KTextEditor::Range> &selectionRanges);
0268 
0269     // Returns true if primary or secondary cursors have selection
0270     bool hasSelections() const;
0271 
0272 private:
0273     KTEXTEDITOR_NO_EXPORT
0274     bool removeSecondaryCursors(const std::vector<KTextEditor::Cursor> &cursorToRemove, bool removeIfOverlapsSelection = false);
0275     KTEXTEDITOR_NO_EXPORT
0276     Kate::TextRange *newSecondarySelectionRange(KTextEditor::Range);
0277     KTEXTEDITOR_NO_EXPORT
0278     void sortCursors();
0279     KTEXTEDITOR_NO_EXPORT
0280     void paintCursors();
0281 
0282     std::vector<SecondaryCursor> m_secondaryCursors;
0283     bool m_skipCurrentSelection = false;
0284 
0285     void addSecondaryCursorDown();
0286     // exported for multicursortest
0287     void addSecondaryCursorUp();
0288     // exported for multicursortest
0289 
0290 private:
0291     KTEXTEDITOR_NO_EXPORT
0292     void notifyMousePositionChanged(const KTextEditor::Cursor newPosition);
0293 
0294     // Internal
0295 public:
0296     bool setCursorPositionInternal(const KTextEditor::Cursor position, uint tabwidth = 1, bool calledExternally = false);
0297 
0298     //
0299     // KTextEditor::ConfigInterface
0300     //
0301 public:
0302     QStringList configKeys() const override;
0303     QVariant configValue(const QString &key) override;
0304     void setConfigValue(const QString &key, const QVariant &value) override;
0305 
0306 public:
0307     /**
0308      * Try to fold an unfolded range starting at @p line
0309      * @return the new folded range on success, otherwise an unvalid range
0310      */
0311     KTextEditor::Range foldLine(int line);
0312 
0313     /**
0314      * Try to unfold a folded range starting at @p line
0315      * @return true when a range was unfolded, otherwise false
0316      */
0317     bool unfoldLine(int line);
0318 
0319     /**
0320      * Try to toggle the folding state of a range starting at line @p line
0321      * @return true when the line was toggled, false when not
0322      */
0323     bool toggleFoldingOfLine(int line);
0324 
0325     /**
0326      * Try to change all the foldings inside a folding range starting at @p line
0327      * but not the range itself starting there.
0328      * However, should the range itself be folded, will only the range unfolded
0329      * and the containing ranges kept untouched.
0330      * Should the range not contain other ranges will the range itself folded,
0331      * @return true when any range was folded or unfolded, otherwise false
0332      */
0333     bool toggleFoldingsInRange(int line);
0334 
0335     //
0336     // KTextEditor::CodeCompletionInterfaceV2
0337     //
0338 public:
0339     bool isCompletionActive() const override;
0340     void startCompletion(const KTextEditor::Range &word, KTextEditor::CodeCompletionModel *model) override;
0341     void startCompletion(const Range &word,
0342                          const QList<KTextEditor::CodeCompletionModel *> &models = QList<KTextEditor::CodeCompletionModel *>(),
0343                          KTextEditor::CodeCompletionModel::InvocationType invocationType = KTextEditor::CodeCompletionModel::ManualInvocation) override;
0344     void abortCompletion() override;
0345     void forceCompletion() override;
0346     void registerCompletionModel(KTextEditor::CodeCompletionModel *model) override;
0347     void unregisterCompletionModel(KTextEditor::CodeCompletionModel *model) override;
0348     bool isCompletionModelRegistered(KTextEditor::CodeCompletionModel *model) const;
0349     QList<KTextEditor::CodeCompletionModel *> codeCompletionModels() const override;
0350     bool isAutomaticInvocationEnabled() const override;
0351     void setAutomaticInvocationEnabled(bool enabled = true) override;
0352 
0353 Q_SIGNALS:
0354     void completionExecuted(KTextEditor::View *view, const KTextEditor::Cursor &position, KTextEditor::CodeCompletionModel *model, const QModelIndex &);
0355     void completionAborted(KTextEditor::View *view);
0356 
0357 public Q_SLOTS:
0358     void userInvokedCompletion();
0359 
0360 public:
0361     KateCompletionWidget *completionWidget() const;
0362     mutable KateCompletionWidget *m_completionWidget;
0363     void sendCompletionExecuted(const KTextEditor::Cursor position, KTextEditor::CodeCompletionModel *model, const QModelIndex &index);
0364     void sendCompletionAborted();
0365 
0366     //
0367     // KTextEditor::TextHintInterface
0368     //
0369 public:
0370     void registerTextHintProvider(KTextEditor::TextHintProvider *provider) override;
0371     void unregisterTextHintProvider(KTextEditor::TextHintProvider *provider) override;
0372     void setTextHintDelay(int delay) override;
0373     int textHintDelay() const override;
0374 
0375 public:
0376     bool dynWordWrap() const
0377     {
0378         return m_hasWrap;
0379     }
0380 
0381     //
0382     // Inline Notes Interface
0383     //
0384 public:
0385     void registerInlineNoteProvider(KTextEditor::InlineNoteProvider *provider) override;
0386     void unregisterInlineNoteProvider(KTextEditor::InlineNoteProvider *provider) override;
0387     QRect inlineNoteRect(const KateInlineNoteData &note) const;
0388 
0389     QVarLengthArray<KateInlineNoteData, 8> inlineNotes(int line) const;
0390 
0391 private:
0392     std::vector<KTextEditor::InlineNoteProvider *> m_inlineNoteProviders;
0393 
0394 private Q_SLOTS:
0395     void inlineNotesReset();
0396     void inlineNotesLineChanged(int line);
0397 
0398     //
0399     // KTextEditor::SelectionInterface stuff
0400     //
0401 public Q_SLOTS:
0402     bool setSelection(const KTextEditor::Range &selection) override;
0403 
0404     bool removeSelection() override
0405     {
0406         return clearSelection();
0407     }
0408 
0409     bool removeSelectionText() override
0410     {
0411         return removeSelectedText();
0412     }
0413 
0414     bool setBlockSelection(bool on) override;
0415     bool toggleBlockSelection();
0416 
0417     bool clearSelection();
0418     bool clearSelection(bool redraw, bool finishedChangingSelection = true);
0419 
0420     bool removeSelectedText();
0421 
0422     bool selectAll();
0423 
0424 public:
0425     bool selection() const override;
0426     QString selectionText() const override;
0427     bool blockSelection() const override;
0428     KTextEditor::Range selectionRange() const override;
0429 
0430     static void blockFix(KTextEditor::Range &range);
0431 
0432     //
0433     // Arbitrary Syntax HL + Action extensions
0434     //
0435 public:
0436     // Action association extension
0437     void deactivateEditActions();
0438     void activateEditActions();
0439 
0440     //
0441     // internal helper stuff, for katerenderer and so on
0442     //
0443 public:
0444     // should cursor be wrapped ? take config + blockselection state in account
0445     bool wrapCursor() const;
0446 
0447     // some internal functions to get selection state of a line/col
0448     bool cursorSelected(const KTextEditor::Cursor cursor);
0449     bool lineSelected(int line);
0450     bool lineEndSelected(const KTextEditor::Cursor lineEndPos);
0451     bool lineHasSelected(int line);
0452     bool lineIsSelection(int line);
0453 
0454     void ensureCursorColumnValid();
0455 
0456     void tagSelection(KTextEditor::Range oldSelection);
0457 
0458     void selectWord(const KTextEditor::Cursor cursor);
0459     void selectLine(const KTextEditor::Cursor cursor);
0460 
0461     // BEGIN EDIT STUFF
0462 public:
0463     void editStart();
0464     void editEnd(int editTagLineStart, int editTagLineEnd, bool tagFrom);
0465 
0466     void editSetCursor(const KTextEditor::Cursor cursor);
0467     // END
0468 
0469     // BEGIN TAG & CLEAR
0470 public:
0471     bool tagLine(const KTextEditor::Cursor virtualCursor);
0472 
0473     bool tagRange(KTextEditor::Range range, bool realLines = false);
0474     bool tagLines(KTextEditor::LineRange lineRange, bool realLines = false);
0475     bool tagLines(KTextEditor::Cursor start, KTextEditor::Cursor end, bool realCursors = false);
0476     bool tagLines(KTextEditor::Range range, bool realRange = false);
0477 
0478     void tagAll();
0479 
0480     void clear();
0481 
0482     void repaintText(bool paintOnlyDirty = false);
0483 
0484     void updateView(bool changed = false);
0485     // END
0486 
0487     //
0488     // KTextEditor::AnnotationView
0489     //
0490 public:
0491     void setAnnotationModel(KTextEditor::AnnotationModel *model) override;
0492     KTextEditor::AnnotationModel *annotationModel() const override;
0493     void setAnnotationBorderVisible(bool visible) override;
0494     bool isAnnotationBorderVisible() const override;
0495     void setAnnotationItemDelegate(KTextEditor::AbstractAnnotationItemDelegate *delegate) override;
0496     KTextEditor::AbstractAnnotationItemDelegate *annotationItemDelegate() const override;
0497     void setAnnotationUniformItemSizes(bool enable) override;
0498     bool uniformAnnotationItemSizes() const override;
0499 
0500 Q_SIGNALS:
0501     void annotationContextMenuAboutToShow(KTextEditor::View *view, QMenu *menu, int line) override;
0502     void annotationActivated(KTextEditor::View *view, int line) override;
0503     // KF6: fix View -> KTextEditor::View
0504     void annotationBorderVisibilityChanged(View *view, bool visible) override;
0505 
0506     void navigateLeft();
0507     void navigateRight();
0508     void navigateUp();
0509     void navigateDown();
0510     void navigateAccept();
0511     void navigateBack();
0512 
0513 private:
0514     KTextEditor::AnnotationModel *m_annotationModel;
0515 
0516     //
0517     // KTextEditor::View
0518     //
0519 public:
0520     void emitNavigateLeft()
0521     {
0522         Q_EMIT navigateLeft();
0523     }
0524     void emitNavigateRight()
0525     {
0526         Q_EMIT navigateRight();
0527     }
0528     void emitNavigateUp()
0529     {
0530         Q_EMIT navigateUp();
0531     }
0532     void emitNavigateDown()
0533     {
0534         Q_EMIT navigateDown();
0535     }
0536     void emitNavigateAccept()
0537     {
0538         Q_EMIT navigateAccept();
0539     }
0540     void emitNavigateBack()
0541     {
0542         Q_EMIT navigateBack();
0543     }
0544     /**
0545      Return values for "save" related commands.
0546     */
0547     bool isOverwriteMode() const;
0548 
0549     bool isLineRTL(int line) const;
0550 
0551     QTextLayout *textLayout(int line) const;
0552     QTextLayout *textLayout(const KTextEditor::Cursor pos) const;
0553 
0554 public Q_SLOTS:
0555     void indent();
0556     void unIndent();
0557     void cleanIndent();
0558     void formatIndent();
0559     void align(); // alias of formatIndent, for backward compatibility
0560     void alignOn();
0561     void comment();
0562     void uncomment();
0563     void toggleComment();
0564     void killLine();
0565 
0566     /**
0567      * Sets the cursor to the previous editing position in this document
0568      */
0569     void goToPreviousEditingPosition();
0570 
0571     /**
0572      * Sets the cursor to the next editing position in this document.
0573      */
0574     void goToNextEditingPosition();
0575 
0576     /**
0577      * Uppercases selected text, or an alphabetic character next to the cursor.
0578      */
0579     void uppercase();
0580 
0581     /**
0582      * Lowercases selected text, or an alphabetic character next to the cursor.
0583      */
0584     void lowercase();
0585 
0586     /**
0587      * Capitalizes the selection (makes each word start with an uppercase) or
0588      * the word under the cursor.
0589      */
0590     void capitalize();
0591 
0592     /**
0593      * Joins lines touched by the selection.
0594      */
0595     void joinLines();
0596 
0597     /**
0598      * Performs a line break (insert a new line char) at current cursor position
0599      * and indent the new line.
0600      *
0601      * Most work is done by @c KTextEditor::DocumentPrivate::newLine and
0602      * @c KateAutoIndent::userTypedChar
0603      * @see KTextEditor::DocumentPrivate::newLine, KateAutoIndent
0604      */
0605     void keyReturn();
0606 
0607     /**
0608      * Performs a line break (insert a new line char) at current cursor position
0609      * but keep all leading non word char as indent for the new line.
0610      */
0611     void smartNewline();
0612 
0613     /**
0614      * Inserts a new line character at the current cursor position, with
0615      * the newly inserted line having no indentation regardless of indentation
0616      * settings. Useful e.g. for inserting a new, empty, line to separate
0617      * blocks of code inside a function.
0618      */
0619     void noIndentNewline();
0620 
0621     void newLineAbove();
0622 
0623     void newLineBelow();
0624 
0625     /**
0626      * Insert a tabulator char at current cursor position.
0627      */
0628     void backspace();
0629 
0630     /**
0631      * Remove the word left from the current cursor position including all leading
0632      * space.
0633      * @see KateViewInternal::wordPrev
0634      */
0635     void deleteWordLeft();
0636 
0637     /**
0638      * Remove the current selection. When nothing is selected the char right
0639      * from the current cursor position is removed.
0640      * @see KTextEditor::DocumentPrivate::del
0641      */
0642     void keyDelete();
0643 
0644     /**
0645      * When the char right from the current cursor position is a space is all
0646      * space to the right removed. Otherwise is the word to the right including
0647      * all trialling space removed.
0648      * @see KateViewInternal::wordNext
0649      */
0650     void deleteWordRight();
0651 
0652     /**
0653      * Transpose the characters left and right from the current cursor position
0654      * and move the cursor one position to the right. If the char right to the
0655      * current cursor position is a new line char, nothing is done.
0656      * @see KTextEditor::DocumentPrivate::transpose
0657      */
0658     void transpose();
0659 
0660     /**
0661      * Transpose the word at the current cursor position with the word to the right (or to the left for RTL layouts).
0662      * If the word is the last in the line, try swapping with the previous word instead.
0663      * If the word is the only one in the line, no swapping is done.
0664      * @see KTextEditor::DocumentPrivate::swapTextRanges
0665      */
0666     void transposeWord();
0667     void cursorLeft();
0668     void shiftCursorLeft();
0669     void cursorRight();
0670     void shiftCursorRight();
0671     void wordLeft();
0672     void shiftWordLeft();
0673     void wordRight();
0674     void shiftWordRight();
0675     void home();
0676     void shiftHome();
0677     void end();
0678     void shiftEnd();
0679     void up();
0680     void shiftUp();
0681     void down();
0682     void shiftDown();
0683     void scrollUp();
0684     void scrollDown();
0685     void topOfView();
0686     void shiftTopOfView();
0687     void bottomOfView();
0688     void shiftBottomOfView();
0689     void pageUp();
0690     void shiftPageUp();
0691     void pageDown();
0692     void shiftPageDown();
0693     void top();
0694     void shiftTop();
0695     void bottom();
0696     void shiftBottom();
0697     void toMatchingBracket();
0698     void shiftToMatchingBracket();
0699     void toPrevModifiedLine();
0700     void toNextModifiedLine();
0701     /**
0702      * Insert a tabulator char at current cursor position.
0703      */
0704     void insertTab();
0705 
0706     void gotoLine();
0707 
0708     // config file / session management functions
0709 public:
0710     /**
0711      * Read session settings from the given \p config.
0712      *
0713      * Known flags:
0714      *  "SkipUrl" => don't save/restore the file
0715      *  "SkipMode" => don't save/restore the mode
0716      *  "SkipHighlighting" => don't save/restore the highlighting
0717      *  "SkipEncoding" => don't save/restore the encoding
0718      *
0719      * \param config read the session settings from this KConfigGroup
0720      * \param flags additional flags
0721      * \see writeSessionConfig()
0722      */
0723     void readSessionConfig(const KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override;
0724 
0725     /**
0726      * Write session settings to the \p config.
0727      * See readSessionConfig() for more details.
0728      *
0729      * \param config write the session settings to this KConfigGroup
0730      * \param flags additional flags
0731      * \see readSessionConfig()
0732      */
0733     void writeSessionConfig(KConfigGroup &config, const QSet<QString> &flags = QSet<QString>()) override;
0734 
0735 public Q_SLOTS:
0736     void setEol(int eol);
0737     void setAddBom(bool enabled);
0738     void find();
0739     void findSelectedForwards();
0740     void findSelectedBackwards();
0741     void findNextOccurunceAndSelect();
0742     void findAllOccuruncesAndSelect();
0743     void skipCurrentOccurunceSelection();
0744     void replace();
0745     void findNext();
0746     void findPrevious();
0747     void showSearchWrappedHint(bool isReverseSearch);
0748     void createMultiCursorsFromSelection();
0749     void removeCursorsFromEmptyLines();
0750 
0751     void setFoldingMarkersOn(bool enable); // Not in KTextEditor::View, but should be
0752     void setIconBorder(bool enable);
0753     void setLineNumbersOn(bool enable);
0754     void setScrollBarMarks(bool enable);
0755     void setScrollBarMiniMap(bool enable);
0756     void setScrollBarMiniMapAll(bool enable);
0757     void setScrollBarMiniMapWidth(int width);
0758     void toggleFoldingMarkers();
0759     void toggleIconBorder();
0760     void toggleLineNumbersOn();
0761     void toggleScrollBarMarks();
0762     void toggleScrollBarMiniMap();
0763     void toggleScrollBarMiniMapAll();
0764     void toggleDynWordWrap();
0765     void setDynWrapIndicators(int mode);
0766 
0767 public:
0768     int getEol() const;
0769     QMenu *getEolMenu();
0770 
0771 public:
0772     KateRenderer *renderer();
0773 
0774     bool iconBorder();
0775     bool lineNumbersOn();
0776     bool scrollBarMarks();
0777     bool scrollBarMiniMap();
0778     bool scrollBarMiniMapAll();
0779     int dynWrapIndicators();
0780     bool foldingMarkersOn();
0781 
0782 private Q_SLOTS:
0783     /**
0784      * used to update actions after selection changed
0785      */
0786     void slotSelectionChanged();
0787 
0788     void toggleInputMode();
0789     void cycleInputMode();
0790 
0791 public:
0792     /**
0793      * accessor to katedocument pointer
0794      * @return pointer to document
0795      */
0796     KTextEditor::DocumentPrivate *doc()
0797     {
0798         return m_doc;
0799     }
0800     const KTextEditor::DocumentPrivate *doc() const
0801     {
0802         return m_doc;
0803     }
0804 
0805 public Q_SLOTS:
0806     void slotUpdateUndo();
0807     void toggleInsert();
0808     void reloadFile();
0809     void toggleWWMarker();
0810     void toggleNPSpaces();
0811     void toggleWordCount(bool on);
0812     void toggleWriteLock();
0813     void switchToCmdLine();
0814     void slotReadWriteChanged();
0815     void toggleCamelCaseCursor();
0816 
0817 Q_SIGNALS:
0818     void dropEventPass(QDropEvent *);
0819 
0820 public:
0821     /**
0822      * Folding handler for this view.
0823      * @return folding handler
0824      */
0825     Kate::TextFolding &textFolding()
0826     {
0827         return m_textFolding;
0828     }
0829 
0830 public:
0831     void slotTextInserted(KTextEditor::View *view, const KTextEditor::Cursor position, const QString &text);
0832 
0833     void exportHtmlToFile(const QString &file);
0834 
0835 private Q_SLOTS:
0836     void slotDocumentReloaded();
0837     void slotDocumentAboutToReload();
0838     void slotGotFocus();
0839     void slotLostFocus();
0840     void slotSaveCanceled(const QString &error);
0841     void slotConfigDialog();
0842     void exportHtmlToClipboard();
0843     void exportHtmlToFile();
0844 
0845 public Q_SLOTS:
0846     void slotFoldToplevelNodes();
0847     void slotExpandToplevelNodes();
0848     void slotToggleFolding();
0849     void slotToggleFoldingsInRange();
0850 
0851 private:
0852     KTEXTEDITOR_NO_EXPORT
0853     void setupLayout();
0854     KTEXTEDITOR_NO_EXPORT
0855     void setupConnections();
0856     KTEXTEDITOR_NO_EXPORT
0857     void setupActions();
0858     KTEXTEDITOR_NO_EXPORT
0859     void setupEditActions();
0860     KTEXTEDITOR_NO_EXPORT
0861     void setupCodeFolding();
0862 
0863     std::vector<QAction *> m_editActions;
0864     QAction *m_editUndo;
0865     QAction *m_editRedo;
0866     bool m_gotoBottomAfterReload;
0867     KToggleAction *m_toggleFoldingMarkers;
0868     KToggleAction *m_toggleIconBar;
0869     KToggleAction *m_toggleLineNumbers;
0870     KToggleAction *m_toggleScrollBarMarks;
0871     KToggleAction *m_toggleScrollBarMiniMap;
0872     KToggleAction *m_toggleScrollBarMiniMapAll;
0873     KToggleAction *m_toggleDynWrap;
0874     KSelectAction *m_setDynWrapIndicators;
0875     KToggleAction *m_toggleWWMarker;
0876     KToggleAction *m_toggleNPSpaces;
0877     KToggleAction *m_toggleWordCount;
0878     QAction *m_switchCmdLine;
0879     KToggleAction *m_viInputModeAction;
0880 
0881     KSelectAction *m_setEndOfLine;
0882     KToggleAction *m_addBom;
0883 
0884     QAction *m_cut;
0885     QAction *m_copy;
0886     QAction *m_copyHtmlAction;
0887     QAction *m_paste;
0888     QAction *m_clipboardHistory;
0889     // always nullptr if paste selection isn't supported
0890     QAction *m_pasteSelection = nullptr;
0891     QAction *m_swapWithClipboard;
0892     QAction *m_selectAll;
0893     QAction *m_deSelect;
0894 
0895     QActionGroup *m_inputModeActions;
0896 
0897     KToggleAction *m_toggleBlockSelection;
0898     KToggleAction *m_toggleInsert;
0899     KToggleAction *m_toggleWriteLock;
0900 
0901     bool m_hasWrap;
0902 
0903     KTextEditor::DocumentPrivate *const m_doc;
0904     Kate::TextFolding m_textFolding;
0905     KateViewConfig *const m_config;
0906     KateRenderer *const m_renderer;
0907     KateViewInternal *const m_viewInternal;
0908     KateSpellCheckDialog *m_spell;
0909     KateBookmarks *const m_bookmarks;
0910 
0911     //* margins
0912     QSpacerItem *m_topSpacer;
0913     QSpacerItem *m_leftSpacer;
0914     QSpacerItem *m_rightSpacer;
0915     QSpacerItem *m_bottomSpacer;
0916 
0917 private Q_SLOTS:
0918     void slotHlChanged();
0919 
0920     /**
0921      * Configuration
0922      */
0923 public:
0924     inline KateViewConfig *config()
0925     {
0926         return m_config;
0927     }
0928 
0929     void updateConfig();
0930 
0931     void updateDocumentConfig();
0932 
0933     void updateRendererConfig();
0934 
0935 private Q_SLOTS:
0936     void updateFoldingConfig();
0937 
0938 private:
0939     bool m_startingUp;
0940     bool m_updatingDocumentConfig;
0941 
0942     // stores the current selection
0943     Kate::TextRange m_selection;
0944 
0945     // do we select normal or blockwise ?
0946     bool blockSelect;
0947 
0948     // templates
0949 public:
0950     bool insertTemplateInternal(const KTextEditor::Cursor insertPosition, const QString &templateString, const QString &script = QString());
0951 
0952     /**
0953      * Accessors to the bars...
0954      */
0955 public:
0956     KateViewBar *bottomViewBar() const;
0957     KateDictionaryBar *dictionaryBar();
0958 
0959 private:
0960     KTEXTEDITOR_NO_EXPORT
0961     KateGotoBar *gotoBar();
0962 
0963     /**
0964      * viewbar + its widgets
0965      * they are created on demand...
0966      */
0967 private:
0968     // created in constructor of the view
0969     KateViewBar *m_bottomViewBar;
0970 
0971     // created on demand..., only access them through the above accessors....
0972     KateGotoBar *m_gotoBar;
0973     KateDictionaryBar *m_dictionaryBar;
0974 
0975     // input modes
0976 public:
0977     KateAbstractInputMode *currentInputMode() const;
0978 
0979 public:
0980     KTextEditor::Range visibleRange();
0981 
0982 Q_SIGNALS:
0983     void displayRangeChanged(KTextEditor::ViewPrivate *view);
0984 
0985 protected:
0986     bool event(QEvent *e) override;
0987     void paintEvent(QPaintEvent *e) override;
0988 
0989     KToggleAction *m_toggleOnTheFlySpellCheck;
0990     KateSpellingMenu *m_spellingMenu;
0991 
0992 protected Q_SLOTS:
0993     void toggleOnTheFlySpellCheck(bool b);
0994 
0995 public Q_SLOTS:
0996     void changeDictionary();
0997     void reflectOnTheFlySpellCheckStatus(bool enabled);
0998 
0999 public:
1000     KateSpellingMenu *spellingMenu();
1001 
1002 private:
1003     bool m_userContextMenuSet;
1004 
1005 private Q_SLOTS:
1006     /**
1007      * save folding state before document reload
1008      */
1009     void saveFoldingState();
1010 
1011     /**
1012      * restore folding state after document reload
1013      */
1014     void applyFoldingState();
1015 
1016 public:
1017     /**
1018      * Clear any saved folding state
1019      */
1020     void clearFoldingState();
1021 
1022 private:
1023     KTEXTEDITOR_NO_EXPORT
1024     void clearHighlights();
1025     KTEXTEDITOR_NO_EXPORT
1026     void createHighlights();
1027 
1028 private:
1029     KTEXTEDITOR_NO_EXPORT
1030     void selectionChangedForHighlights();
1031 
1032     /**
1033      * saved folding state
1034      */
1035     QJsonDocument m_savedFoldingState;
1036 
1037     QString m_currentTextForHighlights;
1038 
1039     std::vector<std::unique_ptr<KTextEditor::MovingRange>> m_rangesForHighlights;
1040 
1041 public:
1042     /**
1043      * Attribute of a range changed or range with attribute changed in given line range.
1044      * @param lineRange line range that the change spans
1045      * @param needsRepaint do we need to trigger repaints? e.g. if ranges with attributes change
1046      */
1047     void notifyAboutRangeChange(KTextEditor::LineRange lineRange, bool needsRepaint);
1048 
1049 private Q_SLOTS:
1050     /**
1051      * Delayed update for view after text ranges changed
1052      */
1053     void slotDelayedUpdateOfView();
1054 
1055 Q_SIGNALS:
1056     /**
1057      * Delayed update for view after text ranges changed
1058      */
1059     void delayedUpdateOfView();
1060 
1061     /**
1062      * Emitted whenever the caret enter or leave a range.
1063      * ATM only used by KateStatusBar to update the dict button
1064      */
1065     void caretChangedRange(KTextEditor::View *);
1066 
1067 public:
1068     /**
1069      * set of ranges which had the mouse inside last time, used for rendering
1070      * @return set of ranges which had the mouse inside last time checked
1071      */
1072     const QSet<Kate::TextRange *> *rangesMouseIn() const
1073     {
1074         return &m_rangesMouseIn;
1075     }
1076 
1077     /**
1078      * set of ranges which had the caret inside last time, used for rendering
1079      * @return set of ranges which had the caret inside last time checked
1080      */
1081     const QSet<Kate::TextRange *> *rangesCaretIn() const
1082     {
1083         return &m_rangesCaretIn;
1084     }
1085 
1086     /**
1087      * check if ranges changed for mouse in and caret in
1088      * @param activationType type of activation to check
1089      */
1090     void updateRangesIn(KTextEditor::Attribute::ActivationType activationType);
1091 
1092     //
1093     // helpers for delayed view update after ranges changes
1094     //
1095 private:
1096     /**
1097      * delayed update timer
1098      */
1099     QTimer m_delayedUpdateTimer;
1100 
1101     /**
1102      * line range to update
1103      */
1104     KTextEditor::LineRange m_lineToUpdateRange;
1105 
1106     /**
1107      * set of ranges which had the mouse inside last time
1108      */
1109     QSet<Kate::TextRange *> m_rangesMouseIn;
1110 
1111     /**
1112      * set of ranges which had the caret inside last time
1113      */
1114     QSet<Kate::TextRange *> m_rangesCaretIn;
1115 
1116     //
1117     // forward impl for KTextEditor::MessageInterface
1118     //
1119 public:
1120     /**
1121      * Used by Document::postMessage().
1122      */
1123     void postMessage(KTextEditor::Message *message, QList<QSharedPointer<QAction>> actions);
1124 
1125 private:
1126     /**
1127      * Message widgets showing KTextEditor::Messages.
1128      * The index of the array maps to the enum KTextEditor::Message::MessagePosition.
1129      */
1130     std::array<KateMessageWidget *, 5> m_messageWidgets{{nullptr}};
1131     /** Layout for floating notifications */
1132     KateMessageLayout *m_notificationLayout = nullptr;
1133 
1134     // for unit test 'tests/messagetest.cpp'
1135 public:
1136     KateMessageWidget *messageWidget();
1137 
1138 private:
1139     /**
1140      * The main window responsible for this view, if any
1141      */
1142     QPointer<KTextEditor::MainWindow> m_mainWindow;
1143 
1144     //
1145     // KTextEditor::PrintInterface
1146     //
1147 public Q_SLOTS:
1148     bool print() override;
1149     void printPreview() override;
1150 
1151 public:
1152     /**
1153      * Get the view status bar
1154      * @return status bar, in enabled
1155      */
1156     KateStatusBar *statusBar() const
1157     {
1158         return m_statusBar;
1159     }
1160 
1161     /**
1162      * Toogle status bar, e.g. create or remove it
1163      */
1164     void toggleStatusBar();
1165 
1166     /**
1167      * Get the encoding menu
1168      * @return the encoding menu
1169      */
1170     KateViewEncodingAction *encodingAction() const
1171     {
1172         return m_encodingAction;
1173     }
1174 
1175     /**
1176      * Get the mode menu
1177      * @return the mode menu
1178      */
1179     KateModeMenu *modeAction() const
1180     {
1181         return m_modeAction;
1182     }
1183 
1184 private:
1185     /**
1186      * the status bar of this view
1187      */
1188     KateStatusBar *m_statusBar;
1189 
1190     /**
1191      * the encoding selection menu, used by view + status bar
1192      */
1193     KateViewEncodingAction *m_encodingAction;
1194 
1195     /**
1196      * the mode selection menu, used by view
1197      */
1198     KateModeMenu *m_modeAction;
1199 
1200     /**
1201      * is automatic invocation of completion disabled temporarily?
1202      */
1203     bool m_temporaryAutomaticInvocationDisabled;
1204 
1205 public:
1206     /**
1207      * Returns the attribute for the default style \p defaultStyle.
1208      */
1209     Attribute::Ptr defaultStyleAttribute(DefaultStyle defaultStyle) const override;
1210 
1211     /**
1212      * Get the list of AttributeBlocks for a given \p line in the document.
1213      *
1214      * \return list of AttributeBlocks for given \p line.
1215      */
1216     QList<KTextEditor::AttributeBlock> lineAttributes(int line) override;
1217 
1218 private:
1219     // remember folding state to prevent refolding the first line if it was manually unfolded,
1220     // e.g. when saving a file or changing other config vars
1221     bool m_autoFoldedFirstLine;
1222 
1223 public:
1224     void setScrollPositionInternal(KTextEditor::Cursor cursor);
1225 
1226     void setHorizontalScrollPositionInternal(int x);
1227 
1228     KTextEditor::Cursor maxScrollPositionInternal() const;
1229 
1230     int firstDisplayedLineInternal(LineType lineType) const;
1231 
1232     int lastDisplayedLineInternal(LineType lineType) const;
1233 
1234     QRect textAreaRectInternal() const;
1235 
1236 private:
1237     /**
1238      * script action menu, stored in scoped pointer to ensure
1239      * destruction before other QObject auto-cleanup as it
1240      * manage sub objects on its own that have this view as parent
1241      */
1242     QScopedPointer<KateScriptActionMenu> m_scriptActionMenu;
1243 
1244     // for showSearchWrappedHint()
1245     QPointer<KTextEditor::Message> m_wrappedMessage;
1246     bool m_isLastSearchReversed = false;
1247 };
1248 
1249 }
1250 
1251 #endif