Commit 3d81ae85 authored by Roberto Raggi's avatar Roberto Raggi

Reduced the usage of CppQuickFixOperation.

parent a40349c0
......@@ -1586,11 +1586,8 @@ bool CPPEditor::event(QEvent *e)
void CPPEditor::performQuickFix(int index)
{
CppQuickFixCollector *quickFixCollector = CppPlugin::instance()->quickFixCollector();
CppQuickFixOperationPtr op = m_quickFixes.at(index);
quickFixCollector->perform(op);
//op->createChangeSet();
//setChangeSet(op->changeSet());
TextEditor::QuickFixOperation::Ptr op = m_quickFixes.at(index);
op->perform();
}
void CPPEditor::contextMenuEvent(QContextMenuEvent *e)
......@@ -1614,7 +1611,7 @@ void CPPEditor::contextMenuEvent(QContextMenuEvent *e)
m_quickFixes = quickFixCollector->quickFixes();
for (int index = 0; index < m_quickFixes.size(); ++index) {
CppQuickFixOperationPtr op = m_quickFixes.at(index);
TextEditor::QuickFixOperation::Ptr op = m_quickFixes.at(index);
QAction *action = menu->addAction(op->description());
mapper.setMapping(action, index);
connect(action, SIGNAL(triggered()), &mapper, SLOT(map()));
......
......@@ -309,7 +309,7 @@ private:
SemanticHighlighter *m_semanticHighlighter;
SemanticInfo m_lastSemanticInfo;
QList<CppQuickFixOperationPtr> m_quickFixes;
QList<TextEditor::QuickFixOperation::Ptr> m_quickFixes;
bool m_initialized;
};
......
......@@ -62,6 +62,7 @@ class CppQuickFixState: public TextEditor::QuickFixState
{
public:
QList<CPlusPlus::AST *> path;
SemanticInfo info;
};
/*
......@@ -880,6 +881,8 @@ CppQuickFixOperation::Range CppQuickFixOperation::topLevelRange() const
int CppQuickFixOperation::match(TextEditor::QuickFixState *state)
{
CppQuickFixState *s = static_cast<CppQuickFixState *>(state);
_document = s->info.doc;
_snapshot = s->info.snapshot;
return match(s->path);
}
......@@ -892,15 +895,9 @@ void CppQuickFixOperation::setTopLevelNode(CPlusPlus::AST *topLevelNode)
Document::Ptr CppQuickFixOperation::document() const
{ return _document; }
void CppQuickFixOperation::setDocument(CPlusPlus::Document::Ptr document)
{ _document = document; }
Snapshot CppQuickFixOperation::snapshot() const
const Snapshot &CppQuickFixOperation::snapshot() const
{ return _snapshot; }
void CppQuickFixOperation::setSnapshot(const CPlusPlus::Snapshot &snapshot)
{ _snapshot = snapshot; }
const CPlusPlus::Token &CppQuickFixOperation::tokenAt(unsigned index) const
{ return _document->translationUnit()->tokenAt(index); }
......@@ -1081,7 +1078,7 @@ int CppQuickFixCollector::startCompletion(TextEditor::ITextEditable *editable)
QSharedPointer<WrapStringLiteral> wrapStringLiteral(new WrapStringLiteral(_editor));
QSharedPointer<CStringToNSString> wrapCString(new CStringToNSString(_editor));
QList<CppQuickFixOperationPtr> candidates;
QList<TextEditor::QuickFixOperation::Ptr> candidates;
candidates.append(rewriteLogicalAndOp);
candidates.append(splitIfStatementOp);
candidates.append(moveDeclarationOutOfIfOp);
......@@ -1094,21 +1091,20 @@ int CppQuickFixCollector::startCompletion(TextEditor::ITextEditable *editable)
if (_editor->mimeType() == CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)
candidates.append(wrapCString);
QMap<int, QList<CppQuickFixOperationPtr> > matchedOps;
QMap<int, QList<TextEditor::QuickFixOperation::Ptr> > matchedOps;
CppQuickFixState state;
state.path = path;
state.info = info;
foreach (CppQuickFixOperationPtr op, candidates) {
op->setSnapshot(info.snapshot);
op->setDocument(info.doc);
foreach (TextEditor::QuickFixOperation::Ptr op, candidates) {
op->setTextCursor(_editor->textCursor());
int priority = op->match(&state);
if (priority != -1)
matchedOps[priority].append(op);
}
QMapIterator<int, QList<CppQuickFixOperationPtr> > it(matchedOps);
QMapIterator<int, QList<TextEditor::QuickFixOperation::Ptr> > it(matchedOps);
it.toBack();
if (it.hasPrevious()) {
it.previous();
......@@ -1126,7 +1122,7 @@ int CppQuickFixCollector::startCompletion(TextEditor::ITextEditable *editable)
void CppQuickFixCollector::completions(QList<TextEditor::CompletionItem> *quickFixItems)
{
for (int i = 0; i < _quickFixes.size(); ++i) {
CppQuickFixOperationPtr op = _quickFixes.at(i);
TextEditor::QuickFixOperation::Ptr op = _quickFixes.at(i);
TextEditor::CompletionItem item(this);
item.text = op->description();
......@@ -1140,18 +1136,11 @@ void CppQuickFixCollector::complete(const TextEditor::CompletionItem &item)
const int index = item.data.toInt();
if (index < _quickFixes.size()) {
CppQuickFixOperationPtr quickFix = _quickFixes.at(index);
perform(quickFix);
TextEditor::QuickFixOperation::Ptr quickFix = _quickFixes.at(index);
quickFix->perform();
}
}
void CppQuickFixCollector::perform(CppQuickFixOperationPtr op)
{
op->setTextCursor(_editor->textCursor());
op->createChangeSet();
op->apply();
}
void CppQuickFixCollector::cleanup()
{
_quickFixes.clear();
......
......@@ -63,10 +63,7 @@ public:
virtual int match(const QList<CPlusPlus::AST *> &path) = 0;
CPlusPlus::Document::Ptr document() const;
void setDocument(CPlusPlus::Document::Ptr document);
CPlusPlus::Snapshot snapshot() const;
void setSnapshot(const CPlusPlus::Snapshot &snapshot);
const CPlusPlus::Snapshot &snapshot() const;
virtual Range topLevelRange() const;
virtual int match(TextEditor::QuickFixState *state);
......@@ -123,7 +120,7 @@ public:
CppQuickFixCollector();
virtual ~CppQuickFixCollector();
QList<CppQuickFixOperationPtr> quickFixes() const { return _quickFixes; }
QList<TextEditor::QuickFixOperation::Ptr> quickFixes() const { return _quickFixes; }
virtual TextEditor::ITextEditable *editor() const;
virtual int startPosition() const;
......@@ -134,14 +131,11 @@ public:
virtual void complete(const TextEditor::CompletionItem &item);
virtual void cleanup();
public Q_SLOTS:
void perform(CppQuickFixOperationPtr op);
private:
CppTools::CppModelManagerInterface *_modelManager;
TextEditor::ITextEditable *_editable;
CPPEditor *_editor;
QList<CppQuickFixOperationPtr> _quickFixes;
QList<TextEditor::QuickFixOperation::Ptr> _quickFixes;
};
} // end of namespace Internal
......
......@@ -160,3 +160,9 @@ QString QuickFixOperation::textOf(int start, int end) const
tc.setPosition(end, QTextCursor::KeepAnchor);
return tc.selectedText();
}
void QuickFixOperation::perform()
{
createChangeSet();
apply();
}
......@@ -77,6 +77,7 @@ public:
virtual int match(QuickFixState *state) = 0;
void perform();
void apply();
TextEditor::BaseTextEditor *editor() const;
......
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