~ubuntu-branches/ubuntu/vivid/kate/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/codecompletiontestmodels.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE libraries
2
 
   Copyright (C) 2008 Niko Sams <niko.sams\gmail.com>
3
 
 
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.
8
 
 
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.
13
 
 
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.
18
 
*/
19
 
 
20
 
#ifndef KATE_COMPLETIONTESTMODELS_H
21
 
#define KATE_COMPLETIONTESTMODELS_H
22
 
 
23
 
#include "codecompletiontestmodel.h"
24
 
#include <ktexteditor/codecompletionmodelcontrollerinterface.h>
25
 
 
26
 
#include <ktexteditor/document.h>
27
 
#include <ktexteditor/view.h>
28
 
 
29
 
using namespace KTextEditor;
30
 
 
31
 
 
32
 
class CustomRangeModel : public CodeCompletionTestModel, public CodeCompletionModelControllerInterface3
33
 
{
34
 
    Q_OBJECT
35
 
    Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
36
 
public:
37
 
    CustomRangeModel(KTextEditor::View* parent = 0L, const QString &startText = QString())
38
 
        : CodeCompletionTestModel(parent, startText)
39
 
    {}
40
 
    Range completionRange(View* view, const Cursor &position)
41
 
    {
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;
50
 
            }
51
 
        }
52
 
        return range;
53
 
    }
54
 
 
55
 
    bool shouldAbortCompletion(View* view, const Range& range, const QString &currentCompletion)
56
 
    {
57
 
        Q_UNUSED(view);
58
 
        Q_UNUSED(range);
59
 
        static const QRegExp allowedText("^\\$?(\\w*)");
60
 
        return !allowedText.exactMatch(currentCompletion);
61
 
    }
62
 
};
63
 
 
64
 
class CustomAbortModel : public CodeCompletionTestModel, public CodeCompletionModelControllerInterface3
65
 
{
66
 
    Q_OBJECT
67
 
    Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
68
 
public:
69
 
    CustomAbortModel(KTextEditor::View* parent = 0L, const QString &startText = QString())
70
 
        : CodeCompletionTestModel(parent, startText)
71
 
    {}
72
 
 
73
 
    bool shouldAbortCompletion(View* view, const Range& range, const QString &currentCompletion)
74
 
    {
75
 
        Q_UNUSED(view);
76
 
        Q_UNUSED(range);
77
 
        static const QRegExp allowedText("^([\\w-]*)");
78
 
        return !allowedText.exactMatch(currentCompletion);
79
 
    }
80
 
};
81
 
 
82
 
class EmptyFilterStringModel : public CodeCompletionTestModel, public CodeCompletionModelControllerInterface3
83
 
{
84
 
    Q_OBJECT
85
 
    Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
86
 
public:
87
 
    EmptyFilterStringModel(KTextEditor::View* parent = 0L, const QString &startText = QString())
88
 
        : CodeCompletionTestModel(parent, startText)
89
 
    {}
90
 
 
91
 
    QString filterString(View*, const Range&, const Cursor &)
92
 
    {
93
 
        return QString();
94
 
    }
95
 
};
96
 
 
97
 
class UpdateCompletionRangeModel : public CodeCompletionTestModel, public CodeCompletionModelControllerInterface3
98
 
{
99
 
    Q_OBJECT
100
 
    Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
101
 
public:
102
 
    UpdateCompletionRangeModel(KTextEditor::View* parent = 0L, const QString &startText = QString())
103
 
        : CodeCompletionTestModel(parent, startText)
104
 
    {}
105
 
 
106
 
    Range updateCompletionRange(View* view, const Range& range)
107
 
    {
108
 
        Q_UNUSED(view);
109
 
        if (view->document()->text(range) == QString("ab")) {
110
 
            return Range(Cursor(range.start().line(), 0), range.end());
111
 
        }
112
 
        return range;
113
 
    }
114
 
    bool shouldAbortCompletion(View* view, const Range &range, const QString &currentCompletion)
115
 
    {
116
 
        Q_UNUSED(view);
117
 
        Q_UNUSED(range);
118
 
        Q_UNUSED(currentCompletion);
119
 
        return false;
120
 
    }
121
 
};
122
 
 
123
 
class StartCompletionModel : public CodeCompletionTestModel, public CodeCompletionModelControllerInterface3
124
 
{
125
 
    Q_OBJECT
126
 
    Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
127
 
public:
128
 
    StartCompletionModel(KTextEditor::View* parent = 0L, const QString &startText = QString())
129
 
        : CodeCompletionTestModel(parent, startText)
130
 
    {}
131
 
 
132
 
    bool shouldStartCompletion(View* view, const QString &insertedText, bool userInsertion, const Cursor &position)
133
 
    {
134
 
        Q_UNUSED(view);
135
 
        Q_UNUSED(userInsertion);
136
 
        Q_UNUSED(position);
137
 
        if(insertedText.isEmpty())
138
 
            return false;
139
 
 
140
 
        QChar lastChar = insertedText.at(insertedText.count() - 1);
141
 
        if (lastChar == '%') {
142
 
            return true;
143
 
        }
144
 
        return false;
145
 
    }
146
 
};
147
 
 
148
 
class ImmideatelyAbortCompletionModel : public CodeCompletionTestModel, public CodeCompletionModelControllerInterface3
149
 
{
150
 
    Q_OBJECT
151
 
    Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
152
 
public:
153
 
    ImmideatelyAbortCompletionModel(KTextEditor::View* parent = 0L, const QString &startText = QString())
154
 
        : CodeCompletionTestModel(parent, startText)
155
 
    {}
156
 
 
157
 
    virtual bool shouldAbortCompletion(KTextEditor::View* view, const KTextEditor::Range& range, const QString& currentCompletion)
158
 
    {
159
 
        Q_UNUSED(view);
160
 
        Q_UNUSED(range);
161
 
        Q_UNUSED(currentCompletion);
162
 
        return true;
163
 
    }
164
 
};
165
 
 
166
 
#endif