File indexing completed on 2024-04-28 11:45:56
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 #include <vimode/commandinterface.h> 0016 0017 #include <QStringList> 0018 0019 namespace KTextEditor 0020 { 0021 class DocumentPrivate; 0022 } 0023 class KCompletion; 0024 0025 namespace KateVi 0026 { 0027 /** 0028 * This KTextEditor::Command provides vi 'ex' commands 0029 */ 0030 class Commands : public KTextEditor::Command, public KateViCommandInterface 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 0041 public: 0042 ~Commands() override 0043 { 0044 m_instance = nullptr; 0045 } 0046 0047 /** 0048 * execute command on given range 0049 * @param view view to use for execution 0050 * @param cmd cmd string 0051 * @param msg message returned from running the command 0052 * @param range range to execute command on 0053 * @return success 0054 */ 0055 bool exec(class KTextEditor::View *view, const QString &cmd, QString &msg, const KTextEditor::Range &range = KTextEditor::Range(-1, -0, -1, 0)) override; 0056 0057 bool supportsRange(const QString &range) override; 0058 0059 /** This command does not have help. @see KTextEditor::Command::help */ 0060 bool help(class KTextEditor::View *, const QString &, QString &) override 0061 { 0062 return false; 0063 } 0064 0065 /** 0066 * Reimplement from KTextEditor::Command 0067 */ 0068 KCompletion *completionObject(KTextEditor::View *, const QString &) override; 0069 0070 static Commands *self() 0071 { 0072 if (m_instance == nullptr) { 0073 m_instance = new Commands(); 0074 } 0075 return m_instance; 0076 } 0077 0078 private: 0079 static const QStringList &mappingCommands(); 0080 static Mappings::MappingMode modeForMapCommand(const QString &mapCommand); 0081 static bool isMapCommandRecursive(const QString &mapCommand); 0082 }; 0083 0084 /** 0085 * Support vim/sed style search and replace 0086 * @author Charles Samuels <charles@kde.org> 0087 **/ 0088 class SedReplace : public KateCommands::SedReplace, public KateViCommandInterface 0089 { 0090 SedReplace() 0091 { 0092 } 0093 static SedReplace *m_instance; 0094 0095 public: 0096 ~SedReplace() override 0097 { 0098 m_instance = nullptr; 0099 } 0100 0101 static SedReplace *self() 0102 { 0103 if (m_instance == nullptr) { 0104 m_instance = new SedReplace(); 0105 } 0106 return m_instance; 0107 } 0108 0109 protected: 0110 bool interactiveSedReplace(KTextEditor::ViewPrivate *kateView, QSharedPointer<InteractiveSedReplacer> interactiveSedReplace) override; 0111 }; 0112 0113 } 0114 0115 #endif /* KATEVI_CMDS_H */