OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qmljseditor / qmljscodecompletion.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef QMLJSCODECOMPLETION_H
34 #define QMLJSCODECOMPLETION_H
35
36 #include <qmljs/qmljsdocument.h>
37 #include <texteditor/icompletioncollector.h>
38 #include <texteditor/snippets/snippetcollector.h>
39 #include <QtCore/QDateTime>
40 #include <QtCore/QPointer>
41
42 namespace TextEditor {
43 class ITextEditor;
44 }
45
46 namespace QmlJS {
47     class ModelManagerInterface;
48
49     namespace Interpreter {
50         class Value;
51     }
52 }
53
54 namespace QmlJSEditor {
55
56 namespace Internal {
57
58 class FunctionArgumentWidget;
59
60 class CodeCompletion: public TextEditor::ICompletionCollector
61 {
62     Q_OBJECT
63
64 public:
65     explicit CodeCompletion(QmlJS::ModelManagerInterface *modelManager, QObject *parent = 0);
66     virtual ~CodeCompletion();
67
68     virtual TextEditor::ITextEditor *editor() const;
69     virtual int startPosition() const;
70     virtual bool shouldRestartCompletion();
71     virtual bool supportsEditor(TextEditor::ITextEditor *editor) const;
72     virtual bool supportsPolicy(TextEditor::CompletionPolicy policy) const;
73     virtual bool triggersCompletion(TextEditor::ITextEditor *editor);
74     virtual int startCompletion(TextEditor::ITextEditor *editor);
75     virtual void completions(QList<TextEditor::CompletionItem> *completions);
76     virtual bool typedCharCompletes(const TextEditor::CompletionItem &item, QChar typedChar);
77     virtual void complete(const TextEditor::CompletionItem &item, QChar typedChar);
78     virtual bool partiallyComplete(const QList<TextEditor::CompletionItem> &completionItems);
79     virtual QList<TextEditor::CompletionItem> getCompletions();
80     virtual void sortCompletion(QList<TextEditor::CompletionItem> &completionItems);
81
82     virtual void cleanup();
83
84 private:
85
86     bool maybeTriggersCompletion(TextEditor::ITextEditor *editor);
87     bool isDelimiter(QChar ch) const;
88
89     bool completeUrl(const QString &relativeBasePath, const QString &urlString);
90     bool completeFileName(const QString &relativeBasePath, const QString &fileName,
91                           const QStringList &patterns = QStringList());
92
93     void addCompletions(const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
94                         const QIcon &icon, int relevance);
95     void addCompletions(const QStringList &newCompletions,
96                         const QIcon &icon, int relevance);
97     void addCompletionsPropertyLhs(
98             const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
99             const QIcon &icon, int relevance, bool afterOn);
100
101     QmlJS::ModelManagerInterface *m_modelManager;
102     TextEditor::ITextEditor *m_editor;
103     int m_startPosition;
104     bool m_restartCompletion;
105     TextEditor::SnippetCollector m_snippetProvider;
106     QList<TextEditor::CompletionItem> m_completions;
107     QPointer<FunctionArgumentWidget> m_functionArgumentWidget;
108 };
109
110
111 } // namespace Internal
112 } // namespace QmlJSEditor
113
114 #endif // QMLJSCODECOMPLETION_H