Commit ee6cca95 authored by Christoph Cullmann's avatar Christoph Cullmann

kill the complete Smart* stuff

parent 90a97f7a
#include "../../ktexteditor/smartcursor.h"
#include "../../ktexteditor/cursorfeedback.h"
#include "../../ktexteditor/cursorfeedback.h"
#include "../../ktexteditor/smartinterface.h"
#include "../../ktexteditor/smartrange.h"
#include "../../ktexteditor/rangefeedback.h"
#include "../../ktexteditor/rangefeedback.h"
......@@ -19,16 +19,7 @@ set(KTEXTEDITOR_PUBLIC_HEADERS
templateinterface2.h
modificationinterface.h
commandinterface.h
smartinterface.h
attribute.h
cursorfeedback.h
rangefeedback.h
smartcursor.h
smartcursornotifier.h
smartcursorwatcher.h
smartrange.h
smartrangenotifier.h
smartrangewatcher.h
codecompletioninterface.h
codecompletionmodel.h
codecompletionmodelcontrollerinterface.h
......@@ -56,15 +47,10 @@ set(ktexteditor_LIB_SRCS
templateinterface2.cpp
editorchooser.cpp
attribute.cpp
cursorfeedback.cpp
rangefeedback.cpp
smartcursor.cpp
smartrange.cpp
codecompletioninterface.cpp
codecompletionmodel.cpp
codecompletionmodelcontrollerinterface.cpp
configinterface.cpp
smartinterface.cpp
highlightinterface.cpp
movinginterface.cpp
movingcursor.cpp
......
......@@ -26,94 +26,6 @@
namespace KTextEditor {
//BEGIN OLD
CodeCompletionModelControllerInterface::CodeCompletionModelControllerInterface()
{
}
CodeCompletionModelControllerInterface::~CodeCompletionModelControllerInterface()
{
}
bool CodeCompletionModelControllerInterface::shouldStartCompletion(View* view, const QString &insertedText, bool userInsertion, const Cursor &position)
{
Q_UNUSED(view);
Q_UNUSED(position);
if(insertedText.isEmpty())
return false;
QChar lastChar = insertedText.at(insertedText.count() - 1);
if ((userInsertion && (lastChar.isLetter() || lastChar.isNumber() || lastChar == '_')) ||
lastChar == '.' || insertedText.endsWith(QLatin1String("->"))) {
return true;
}
return false;
}
Range CodeCompletionModelControllerInterface::completionRange(View* view, const Cursor &position)
{
Cursor end = position;
QString text = view->document()->line(end.line());
static QRegExp findWordStart( "\\b([_\\w]+)$" );
static QRegExp findWordEnd( "^([_\\w]*)\\b" );
Cursor start = end;
if (findWordStart.lastIndexIn(text.left(end.column())) >= 0)
start.setColumn(findWordStart.pos(1));
if (findWordEnd.indexIn(text.mid(end.column())) >= 0)
end.setColumn(end.column() + findWordEnd.cap(1).length());
//kDebug()<<"returning:"<<Range(start,end);
return Range(start, end);
}
void CodeCompletionModelControllerInterface::updateCompletionRange(View* view, SmartRange& range)
{
Q_UNUSED(view);
if(!range.text().isEmpty() && range.text().count() == 1 && range.text().first().trimmed().isEmpty())
//When inserting a newline behind an empty completion-range,, move the range forward to its end
range.start() = range.end();
}
QString CodeCompletionModelControllerInterface::filterString(View* view, const SmartRange &range, const Cursor &position)
{
return view->document()->text(KTextEditor::Range(range.start(), position));
}
bool CodeCompletionModelControllerInterface::shouldAbortCompletion(View* view, const SmartRange &range, const QString &currentCompletion)
{
//kDebug()<<view->cursorPosition();
//kDebug()<<range;
if(view->cursorPosition() < range.start() || view->cursorPosition() > range.end())
return true; //Always abort when the completion-range has been left
//Do not abort completions when the text has been empty already before and a newline has been entered
static const QRegExp allowedText("^(\\w*)");
return !allowedText.exactMatch(currentCompletion);
}
void CodeCompletionModelControllerInterface::aborted(KTextEditor::View* view) {
Q_UNUSED(view);
}
bool CodeCompletionModelControllerInterface::shouldExecute(const QModelIndex& index, QChar inserted) {
Q_UNUSED(index);
Q_UNUSED(inserted);
return false;
}
KTextEditor::CodeCompletionModelControllerInterface2::MatchReaction CodeCompletionModelControllerInterface2::matchingItem(const QModelIndex& selected) {
Q_UNUSED(selected)
return HideListIfAutomaticInvocation;
}
//END OLD
//BEGIN V3
CodeCompletionModelControllerInterface3::CodeCompletionModelControllerInterface3()
......
......@@ -21,7 +21,6 @@
#define KDELIBS_KTEXTEDITOR_CODECOMPLETIONMODELCONTROLLERINTERFACE_H
#include <ktexteditor/ktexteditor_export.h>
#include <ktexteditor/smartrange.h>
#include <ktexteditor/cursor.h>
#include "codecompletionmodel.h"
......@@ -29,159 +28,6 @@ class QModelIndex;
namespace KTextEditor {
class View;
/**
* \short Controller interface for a CodeCompletionModel
*
* \ingroup kte_group_ccmodel_extensions
*
* The CodeCompletionModelControllerInterface gives an CodeCompletionModel better
* control over the completion.
*
* By implementing methods defined in this interface you can:
* - control when automatic completion should start (shouldStartCompletion())
* - define a custom completion range (that will be replaced when the completion
* is executed) (completionRange())
* - dynamically modify the completion range during completion (updateCompletionRange())
* - specify the string used for filtering the completion (filterString())
* - control when completion should stop (shouldAbortCompletion())
*
* When the interface is not implemented, or no methods are overridden the
* default behaviour is used, which will be correct in many situations.
*
*
* \section markext_access Implemeting the Interface
* To use this class implement it in your CodeCompletionModel.
*
* \code
* class MyCodeCompletion : public KTextEditor::CodeCompletionTestModel,
public KTextEditor::CodeCompletionModelControllerInterface
* {
* Q_OBJECT
* Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface)
* public:
* KTextEditor::Range completionRange(KTextEditor::View* view, const KTextEditor::Cursor &position);
* };
* \endcode
*
* \see CodeCompletionModel
* \author Niko Sams \<niko.sams@gmail.com\>
* \since 4.2
*/
class KTEXTEDITOR_EXPORT_DEPRECATED CodeCompletionModelControllerInterface
{
public:
CodeCompletionModelControllerInterface();
virtual ~CodeCompletionModelControllerInterface();
/**
* This function decides if the automatic completion should be started when
* the user entered some text.
*
* The default implementation will return true if the last character in
* \p insertedText is a letter, a number, '.', '_' or '\>'
*
* \param view The view to generate completions for
* \param insertedText The text that was inserted by the user
* \param userInsertion Whether the text was inserted by the user using typing.
* If false, it may have been inserted for example by code-completion.
* \param position Current cursor position
* \return \e true, if the completion should be started, otherwise \e false
*/
virtual bool shouldStartCompletion(View* view, const QString &insertedText, bool userInsertion, const Cursor &position);
/**
* This function returns the completion range that will be used for the
* current completion.
*
* This range will be used for filtering the completion list and will get
* replaced when executing the completion
*
* The default implementation will work for most languages that don't have
* special chars in identifiers.
*
* \param view The view to generate completions for
* \param position Current cursor position
* \return the completion range
*/
virtual Range completionRange(View* view, const Cursor &position);
/**
* This function lets the CompletionModel dynamically modify the range.
* Called after every change to the range (eg. when user entered text)
*
* The default implementation does nothing.
*
* The smart-mutex is not locked when this is called.
* @warning Make sure you lock it before you change the range
*
* \param view The view to generate completions for
* \param range Reference to the current range
*/
virtual void updateCompletionRange(View* view, SmartRange& range);
/**
* This function returns the filter-text used for the current completion.
* Can return an empty string to disable filtering.
*
* The default implementation will return the text from \p range start to
* the cursor \p position.
*
* The smart-mutex is not locked when this is called.
*
* \param view The view to generate completions for
* \param range The completion range
* \param position Current cursor position
* \return the string used for filtering the completion list
*/
virtual QString filterString(View* view, const SmartRange& range, const Cursor &position);
/**
* This function decides if the completion should be aborted.
* Called after every change to the range (eg. when user entered text)
*
* The default implementation will return true when any special character was entered, or when the range is empty.
*
* The smart-mutex is not locked when this is called.
*
* \param view The view to generate completions for
* \param range The completion range
* \param currentCompletion The text typed so far
* \return \e true, if the completion should be aborted, otherwise \e false
*/
virtual bool shouldAbortCompletion(View* view, const SmartRange& range, const QString &currentCompletion);
/**
* When an item within this model is currently selected in the completion-list, and the user inserted the given character,
* should the completion-item be executed? This can be used to execute items from other inputs than the return-key.
* For example a function item could be executed by typing '(', or variable items by typing '.'.
* \param selected The currently selected index
* \param inserted The character that was inserted by tue user
*/
virtual bool shouldExecute(const QModelIndex& selected, QChar inserted);
/**
* Notification that completion for this model has been aborted.
* \param view The view in which the completion for this model was aborted
*/
virtual void aborted(View* view);
};
///Extension of CodeCompletionModelControllerInterface
class KTEXTEDITOR_EXPORT_DEPRECATED CodeCompletionModelControllerInterface2 : public CodeCompletionModelControllerInterface {
public:
enum MatchReaction {
None,
HideListIfAutomaticInvocation /** If this is returned, the completion-list is hidden if it was invoked automatically */
};
/**
* Called whenever an item in the completion-list perfectly matches the current filter text.
* \param The index that is matched
* \return Whether the completion-list should be hidden on this event. The default-implementation always returns HideListIfAutomaticInvocation
*/
virtual MatchReaction matchingItem(const QModelIndex& matched);
};
//BEGIN V3
/**
......
/* This file is part of the KDE project
Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "cursorfeedback.h"
using namespace KTextEditor;
SmartCursorWatcher::SmartCursorWatcher( )
: m_wantDirectChanges(true)
{
}
SmartCursorWatcher::~ SmartCursorWatcher( )
{
}
void SmartCursorWatcher::positionChanged( SmartCursor * )
{
}
void SmartCursorWatcher::positionDeleted( SmartCursor * )
{
}
void SmartCursorWatcher::characterDeleted( SmartCursor * , bool )
{
}
void SmartCursorWatcher::characterInserted( SmartCursor * , bool )
{
}
bool SmartCursorWatcher::wantsDirectChanges( ) const
{
return m_wantDirectChanges;
}
void SmartCursorWatcher::setWantsDirectChanges( bool wantsDirectChanges )
{
m_wantDirectChanges = wantsDirectChanges;
}
SmartCursorNotifier::SmartCursorNotifier( )
: m_wantDirectChanges(true)
{
}
bool SmartCursorNotifier::wantsDirectChanges( ) const
{
return m_wantDirectChanges;
}
void SmartCursorNotifier::setWantsDirectChanges( bool wantsDirectChanges )
{
m_wantDirectChanges = wantsDirectChanges;
}
void SmartCursorWatcher::deleted( SmartCursor * )
{
}
// kate: space-indent on; indent-width 2; replace-tabs on;
/* This file is part of the KDE libraries
Copyright (C) 2009 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KDELIBS_KTEXTEDITOR_CURSORFEEDBACK_H
#define KDELIBS_KTEXTEDITOR_CURSORFEEDBACK_H
#include "smartcursornotifier.h"
#include "smartcursorwatcher.h"
#endif // KDELIBS_KTEXTEDITOR_CURSORFEEDBACK_H
/* This file is part of the KDE libraries
* Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.*/
#include "rangefeedback.h"
using namespace KTextEditor;
SmartRangeWatcher::~ SmartRangeWatcher( )
{
}
SmartRangeNotifier::SmartRangeNotifier( )
: m_wantDirectChanges(true)
{
}
bool SmartRangeNotifier::wantsDirectChanges( ) const
{
return m_wantDirectChanges;
}
void SmartRangeNotifier::setWantsDirectChanges( bool wantsDirectChanges )
{
m_wantDirectChanges = wantsDirectChanges;
}
SmartRangeWatcher::SmartRangeWatcher( )
: m_wantDirectChanges(true)
{
}
bool SmartRangeWatcher::wantsDirectChanges( ) const
{
return m_wantDirectChanges;
}
void SmartRangeWatcher::setWantsDirectChanges( bool wantsDirectChanges )
{
m_wantDirectChanges = wantsDirectChanges;
}
void SmartRangeWatcher::rangePositionChanged( SmartRange* )
{
}
void SmartRangeWatcher::rangeContentsChanged( SmartRange* )
{
}
void SmartRangeWatcher::rangeContentsChanged( SmartRange*, SmartRange* )
{
}
void SmartRangeWatcher::mouseEnteredRange( SmartRange*, View* )
{
}
void SmartRangeWatcher::mouseExitedRange( SmartRange*, View* )
{
}
void SmartRangeWatcher::caretEnteredRange( SmartRange*, View* )
{
}
void SmartRangeWatcher::caretExitedRange( SmartRange*, View* )
{
}
void SmartRangeWatcher::rangeEliminated( SmartRange* )
{
}
void SmartRangeWatcher::rangeDeleted( SmartRange* )
{
}
void SmartRangeWatcher::childRangeInserted( SmartRange*, SmartRange* )
{
}
void SmartRangeWatcher::childRangeRemoved( SmartRange*, SmartRange* )
{
}
void SmartRangeWatcher::rangeAttributeChanged( SmartRange*, Attribute::Ptr, Attribute::Ptr )
{
}
void SmartRangeWatcher::parentRangeChanged( SmartRange *, SmartRange *, SmartRange * )
{
}
// kate: space-indent on; indent-width 2; replace-tabs on;
/* This file is part of the KDE libraries
* Copyright (C) 2009 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.*/
#ifndef KDELIBS_KTEXTEDITOR_RANGEFEEDBACK_H
#define KDELIBS_KTEXTEDITOR_RANGEFEEDBACK_H
#include "smartrangenotifier.h"
#include "smartrangewatcher.h"
#endif // KDELIBS_KTEXTEDITOR_RANGEFEEDBACK_H
/* This file is part of the KDE project
Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "smartcursor.h"
#include "document.h"
#include "smartrange.h"
using namespace KTextEditor;
SmartCursor::SmartCursor( const Cursor & position, Document * doc, InsertBehavior insertBehavior )
: Cursor(position)
, m_doc(doc)
, m_moveOnInsert(insertBehavior == MoveOnInsert)
{
Q_ASSERT(m_doc);
}
SmartCursor::~ SmartCursor( )
{
}
bool SmartCursor::isValid( ) const
{
return m_doc->cursorInText(*this);
}
bool SmartCursor::atEndOfDocument( ) const
{
return *this >= m_doc->documentEnd();
}
bool SmartCursor::isSmartCursor( ) const
{
return true;
}
bool SmartCursor::insertText( const QStringList & text, bool block )
{
return document()->insertText(*this, text, block);
}
QChar SmartCursor::character( ) const
{
return document()->character(*this);
}
SmartRange * SmartCursor::smartRange( ) const
{
return static_cast<SmartRange*>(m_range);
}
Document* SmartCursor::document() const
{
return m_doc;
}
bool SmartCursor::atEndOfLine( ) const
{
return column() == m_doc->lineLength(line());
}
SmartCursor::InsertBehavior SmartCursor::insertBehavior( ) const
{
return m_moveOnInsert ? MoveOnInsert : StayOnInsert;
}
void SmartCursor::setInsertBehavior( InsertBehavior insertBehavior )
{
m_moveOnInsert = insertBehavior == MoveOnInsert;
}
SmartCursor * SmartCursor::toSmartCursor( ) const
{
return const_cast<SmartCursor*>(this);
}
bool SmartCursor::advance(int distance, AdvanceMode mode)
{
Cursor c = *this;
if (mode == ByCharacter) {
while (distance) {
int lineLength = document()->lineLength(c.line());
if (distance > 0) {
int advance = qMin(lineLength - c.column(), distance);
if (distance > advance) {
if (c.line() + 1 >= document()->lines())
return false;
c.setPosition(c.line() + 1, 0);
// Account for end of line advancement
distance -= advance + 1;
} else {
c.setColumn(c.column() + distance);
distance = 0;
}
} else {
int back = qMin(c.column(), -distance);
if (-distance > back) {
if (c.line() - 1 < 0)
return false;
c.setPosition(c.line() - 1, document()->lineLength(c.line() - 1));
// Account for end of line advancement
distance += back + 1;
} else {
c.setColumn(c.column() + distance);
distance = 0;
}
}
}
} else {
// Not supported by the interface alone
return false;
}
setPosition(c);
return true;
}
// kate: space-indent on; indent-width 2; replace-tabs on;
This diff is collapsed.
/* This file is part of the KDE project
Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to