Commit ef0e1a64 authored by Roberto Raggi's avatar Roberto Raggi

Show a warning message when using global renaming.

parent c70f968f
...@@ -869,6 +869,16 @@ void CPPEditor::findUsages() ...@@ -869,6 +869,16 @@ void CPPEditor::findUsages()
void CPPEditor::renameUsages() void CPPEditor::renameUsages()
{ {
Core::EditorManager::instance()->showEditorInfoBar(QLatin1String("CppEditor.Rename"),
tr("This change cannot be undone."),
tr("Yes, I know what I am doing."),
this, SLOT(renameUsagesNow()));
}
void CPPEditor::renameUsagesNow()
{
Core::EditorManager::instance()->hideEditorInfoBar(QLatin1String("CppEditor.Rename"));
m_currentRenameSelection = -1; m_currentRenameSelection = -1;
QList<QTextEdit::ExtraSelection> selections; QList<QTextEdit::ExtraSelection> selections;
......
...@@ -192,6 +192,7 @@ public Q_SLOTS: ...@@ -192,6 +192,7 @@ public Q_SLOTS:
void renameSymbolUnderCursor(); void renameSymbolUnderCursor();
void renameUsages(); void renameUsages();
void findUsages(); void findUsages();
void renameUsagesNow();
void moveToPreviousToken(); void moveToPreviousToken();
void moveToNextToken(); void moveToNextToken();
......
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
#include <QtCore/QTime> #include <QtCore/QTime>
#include <QtCore/QtConcurrentRun> #include <QtCore/QtConcurrentRun>
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtGui/QApplication>
#include <qtconcurrent/runextensions.h> #include <qtconcurrent/runextensions.h>
using namespace CppTools::Internal; using namespace CppTools::Internal;
...@@ -545,7 +545,11 @@ void CppFindReferences::findUsages(Symbol *symbol) ...@@ -545,7 +545,11 @@ void CppFindReferences::findUsages(Symbol *symbol)
void CppFindReferences::renameUsages(Symbol *symbol) void CppFindReferences::renameUsages(Symbol *symbol)
{ {
if (Identifier *id = symbol->identifier()) {
const QString textToReplace = QString::fromUtf8(id->chars(), id->size());
Find::SearchResult *search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchAndReplace); Find::SearchResult *search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchAndReplace);
_resultWindow->setTextToReplace(textToReplace);
connect(search, SIGNAL(activated(Find::SearchResultItem)), connect(search, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem))); this, SLOT(openEditor(Find::SearchResultItem)));
...@@ -554,6 +558,7 @@ void CppFindReferences::renameUsages(Symbol *symbol) ...@@ -554,6 +558,7 @@ void CppFindReferences::renameUsages(Symbol *symbol)
SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>))); SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>)));
findAll_helper(symbol); findAll_helper(symbol);
}
} }
void CppFindReferences::findAll_helper(Symbol *symbol) void CppFindReferences::findAll_helper(Symbol *symbol)
...@@ -651,6 +656,7 @@ void CppFindReferences::onReplaceButtonClicked(const QString &text, ...@@ -651,6 +656,7 @@ void CppFindReferences::onReplaceButtonClicked(const QString &text,
const QStringList fileNames = changes.keys(); const QStringList fileNames = changes.keys();
_modelManager->updateSourceFiles(fileNames); _modelManager->updateSourceFiles(fileNames);
_resultWindow->hide();
} }
void CppFindReferences::displayResult(int index) void CppFindReferences::displayResult(int index)
......
...@@ -104,6 +104,17 @@ SearchResultWindow::~SearchResultWindow() ...@@ -104,6 +104,17 @@ SearchResultWindow::~SearchResultWindow()
m_items.clear(); m_items.clear();
} }
void SearchResultWindow::setTextToReplace(const QString &textToReplace)
{
m_replaceTextEdit->setText(textToReplace);
m_replaceTextEdit->selectAll();
}
QString SearchResultWindow::textToReplace() const
{
return m_replaceTextEdit->text();
}
void SearchResultWindow::setShowReplaceUI(bool show) void SearchResultWindow::setShowReplaceUI(bool show)
{ {
m_searchResultTreeView->model()->setShowReplaceUI(show); m_searchResultTreeView->model()->setShowReplaceUI(show);
...@@ -169,6 +180,7 @@ SearchResult *SearchResultWindow::startNewSearch(SearchMode searchOrSearchAndRep ...@@ -169,6 +180,7 @@ SearchResult *SearchResultWindow::startNewSearch(SearchMode searchOrSearchAndRep
void SearchResultWindow::clearContents() void SearchResultWindow::clearContents()
{ {
setReplaceUIEnabled(false); setReplaceUIEnabled(false);
m_replaceTextEdit->clear();
m_searchResultTreeView->clear(); m_searchResultTreeView->clear();
m_items.clear(); m_items.clear();
m_widget->setCurrentWidget(m_searchResultTreeView); m_widget->setCurrentWidget(m_searchResultTreeView);
......
...@@ -106,6 +106,9 @@ public: ...@@ -106,6 +106,9 @@ public:
void setShowReplaceUI(bool show); void setShowReplaceUI(bool show);
bool isShowingReplaceUI() const; bool isShowingReplaceUI() const;
void setTextToReplace(const QString &textToReplace);
QString textToReplace() const;
// search result object only lives till next startnewsearch call // search result object only lives till next startnewsearch call
SearchResult *startNewSearch(SearchMode searchOrSearchAndReplace = SearchOnly); SearchResult *startNewSearch(SearchMode searchOrSearchAndReplace = SearchOnly);
......
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