File indexing completed on 2024-04-28 15:30:52
0001 /* 0002 SPDX-FileCopyrightText: 2001-2010 Christoph Cullmann <cullmann@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef _KATE_CMD_H 0008 #define _KATE_CMD_H 0009 0010 #include <ktexteditor_export.h> 0011 0012 #include <KCompletion> 0013 0014 #include <QHash> 0015 #include <QStringList> 0016 0017 namespace KTextEditor 0018 { 0019 class Command; 0020 } 0021 0022 class KTEXTEDITOR_EXPORT KateCmd 0023 { 0024 public: 0025 KateCmd(); 0026 ~KateCmd(); 0027 0028 static KateCmd *self(); 0029 0030 bool registerCommand(KTextEditor::Command *cmd); 0031 bool unregisterCommand(KTextEditor::Command *cmd); 0032 KTextEditor::Command *queryCommand(const QString &cmd) const; 0033 QList<KTextEditor::Command *> commands() const; 0034 QStringList commandList() const; 0035 0036 QStringList cmds(); 0037 void appendHistory(const QString &cmd); 0038 const QString fromHistory(int i) const; 0039 uint historyLength() const 0040 { 0041 return m_history.count(); 0042 } 0043 0044 KCompletion *commandCompletionObject(); 0045 0046 private: 0047 QHash<QString, KTextEditor::Command *> m_dict; 0048 QStringList m_cmds; 0049 QStringList m_history; 0050 KCompletion m_cmdCompletion; // shared completion object for all KateCmdLineEdits in each KTE::View 0051 }; 0052 0053 /** 0054 * A KCompletion object that completes last ?unquoted? word in the string 0055 * passed. Do not mistake "shell" for anything related to quoting, this 0056 * simply mimics shell tab completion by completing the last word in the 0057 * provided text. 0058 */ 0059 class KateCmdShellCompletion : public KCompletion 0060 { 0061 public: 0062 KateCmdShellCompletion(); 0063 0064 /** 0065 * Finds completions to the given text. 0066 * The first match is returned and emitted in the signal match(). 0067 * @param text the text to complete 0068 * @return the first match, or QString() if not found 0069 */ 0070 QString makeCompletion(const QString &text) override; 0071 0072 protected: 0073 // Called by KCompletion 0074 void postProcessMatch(QString *match) const override; 0075 void postProcessMatches(QStringList *matches) const override; 0076 void postProcessMatches(KCompletionMatches *matches) const override; 0077 0078 private: 0079 /** 0080 * Split text at the last unquoted space 0081 * 0082 * @param text_start will be set to the text at the left, including the space 0083 * @param text_compl Will be set to the text at the right. This is the text to complete. 0084 */ 0085 void splitText(const QString &text, QString &text_start, QString &text_compl) const; 0086 0087 QChar m_word_break_char; 0088 QChar m_quote_char1; 0089 QChar m_quote_char2; 0090 QChar m_escape_char; 0091 0092 QString m_text_start; 0093 QString m_text_compl; 0094 }; 0095 0096 #endif