File indexing completed on 2024-04-14 03:55:37

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