File indexing completed on 2024-04-28 07:47:05
0001 /* 0002 SPDX-FileCopyrightText: 2003-2005 Anders Lund <anders@alweb.dk> 0003 SPDX-FileCopyrightText: 2001-2010 Christoph Cullmann <cullmann@kde.org> 0004 SPDX-FileCopyrightText: 2001 Charles Samuels <charles@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KATEVI_CMDS_H 0010 #define KATEVI_CMDS_H 0011 0012 #include "mappings.h" 0013 #include <KTextEditor/Command> 0014 #include <katesedcmd.h> 0015 0016 #include <QStringList> 0017 0018 namespace KTextEditor 0019 { 0020 class DocumentPrivate; 0021 } 0022 class KCompletion; 0023 0024 namespace KateVi 0025 { 0026 class InputModeManager; 0027 /** 0028 * This KTextEditor::Command provides vi 'ex' commands 0029 */ 0030 class Commands : public KTextEditor::Command 0031 { 0032 Commands() 0033 : KTextEditor::Command(QStringList() << mappingCommands() << QStringLiteral("d") << QStringLiteral("delete") << QStringLiteral("j") 0034 << QStringLiteral("c") << QStringLiteral("change") << QStringLiteral("<") << QStringLiteral(">") 0035 << QStringLiteral("y") << QStringLiteral("yank") << QStringLiteral("ma") << QStringLiteral("mark") 0036 << QStringLiteral("k")) 0037 { 0038 } 0039 static Commands *m_instance; 0040 InputModeManager *m_viInputModeManager; 0041 0042 public: 0043 ~Commands() override 0044 { 0045 m_instance = nullptr; 0046 } 0047 0048 /** 0049 * execute command on given range 0050 * @param view view to use for execution 0051 * @param cmd cmd string 0052 * @param msg message returned from running the command 0053 * @param range range to execute command on 0054 * @return success 0055 */ 0056 bool exec(class KTextEditor::View *view, const QString &cmd, QString &msg, const KTextEditor::Range &range = KTextEditor::Range(-1, -0, -1, 0)) override; 0057 0058 bool supportsRange(const QString &range) override; 0059 0060 /** This command does not have help. @see KTextEditor::Command::help */ 0061 bool help(class KTextEditor::View *, const QString &, QString &) override 0062 { 0063 return false; 0064 } 0065 0066 /** 0067 * Reimplement from KTextEditor::Command 0068 */ 0069 KCompletion *completionObject(KTextEditor::View *, const QString &) override; 0070 0071 static Commands *self() 0072 { 0073 if (m_instance == nullptr) { 0074 m_instance = new Commands(); 0075 } 0076 return m_instance; 0077 } 0078 0079 void setViInputModeManager(InputModeManager *m) 0080 { 0081 m_viInputModeManager = m; 0082 } 0083 0084 private: 0085 static const QStringList &mappingCommands(); 0086 static Mappings::MappingMode modeForMapCommand(const QString &mapCommand); 0087 static bool isMapCommandRecursive(const QString &mapCommand); 0088 }; 0089 0090 /** 0091 * Support vim/sed style search and replace 0092 * @author Charles Samuels <charles@kde.org> 0093 **/ 0094 class SedReplace : public KateCommands::SedReplace 0095 { 0096 SedReplace() 0097 { 0098 } 0099 static SedReplace *m_instance; 0100 InputModeManager *m_viInputModeManager; 0101 0102 public: 0103 ~SedReplace() override 0104 { 0105 m_instance = nullptr; 0106 } 0107 0108 static SedReplace *self() 0109 { 0110 if (m_instance == nullptr) { 0111 m_instance = new SedReplace(); 0112 } 0113 return m_instance; 0114 } 0115 0116 void setViInputModeManager(InputModeManager *m) 0117 { 0118 m_viInputModeManager = m; 0119 } 0120 0121 protected: 0122 bool interactiveSedReplace(KTextEditor::ViewPrivate *kateView, std::shared_ptr<InteractiveSedReplacer> interactiveSedReplace) override; 0123 }; 0124 0125 } 0126 0127 #endif /* KATEVI_CMDS_H */