Commit 44a3a5e0 authored by Andre Hartmann's avatar Andre Hartmann Committed by Leandro Melo

Implemented Rename Macro Usages

Works the same way as Rename Usages for C++ Symbols.

For now, no Search Again as this requieres further work.

Task-number: QTCREATORBUG-413

Change-Id: I09e85ea1e8c247f5ce0b6bc566aba8018c1569e4
Reviewed-by: default avatarLeandro Melo <leandro.melo@nokia.com>
parent 6147419f
......@@ -742,10 +742,14 @@ void CPPEditorWidget::renameUsagesNow(const QString &replacement)
info.snapshot = CppModelManagerInterface::instance()->snapshot();
info.snapshot.insert(info.doc);
CanonicalSymbol cs(this, info);
if (Symbol *canonicalSymbol = cs(textCursor()))
if (canonicalSymbol->identifier() != 0)
m_modelManager->renameUsages(canonicalSymbol, cs.context(), replacement);
if (const Macro *macro = findCanonicalMacro(textCursor(), info.doc)) {
m_modelManager->renameMacroUsages(*macro, replacement);
} else {
CanonicalSymbol cs(this, info);
if (Symbol *canonicalSymbol = cs(textCursor()))
if (canonicalSymbol->identifier() != 0)
m_modelManager->renameUsages(canonicalSymbol, cs.context(), replacement);
}
}
void CPPEditorWidget::renameUsages()
......
......@@ -209,6 +209,7 @@ public:
const QString &replacement = QString()) = 0;
virtual void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) = 0;
virtual void renameMacroUsages(const CPlusPlus::Macro &macro, const QString &replacement = QString()) = 0;
virtual void findMacroUsages(const CPlusPlus::Macro &macro) = 0;
virtual void setExtraDiagnostics(const QString &fileName, int key,
......
......@@ -645,12 +645,23 @@ static void findMacroUses_helper(QFutureInterface<Usage> &future,
}
void CppFindReferences::findMacroUses(const Macro &macro)
{
findMacroUses(macro, QString(), false);
}
void CppFindReferences::findMacroUses(const Macro &macro, const QString &replacement, bool replace)
{
Find::SearchResult *search = Find::SearchResultWindow::instance()->startNewSearch(
tr("C++ Macro Usages:"),
QString(),
macro.name(),
Find::SearchResultWindow::SearchOnly);
replace ? Find::SearchResultWindow::SearchAndReplace
: Find::SearchResultWindow::SearchOnly,
QLatin1String("CppEditor"));
search->setTextToReplace(replacement);
connect(search, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>)));
Find::SearchResultWindow::instance()->popup(true);
......@@ -685,6 +696,12 @@ void CppFindReferences::findMacroUses(const Macro &macro)
connect(progress, SIGNAL(clicked()), search, SLOT(popup()));
}
void CppFindReferences::renameMacroUses(const Macro &macro, const QString &replacement)
{
const QString textToReplace = replacement.isEmpty() ? macro.name() : replacement;
findMacroUses(macro, textToReplace, true);
}
DependencyTable CppFindReferences::updateDependencyTable(CPlusPlus::Snapshot snapshot)
{
DependencyTable oldDeps = dependencyTable();
......
......@@ -82,6 +82,7 @@ public:
const QString &replacement = QString());
void findMacroUses(const CPlusPlus::Macro &macro);
void renameMacroUses(const CPlusPlus::Macro &macro, const QString &replacement = QString());
CPlusPlus::DependencyTable updateDependencyTable(CPlusPlus::Snapshot snapshot);
......@@ -97,6 +98,8 @@ private Q_SLOTS:
private:
void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
const QString &replacement, bool replace);
void findMacroUses(const CPlusPlus::Macro &macro, const QString &replacement,
bool replace);
void findAll_helper(Find::SearchResult *search);
CPlusPlus::DependencyTable dependencyTable() const;
void setDependencyTable(const CPlusPlus::DependencyTable &newTable);
......
......@@ -870,6 +870,11 @@ void CppModelManager::findMacroUsages(const CPlusPlus::Macro &macro)
m_findReferences->findMacroUses(macro);
}
void CppModelManager::renameMacroUsages(const CPlusPlus::Macro &macro, const QString &replacement)
{
m_findReferences->renameMacroUses(macro, replacement);
}
CppModelManager::WorkingCopy CppModelManager::buildWorkingCopyList()
{
WorkingCopy workingCopy;
......
......@@ -129,6 +129,7 @@ public:
virtual void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
virtual void findMacroUsages(const CPlusPlus::Macro &macro);
virtual void renameMacroUsages(const CPlusPlus::Macro &macro, const QString &replacement);
virtual void setExtraDiagnostics(const QString &fileName, int key,
const QList<CPlusPlus::Document::DiagnosticMessage> &diagnostics);
......
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