File indexing completed on 2024-05-05 03:58:34

0001 /*
0002     SPDX-FileCopyrightText: 2013-2016 Simon St James <kdedevel@etotheipiplusone.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KATEVI_EMULATED_COMMAND_BAR_ACTIVEMODE_H
0008 #define KATEVI_EMULATED_COMMAND_BAR_ACTIVEMODE_H
0009 
0010 #include "completer.h"
0011 
0012 class QKeyEvent;
0013 class QString;
0014 class QWidget;
0015 
0016 namespace KTextEditor
0017 {
0018 class Cursor;
0019 class Range;
0020 class ViewPrivate;
0021 }
0022 
0023 namespace KateVi
0024 {
0025 class EmulatedCommandBar;
0026 struct CompletionStartParams;
0027 class MatchHighlighter;
0028 class InputModeManager;
0029 
0030 class ActiveMode
0031 {
0032 public:
0033     ActiveMode(EmulatedCommandBar *emulatedCommandBar, MatchHighlighter *matchHighlighter, InputModeManager *viInputModeManager, KTextEditor::ViewPrivate *view)
0034         : m_emulatedCommandBar(emulatedCommandBar)
0035         , m_viInputModeManager(viInputModeManager)
0036         , m_view(view)
0037         , m_matchHighligher(matchHighlighter)
0038     {
0039     }
0040     virtual ~ActiveMode() = 0;
0041     virtual bool handleKeyPress(const QKeyEvent *keyEvent) = 0;
0042     virtual void editTextChanged(const QString &newText)
0043     {
0044         Q_UNUSED(newText);
0045     }
0046     virtual KateVi::CompletionStartParams completionInvoked(Completer::CompletionInvocation invocationType);
0047     virtual void completionChosen()
0048     {
0049     }
0050     virtual void deactivate(bool wasAborted) = 0;
0051     void setViInputModeManager(InputModeManager *viInputModeManager);
0052 
0053 protected:
0054     // Helper methods.
0055     void hideAllWidgetsExcept(QWidget *widgetToKeepVisible);
0056     void updateMatchHighlight(KTextEditor::Range matchRange);
0057     void close(bool wasAborted);
0058     void closeWithStatusMessage(const QString &exitStatusMessage);
0059     void startCompletion(const CompletionStartParams &completionStartParams);
0060     void moveCursorTo(const KTextEditor::Cursor cursorPos);
0061     EmulatedCommandBar *emulatedCommandBar();
0062     KTextEditor::ViewPrivate *view();
0063     InputModeManager *viInputModeManager();
0064 
0065 private:
0066     EmulatedCommandBar *m_emulatedCommandBar = nullptr;
0067     InputModeManager *m_viInputModeManager = nullptr;
0068     KTextEditor::ViewPrivate *m_view = nullptr;
0069     MatchHighlighter *m_matchHighligher = nullptr;
0070 };
0071 }
0072 #endif