forked from qt-creator/qt-creator
move the "cannot undo" warning to the search result pane
this is where it belongs, rather than into some arbitrary editor. as a nice side effect, now not only the "rename symbol", but also the global search&replace has such a warning.
This commit is contained in:
@@ -68,7 +68,6 @@
|
|||||||
#include <cpptools/cppcodeformatter.h>
|
#include <cpptools/cppcodeformatter.h>
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/infobar.h>
|
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||||
#include <coreplugin/actionmanager/command.h>
|
#include <coreplugin/actionmanager/command.h>
|
||||||
@@ -680,20 +679,9 @@ void CPPEditorWidget::renameUsagesNow(const QString &replacement)
|
|||||||
info.snapshot.insert(info.doc);
|
info.snapshot.insert(info.doc);
|
||||||
|
|
||||||
CanonicalSymbol cs(this, info);
|
CanonicalSymbol cs(this, info);
|
||||||
if (Symbol *canonicalSymbol = cs(textCursor())) {
|
if (Symbol *canonicalSymbol = cs(textCursor()))
|
||||||
if (canonicalSymbol->identifier() != 0) {
|
if (canonicalSymbol->identifier() != 0)
|
||||||
if (showWarningMessage()) {
|
|
||||||
// FIXME: abuse
|
|
||||||
Core::InfoBarEntry info(QLatin1String("CppEditor.Rename"),
|
|
||||||
tr("This change cannot be undone."));
|
|
||||||
info.setCustomButtonInfo(tr("Yes, I know what I am doing."),
|
|
||||||
this, SLOT(hideRenameNotification()));
|
|
||||||
file()->infoBar()->addInfo(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_modelManager->renameUsages(canonicalSymbol, cs.context(), replacement);
|
m_modelManager->renameUsages(canonicalSymbol, cs.context(), replacement);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPPEditorWidget::renameUsages()
|
void CPPEditorWidget::renameUsages()
|
||||||
@@ -701,35 +689,6 @@ void CPPEditorWidget::renameUsages()
|
|||||||
renameUsagesNow();
|
renameUsagesNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPPEditorWidget::showWarningMessage() const
|
|
||||||
{
|
|
||||||
// Restore settings
|
|
||||||
QSettings *settings = Core::ICore::instance()->settings();
|
|
||||||
settings->beginGroup(QLatin1String("CppEditor"));
|
|
||||||
settings->beginGroup(QLatin1String("Rename"));
|
|
||||||
const bool showWarningMessage = settings->value(QLatin1String("ShowWarningMessage"), true).toBool();
|
|
||||||
settings->endGroup();
|
|
||||||
settings->endGroup();
|
|
||||||
return showWarningMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPPEditorWidget::setShowWarningMessage(bool showWarningMessage)
|
|
||||||
{
|
|
||||||
// Restore settings
|
|
||||||
QSettings *settings = Core::ICore::instance()->settings();
|
|
||||||
settings->beginGroup(QLatin1String("CppEditor"));
|
|
||||||
settings->beginGroup(QLatin1String("Rename"));
|
|
||||||
settings->setValue(QLatin1String("ShowWarningMessage"), showWarningMessage);
|
|
||||||
settings->endGroup();
|
|
||||||
settings->endGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPPEditorWidget::hideRenameNotification()
|
|
||||||
{
|
|
||||||
setShowWarningMessage(false);
|
|
||||||
file()->infoBar()->removeInfo(QLatin1String("CppEditor.Rename"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPPEditorWidget::markSymbolsNow()
|
void CPPEditorWidget::markSymbolsNow()
|
||||||
{
|
{
|
||||||
if (m_references.isCanceled())
|
if (m_references.isCanceled())
|
||||||
|
|||||||
@@ -202,7 +202,6 @@ public Q_SLOTS:
|
|||||||
void renameUsages();
|
void renameUsages();
|
||||||
void findUsages();
|
void findUsages();
|
||||||
void renameUsagesNow(const QString &replacement = QString());
|
void renameUsagesNow(const QString &replacement = QString());
|
||||||
void hideRenameNotification();
|
|
||||||
void rehighlight(bool force = false);
|
void rehighlight(bool force = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -237,9 +236,6 @@ private Q_SLOTS:
|
|||||||
void performQuickFix(int index);
|
void performQuickFix(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool showWarningMessage() const;
|
|
||||||
void setShowWarningMessage(bool showWarningMessage);
|
|
||||||
|
|
||||||
void markSymbols(const QTextCursor &tc, const SemanticInfo &info);
|
void markSymbols(const QTextCursor &tc, const SemanticInfo &info);
|
||||||
bool sortedOutline() const;
|
bool sortedOutline() const;
|
||||||
CPlusPlus::Symbol *findDefinition(CPlusPlus::Symbol *symbol, const CPlusPlus::Snapshot &snapshot) const;
|
CPlusPlus::Symbol *findDefinition(CPlusPlus::Symbol *symbol, const CPlusPlus::Snapshot &snapshot) const;
|
||||||
|
|||||||
@@ -242,7 +242,8 @@ void CppFindReferences::renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus:
|
|||||||
const QString textToReplace = replacement.isEmpty()
|
const QString textToReplace = replacement.isEmpty()
|
||||||
? QString::fromUtf8(id->chars(), id->size()) : replacement;
|
? QString::fromUtf8(id->chars(), id->size()) : replacement;
|
||||||
|
|
||||||
Find::SearchResult *search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchAndReplace);
|
Find::SearchResult *search = _resultWindow->startNewSearch(
|
||||||
|
Find::SearchResultWindow::SearchAndReplace, QLatin1String("CppEditor"));
|
||||||
_resultWindow->setTextToReplace(textToReplace);
|
_resultWindow->setTextToReplace(textToReplace);
|
||||||
|
|
||||||
connect(search, SIGNAL(activated(Find::SearchResultItem)),
|
connect(search, SIGNAL(activated(Find::SearchResultItem)),
|
||||||
@@ -280,10 +281,6 @@ void CppFindReferences::findAll_helper(Symbol *symbol, const LookupContext &cont
|
|||||||
void CppFindReferences::onReplaceButtonClicked(const QString &text,
|
void CppFindReferences::onReplaceButtonClicked(const QString &text,
|
||||||
const QList<Find::SearchResultItem> &items)
|
const QList<Find::SearchResultItem> &items)
|
||||||
{
|
{
|
||||||
// FIXME: abuse
|
|
||||||
Core::EditorManager::instance()->currentEditor()->file()->infoBar()->removeInfo(
|
|
||||||
QLatin1String("CppEditor.Rename"));
|
|
||||||
|
|
||||||
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items);
|
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items);
|
||||||
if (!fileNames.isEmpty()) {
|
if (!fileNames.isEmpty()) {
|
||||||
_modelManager->updateSourceFiles(fileNames);
|
_modelManager->updateSourceFiles(fileNames);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include <aggregation/aggregate.h>
|
#include <aggregation/aggregate.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/infobar.h>
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/actionmanager/command.h>
|
#include <coreplugin/actionmanager/command.h>
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
@@ -232,6 +233,9 @@ namespace Internal {
|
|||||||
int m_itemCount;
|
int m_itemCount;
|
||||||
bool m_isShowingReplaceUI;
|
bool m_isShowingReplaceUI;
|
||||||
bool m_focusReplaceEdit;
|
bool m_focusReplaceEdit;
|
||||||
|
QString m_dontAskAgainGroup;
|
||||||
|
Core::InfoBar m_infoBar;
|
||||||
|
Core::InfoBarDisplay m_infoBarDisplay;
|
||||||
};
|
};
|
||||||
|
|
||||||
SearchResultWindowPrivate::SearchResultWindowPrivate()
|
SearchResultWindowPrivate::SearchResultWindowPrivate()
|
||||||
@@ -349,6 +353,9 @@ SearchResultWindow::SearchResultWindow() : d(new SearchResultWindowPrivate)
|
|||||||
vlay->addWidget(d->m_noMatchesFoundDisplay);
|
vlay->addWidget(d->m_noMatchesFoundDisplay);
|
||||||
vlay->addWidget(d->m_searchResultTreeView);
|
vlay->addWidget(d->m_searchResultTreeView);
|
||||||
|
|
||||||
|
d->m_infoBarDisplay.setTarget(vlay, 0);
|
||||||
|
d->m_infoBarDisplay.setInfoBar(&d->m_infoBar);
|
||||||
|
|
||||||
d->m_expandCollapseButton = new QToolButton(d->m_widget);
|
d->m_expandCollapseButton = new QToolButton(d->m_widget);
|
||||||
d->m_expandCollapseButton->setAutoRaise(true);
|
d->m_expandCollapseButton->setAutoRaise(true);
|
||||||
|
|
||||||
@@ -446,8 +453,10 @@ void SearchResultWindow::handleReplaceButton()
|
|||||||
QTC_ASSERT(d->m_currentSearch, return);
|
QTC_ASSERT(d->m_currentSearch, return);
|
||||||
// check if button is actually enabled, because this is also triggered
|
// check if button is actually enabled, because this is also triggered
|
||||||
// by pressing return in replace line edit
|
// by pressing return in replace line edit
|
||||||
if (d->m_replaceButton->isEnabled())
|
if (d->m_replaceButton->isEnabled()) {
|
||||||
|
d->m_infoBar.clear();
|
||||||
d->m_currentSearch->replaceButtonClicked(d->m_replaceTextEdit->text(), checkedItems());
|
d->m_currentSearch->replaceButtonClicked(d->m_replaceTextEdit->text(), checkedItems());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -500,19 +509,22 @@ QList<QWidget*> SearchResultWindow::toolBarWidgets() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn SearchResult *SearchResultWindow::startNewSearch(SearchMode searchOrSearchAndReplace)
|
|
||||||
\brief Tells the search results window to start a new search.
|
\brief Tells the search results window to start a new search.
|
||||||
|
|
||||||
This will clear the contents of the previous search and initialize the UI
|
This will clear the contents of the previous search and initialize the UI
|
||||||
with regard to showing the replace UI or not (depending on the search mode
|
with regard to showing the replace UI or not (depending on the search mode
|
||||||
in \a searchOrSearchAndReplace).
|
in \a searchOrSearchAndReplace).
|
||||||
|
If \a cfgGroup is not empty, it will be used for storing the "do not ask again"
|
||||||
|
setting of a "this change cannot be undone" warning (which is implicitly requested
|
||||||
|
by passing a non-empty group).
|
||||||
Returns a SearchResult object that is used for signaling user interaction
|
Returns a SearchResult object that is used for signaling user interaction
|
||||||
with the results of this search.
|
with the results of this search.
|
||||||
*/
|
*/
|
||||||
SearchResult *SearchResultWindow::startNewSearch(SearchMode searchOrSearchAndReplace)
|
SearchResult *SearchResultWindow::startNewSearch(SearchMode searchOrSearchAndReplace, const QString &cfgGroup)
|
||||||
{
|
{
|
||||||
clearContents();
|
clearContents();
|
||||||
setShowReplaceUI(searchOrSearchAndReplace != SearchOnly);
|
setShowReplaceUI(searchOrSearchAndReplace != SearchOnly);
|
||||||
|
d->m_dontAskAgainGroup = cfgGroup;
|
||||||
delete d->m_currentSearch;
|
delete d->m_currentSearch;
|
||||||
d->m_currentSearch = new SearchResult;
|
d->m_currentSearch = new SearchResult;
|
||||||
return d->m_currentSearch;
|
return d->m_currentSearch;
|
||||||
@@ -544,6 +556,7 @@ void SearchResultWindow::clearContents()
|
|||||||
d->m_searchResultTreeView->clear();
|
d->m_searchResultTreeView->clear();
|
||||||
d->m_itemCount = 0;
|
d->m_itemCount = 0;
|
||||||
d->m_noMatchesFoundDisplay->hide();
|
d->m_noMatchesFoundDisplay->hide();
|
||||||
|
d->m_infoBar.clear();
|
||||||
navigateStateChanged();
|
navigateStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -675,6 +688,12 @@ void SearchResultWindow::addResults(QList<SearchResultItem> &items, AddMode mode
|
|||||||
d->m_itemCount += items.size();
|
d->m_itemCount += items.size();
|
||||||
d->m_searchResultTreeView->addResults(items, mode);
|
d->m_searchResultTreeView->addResults(items, mode);
|
||||||
if (firstItems) {
|
if (firstItems) {
|
||||||
|
if (!d->m_dontAskAgainGroup.isEmpty() && showWarningMessage()) {
|
||||||
|
Core::InfoBarEntry info("warninglabel", tr("This change cannot be undone."));
|
||||||
|
info.setCustomButtonInfo(tr("Do not warn again"), this, SLOT(hideNoUndoWarning()));
|
||||||
|
d->m_infoBar.addInfo(info);
|
||||||
|
}
|
||||||
|
|
||||||
d->m_replaceTextEdit->setEnabled(true);
|
d->m_replaceTextEdit->setEnabled(true);
|
||||||
// We didn't have an item before, set the focus to the search widget
|
// We didn't have an item before, set the focus to the search widget
|
||||||
d->m_focusReplaceEdit = true;
|
d->m_focusReplaceEdit = true;
|
||||||
@@ -685,6 +704,35 @@ void SearchResultWindow::addResults(QList<SearchResultItem> &items, AddMode mode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SearchResultWindow::showWarningMessage() const
|
||||||
|
{
|
||||||
|
// Restore settings
|
||||||
|
QSettings *settings = Core::ICore::instance()->settings();
|
||||||
|
settings->beginGroup(d->m_dontAskAgainGroup);
|
||||||
|
settings->beginGroup(QLatin1String("Rename"));
|
||||||
|
const bool showWarningMessage = settings->value(QLatin1String("ShowWarningMessage"), true).toBool();
|
||||||
|
settings->endGroup();
|
||||||
|
settings->endGroup();
|
||||||
|
return showWarningMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchResultWindow::setShowWarningMessage(bool showWarningMessage)
|
||||||
|
{
|
||||||
|
// Restore settings
|
||||||
|
QSettings *settings = Core::ICore::instance()->settings();
|
||||||
|
settings->beginGroup(d->m_dontAskAgainGroup);
|
||||||
|
settings->beginGroup(QLatin1String("Rename"));
|
||||||
|
settings->setValue(QLatin1String("ShowWarningMessage"), showWarningMessage);
|
||||||
|
settings->endGroup();
|
||||||
|
settings->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchResultWindow::hideNoUndoWarning()
|
||||||
|
{
|
||||||
|
setShowWarningMessage(false);
|
||||||
|
d->m_infoBar.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn void SearchResultWindow::handleExpandCollapseToolButton(bool checked)
|
\fn void SearchResultWindow::handleExpandCollapseToolButton(bool checked)
|
||||||
\internal
|
\internal
|
||||||
|
|||||||
@@ -138,9 +138,11 @@ public:
|
|||||||
QString textToReplace() const;
|
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,
|
||||||
|
const QString &cfgGroup = QString());
|
||||||
|
|
||||||
void addResults(QList<SearchResultItem> &items, AddMode mode);
|
void addResults(QList<SearchResultItem> &items, AddMode mode);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void clearContents();
|
void clearContents();
|
||||||
void addResult(const QString &fileName, int lineNumber, const QString &lineText,
|
void addResult(const QString &fileName, int lineNumber, const QString &lineText,
|
||||||
@@ -152,12 +154,15 @@ private slots:
|
|||||||
void handleJumpToSearchResult(const SearchResultItem &item);
|
void handleJumpToSearchResult(const SearchResultItem &item);
|
||||||
void handleReplaceButton();
|
void handleReplaceButton();
|
||||||
void showNoMatchesFound();
|
void showNoMatchesFound();
|
||||||
|
void hideNoUndoWarning();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setShowReplaceUI(bool show);
|
void setShowReplaceUI(bool show);
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
QList<SearchResultItem> checkedItems() const;
|
QList<SearchResultItem> checkedItems() const;
|
||||||
|
bool showWarningMessage() const;
|
||||||
|
void setShowWarningMessage(bool showWarningMessage);
|
||||||
|
|
||||||
Internal::SearchResultWindowPrivate *d;
|
Internal::SearchResultWindowPrivate *d;
|
||||||
static SearchResultWindow *m_instance;
|
static SearchResultWindow *m_instance;
|
||||||
|
|||||||
@@ -132,7 +132,8 @@ void BaseFileFind::replaceAll(const QString &txt, Find::FindFlags findFlags)
|
|||||||
if (m_filterCombo)
|
if (m_filterCombo)
|
||||||
updateComboEntries(m_filterCombo, true);
|
updateComboEntries(m_filterCombo, true);
|
||||||
m_watcher.setFuture(QFuture<FileSearchResultList>());
|
m_watcher.setFuture(QFuture<FileSearchResultList>());
|
||||||
SearchResult *result = m_resultWindow->startNewSearch(SearchResultWindow::SearchAndReplace);
|
SearchResult *result = m_resultWindow->startNewSearch(
|
||||||
|
SearchResultWindow::SearchAndReplace, QLatin1String("TextEditor"));
|
||||||
connect(result, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem)));
|
connect(result, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem)));
|
||||||
connect(result, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
|
connect(result, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
|
||||||
this, SLOT(doReplace(QString,QList<Find::SearchResultItem>)));
|
this, SLOT(doReplace(QString,QList<Find::SearchResultItem>)));
|
||||||
|
|||||||
Reference in New Issue
Block a user