|
@@ -86,6 +86,8 @@ public:
|
|
|
|
|
|
virtual int cursorOffset(const QString& completion);
|
|
|
virtual void updateCompletionModel(const QString& completion);
|
|
|
+ static QString searchUsableCharForCompletion(const QString& completion);
|
|
|
+
|
|
|
|
|
|
protected:
|
|
|
bool isInUserDefinedClass(const QString &pythonFunctionPath);
|
|
@@ -264,39 +266,47 @@ int ctkPythonConsoleCompleter::parameterCountFromDocumentation(const QString& py
|
|
|
return parameterCount;
|
|
|
}
|
|
|
|
|
|
-void ctkPythonConsoleCompleter::updateCompletionModel(const QString& completion)
|
|
|
+//----------------------------------------------------------------------------
|
|
|
+QString ctkPythonConsoleCompleter::searchUsableCharForCompletion(const QString& completion)
|
|
|
{
|
|
|
- // Start by clearing the model
|
|
|
- this->setModel(0);
|
|
|
-
|
|
|
- // Don't try to complete the empty string
|
|
|
- if (completion.isEmpty())
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- bool appendParenthesis = true;
|
|
|
-
|
|
|
- int numeberOfParenthesisClosed = 0;
|
|
|
+ bool betweenSingleQuotes = false;
|
|
|
+ bool betweenDoubleQuotes = false;
|
|
|
+ int numberOfParenthesisClosed = 0;
|
|
|
// Search backward through the string for usable characters
|
|
|
QString textToComplete;
|
|
|
for (int i = completion.length()-1; i >= 0; --i)
|
|
|
{
|
|
|
QChar c = completion.at(i);
|
|
|
- if (c.isLetterOrNumber() || c == '.' || c == '_' || c == '(' || c == ')' || c.isSymbol() || c.isPunct() || c.isSpace())
|
|
|
+ if (c == '\'' && !betweenDoubleQuotes)
|
|
|
+ {
|
|
|
+ betweenSingleQuotes = !betweenSingleQuotes;
|
|
|
+ }
|
|
|
+ if (c == '"' && !betweenSingleQuotes)
|
|
|
+ {
|
|
|
+ betweenDoubleQuotes = !betweenDoubleQuotes;
|
|
|
+ }
|
|
|
+ // Stop the completion if c is not a letter,number,.,_,(,) and outside parenthesis
|
|
|
+ if (c.isLetterOrNumber() || c == '.' || c == '_' || c == '(' || c == ')'
|
|
|
+ || numberOfParenthesisClosed)
|
|
|
{
|
|
|
- if (c == '(')
|
|
|
+ // Keep adding caractere to the completion if
|
|
|
+ // the number of '(' is always <= to the number of ')'
|
|
|
+ // note that we must not count parenthesis if they are between quote...
|
|
|
+ if (!betweenSingleQuotes && !betweenDoubleQuotes)
|
|
|
{
|
|
|
- if (numeberOfParenthesisClosed>0)
|
|
|
+ if (c == '(')
|
|
|
{
|
|
|
- numeberOfParenthesisClosed--;
|
|
|
+ if (numberOfParenthesisClosed>0)
|
|
|
+ {
|
|
|
+ numberOfParenthesisClosed--;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ break; // stop to prepend
|
|
|
+ }
|
|
|
+ if (c == ')')
|
|
|
+ {
|
|
|
+ numberOfParenthesisClosed++;
|
|
|
}
|
|
|
- else
|
|
|
- break; // stop to prepend
|
|
|
- }
|
|
|
- if (c == ')')
|
|
|
- {
|
|
|
- numeberOfParenthesisClosed++;
|
|
|
}
|
|
|
textToComplete.prepend(c);
|
|
|
}
|
|
@@ -304,7 +314,25 @@ void ctkPythonConsoleCompleter::updateCompletionModel(const QString& completion)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+ return textToComplete;
|
|
|
+}
|
|
|
+
|
|
|
+//----------------------------------------------------------------------------
|
|
|
+void ctkPythonConsoleCompleter::updateCompletionModel(const QString& completion)
|
|
|
+{
|
|
|
+ // Start by clearing the model
|
|
|
+ this->setModel(0);
|
|
|
+
|
|
|
+ // Don't try to complete the empty string
|
|
|
+ if (completion.isEmpty())
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool appendParenthesis = true;
|
|
|
+ // Search backward through the string for usable characters
|
|
|
+ QString textToComplete = searchUsableCharForCompletion(completion);
|
|
|
|
|
|
// Split the string at the last dot, if one exists
|
|
|
QString lookup;
|