Warning, file /frameworks/ktexteditor/src/include/ktexteditor/codecompletioninterface.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KTEXTEDITOR_CODECOMPLETIONINTERFACE_H 0008 #define KTEXTEDITOR_CODECOMPLETIONINTERFACE_H 0009 0010 #include <QObject> 0011 #include <ktexteditor/codecompletionmodel.h> 0012 #include <ktexteditor/range.h> 0013 #include <ktexteditor_export.h> 0014 0015 namespace KTextEditor 0016 { 0017 class CodeCompletionModel; 0018 0019 /** 0020 * \class CodeCompletionInterface codecompletioninterface.h <KTextEditor/CodeCompletionInterface> 0021 * 0022 * \brief Code completion extension interface for the View. 0023 * 0024 * \ingroup kte_group_view_extensions 0025 * 0026 * \section compiface_intro Introduction 0027 * 0028 * The CodeCompletionInterface is designed to provide code completion 0029 * functionality for a KTextEditor::View. This interface provides the basic 0030 * mechanisms to display a list of completions, update this list according 0031 * to user input, and allow the user to select a completion. 0032 * 0033 * Essentially, this provides an item view for the available completions. In 0034 * order to use this interface, you will need to implement a 0035 * CodeCompletionModel that generates the relevant completions given the 0036 * current input. 0037 * 0038 * \section compiface_access Accessing the CodeCompletionInterface 0039 * 0040 * The CodeCompletionInterface is an extension interface for a 0041 * View, i.e. the View inherits the interface \e provided that the 0042 * used KTextEditor library implements the interface. Use qobject_cast to 0043 * access the interface: 0044 * \code 0045 * // view is of type KTextEditor::View* 0046 * auto iface = qobject_cast<KTextEditor::CodeCompletionInterface*>(view); 0047 * 0048 * if (iface) { 0049 * // the implementation supports the interface 0050 * // do stuff 0051 * } else { 0052 * // the implementation does not support the interface 0053 * } 0054 * \endcode 0055 * 0056 * \section compiface_usage Using the CodeCompletionInterface 0057 * 0058 * The CodeCompletionInterface can be used in different ways, which we 0059 * will call "automatic", and "manual". 0060 * 0061 * \subsection compiface_automatic Automatic 0062 * 0063 * In automatic mode, the CodeCompletionInterface will take care of 0064 * starting and aborting the generation of code completions as 0065 * appropriate, when the users inserts or changes text. 0066 * 0067 * To use the interface in this way, first register a CodeCompletionModel 0068 * using registerCompletionModel(). Now call setAutomaticCompletionEnabled() 0069 * to enabled automatic completions. 0070 * 0071 * \subsection compiface_manual Manual 0072 * 0073 * If you need more control over when code completions get shown or not, 0074 * or which fragment of the text should be considered as the basis for 0075 * generated completions, proceed as follows: 0076 * 0077 * Call setAutomaticCompletionEnabled(false) to disable automatic 0078 * completions. To start the generation of code completions for the current 0079 * word, call startCompletion(), with the appropriate parameters. To hide the 0080 * generated completions, use abortCompletion(). 0081 * 0082 * \see KTextEditor::View, KTextEditor::CodeCompletionModel 0083 */ 0084 class KTEXTEDITOR_EXPORT CodeCompletionInterface 0085 { 0086 public: 0087 virtual ~CodeCompletionInterface(); 0088 0089 /** 0090 * Query whether the code completion box is currently displayed. 0091 */ 0092 virtual bool isCompletionActive() const = 0; 0093 0094 /** 0095 * Invoke code completion over a given range, with a specific \a model. 0096 */ 0097 virtual void startCompletion(const Range &word, CodeCompletionModel *model) = 0; 0098 0099 /** 0100 * Abort the currently displayed code completion without executing any currently 0101 * selected completion. This is safe, even when the completion box is not currently 0102 * active. 0103 * \see isCompletionActive() 0104 */ 0105 virtual void abortCompletion() = 0; 0106 0107 /** 0108 * Force execution of the currently selected completion, and hide the code completion 0109 * box. 0110 */ 0111 virtual void forceCompletion() = 0; 0112 0113 /** 0114 * Register a new code completion \p model. 0115 * \param model new completion model 0116 * \see unregisterCompletionModel() 0117 */ 0118 virtual void registerCompletionModel(CodeCompletionModel *model) = 0; 0119 0120 /** 0121 * Unregister a code completion \p model. 0122 * \param model the model that should be unregistered 0123 * \see registerCompletionModel() 0124 */ 0125 virtual void unregisterCompletionModel(CodeCompletionModel *model) = 0; 0126 0127 /** 0128 * Determine the status of automatic code completion invocation. 0129 */ 0130 virtual bool isAutomaticInvocationEnabled() const = 0; 0131 0132 /** 0133 * Enable or disable automatic code completion invocation. 0134 */ 0135 virtual void setAutomaticInvocationEnabled(bool enabled = true) = 0; 0136 0137 // Q_SIGNALS: 0138 // void completionExecuted(KTextEditor::View* view, const KTextEditor::Cursor& position, KTextEditor::CodeCompletionModel* model, int row); 0139 // void completionAborted(KTextEditor::View* view); 0140 }; 0141 0142 /** 0143 * \class CodeCompletionInterfaceV2 codecompletioninterface.h <KTextEditor/CodeCompletionInterface> 0144 * 0145 * \brief Code completion extension interface for the View, version 2. 0146 * 0147 * \ingroup kte_group_view_extensions 0148 * 0149 * \section compifacev2_intro Introduction 0150 * 0151 * The CodeCompletionInterfaceV2 is an extended version of the CodeCompletionInterface. 0152 * Refer to the base CodeCompletionInterface for a more detailed description. 0153 * 0154 * \section compifacev2_access Accessing the CodeCompletionInterfaceV2 0155 * 0156 * The CodeCompletionInterfaceV2 is an extension interface for a 0157 * View, i.e. the View inherits the interface \e provided that the 0158 * used KTextEditor library implements the interface. Use qobject_cast to 0159 * access the interface: 0160 * \code 0161 * // view is of type KTextEditor::View* 0162 * auto iface = qobject_cast<KTextEditor::CodeCompletionInterfaceV2*>(view); 0163 * 0164 * if (iface) { 0165 * // the implementation supports the interface 0166 * // do stuff 0167 * } else { 0168 * // the implementation does not support the interface 0169 * } 0170 * \endcode 0171 * 0172 * \since 5.74 0173 */ 0174 class KTEXTEDITOR_EXPORT CodeCompletionInterfaceV2 : public CodeCompletionInterface 0175 { 0176 // KF6: Merge KTextEditor::CodeCompletionInterfaceV2 into KTextEditor::CodeCompletionInterface 0177 public: 0178 ~CodeCompletionInterfaceV2() override; 0179 /** 0180 * Invoke code completion over a given range, with specific models and invocation type. 0181 * \param models list of models to start. If this is an empty list, all registered models are started. 0182 */ 0183 virtual void startCompletion(const Range &word, 0184 const QList<CodeCompletionModel *> &models = QList<CodeCompletionModel *>(), 0185 CodeCompletionModel::InvocationType invocationType = CodeCompletionModel::ManualInvocation) = 0; 0186 using CodeCompletionInterface::startCompletion; 0187 0188 /** 0189 * Obtain the list of registered code completion models. 0190 * \returns a list of a models that are currently registered 0191 * \see registerCompletionModel(CodeCompletionModel*) 0192 */ 0193 virtual QList<CodeCompletionModel *> codeCompletionModels() const = 0; 0194 }; 0195 0196 } 0197 0198 Q_DECLARE_INTERFACE(KTextEditor::CodeCompletionInterface, "org.kde.KTextEditor.CodeCompletionInterface") 0199 Q_DECLARE_INTERFACE(KTextEditor::CodeCompletionInterfaceV2, "org.kde.KTextEditor.CodeCompletionInterfaceV2") 0200 0201 #endif // KTEXTEDITOR_CODECOMPLETIONINTERFACE_H