File indexing completed on 2024-05-05 04:36:48

0001 /* This file is part of KDevelop
0002  *
0003  * Copyright (C) 2012-2015 Miquel Sabaté Solà <mikisabate@gmail.com>
0004  *
0005  * This program is free software: you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation, either version 3 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 
0019 #ifndef RUBY_KEYWORD_ITEM_H
0020 #define RUBY_KEYWORD_ITEM_H
0021 
0022 #include <language/codecompletion/normaldeclarationcompletionitem.h>
0023 #include <completion/completionexport.h>
0024 
0025 namespace ruby {
0026 
0027 /**
0028  * @class KeywordItem
0029  *
0030  * A completion item for a ruby keyword. Depending on how it's initialized
0031  * this class, it will add some extra code.
0032  */
0033 class KDEVRUBYCOMPLETION_EXPORT KeywordItem
0034     : public KDevelop::NormalDeclarationCompletionItem
0035 {
0036 public:
0037     /**
0038      * Constructor.
0039      * @param ctx The code completion context.
0040      * @param keyword The keyword that this item is representing.
0041      * @param customReplacement If the \p line is set to false, it can be used
0042      * for additional power on how the keyword gets replaced. To place the
0043      * cursor, use %CURSOR%. You can select a word with
0044      * %SELECT%word%ENDSELECT%. Finally, use %END% to place an end keyword
0045      * indented to the indentation level of the line we execute the item on.
0046      * If the \p line is set to true, this parameter only acts as a descriptor.
0047      * @param line Set to true if you want that the whole line gets replaced.
0048      * False by default.
0049      */
0050     explicit KeywordItem(KDevelop::CodeCompletionContext::Ptr ctx,
0051                          const QString &keyword,
0052                          const QString &customReplacement = QString(""),
0053                          bool line = false);
0054 
0055     /// Re-implemented from KDevelop::NormalDeclarationCompletionItem.
0056     void execute(KTextEditor::View *view,
0057                  const KTextEditor::Range &word) override;
0058 
0059     /// Re-implemented from KDevelop::NormalDeclarationCompletionItem.
0060     QVariant data(const QModelIndex &index,
0061                   int role,
0062                   const KDevelop::CodeCompletionModel *model) const override;
0063 
0064 private:
0065     QString m_keyword;
0066     QString m_replacement;
0067     bool m_wholeLine;
0068 };
0069 
0070 }
0071 
0072 #endif // RUBY_KEYWORD_ITEM_H