File indexing completed on 2024-04-28 05:49:07

0001 /*  This file is part of the Kate project.
0002  *
0003  *  SPDX-FileCopyrightText: 2010 Christoph Cullmann <cullmann@kde.org>
0004  *  SPDX-FileCopyrightText: 2003 Anders Lund <anders.lund@lund.tdcadsl.dk>
0005  *
0006  *  SPDX-License-Identifier: LGPL-2.0-or-later
0007  */
0008 
0009 #pragma once
0010 
0011 #include <ktexteditor/codecompletionmodel.h>
0012 #include <ktexteditor/codecompletionmodelcontrollerinterface.h>
0013 #include <ktexteditor/view.h>
0014 
0015 #include <QStandardItemModel>
0016 
0017 /**
0018  * Project wide completion support.
0019  */
0020 class KateProjectCompletion : public KTextEditor::CodeCompletionModel, public KTextEditor::CodeCompletionModelControllerInterface
0021 {
0022     Q_OBJECT
0023 
0024     Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface)
0025 
0026 public:
0027     /**
0028      * Construct project completion.
0029      * @param plugin our plugin
0030      */
0031     explicit KateProjectCompletion(class KateProjectPlugin *plugin);
0032 
0033     /**
0034      * Deconstruct project completion.
0035      */
0036     ~KateProjectCompletion() override;
0037 
0038     /**
0039      * This function is responsible to generating / updating the list of current
0040      * completions. The default implementation does nothing.
0041      *
0042      * When implementing this function, remember to call setRowCount() (or implement
0043      * rowCount()), and to generate the appropriate change notifications (for instance
0044      * by calling QAbstractItemModel::reset()).
0045      * @param view The view to generate completions for
0046      * @param range The range of text to generate completions for
0047      * */
0048     void completionInvoked(KTextEditor::View *view, const KTextEditor::Range &range, InvocationType invocationType) override;
0049 
0050     bool shouldStartCompletion(KTextEditor::View *view, const QString &insertedText, bool userInsertion, const KTextEditor::Cursor &position) override;
0051     bool shouldAbortCompletion(KTextEditor::View *view, const KTextEditor::Range &range, const QString &currentCompletion) override;
0052 
0053     void saveMatches(KTextEditor::View *view, const KTextEditor::Range &range);
0054 
0055     int rowCount(const QModelIndex &parent) const override;
0056 
0057     QVariant data(const QModelIndex &index, int role) const override;
0058     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0059     QModelIndex parent(const QModelIndex &index) const override;
0060     MatchReaction matchingItem(const QModelIndex &matched) override;
0061 
0062     KTextEditor::Range completionRange(KTextEditor::View *view, const KTextEditor::Cursor &position) override;
0063 
0064     void allMatches(QStandardItemModel &model, KTextEditor::View *view, const KTextEditor::Range &range) const;
0065 
0066 private:
0067     /**
0068      * our plugin view
0069      */
0070     KateProjectPlugin *m_plugin;
0071 
0072     /**
0073      * model with matching data
0074      */
0075     QStandardItemModel m_matches;
0076 
0077     /**
0078      * automatic invocation?
0079      */
0080     bool m_automatic = false;
0081 };