1
/* This file is part of the KDE libraries
2
Copyright (C) 2008 Niko Sams <niko.sams\gmail.com>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#ifndef KATE_COMPLETIONTESTMODELS_H
21
#define KATE_COMPLETIONTESTMODELS_H
23
#include "codecompletiontestmodel.h"
24
#include <ktexteditor/codecompletionmodelcontrollerinterface.h>
26
#include <ktexteditor/document.h>
27
#include <ktexteditor/view.h>
29
using namespace KTextEditor;
32
class CustomRangeModel : public CodeCompletionTestModel, public CodeCompletionModelControllerInterface3
35
Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
37
CustomRangeModel(KTextEditor::View* parent = 0L, const QString &startText = QString())
38
: CodeCompletionTestModel(parent, startText)
40
Range completionRange(View* view, const Cursor &position)
42
Range range = CodeCompletionModelControllerInterface3::completionRange(view, position);
43
if (range.start().column() > 0) {
44
KTextEditor::Range preRange(Cursor(range.start().line(), range.start().column()-1),
45
Cursor(range.start().line(), range.start().column()));
46
kDebug() << preRange << view->document()->text(preRange);
47
if (view->document()->text(preRange) == "$") {
48
range.expandToRange(preRange);
49
kDebug() << "using custom completion range" << range;
55
bool shouldAbortCompletion(View* view, const Range& range, const QString ¤tCompletion)
59
static const QRegExp allowedText("^\\$?(\\w*)");
60
return !allowedText.exactMatch(currentCompletion);
64
class CustomAbortModel : public CodeCompletionTestModel, public CodeCompletionModelControllerInterface3
67
Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
69
CustomAbortModel(KTextEditor::View* parent = 0L, const QString &startText = QString())
70
: CodeCompletionTestModel(parent, startText)
73
bool shouldAbortCompletion(View* view, const Range& range, const QString ¤tCompletion)
77
static const QRegExp allowedText("^([\\w-]*)");
78
return !allowedText.exactMatch(currentCompletion);
82
class EmptyFilterStringModel : public CodeCompletionTestModel, public CodeCompletionModelControllerInterface3
85
Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
87
EmptyFilterStringModel(KTextEditor::View* parent = 0L, const QString &startText = QString())
88
: CodeCompletionTestModel(parent, startText)
91
QString filterString(View*, const Range&, const Cursor &)
97
class UpdateCompletionRangeModel : public CodeCompletionTestModel, public CodeCompletionModelControllerInterface3
100
Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
102
UpdateCompletionRangeModel(KTextEditor::View* parent = 0L, const QString &startText = QString())
103
: CodeCompletionTestModel(parent, startText)
106
Range updateCompletionRange(View* view, const Range& range)
109
if (view->document()->text(range) == QString("ab")) {
110
return Range(Cursor(range.start().line(), 0), range.end());
114
bool shouldAbortCompletion(View* view, const Range &range, const QString ¤tCompletion)
118
Q_UNUSED(currentCompletion);
123
class StartCompletionModel : public CodeCompletionTestModel, public CodeCompletionModelControllerInterface3
126
Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
128
StartCompletionModel(KTextEditor::View* parent = 0L, const QString &startText = QString())
129
: CodeCompletionTestModel(parent, startText)
132
bool shouldStartCompletion(View* view, const QString &insertedText, bool userInsertion, const Cursor &position)
135
Q_UNUSED(userInsertion);
137
if(insertedText.isEmpty())
140
QChar lastChar = insertedText.at(insertedText.count() - 1);
141
if (lastChar == '%') {
148
class ImmideatelyAbortCompletionModel : public CodeCompletionTestModel, public CodeCompletionModelControllerInterface3
151
Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
153
ImmideatelyAbortCompletionModel(KTextEditor::View* parent = 0L, const QString &startText = QString())
154
: CodeCompletionTestModel(parent, startText)
157
virtual bool shouldAbortCompletion(KTextEditor::View* view, const KTextEditor::Range& range, const QString& currentCompletion)
161
Q_UNUSED(currentCompletion);