KTextEditor

emulatedcommandbar.h
1/*
2 SPDX-FileCopyrightText: 2013-2016 Simon St James <kdedevel@etotheipiplusone.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KATEVI_EMULATED_COMMAND_BAR_H
8#define KATEVI_EMULATED_COMMAND_BAR_H
9
10#include "kateviewhelpers.h"
11#include <vimode/cmds.h>
12
13namespace KTextEditor
14{
15class ViewPrivate;
16class Command;
17}
18
19class QLabel;
20class QLayout;
21
22namespace KateVi
23{
24class MatchHighlighter;
25class InteractiveSedReplaceMode;
26class SearchMode;
27class CommandMode;
28class ActiveMode;
29class Completer;
30
31/**
32 * A KateViewBarWidget that attempts to emulate some of the features of Vim's own command bar,
33 * including insertion of register contents via ctr-r<registername>; dismissal via
34 * ctrl-c and ctrl-[; bi-directional incremental searching, with SmartCase; interactive sed-replace;
35 * plus a few extensions such as completion from document and navigable sed search and sed replace history.
36 */
37class EmulatedCommandBar : public KateViewBarWidget
38{
39public:
40 enum Mode { NoMode, SearchForward, SearchBackward, Command };
41 explicit EmulatedCommandBar(KateViInputMode *viInputMode, InputModeManager *viInputModeManager, QWidget *parent = nullptr);
42 ~EmulatedCommandBar() override;
43 void init(Mode mode, const QString &initialText = QString());
44 bool isActive() const;
45 KTEXTEDITOR_EXPORT void setCommandResponseMessageTimeout(long commandResponseMessageTimeOutMS);
46 bool handleKeyPress(const QKeyEvent *keyEvent);
47 bool isSendingSyntheticSearchCompletedKeypress();
48
49 void startInteractiveSearchAndReplace(std::shared_ptr<SedReplace::InteractiveSedReplacer> interactiveSedReplace);
50 KTEXTEDITOR_EXPORT QString executeCommand(const QString &commandToExecute);
51
52 void setViInputModeManager(InputModeManager *viInputModeManager);
53
54private:
55 KateViInputMode *m_viInputMode;
56 InputModeManager *m_viInputModeManager;
57 bool m_isActive = false;
58 bool m_wasAborted = true;
59 Mode m_mode = NoMode;
60 KTextEditor::ViewPrivate *m_view = nullptr;
61 QLineEdit *m_edit = nullptr;
62
63 QLabel *m_barTypeIndicator = nullptr;
64 void showBarTypeIndicator(Mode mode);
65
66 bool m_suspendEditEventFiltering = false;
67
68 bool m_waitingForRegister = false;
69 QLabel *m_waitingForRegisterIndicator;
70 bool m_insertedTextShouldBeEscapedForSearchingAsLiteral = false;
71
72 void hideAllWidgetsExcept(QWidget *widgetToKeepVisible);
73
74 friend class ActiveMode;
75 std::unique_ptr<MatchHighlighter> m_matchHighligher;
76
77 std::unique_ptr<Completer> m_completer;
78
79 std::unique_ptr<InteractiveSedReplaceMode> m_interactiveSedReplaceMode;
80 std::unique_ptr<SearchMode> m_searchMode;
81 std::unique_ptr<CommandMode> m_commandMode;
82
83 void switchToMode(ActiveMode *newMode);
84 ActiveMode *m_currentMode = nullptr;
85
86 bool barHandledKeypress(const QKeyEvent *keyEvent);
87 void insertRegisterContents(const QKeyEvent *keyEvent);
88 bool eventFilter(QObject *object, QEvent *event) override;
89 void deleteSpacesToLeftOfCursor();
90 void deleteWordCharsToLeftOfCursor();
91 bool deleteNonWordCharsToLeftOfCursor();
92
93 void closed() override;
94 void closeWithStatusMessage(const QString &exitStatusMessage);
95 QTimer *m_exitStatusMessageDisplayHideTimer;
96 QLabel *m_exitStatusMessageDisplay;
97 long m_exitStatusMessageHideTimeOutMS = 4000;
98
99 void createAndAddBarTypeIndicator(QLayout *layout);
100 void createAndAddEditWidget(QLayout *layout);
101 void createAndAddExitStatusMessageDisplay(QLayout *layout);
102 void createAndInitExitStatusMessageDisplayTimer();
103 void createAndAddWaitingForRegisterIndicator(QLayout *layout);
104
105private:
106 void editTextChanged(const QString &newText);
107 void startHideExitStatusMessageTimer();
108};
109}
110
111#endif /* KATEVI_EMULATED_COMMAND_BAR_H */
A KateViewBarWidget that attempts to emulate some of the features of Vim's own command bar,...
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
QObject * parent() const const
virtual bool event(QEvent *event) override
QLayout * layout() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Feb 24 2024 20:00:58 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.