~ubuntu-branches/ubuntu/jaunty/kde4libs/jaunty-updates

« back to all changes in this revision

Viewing changes to interfaces/ktexteditor/codecompletionmodelcontrollerinterface.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2008-12-11 18:26:08 UTC
  • mfrom: (1.1.24 upstream)
  • Revision ID: james.westby@ubuntu.com-20081211182608-tsu6p8ncbw1gnqxt
Tags: 4:4.1.85-0ubuntu1
* New upstream release
* Patches:
  + Removed 15_kfreebsd_support.diff from patches/series (doesn't apply and
    has no use for Ubuntu)
  + Redid 20_use_dejavu_as_default_font.diff
  + Completely removed kubuntu_09_fix_application_menu.diff (applied upstream)
  + Refreshed kubuntu_54_use_xdg_menu_prefix.diff
  + Dropped plasma/widgets/toolbutton.cpp from kubuntu_qt_ftbfs.diff (applied
    upstream)
  + Global quilt refresh

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
#include "codecompletionmodelcontrollerinterface.h"
 
21
 
 
22
#include <ktexteditor/view.h>
 
23
#include <ktexteditor/document.h>
 
24
 
 
25
namespace KTextEditor {
 
26
 
 
27
CodeCompletionModelControllerInterface::CodeCompletionModelControllerInterface()
 
28
{
 
29
}
 
30
 
 
31
CodeCompletionModelControllerInterface::~CodeCompletionModelControllerInterface()
 
32
{
 
33
}
 
34
 
 
35
bool CodeCompletionModelControllerInterface::shouldStartCompletion(View* view, const QString &insertedText, const Cursor &position)
 
36
{
 
37
    Q_UNUSED(view);
 
38
    Q_UNUSED(position);
 
39
    if(insertedText.isEmpty())
 
40
        return false;
 
41
 
 
42
    QChar lastChar = insertedText.at(insertedText.count() - 1);
 
43
    if (lastChar.isLetter() || lastChar.isNumber() || lastChar == '.' || lastChar == '_' || lastChar == '>') {
 
44
        return true;
 
45
    }
 
46
    return false;
 
47
}
 
48
 
 
49
Range CodeCompletionModelControllerInterface::completionRange(View* view, const Cursor &position)
 
50
{
 
51
    Cursor end = position;
 
52
 
 
53
    QString text = view->document()->line(end.line());
 
54
 
 
55
    static QRegExp findWordStart( "\\b([_\\w]+)$" );
 
56
    static QRegExp findWordEnd( "^([_\\w]*)\\b" );
 
57
 
 
58
    Cursor start = end;
 
59
 
 
60
    if (findWordStart.lastIndexIn(text.left(end.column())) >= 0)
 
61
        start.setColumn(findWordStart.pos(1));
 
62
 
 
63
    if (findWordEnd.indexIn(text.mid(end.column())) >= 0)
 
64
        end.setColumn(end.column() + findWordEnd.cap(1).length());
 
65
 
 
66
    return Range(start, end);
 
67
}
 
68
 
 
69
void CodeCompletionModelControllerInterface::updateCompletionRange(View* view, SmartRange& range)
 
70
{
 
71
    Q_UNUSED(view);
 
72
    Q_UNUSED(range);
 
73
}
 
74
 
 
75
QString CodeCompletionModelControllerInterface::filterString(View* view, const SmartRange &range, const Cursor &position)
 
76
{
 
77
    return view->document()->text(KTextEditor::Range(range.start(), position));
 
78
}
 
79
 
 
80
bool CodeCompletionModelControllerInterface::shouldAbortCompletion(View* view, const SmartRange &range, const QString &currentCompletion)
 
81
{
 
82
    Q_UNUSED(view);
 
83
    Q_UNUSED(range);
 
84
    static const QRegExp allowedText("^(\\w*)");
 
85
    return !allowedText.exactMatch(currentCompletion);
 
86
}
 
87
 
 
88
}