File indexing completed on 2024-05-05 03:58:35
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_H 0008 #define KATEVI_EMULATED_COMMAND_BAR_H 0009 0010 #include "kateviewhelpers.h" 0011 #include <vimode/cmds.h> 0012 0013 namespace KTextEditor 0014 { 0015 class ViewPrivate; 0016 class Command; 0017 } 0018 0019 class QLabel; 0020 class QLayout; 0021 0022 namespace KateVi 0023 { 0024 class MatchHighlighter; 0025 class InteractiveSedReplaceMode; 0026 class SearchMode; 0027 class CommandMode; 0028 class ActiveMode; 0029 class Completer; 0030 0031 /** 0032 * A KateViewBarWidget that attempts to emulate some of the features of Vim's own command bar, 0033 * including insertion of register contents via ctr-r<registername>; dismissal via 0034 * ctrl-c and ctrl-[; bi-directional incremental searching, with SmartCase; interactive sed-replace; 0035 * plus a few extensions such as completion from document and navigable sed search and sed replace history. 0036 */ 0037 class EmulatedCommandBar : public KateViewBarWidget 0038 { 0039 public: 0040 enum Mode { NoMode, SearchForward, SearchBackward, Command }; 0041 explicit EmulatedCommandBar(KateViInputMode *viInputMode, InputModeManager *viInputModeManager, QWidget *parent = nullptr); 0042 ~EmulatedCommandBar() override; 0043 void init(Mode mode, const QString &initialText = QString()); 0044 bool isActive() const; 0045 KTEXTEDITOR_EXPORT void setCommandResponseMessageTimeout(long commandResponseMessageTimeOutMS); 0046 bool handleKeyPress(const QKeyEvent *keyEvent); 0047 bool isSendingSyntheticSearchCompletedKeypress(); 0048 0049 void startInteractiveSearchAndReplace(std::shared_ptr<SedReplace::InteractiveSedReplacer> interactiveSedReplace); 0050 KTEXTEDITOR_EXPORT QString executeCommand(const QString &commandToExecute); 0051 0052 void setViInputModeManager(InputModeManager *viInputModeManager); 0053 0054 private: 0055 KateViInputMode *m_viInputMode; 0056 InputModeManager *m_viInputModeManager; 0057 bool m_isActive = false; 0058 bool m_wasAborted = true; 0059 Mode m_mode = NoMode; 0060 KTextEditor::ViewPrivate *m_view = nullptr; 0061 QLineEdit *m_edit = nullptr; 0062 0063 QLabel *m_barTypeIndicator = nullptr; 0064 void showBarTypeIndicator(Mode mode); 0065 0066 bool m_suspendEditEventFiltering = false; 0067 0068 bool m_waitingForRegister = false; 0069 QLabel *m_waitingForRegisterIndicator; 0070 bool m_insertedTextShouldBeEscapedForSearchingAsLiteral = false; 0071 0072 void hideAllWidgetsExcept(QWidget *widgetToKeepVisible); 0073 0074 friend class ActiveMode; 0075 std::unique_ptr<MatchHighlighter> m_matchHighligher; 0076 0077 std::unique_ptr<Completer> m_completer; 0078 0079 std::unique_ptr<InteractiveSedReplaceMode> m_interactiveSedReplaceMode; 0080 std::unique_ptr<SearchMode> m_searchMode; 0081 std::unique_ptr<CommandMode> m_commandMode; 0082 0083 void switchToMode(ActiveMode *newMode); 0084 ActiveMode *m_currentMode = nullptr; 0085 0086 bool barHandledKeypress(const QKeyEvent *keyEvent); 0087 void insertRegisterContents(const QKeyEvent *keyEvent); 0088 bool eventFilter(QObject *object, QEvent *event) override; 0089 void deleteSpacesToLeftOfCursor(); 0090 void deleteWordCharsToLeftOfCursor(); 0091 bool deleteNonWordCharsToLeftOfCursor(); 0092 0093 void closed() override; 0094 void closeWithStatusMessage(const QString &exitStatusMessage); 0095 QTimer *m_exitStatusMessageDisplayHideTimer; 0096 QLabel *m_exitStatusMessageDisplay; 0097 long m_exitStatusMessageHideTimeOutMS = 4000; 0098 0099 void createAndAddBarTypeIndicator(QLayout *layout); 0100 void createAndAddEditWidget(QLayout *layout); 0101 void createAndAddExitStatusMessageDisplay(QLayout *layout); 0102 void createAndInitExitStatusMessageDisplayTimer(); 0103 void createAndAddWaitingForRegisterIndicator(QLayout *layout); 0104 0105 private: 0106 void editTextChanged(const QString &newText); 0107 void startHideExitStatusMessageTimer(); 0108 }; 0109 } 0110 0111 #endif /* KATEVI_EMULATED_COMMAND_BAR_H */