Commit 6635ddbd authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Introduced ICompletionCollector::isValid(editor).

parent 1997d8fb
......@@ -508,6 +508,9 @@ static int startOfOperator(TextEditor::ITextEditable *editor,
return start;
}
bool CppCodeCompletion::isValid(TextEditor::ITextEditable *editor)
{ return m_manager->isCppEditor(editor); }
bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
{
if (! m_manager->isCppEditor(editor)) // ### remove me
......
......@@ -58,6 +58,7 @@ class CppCodeCompletion : public TextEditor::ICompletionCollector
public:
explicit CppCodeCompletion(CppModelManager *manager);
bool isValid(TextEditor::ITextEditable *editor);
bool triggersCompletion(TextEditor::ITextEditable *editor);
int startCompletion(TextEditor::ITextEditable *editor);
void completions(QList<TextEditor::CompletionItem> *completions);
......
......@@ -58,10 +58,11 @@ CompletionSupport::CompletionSupport()
m_completionList(0),
m_startPosition(0),
m_checkCompletionTrigger(false),
m_editor(0)
m_editor(0),
m_completionCollector(0)
{
m_completionCollector = ExtensionSystem::PluginManager::instance()
->getObject<ICompletionCollector>();
m_completionCollectors = ExtensionSystem::PluginManager::instance()
->getObjects<ICompletionCollector>();
}
void CompletionSupport::performCompletion(const CompletionItem &item)
......@@ -90,6 +91,15 @@ void CompletionSupport::cleanupCompletions()
void CompletionSupport::autoComplete(ITextEditable *editor, bool forced)
{
m_completionCollector = 0;
foreach (ICompletionCollector *collector, m_completionCollectors) {
if (collector->isValid(editor)) {
m_completionCollector = collector;
break;
}
}
if (!m_completionCollector)
return;
......
......@@ -69,6 +69,7 @@ private:
int m_startPosition;
bool m_checkCompletionTrigger; // Whether to check for completion trigger after cleanup
ITextEditable *m_editor;
QList<ICompletionCollector *> m_completionCollectors;
ICompletionCollector *m_completionCollector;
};
......
......@@ -77,6 +77,11 @@ public:
ICompletionCollector(QObject *parent = 0) : QObject(parent) {}
virtual ~ICompletionCollector() {}
/*
* Returns true if this completion collector can be used with the given editor.
*/
virtual bool isValid(ITextEditable *editor) = 0;
/* This method should return whether the cursor is at a position which could
* trigger an autocomplete. It will be called each time a character is typed in
* the text editor.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment