CodeCompletionModelControllerInterface3 Class Reference
from PyKDE4.ktexteditor import *
Namespace: KTextEditor
Detailed Description
Controller interface for a CodeCompletionModel
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.
Implemeting the Interface To use this class implement it in your CodeCompletionModel.
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); };
- See also:
- CodeCompletionModel
- Since:
- 4.5
Enumerations | |
MatchReaction | { None, HideListIfAutomaticInvocation, ForExtension } |
Methods | |
__init__ (self) | |
aborted (self, KTextEditor.View view) | |
KTextEditor.Range | completionRange (self, KTextEditor.View view, KTextEditor.Cursor position) |
QString | filterString (self, KTextEditor.View view, KTextEditor.Range range, KTextEditor.Cursor position) |
KTextEditor.CodeCompletionModelControllerInterface3.MatchReaction | matchingItem (self, QModelIndex matched) |
bool | shouldAbortCompletion (self, KTextEditor.View view, KTextEditor.Range range, QString currentCompletion) |
bool | shouldExecute (self, QModelIndex selected, QChar inserted) |
bool | shouldStartCompletion (self, KTextEditor.View view, QString insertedText, bool userInsertion, KTextEditor.Cursor position) |
KTextEditor.Range | updateCompletionRange (self, KTextEditor.View view, KTextEditor.Range range) |
Method Documentation
__init__ | ( | self ) |
aborted | ( | self, | ||
KTextEditor.View | view | |||
) |
Notification that completion for this model has been aborted.
- Parameters:
-
view The view in which the completion for this model was aborted
KTextEditor.Range completionRange | ( | self, | ||
KTextEditor.View | view, | |||
KTextEditor.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.
- Parameters:
-
view The view to generate completions for
- Parameters:
-
position Current cursor position
- Returns:
- the completion range
QString filterString | ( | self, | ||
KTextEditor.View | view, | |||
KTextEditor.Range | range, | |||
KTextEditor.Cursor | position | |||
) |
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 range start to the cursor position.
The smart-mutex is not locked when this is called.
- Parameters:
-
view The view to generate completions for
- Parameters:
-
range The completion range
- Parameters:
-
position Current cursor position
- Returns:
- the string used for filtering the completion list
KTextEditor.CodeCompletionModelControllerInterface3.MatchReaction matchingItem | ( | self, | ||
QModelIndex | matched | |||
) |
Called whenever an item in the completion-list perfectly matches the current filter text.
- Parameters:
-
The index that is matched
- Returns:
- Whether the completion-list should be hidden on this event. The default-implementation always returns HideListIfAutomaticInvocation
bool shouldAbortCompletion | ( | self, | ||
KTextEditor.View | view, | |||
KTextEditor.Range | range, | |||
QString | currentCompletion | |||
) |
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.
- Parameters:
-
view The view to generate completions for
- Parameters:
-
range The completion range
- Parameters:
-
currentCompletion The text typed so far
- Returns:
- true, if the completion should be aborted, otherwise false
bool shouldExecute | ( | self, | ||
QModelIndex | selected, | |||
QChar | inserted | |||
) |
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 '.'.
- Parameters:
-
selected The currently selected index
- Parameters:
-
inserted The character that was inserted by tue user
bool shouldStartCompletion | ( | self, | ||
KTextEditor.View | view, | |||
QString | insertedText, | |||
bool | userInsertion, | |||
KTextEditor.Cursor | position | |||
) |
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 insertedText is a letter, a number, '.', '_' or '>'
- Parameters:
-
view The view to generate completions for
- Parameters:
-
insertedText The text that was inserted by the user
- Parameters:
-
userInsertion Whether the the text was inserted by the user using typing. If false, it may have been inserted for example by code-completion.
- Parameters:
-
position Current cursor position
- Returns:
- true, if the completion should be started, otherwise false
KTextEditor.Range updateCompletionRange | ( | self, | ||
KTextEditor.View | view, | |||
KTextEditor.Range | range | |||
) |
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
- Parameters:
-
view The view to generate completions for
- Parameters:
-
range Reference to the current range
- Returns:
- the modified range
Enumeration Documentation
MatchReaction |
- Enumerator:
-
None = 0 HideListIfAutomaticInvocation = 1 ForExtension = 0xffff