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_COMMANDMODE_H |
8 | #define KATEVI_EMULATED_COMMAND_BAR_COMMANDMODE_H |
9 | |
10 | #include "activemode.h" |
11 | |
12 | #include <QHash> |
13 | |
14 | #include <KCompletion> |
15 | |
16 | namespace KTextEditor |
17 | { |
18 | class ViewPrivate; |
19 | class Command; |
20 | } |
21 | |
22 | namespace KateVi |
23 | { |
24 | class EmulatedCommandBar; |
25 | class MatchHighlighter; |
26 | class InteractiveSedReplaceMode; |
27 | class Completer; |
28 | class InputModeManager; |
29 | |
30 | class CommandMode : public ActiveMode |
31 | { |
32 | public: |
33 | CommandMode(EmulatedCommandBar *emulatedCommandBar, |
34 | MatchHighlighter *matchHighlighter, |
35 | InputModeManager *viInputModeManager, |
36 | KTextEditor::ViewPrivate *view, |
37 | QLineEdit *edit, |
38 | InteractiveSedReplaceMode *interactiveSedReplaceMode, |
39 | Completer *completer); |
40 | ~CommandMode() override |
41 | { |
42 | } |
43 | bool handleKeyPress(const QKeyEvent *keyEvent) override; |
44 | void editTextChanged(const QString &newText) override; |
45 | CompletionStartParams completionInvoked(Completer::CompletionInvocation invocationType) override; |
46 | void completionChosen() override; |
47 | void deactivate(bool wasAborted) override; |
48 | QString executeCommand(const QString &commandToExecute); |
49 | |
50 | private: |
51 | CompletionStartParams activateCommandCompletion(); |
52 | CompletionStartParams activateCommandHistoryCompletion(); |
53 | CompletionStartParams activateSedFindHistoryCompletion(); |
54 | CompletionStartParams activateSedReplaceHistoryCompletion(); |
55 | QString withoutRangeExpression(); |
56 | QString rangeExpression(); |
57 | QString withSedFindTermReplacedWith(const QString &newFindTerm); |
58 | QString withSedDelimiterEscaped(const QString &text); |
59 | bool isCursorInFindTermOfSed(); |
60 | bool isCursorInReplaceTermOfSed(); |
61 | QString sedFindTerm(); |
62 | QString sedReplaceTerm(); |
63 | /** |
64 | * Stuff to do with expressions of the form: |
65 | * |
66 | * s/find/replace/<sedflags> |
67 | */ |
68 | struct ParsedSedExpression { |
69 | bool parsedSuccessfully; |
70 | int findBeginPos; |
71 | int findEndPos; |
72 | int replaceBeginPos; |
73 | int replaceEndPos; |
74 | QChar delimiter; |
75 | }; |
76 | /** |
77 | * The "range expression" is the (optional) expression before the command that describes |
78 | * the range over which the command should be run e.g. '<,'>. @see CommandRangeExpressionParser |
79 | */ |
80 | CommandMode::ParsedSedExpression parseAsSedExpression(); |
81 | int commandBeforeCursorBegin(); |
82 | QLineEdit *m_edit; |
83 | InteractiveSedReplaceMode *m_interactiveSedReplaceMode; |
84 | Completer *m_completer; |
85 | KCompletion m_cmdCompletion; |
86 | QHash<QString, KTextEditor::Command *> m_cmdDict; |
87 | KTextEditor::Command *queryCommand(const QString &cmd) const; |
88 | }; |
89 | } |
90 | |
91 | #endif |
92 |