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_COMMANDMODE_H 0008 #define KATEVI_EMULATED_COMMAND_BAR_COMMANDMODE_H 0009 0010 #include "activemode.h" 0011 0012 #include <QHash> 0013 0014 #include <KCompletion> 0015 0016 namespace KTextEditor 0017 { 0018 class ViewPrivate; 0019 class Command; 0020 } 0021 0022 namespace KateVi 0023 { 0024 class EmulatedCommandBar; 0025 class MatchHighlighter; 0026 class InteractiveSedReplaceMode; 0027 class Completer; 0028 class InputModeManager; 0029 0030 class CommandMode : public ActiveMode 0031 { 0032 public: 0033 CommandMode(EmulatedCommandBar *emulatedCommandBar, 0034 MatchHighlighter *matchHighlighter, 0035 InputModeManager *viInputModeManager, 0036 KTextEditor::ViewPrivate *view, 0037 QLineEdit *edit, 0038 InteractiveSedReplaceMode *interactiveSedReplaceMode, 0039 Completer *completer); 0040 ~CommandMode() override 0041 { 0042 } 0043 bool handleKeyPress(const QKeyEvent *keyEvent) override; 0044 void editTextChanged(const QString &newText) override; 0045 CompletionStartParams completionInvoked(Completer::CompletionInvocation invocationType) override; 0046 void completionChosen() override; 0047 void deactivate(bool wasAborted) override; 0048 QString executeCommand(const QString &commandToExecute); 0049 0050 private: 0051 CompletionStartParams activateCommandCompletion(); 0052 CompletionStartParams activateCommandHistoryCompletion(); 0053 CompletionStartParams activateSedFindHistoryCompletion(); 0054 CompletionStartParams activateSedReplaceHistoryCompletion(); 0055 QString withoutRangeExpression(); 0056 QString rangeExpression(); 0057 QString withSedFindTermReplacedWith(const QString &newFindTerm); 0058 QString withSedDelimiterEscaped(const QString &text); 0059 bool isCursorInFindTermOfSed(); 0060 bool isCursorInReplaceTermOfSed(); 0061 QString sedFindTerm(); 0062 QString sedReplaceTerm(); 0063 /** 0064 * Stuff to do with expressions of the form: 0065 * 0066 * s/find/replace/<sedflags> 0067 */ 0068 struct ParsedSedExpression { 0069 bool parsedSuccessfully; 0070 int findBeginPos; 0071 int findEndPos; 0072 int replaceBeginPos; 0073 int replaceEndPos; 0074 QChar delimiter; 0075 }; 0076 /** 0077 * The "range expression" is the (optional) expression before the command that describes 0078 * the range over which the command should be run e.g. '<,'>. @see CommandRangeExpressionParser 0079 */ 0080 CommandMode::ParsedSedExpression parseAsSedExpression(); 0081 int commandBeforeCursorBegin(); 0082 QLineEdit *m_edit; 0083 InteractiveSedReplaceMode *m_interactiveSedReplaceMode; 0084 Completer *m_completer; 0085 KCompletion m_cmdCompletion; 0086 QHash<QString, KTextEditor::Command *> m_cmdDict; 0087 KTextEditor::Command *queryCommand(const QString &cmd) const; 0088 }; 0089 } 0090 0091 #endif