KTextEditor
codecompletionmodelcontrollerinterface.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "codecompletionmodelcontrollerinterface.h"
00021
00022 #include <QtCore/QModelIndex>
00023
00024 #include <ktexteditor/view.h>
00025 #include <ktexteditor/document.h>
00026
00027 namespace KTextEditor {
00028
00029 CodeCompletionModelControllerInterface::CodeCompletionModelControllerInterface()
00030 {
00031 }
00032
00033 CodeCompletionModelControllerInterface::~CodeCompletionModelControllerInterface()
00034 {
00035 }
00036
00037 bool CodeCompletionModelControllerInterface::shouldStartCompletion(View* view, const QString &insertedText, bool userInsertion, const Cursor &position)
00038 {
00039 Q_UNUSED(view);
00040 Q_UNUSED(position);
00041 if(insertedText.isEmpty())
00042 return false;
00043
00044 QChar lastChar = insertedText.at(insertedText.count() - 1);
00045 if ((userInsertion && (lastChar.isLetter() || lastChar.isNumber() || lastChar == '_')) || lastChar == '.' || insertedText.endsWith("->")) {
00046 return true;
00047 }
00048 return false;
00049 }
00050
00051 Range CodeCompletionModelControllerInterface::completionRange(View* view, const Cursor &position)
00052 {
00053 Cursor end = position;
00054
00055 QString text = view->document()->line(end.line());
00056
00057 static QRegExp findWordStart( "\\b([_\\w]+)$" );
00058 static QRegExp findWordEnd( "^([_\\w]*)\\b" );
00059
00060 Cursor start = end;
00061
00062 if (findWordStart.lastIndexIn(text.left(end.column())) >= 0)
00063 start.setColumn(findWordStart.pos(1));
00064
00065 if (findWordEnd.indexIn(text.mid(end.column())) >= 0)
00066 end.setColumn(end.column() + findWordEnd.cap(1).length());
00067
00068 return Range(start, end);
00069 }
00070
00071 void CodeCompletionModelControllerInterface::updateCompletionRange(View* view, SmartRange& range)
00072 {
00073 Q_UNUSED(view);
00074 if(!range.text().isEmpty() && range.text().count() == 1 && range.text().first().trimmed().isEmpty())
00075
00076 range.start() = range.end();
00077 }
00078
00079 QString CodeCompletionModelControllerInterface::filterString(View* view, const SmartRange &range, const Cursor &position)
00080 {
00081 return view->document()->text(KTextEditor::Range(range.start(), position));
00082 }
00083
00084 bool CodeCompletionModelControllerInterface::shouldAbortCompletion(View* view, const SmartRange &range, const QString ¤tCompletion)
00085 {
00086 if(view->cursorPosition() < range.start() || view->cursorPosition() > range.end())
00087 return true;
00088
00089
00090 Q_UNUSED(view);
00091 Q_UNUSED(range);
00092 static const QRegExp allowedText("^(\\w*)");
00093 return !allowedText.exactMatch(currentCompletion);
00094 }
00095
00096 void CodeCompletionModelControllerInterface::aborted(KTextEditor::View* view) {
00097 Q_UNUSED(view);
00098 }
00099
00100 bool CodeCompletionModelControllerInterface::shouldExecute(const QModelIndex& index, QChar inserted) {
00101 Q_UNUSED(index);
00102 Q_UNUSED(inserted);
00103 return false;
00104 }
00105
00106 KTextEditor::CodeCompletionModelControllerInterface2::MatchReaction CodeCompletionModelControllerInterface2::matchingItem(const QModelIndex& selected) {
00107 return HideListIfAutomaticInvocation;
00108 }
00109
00110 }