Commit ea8cb476 authored by Leandro Melo's avatar Leandro Melo

Editors: Move auto-completion code out of the editor

This is basically a continuation of the commits which
refactor code out of the base text editor. For instance,
36fa1de4 and
3a684586.

Also removed the doXXXX() forwarding methods.
parent e117f04f
...@@ -48,8 +48,8 @@ CppAutoCompleter::CppAutoCompleter() ...@@ -48,8 +48,8 @@ CppAutoCompleter::CppAutoCompleter()
CppAutoCompleter::~CppAutoCompleter() CppAutoCompleter::~CppAutoCompleter()
{} {}
bool CppAutoCompleter::doContextAllowsAutoParentheses(const QTextCursor &cursor, bool CppAutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert) const const QString &textToInsert) const
{ {
QChar ch; QChar ch;
...@@ -66,7 +66,7 @@ bool CppAutoCompleter::doContextAllowsAutoParentheses(const QTextCursor &cursor, ...@@ -66,7 +66,7 @@ bool CppAutoCompleter::doContextAllowsAutoParentheses(const QTextCursor &cursor,
return true; return true;
} }
bool CppAutoCompleter::doContextAllowsElectricCharacters(const QTextCursor &cursor) const bool CppAutoCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{ {
const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(), const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(),
BackwardsScanner::previousBlockState(cursor.block())); BackwardsScanner::previousBlockState(cursor.block()));
...@@ -98,7 +98,7 @@ bool CppAutoCompleter::doContextAllowsElectricCharacters(const QTextCursor &curs ...@@ -98,7 +98,7 @@ bool CppAutoCompleter::doContextAllowsElectricCharacters(const QTextCursor &curs
return true; return true;
} }
bool CppAutoCompleter::doIsInComment(const QTextCursor &cursor) const bool CppAutoCompleter::isInComment(const QTextCursor &cursor) const
{ {
const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(), const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(),
BackwardsScanner::previousBlockState(cursor.block())); BackwardsScanner::previousBlockState(cursor.block()));
...@@ -122,7 +122,7 @@ bool CppAutoCompleter::doIsInComment(const QTextCursor &cursor) const ...@@ -122,7 +122,7 @@ bool CppAutoCompleter::doIsInComment(const QTextCursor &cursor) const
return false; return false;
} }
QString CppAutoCompleter::doInsertMatchingBrace(const QTextCursor &cursor, QString CppAutoCompleter::insertMatchingBrace(const QTextCursor &cursor,
const QString &text, const QString &text,
QChar la, QChar la,
int *skippedChars) const int *skippedChars) const
...@@ -131,7 +131,7 @@ QString CppAutoCompleter::doInsertMatchingBrace(const QTextCursor &cursor, ...@@ -131,7 +131,7 @@ QString CppAutoCompleter::doInsertMatchingBrace(const QTextCursor &cursor,
return m.insertMatchingBrace(cursor, text, la, skippedChars); return m.insertMatchingBrace(cursor, text, la, skippedChars);
} }
QString CppAutoCompleter::doInsertParagraphSeparator(const QTextCursor &cursor) const QString CppAutoCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
{ {
MatchingText m; MatchingText m;
return m.insertParagraphSeparator(cursor); return m.insertParagraphSeparator(cursor);
......
...@@ -41,16 +41,15 @@ public: ...@@ -41,16 +41,15 @@ public:
CppAutoCompleter(); CppAutoCompleter();
virtual ~CppAutoCompleter(); virtual ~CppAutoCompleter();
private: virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor,
virtual bool doContextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert = QString()) const;
const QString &textToInsert = QString()) const; virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
virtual bool doContextAllowsElectricCharacters(const QTextCursor &cursor) const; virtual bool isInComment(const QTextCursor &cursor) const;
virtual bool doIsInComment(const QTextCursor &cursor) const; virtual QString insertMatchingBrace(const QTextCursor &cursor,
virtual QString doInsertMatchingBrace(const QTextCursor &cursor, const QString &text,
const QString &text, QChar la,
QChar la, int *skippedChars) const;
int *skippedChars) const; virtual QString insertParagraphSeparator(const QTextCursor &cursor) const;
virtual QString doInsertParagraphSeparator(const QTextCursor &cursor) const;
}; };
} // Internal } // Internal
......
...@@ -47,7 +47,7 @@ CppQtStyleIndenter::CppQtStyleIndenter() ...@@ -47,7 +47,7 @@ CppQtStyleIndenter::CppQtStyleIndenter()
CppQtStyleIndenter::~CppQtStyleIndenter() CppQtStyleIndenter::~CppQtStyleIndenter()
{} {}
bool CppQtStyleIndenter::doIsElectricalCharacter(const QChar &ch) const bool CppQtStyleIndenter::isElectricCharacter(const QChar &ch) const
{ {
if (ch == QLatin1Char('{') || if (ch == QLatin1Char('{') ||
ch == QLatin1Char('}') || ch == QLatin1Char('}') ||
...@@ -58,10 +58,10 @@ bool CppQtStyleIndenter::doIsElectricalCharacter(const QChar &ch) const ...@@ -58,10 +58,10 @@ bool CppQtStyleIndenter::doIsElectricalCharacter(const QChar &ch) const
return false; return false;
} }
void CppQtStyleIndenter::doIndentBlock(QTextDocument *doc, void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
const QTextBlock &block, const QTextBlock &block,
const QChar &typedChar, const QChar &typedChar,
TextEditor::BaseTextEditor *editor) TextEditor::BaseTextEditor *editor)
{ {
Q_UNUSED(doc) Q_UNUSED(doc)
...@@ -86,10 +86,10 @@ void CppQtStyleIndenter::doIndentBlock(QTextDocument *doc, ...@@ -86,10 +86,10 @@ void CppQtStyleIndenter::doIndentBlock(QTextDocument *doc,
ts.indentLine(block, indent + padding, padding); ts.indentLine(block, indent + padding, padding);
} }
void CppQtStyleIndenter::doIndent(QTextDocument *doc, void CppQtStyleIndenter::indent(QTextDocument *doc,
const QTextCursor &cursor, const QTextCursor &cursor,
const QChar &typedChar, const QChar &typedChar,
TextEditor::BaseTextEditor *editor) TextEditor::BaseTextEditor *editor)
{ {
if (cursor.hasSelection()) { if (cursor.hasSelection()) {
QTextBlock block = doc->findBlock(cursor.selectionStart()); QTextBlock block = doc->findBlock(cursor.selectionStart());
......
...@@ -41,17 +41,16 @@ public: ...@@ -41,17 +41,16 @@ public:
CppQtStyleIndenter(); CppQtStyleIndenter();
virtual ~CppQtStyleIndenter(); virtual ~CppQtStyleIndenter();
private: virtual bool isElectricCharacter(const QChar &ch) const;
virtual bool doIsElectricalCharacter(const QChar &ch) const; virtual void indentBlock(QTextDocument *doc,
virtual void doIndentBlock(QTextDocument *doc, const QTextBlock &block,
const QTextBlock &block, const QChar &typedChar,
const QChar &typedChar, TextEditor::BaseTextEditor *editor);
TextEditor::BaseTextEditor *editor);
virtual void indent(QTextDocument *doc,
virtual void doIndent(QTextDocument *doc, const QTextCursor &cursor,
const QTextCursor &cursor, const QChar &typedChar,
const QChar &typedChar, TextEditor::BaseTextEditor *editor);
TextEditor::BaseTextEditor *editor);
}; };
} // Internal } // Internal
......
...@@ -47,8 +47,8 @@ GLSLCompleter::GLSLCompleter() ...@@ -47,8 +47,8 @@ GLSLCompleter::GLSLCompleter()
GLSLCompleter::~GLSLCompleter() GLSLCompleter::~GLSLCompleter()
{} {}
bool GLSLCompleter::doContextAllowsAutoParentheses(const QTextCursor &cursor, bool GLSLCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert) const const QString &textToInsert) const
{ {
QChar ch; QChar ch;
...@@ -65,7 +65,7 @@ bool GLSLCompleter::doContextAllowsAutoParentheses(const QTextCursor &cursor, ...@@ -65,7 +65,7 @@ bool GLSLCompleter::doContextAllowsAutoParentheses(const QTextCursor &cursor,
return true; return true;
} }
bool GLSLCompleter::doContextAllowsElectricCharacters(const QTextCursor &cursor) const bool GLSLCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{ {
const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(), const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(),
BackwardsScanner::previousBlockState(cursor.block())); BackwardsScanner::previousBlockState(cursor.block()));
...@@ -97,7 +97,7 @@ bool GLSLCompleter::doContextAllowsElectricCharacters(const QTextCursor &cursor) ...@@ -97,7 +97,7 @@ bool GLSLCompleter::doContextAllowsElectricCharacters(const QTextCursor &cursor)
return true; return true;
} }
bool GLSLCompleter::doIsInComment(const QTextCursor &cursor) const bool GLSLCompleter::isInComment(const QTextCursor &cursor) const
{ {
const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(), const Token tk = SimpleLexer::tokenAt(cursor.block().text(), cursor.positionInBlock(),
BackwardsScanner::previousBlockState(cursor.block())); BackwardsScanner::previousBlockState(cursor.block()));
...@@ -121,16 +121,16 @@ bool GLSLCompleter::doIsInComment(const QTextCursor &cursor) const ...@@ -121,16 +121,16 @@ bool GLSLCompleter::doIsInComment(const QTextCursor &cursor) const
return false; return false;
} }
QString GLSLCompleter::doInsertMatchingBrace(const QTextCursor &cursor, QString GLSLCompleter::insertMatchingBrace(const QTextCursor &cursor,
const QString &text, const QString &text,
QChar la, QChar la,
int *skippedChars) const int *skippedChars) const
{ {
MatchingText m; MatchingText m;
return m.insertMatchingBrace(cursor, text, la, skippedChars); return m.insertMatchingBrace(cursor, text, la, skippedChars);
} }
QString GLSLCompleter::doInsertParagraphSeparator(const QTextCursor &cursor) const QString GLSLCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
{ {
MatchingText m; MatchingText m;
return m.insertParagraphSeparator(cursor); return m.insertParagraphSeparator(cursor);
......
...@@ -41,16 +41,15 @@ public: ...@@ -41,16 +41,15 @@ public:
GLSLCompleter(); GLSLCompleter();
virtual ~GLSLCompleter(); virtual ~GLSLCompleter();
private: virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor,
virtual bool doContextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert = QString()) const;
const QString &textToInsert = QString()) const; virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
virtual bool doContextAllowsElectricCharacters(const QTextCursor &cursor) const; virtual bool isInComment(const QTextCursor &cursor) const;
virtual bool doIsInComment(const QTextCursor &cursor) const; virtual QString insertMatchingBrace(const QTextCursor &cursor,
virtual QString doInsertMatchingBrace(const QTextCursor &cursor, const QString &text,
const QString &text, QChar la,
QChar la, int *skippedChars) const;
int *skippedChars) const; virtual QString insertParagraphSeparator(const QTextCursor &cursor) const;
virtual QString doInsertParagraphSeparator(const QTextCursor &cursor) const;
}; };
} // Internal } // Internal
......
...@@ -47,7 +47,7 @@ GLSLIndenter::GLSLIndenter() ...@@ -47,7 +47,7 @@ GLSLIndenter::GLSLIndenter()
GLSLIndenter::~GLSLIndenter() GLSLIndenter::~GLSLIndenter()
{} {}
bool GLSLIndenter::doIsElectricalCharacter(const QChar &ch) const bool GLSLIndenter::isElectricCharacter(const QChar &ch) const
{ {
if (ch == QLatin1Char('{') || if (ch == QLatin1Char('{') ||
ch == QLatin1Char('}') || ch == QLatin1Char('}') ||
...@@ -58,10 +58,10 @@ bool GLSLIndenter::doIsElectricalCharacter(const QChar &ch) const ...@@ -58,10 +58,10 @@ bool GLSLIndenter::doIsElectricalCharacter(const QChar &ch) const
return false; return false;
} }
void GLSLIndenter::doIndentBlock(QTextDocument *doc, void GLSLIndenter::indentBlock(QTextDocument *doc,
const QTextBlock &block, const QTextBlock &block,
const QChar &typedChar, const QChar &typedChar,
TextEditor::BaseTextEditor *editor) TextEditor::BaseTextEditor *editor)
{ {
Q_UNUSED(doc) Q_UNUSED(doc)
...@@ -86,10 +86,10 @@ void GLSLIndenter::doIndentBlock(QTextDocument *doc, ...@@ -86,10 +86,10 @@ void GLSLIndenter::doIndentBlock(QTextDocument *doc,
ts.indentLine(block, indent + padding, padding); ts.indentLine(block, indent + padding, padding);
} }
void GLSLIndenter::doIndent(QTextDocument *doc, void GLSLIndenter::indent(QTextDocument *doc,
const QTextCursor &cursor, const QTextCursor &cursor,
const QChar &typedChar, const QChar &typedChar,
TextEditor::BaseTextEditor *editor) TextEditor::BaseTextEditor *editor)
{ {
if (cursor.hasSelection()) { if (cursor.hasSelection()) {
QTextBlock block = doc->findBlock(cursor.selectionStart()); QTextBlock block = doc->findBlock(cursor.selectionStart());
......
...@@ -41,17 +41,16 @@ public: ...@@ -41,17 +41,16 @@ public:
GLSLIndenter(); GLSLIndenter();
virtual ~GLSLIndenter(); virtual ~GLSLIndenter();
private: virtual bool isElectricCharacter(const QChar &ch) const;
virtual bool doIsElectricalCharacter(const QChar &ch) const; virtual void indentBlock(QTextDocument *doc,
virtual void doIndentBlock(QTextDocument *doc, const QTextBlock &block,
const QTextBlock &block, const QChar &typedChar,
const QChar &typedChar, TextEditor::BaseTextEditor *editor);
TextEditor::BaseTextEditor *editor);
virtual void indent(QTextDocument *doc,
virtual void doIndent(QTextDocument *doc, const QTextCursor &cursor,
const QTextCursor &cursor, const QChar &typedChar,
const QChar &typedChar, TextEditor::BaseTextEditor *editor);
TextEditor::BaseTextEditor *editor);
}; };
} // Internal } // Internal
......
...@@ -143,8 +143,8 @@ AutoCompleter::AutoCompleter() ...@@ -143,8 +143,8 @@ AutoCompleter::AutoCompleter()
AutoCompleter::~AutoCompleter() AutoCompleter::~AutoCompleter()
{} {}
bool AutoCompleter::doContextAllowsAutoParentheses(const QTextCursor &cursor, bool AutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert) const const QString &textToInsert) const
{ {
QChar ch; QChar ch;
...@@ -200,7 +200,7 @@ bool AutoCompleter::doContextAllowsAutoParentheses(const QTextCursor &cursor, ...@@ -200,7 +200,7 @@ bool AutoCompleter::doContextAllowsAutoParentheses(const QTextCursor &cursor,
return true; return true;
} }
bool AutoCompleter::doContextAllowsElectricCharacters(const QTextCursor &cursor) const bool AutoCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{ {
Token token = tokenUnderCursor(cursor); Token token = tokenUnderCursor(cursor);
switch (token.kind) { switch (token.kind) {
...@@ -212,15 +212,15 @@ bool AutoCompleter::doContextAllowsElectricCharacters(const QTextCursor &cursor) ...@@ -212,15 +212,15 @@ bool AutoCompleter::doContextAllowsElectricCharacters(const QTextCursor &cursor)
} }
} }
bool AutoCompleter::doIsInComment(const QTextCursor &cursor) const bool AutoCompleter::isInComment(const QTextCursor &cursor) const
{ {
return tokenUnderCursor(cursor).is(Token::Comment); return tokenUnderCursor(cursor).is(Token::Comment);
} }
QString AutoCompleter::doInsertMatchingBrace(const QTextCursor &cursor, QString AutoCompleter::insertMatchingBrace(const QTextCursor &cursor,
const QString &text, const QString &text,
QChar, QChar,
int *skippedChars) const int *skippedChars) const
{ {
if (text.length() != 1) if (text.length() != 1)
return QString(); return QString();
...@@ -268,7 +268,7 @@ QString AutoCompleter::doInsertMatchingBrace(const QTextCursor &cursor, ...@@ -268,7 +268,7 @@ QString AutoCompleter::doInsertMatchingBrace(const QTextCursor &cursor,
return QString(); return QString();
} }
QString AutoCompleter::doInsertParagraphSeparator(const QTextCursor &cursor) const QString AutoCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
{ {
if (shouldInsertNewline(cursor)) { if (shouldInsertNewline(cursor)) {
QTextCursor cursor = cursor; QTextCursor cursor = cursor;
......
...@@ -41,16 +41,15 @@ public: ...@@ -41,16 +41,15 @@ public:
AutoCompleter(); AutoCompleter();
virtual ~AutoCompleter(); virtual ~AutoCompleter();
private: virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor,
virtual bool doContextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert = QString()) const;
const QString &textToInsert = QString()) const; virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
virtual bool doContextAllowsElectricCharacters(const QTextCursor &cursor) const; virtual bool isInComment(const QTextCursor &cursor) const;
virtual bool doIsInComment(const QTextCursor &cursor) const; virtual QString insertMatchingBrace(const QTextCursor &tc,
virtual QString doInsertMatchingBrace(const QTextCursor &tc,
const QString &text, const QString &text,
QChar la, QChar la,
int *skippedChars) const; int *skippedChars) const;
virtual QString doInsertParagraphSeparator(const QTextCursor &tc) const; virtual QString insertParagraphSeparator(const QTextCursor &tc) const;
}; };
} // Internal } // Internal
......
...@@ -47,7 +47,7 @@ Indenter::Indenter() ...@@ -47,7 +47,7 @@ Indenter::Indenter()
Indenter::~Indenter() Indenter::~Indenter()
{} {}
bool Indenter::doIsElectricalCharacter(const QChar &ch) const bool Indenter::isElectricCharacter(const QChar &ch) const
{ {
if (ch == QLatin1Char('}') if (ch == QLatin1Char('}')
|| ch == QLatin1Char(']') || ch == QLatin1Char(']')
...@@ -56,10 +56,10 @@ bool Indenter::doIsElectricalCharacter(const QChar &ch) const ...@@ -56,10 +56,10 @@ bool Indenter::doIsElectricalCharacter(const QChar &ch) const
return false; return false;
} }
void Indenter::doIndentBlock(QTextDocument *doc, void Indenter::indentBlock(QTextDocument *doc,
const QTextBlock &block, const QTextBlock &block,
const QChar &typedChar, const QChar &typedChar,
TextEditor::BaseTextEditor *editor) TextEditor::BaseTextEditor *editor)
{ {
Q_UNUSED(doc) Q_UNUSED(doc)
Q_UNUSED(typedChar) Q_UNUSED(typedChar)
......
...@@ -41,12 +41,11 @@ public: ...@@ -41,12 +41,11 @@ public:
Indenter(); Indenter();
virtual ~Indenter(); virtual ~Indenter();
private: virtual bool isElectricCharacter(const QChar &ch) const;
virtual bool doIsElectricalCharacter(const QChar &ch) const; virtual void indentBlock(QTextDocument *doc,
virtual void doIndentBlock(QTextDocument *doc, const QTextBlock &block,
const QTextBlock &block, const QChar &typedChar,
const QChar &typedChar, TextEditor::BaseTextEditor *editor);
TextEditor::BaseTextEditor *editor);
}; };
} // Internal } // Internal
......
This diff is collapsed.
...@@ -47,30 +47,45 @@ public: ...@@ -47,30 +47,45 @@ public:
AutoCompleter(); AutoCompleter();
virtual ~AutoCompleter(); virtual ~AutoCompleter();
bool contextAllowsAutoParentheses(const QTextCursor &cursor, void setAutoParenthesesEnabled(bool b);
const QString &textToInsert = QString()) const; bool isAutoParenthesesEnabled() const;
bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
void setSurroundWithEnabled(bool b);
bool isSurroundWithEnabled() const;
// Returns the text to complete at the cursor position, or an empty string
virtual QString autoComplete(QTextCursor &cursor, const QString &text) const;
// Handles backspace. When returning true, backspace processing is stopped
virtual bool autoBackspace(QTextCursor &cursor);
// Hook to insert special characters on enter. Returns the number of extra blocks inserted.
virtual int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor);
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert = QString()) const;
virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
// Returns true if the cursor is inside a comment. // Returns true if the cursor is inside a comment.
bool isInComment(const QTextCursor &cursor) const; virtual bool isInComment(const QTextCursor &cursor) const;
virtual QString insertMatchingBrace(const QTextCursor &cursor, const
QString &text,
QChar la,
int *skippedChars) const;
QString insertMatchingBrace(const QTextCursor &cursor, const
QString &text,
QChar la,
int *skippedChars) const;
// Returns the text that needs to be inserted // Returns the text that needs to be inserted
QString insertParagraphSeparator(const QTextCursor &cursor) const; virtual QString insertParagraphSeparator(const QTextCursor &cursor) const;
protected:
static void countBracket(QChar open, QChar close, QChar c, int *errors, int *stillopen);
static void countBrackets(QTextCursor cursor, int from, int end, QChar open, QChar close,
int *errors, int *stillopen);
private: private:
virtual bool doContextAllowsAutoParentheses(const QTextCursor &cursor, mutable bool m_allowSkippingOfBlockEnd;
const QString &textToInsert = QString()) const; bool m_surroundWithEnabled;
virtual bool doContextAllowsElectricCharacters(const QTextCursor &cursor) const; bool m_autoParenthesesEnabled;
virtual bool doIsInComment(const QTextCursor &cursor) const;
virtual QString doInsertMatchingBrace(const QTextCursor &cursor,
const QString &text,
QChar la,
int *skippedChars) const;
virtual QString doInsertParagraphSeparator(const QTextCursor &cursor) const;
}; };
} // TextEditor } // TextEditor
......
This diff is collapsed.
...@@ -168,12 +168,6 @@ public: ...@@ -168,12 +168,6 @@ public:
void setParenthesesMatchingEnabled(bool b); void setParenthesesMatchingEnabled(bool b);
bool isParenthesesMatchingEnabled() const; bool isParenthesesMatchingEnabled() const;
void setAutoParenthesesEnabled(bool b);
bool isAutoParenthesesEnabled() const;
void setSurroundWithEnabled(bool b);
bool isSurroundWithEnabled() const;
void setHighlightCurrentLine(bool b); void setHighlightCurrentLine(bool b);
bool highlightCurrentLine() const; bool highlightCurrentLine() const;