mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
interfaces: interfaces: merge all CodeCompletionModelControllerInterface APIs into single one
kate itself implements version 4 of the same interfaces so that is deffinetly something that needs to be merged but for now that will do
This commit is contained in:
parent
417e777c1f
commit
c852b56374
2 changed files with 18 additions and 270 deletions
|
@ -26,8 +26,6 @@
|
|||
|
||||
namespace KTextEditor {
|
||||
|
||||
//BEGIN OLD
|
||||
|
||||
CodeCompletionModelControllerInterface::CodeCompletionModelControllerInterface()
|
||||
{
|
||||
}
|
||||
|
@ -72,20 +70,22 @@ Range CodeCompletionModelControllerInterface::completionRange(View* view, const
|
|||
return Range(start, end);
|
||||
}
|
||||
|
||||
void CodeCompletionModelControllerInterface::updateCompletionRange(View* view, SmartRange& range)
|
||||
Range CodeCompletionModelControllerInterface::updateCompletionRange(View* view, const Range& range)
|
||||
{
|
||||
Q_UNUSED(view);
|
||||
if(!range.text().isEmpty() && range.text().count() == 1 && range.text().first().trimmed().isEmpty())
|
||||
QStringList text=view->document()->textLines(range,false);
|
||||
if(!text.isEmpty() && text.count() == 1 && text.first().trimmed().isEmpty())
|
||||
//When inserting a newline behind an empty completion-range,, move the range forward to its end
|
||||
range.start() = range.end();
|
||||
return Range(range.end(),range.end());
|
||||
|
||||
return range;
|
||||
}
|
||||
|
||||
QString CodeCompletionModelControllerInterface::filterString(View* view, const SmartRange &range, const Cursor &position)
|
||||
QString CodeCompletionModelControllerInterface::filterString(View* view, const Range &range, const Cursor &position)
|
||||
{
|
||||
return view->document()->text(KTextEditor::Range(range.start(), position));
|
||||
}
|
||||
|
||||
bool CodeCompletionModelControllerInterface::shouldAbortCompletion(View* view, const SmartRange &range, const QString ¤tCompletion)
|
||||
bool CodeCompletionModelControllerInterface::shouldAbortCompletion(View* view, const Range &range, const QString ¤tCompletion)
|
||||
{
|
||||
//kDebug()<<view->cursorPosition();
|
||||
//kDebug()<<range;
|
||||
|
@ -102,106 +102,15 @@ void CodeCompletionModelControllerInterface::aborted(KTextEditor::View* 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()
|
||||
{
|
||||
}
|
||||
|
||||
CodeCompletionModelControllerInterface3::~CodeCompletionModelControllerInterface3()
|
||||
{
|
||||
}
|
||||
|
||||
bool CodeCompletionModelControllerInterface3::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;
|
||||
}
|
||||
Q_UNUSED(index);
|
||||
Q_UNUSED(inserted);
|
||||
return false;
|
||||
}
|
||||
|
||||
Range CodeCompletionModelControllerInterface3::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);
|
||||
KTextEditor::CodeCompletionModelControllerInterface::MatchReaction CodeCompletionModelControllerInterface::matchingItem(const QModelIndex& selected) {
|
||||
Q_UNUSED(selected)
|
||||
return HideListIfAutomaticInvocation;
|
||||
}
|
||||
|
||||
Range CodeCompletionModelControllerInterface3::updateCompletionRange(View* view, const Range& range)
|
||||
{
|
||||
QStringList text=view->document()->textLines(range,false);
|
||||
if(!text.isEmpty() && text.count() == 1 && text.first().trimmed().isEmpty())
|
||||
//When inserting a newline behind an empty completion-range,, move the range forward to its end
|
||||
return Range(range.end(),range.end());
|
||||
|
||||
return range;
|
||||
}
|
||||
|
||||
QString CodeCompletionModelControllerInterface3::filterString(View* view, const Range &range, const Cursor &position)
|
||||
{
|
||||
return view->document()->text(KTextEditor::Range(range.start(), position));
|
||||
}
|
||||
|
||||
bool CodeCompletionModelControllerInterface3::shouldAbortCompletion(View* view, const Range &range, const QString ¤tCompletion)
|
||||
{
|
||||
//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 CodeCompletionModelControllerInterface3::aborted(KTextEditor::View* view) {
|
||||
Q_UNUSED(view);
|
||||
}
|
||||
|
||||
bool CodeCompletionModelControllerInterface3::shouldExecute(const QModelIndex& index, QChar inserted) {
|
||||
Q_UNUSED(index);
|
||||
Q_UNUSED(inserted);
|
||||
return false;
|
||||
}
|
||||
|
||||
KTextEditor::CodeCompletionModelControllerInterface3::MatchReaction CodeCompletionModelControllerInterface3::matchingItem(const QModelIndex& selected) {
|
||||
Q_UNUSED(selected)
|
||||
return HideListIfAutomaticInvocation;
|
||||
}
|
||||
//END V3
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -65,9 +65,10 @@ class View;
|
|||
*
|
||||
* \see CodeCompletionModel
|
||||
* \author Niko Sams \<niko.sams@gmail.com\>
|
||||
* \since 4.2
|
||||
* \author Joseph Wenninger
|
||||
* \since 4.5
|
||||
*/
|
||||
class KTEXTEDITOR_EXPORT_DEPRECATED CodeCompletionModelControllerInterface
|
||||
class KTEXTEDITOR_EXPORT CodeCompletionModelControllerInterface
|
||||
{
|
||||
public:
|
||||
CodeCompletionModelControllerInterface();
|
||||
|
@ -105,162 +106,6 @@ public:
|
|||
*/
|
||||
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 ¤tCompletion);
|
||||
|
||||
/**
|
||||
* 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
|
||||
/**
|
||||
* \short Controller interface for a CodeCompletionModel
|
||||
*
|
||||
* \ingroup kte_group_ccmodel_extensions
|
||||
*
|
||||
* The CodeCompletionModelControllerInterface3 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::CodeCompletionModelControllerInterface3
|
||||
* {
|
||||
* Q_OBJECT
|
||||
* Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
|
||||
* public:
|
||||
* KTextEditor::Range completionRange(KTextEditor::View* view, const KTextEditor::Cursor &position);
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* \see CodeCompletionModel
|
||||
* \author Niko Sams \<niko.sams@gmail.com\>
|
||||
* \author Joseph Wenninger
|
||||
* \since 4.5
|
||||
*/
|
||||
class KTEXTEDITOR_EXPORT CodeCompletionModelControllerInterface3
|
||||
{
|
||||
public:
|
||||
CodeCompletionModelControllerInterface3();
|
||||
virtual ~CodeCompletionModelControllerInterface3();
|
||||
|
||||
/**
|
||||
* 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 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)
|
||||
|
@ -306,7 +151,7 @@ public:
|
|||
* \return \e true, if the completion should be aborted, otherwise \e false
|
||||
*/
|
||||
virtual bool shouldAbortCompletion(View* view, const Range& range, const QString ¤tCompletion);
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -315,7 +160,7 @@ public:
|
|||
* \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
|
||||
|
@ -335,16 +180,10 @@ public:
|
|||
*/
|
||||
virtual MatchReaction matchingItem(const QModelIndex& matched);
|
||||
};
|
||||
//END V3
|
||||
|
||||
|
||||
}
|
||||
|
||||
#ifndef KTEXTEDITOR_NO_DEPRECATED
|
||||
Q_DECLARE_INTERFACE(KTextEditor::CodeCompletionModelControllerInterface, "org.kde.KTextEditor.CodeCompletionModelControllerInterface")
|
||||
Q_DECLARE_INTERFACE(KTextEditor::CodeCompletionModelControllerInterface2, "org.kde.KTextEditor.CodeCompletionModelControllerInterface2")
|
||||
#endif
|
||||
|
||||
Q_DECLARE_INTERFACE(KTextEditor::CodeCompletionModelControllerInterface3, "org.kde.KTextEditor.CodeCompletionModelControllerInterface3")
|
||||
|
||||
#endif // KDELIBS_KTEXTEDITOR_CODECOMPLETIONMODELCONTROLLERINTERFACE_H
|
||||
|
|
Loading…
Add table
Reference in a new issue