Commit 23aa0af8 authored by Roberto Raggi's avatar Roberto Raggi

Introduced IQuickFixFactory.

parent 3e7c7296
......@@ -207,6 +207,8 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
m_quickFixCollector = new CppQuickFixCollector;
addAutoReleasedObject(m_quickFixCollector);
addAutoReleasedObject(new CppQuickFixFactory);
CppFileWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
wizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY));
......
......@@ -50,6 +50,7 @@
#include <cppeditor/cpprefactoringchanges.h>
#include <cpptools/cpptoolsconstants.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <extensionsystem/pluginmanager.h>
#include <QtGui/QApplication>
#include <QtGui/QTextBlock>
......@@ -1079,8 +1080,19 @@ TextEditor::QuickFixState *CppQuickFixCollector::initializeCompletion(TextEditor
return 0;
}
QList<TextEditor::QuickFixOperation::Ptr> CppQuickFixCollector::quickFixOperations(TextEditor::BaseTextEditor *editor) const
CppQuickFixFactory::CppQuickFixFactory(QObject *parent)
: TextEditor::IQuickFixFactory(parent)
{
}
CppQuickFixFactory::~CppQuickFixFactory()
{
}
QList<TextEditor::QuickFixOperation::Ptr> CppQuickFixFactory::quickFixOperations(TextEditor::BaseTextEditor *editor)
{
QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations;
QSharedPointer<RewriteLogicalAndOp> rewriteLogicalAndOp(new RewriteLogicalAndOp(editor));
QSharedPointer<SplitIfStatementOp> splitIfStatementOp(new SplitIfStatementOp(editor));
QSharedPointer<MoveDeclarationOutOfIfOp> moveDeclarationOutOfIfOp(new MoveDeclarationOutOfIfOp(editor));
......@@ -1092,7 +1104,6 @@ QList<TextEditor::QuickFixOperation::Ptr> CppQuickFixCollector::quickFixOperatio
QSharedPointer<WrapStringLiteral> wrapStringLiteral(new WrapStringLiteral(editor));
QSharedPointer<CStringToNSString> wrapCString(new CStringToNSString(editor));
QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations;
quickFixOperations.append(rewriteLogicalAndOp);
quickFixOperations.append(splitIfStatementOp);
quickFixOperations.append(moveDeclarationOutOfIfOp);
......
......@@ -107,7 +107,20 @@ public:
virtual bool supportsEditor(TextEditor::ITextEditable *editor);
virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::ITextEditable *editable);
virtual QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor) const;
};
class CppQuickFixFactory: public TextEditor::IQuickFixFactory
{
Q_OBJECT
public:
CppQuickFixFactory(QObject *parent = 0);
virtual ~CppQuickFixFactory();
/*
* Returns true if this IQuickFixFactory can be used with the given editor.
*/
virtual QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor);
};
} // end of namespace Internal
......
......@@ -31,7 +31,7 @@
#include "basetexteditor.h"
#include <coreplugin/ifile.h>
#include <extensionsystem/pluginmanager.h>
#include <QtGui/QApplication>
#include <QtGui/QTextBlock>
......@@ -40,6 +40,7 @@
using TextEditor::RefactoringChanges;
using TextEditor::QuickFixOperation;
using TextEditor::QuickFixCollector;
using TextEditor::IQuickFixFactory;
QuickFixOperation::QuickFixOperation(TextEditor::BaseTextEditor *editor)
: _editor(editor)
......@@ -184,3 +185,26 @@ void QuickFixCollector::cleanup()
{
_quickFixes.clear();
}
QList<TextEditor::QuickFixOperation::Ptr> QuickFixCollector::quickFixOperations(TextEditor::BaseTextEditor *editor) const
{
QList<TextEditor::IQuickFixFactory *> factories =
ExtensionSystem::PluginManager::instance()->getObjects<TextEditor::IQuickFixFactory>();
QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations;
foreach (TextEditor::IQuickFixFactory *factory, factories)
quickFixOperations += factory->quickFixOperations(editor);
return quickFixOperations;
}
IQuickFixFactory::IQuickFixFactory(QObject *parent)
: QObject(parent)
{
}
IQuickFixFactory::~IQuickFixFactory()
{
}
......@@ -115,13 +115,24 @@ public:
virtual void cleanup();
virtual TextEditor::QuickFixState *initializeCompletion(TextEditor::ITextEditable *editable) = 0;
virtual QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor) const = 0;
virtual QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor) const;
private:
TextEditor::ITextEditable *_editable;
QList<TextEditor::QuickFixOperation::Ptr> _quickFixes;
};
class TEXTEDITOR_EXPORT IQuickFixFactory: public QObject
{
Q_OBJECT
public:
IQuickFixFactory(QObject *parent = 0);
virtual ~IQuickFixFactory();
virtual QList<QuickFixOperation::Ptr> quickFixOperations(TextEditor::BaseTextEditor *editor) = 0;
};
} // end of namespace TextEditor
#endif // TEXTEDITORQUICKFIX_H
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