1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
28 **************************************************************************/
30 #ifndef QMLJSCODECOMPLETION_H
31 #define QMLJSCODECOMPLETION_H
33 #include <qmljs/qmljsdocument.h>
34 #include <texteditor/icompletioncollector.h>
35 #include <QtCore/QDateTime>
36 #include <QtCore/QPointer>
38 namespace TextEditor {
43 class ModelManagerInterface;
45 namespace Interpreter {
50 namespace QmlJSEditor {
54 class FunctionArgumentWidget;
56 class CodeCompletion: public TextEditor::ICompletionCollector
61 CodeCompletion(QmlJS::ModelManagerInterface *modelManager, QObject *parent = 0);
62 virtual ~CodeCompletion();
64 virtual TextEditor::ITextEditable *editor() const;
65 virtual int startPosition() const;
66 virtual bool shouldRestartCompletion();
67 virtual bool supportsEditor(TextEditor::ITextEditable *editor);
68 virtual bool triggersCompletion(TextEditor::ITextEditable *editor);
69 virtual int startCompletion(TextEditor::ITextEditable *editor);
70 virtual void completions(QList<TextEditor::CompletionItem> *completions);
71 virtual void complete(const TextEditor::CompletionItem &item);
72 virtual bool partiallyComplete(const QList<TextEditor::CompletionItem> &completionItems);
73 virtual QList<TextEditor::CompletionItem> getCompletions();
75 virtual void cleanup();
78 void updateSnippets();
80 bool maybeTriggersCompletion(TextEditor::ITextEditable *editor);
81 bool isDelimiter(QChar ch) const;
83 void addCompletions(const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
84 const QIcon &icon, int relevance);
85 void addCompletions(const QStringList &newCompletions,
86 const QIcon &icon, int relevance);
87 void addCompletionsPropertyLhs(
88 const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
89 const QIcon &icon, int relevance);
91 QmlJS::ModelManagerInterface *m_modelManager;
92 TextEditor::ITextEditable *m_editor;
94 QList<TextEditor::CompletionItem> m_completions;
96 QList<TextEditor::CompletionItem> m_snippets;
97 QDateTime m_snippetFileLastModified;
98 QPointer<FunctionArgumentWidget> m_functionArgumentWidget;
99 bool m_restartCompletion;
103 } // end of namespace Internal
104 } // end of namespace QmlJSEditor
106 #endif // QMLJSCODECOMPLETION_H