forked from qt-creator/qt-creator
CppTools: Do not pre-select "external" files in "rename symbol" widget
It's unlikely that the user wants to change files that are not part of the currently loaded projects, so opt-in is the right approach for those. Fixes: QTCREATORBUG-8561 Change-Id: I1812a3e64de66828ac07dea7bbb63acdb4dd40d8 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -124,6 +124,9 @@ public:
|
|||||||
SearchResultColor::Style style() const { return m_style; }
|
SearchResultColor::Style style() const { return m_style; }
|
||||||
void setStyle(SearchResultColor::Style style) { m_style = style; }
|
void setStyle(SearchResultColor::Style style) { m_style = style; }
|
||||||
|
|
||||||
|
bool selectForReplacement() const { return m_selectForReplacement; }
|
||||||
|
void setSelectForReplacement(bool select) { m_selectForReplacement = select; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList m_path; // hierarchy to the parent item of this item
|
QStringList m_path; // hierarchy to the parent item of this item
|
||||||
QString m_lineText; // text to show for the item itself
|
QString m_lineText; // text to show for the item itself
|
||||||
@@ -131,6 +134,7 @@ private:
|
|||||||
QVariant m_userData; // user data for identification of the item
|
QVariant m_userData; // user data for identification of the item
|
||||||
Search::TextRange m_mainRange;
|
Search::TextRange m_mainRange;
|
||||||
bool m_useTextEditorFont = false;
|
bool m_useTextEditorFont = false;
|
||||||
|
bool m_selectForReplacement = true;
|
||||||
SearchResultColor::Style m_style = SearchResultColor::Style::Default;
|
SearchResultColor::Style m_style = SearchResultColor::Style::Default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ SearchResultTreeItem::SearchResultTreeItem(const SearchResultItem &item,
|
|||||||
: item(item),
|
: item(item),
|
||||||
m_parent(parent),
|
m_parent(parent),
|
||||||
m_isGenerated(false),
|
m_isGenerated(false),
|
||||||
m_checkState(Qt::Checked)
|
m_checkState(item.selectForReplacement() ? Qt::Checked : Qt::Unchecked)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ private:
|
|||||||
QSet<SearchResultTreeItem *> addPath(const QStringList &path);
|
QSet<SearchResultTreeItem *> addPath(const QStringList &path);
|
||||||
QVariant data(const SearchResultTreeItem *row, int role) const;
|
QVariant data(const SearchResultTreeItem *row, int role) const;
|
||||||
bool setCheckState(const QModelIndex &idx, Qt::CheckState checkState, bool firstCall = true);
|
bool setCheckState(const QModelIndex &idx, Qt::CheckState checkState, bool firstCall = true);
|
||||||
|
void updateCheckStateFromChildren(const QModelIndex &idx, SearchResultTreeItem *item);
|
||||||
QModelIndex nextIndex(const QModelIndex &idx, bool *wrapped = nullptr) const;
|
QModelIndex nextIndex(const QModelIndex &idx, bool *wrapped = nullptr) const;
|
||||||
QModelIndex prevIndex(const QModelIndex &idx, bool *wrapped = nullptr) const;
|
QModelIndex prevIndex(const QModelIndex &idx, bool *wrapped = nullptr) const;
|
||||||
|
|
||||||
@@ -247,31 +248,7 @@ bool SearchResultTreeModel::setCheckState(const QModelIndex &idx, Qt::CheckState
|
|||||||
item->setCheckState(checkState);
|
item->setCheckState(checkState);
|
||||||
if (firstCall) {
|
if (firstCall) {
|
||||||
emit dataChanged(idx, idx);
|
emit dataChanged(idx, idx);
|
||||||
// check parents
|
updateCheckStateFromChildren(idx.parent(), item->parent());
|
||||||
SearchResultTreeItem *currentItem = item;
|
|
||||||
QModelIndex currentIndex = idx;
|
|
||||||
while (SearchResultTreeItem *parent = currentItem->parent()) {
|
|
||||||
bool hasChecked = false;
|
|
||||||
bool hasUnchecked = false;
|
|
||||||
for (int i = 0; i < parent->childrenCount(); ++i) {
|
|
||||||
SearchResultTreeItem *child = parent->childAt(i);
|
|
||||||
if (child->checkState() == Qt::Checked)
|
|
||||||
hasChecked = true;
|
|
||||||
else if (child->checkState() == Qt::Unchecked)
|
|
||||||
hasUnchecked = true;
|
|
||||||
else if (child->checkState() == Qt::PartiallyChecked)
|
|
||||||
hasChecked = hasUnchecked = true;
|
|
||||||
}
|
|
||||||
if (hasChecked && hasUnchecked)
|
|
||||||
parent->setCheckState(Qt::PartiallyChecked);
|
|
||||||
else if (hasChecked)
|
|
||||||
parent->setCheckState(Qt::Checked);
|
|
||||||
else
|
|
||||||
parent->setCheckState(Qt::Unchecked);
|
|
||||||
emit dataChanged(idx.parent(), idx.parent());
|
|
||||||
currentItem = parent;
|
|
||||||
currentIndex = idx.parent();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// check children
|
// check children
|
||||||
if (int children = item->childrenCount()) {
|
if (int children = item->childrenCount()) {
|
||||||
@@ -282,6 +259,34 @@ bool SearchResultTreeModel::setCheckState(const QModelIndex &idx, Qt::CheckState
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SearchResultTreeModel::updateCheckStateFromChildren(const QModelIndex &idx,
|
||||||
|
SearchResultTreeItem *item)
|
||||||
|
{
|
||||||
|
if (!item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bool hasChecked = false;
|
||||||
|
bool hasUnchecked = false;
|
||||||
|
for (int i = 0; i < item->childrenCount(); ++i) {
|
||||||
|
SearchResultTreeItem *child = item->childAt(i);
|
||||||
|
if (child->checkState() == Qt::Checked)
|
||||||
|
hasChecked = true;
|
||||||
|
else if (child->checkState() == Qt::Unchecked)
|
||||||
|
hasUnchecked = true;
|
||||||
|
else if (child->checkState() == Qt::PartiallyChecked)
|
||||||
|
hasChecked = hasUnchecked = true;
|
||||||
|
}
|
||||||
|
if (hasChecked && hasUnchecked)
|
||||||
|
item->setCheckState(Qt::PartiallyChecked);
|
||||||
|
else if (hasChecked)
|
||||||
|
item->setCheckState(Qt::Checked);
|
||||||
|
else
|
||||||
|
item->setCheckState(Qt::Unchecked);
|
||||||
|
emit dataChanged(idx, idx);
|
||||||
|
|
||||||
|
updateCheckStateFromChildren(idx.parent(), item->parent());
|
||||||
|
}
|
||||||
|
|
||||||
void setDataInternal(const QModelIndex &index, const QVariant &value, int role);
|
void setDataInternal(const QModelIndex &index, const QVariant &value, int role);
|
||||||
|
|
||||||
QVariant SearchResultTreeModel::data(const SearchResultTreeItem *row, int role) const
|
QVariant SearchResultTreeModel::data(const SearchResultTreeItem *row, int role) const
|
||||||
@@ -418,6 +423,7 @@ void SearchResultTreeModel::addResultsToCurrentParent(const QList<SearchResultIt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateCheckStateFromChildren(index(m_currentParent), m_currentParent);
|
||||||
emit dataChanged(m_currentIndex, m_currentIndex); // Make sure that the number after the file name gets updated
|
emit dataChanged(m_currentIndex, m_currentIndex); // Make sure that the number after the file name gets updated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -303,6 +303,11 @@ void SearchResultWidget::setSupportsReplace(bool replaceSupported, const QString
|
|||||||
m_dontAskAgainGroup = group;
|
m_dontAskAgainGroup = group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SearchResultWidget::supportsReplace() const
|
||||||
|
{
|
||||||
|
return m_replaceSupported;
|
||||||
|
}
|
||||||
|
|
||||||
void SearchResultWidget::setTextToReplace(const QString &textToReplace)
|
void SearchResultWidget::setTextToReplace(const QString &textToReplace)
|
||||||
{
|
{
|
||||||
m_replaceTextEdit->setText(textToReplace);
|
m_replaceTextEdit->setText(textToReplace);
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public:
|
|||||||
int count() const;
|
int count() const;
|
||||||
|
|
||||||
void setSupportsReplace(bool replaceSupported, const QString &group);
|
void setSupportsReplace(bool replaceSupported, const QString &group);
|
||||||
|
bool supportsReplace() const;
|
||||||
|
|
||||||
void setTextToReplace(const QString &textToReplace);
|
void setTextToReplace(const QString &textToReplace);
|
||||||
QString textToReplace() const;
|
QString textToReplace() const;
|
||||||
|
|||||||
@@ -760,6 +760,11 @@ QVariant SearchResult::userData() const
|
|||||||
return m_userData;
|
return m_userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SearchResult::supportsReplace() const
|
||||||
|
{
|
||||||
|
return m_widget->supportsReplace();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns the text that should replace the text in search results.
|
Returns the text that should replace the text in search results.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public:
|
|||||||
|
|
||||||
void setUserData(const QVariant &data);
|
void setUserData(const QVariant &data);
|
||||||
QVariant userData() const;
|
QVariant userData() const;
|
||||||
|
bool supportsReplace() const;
|
||||||
QString textToReplace() const;
|
QString textToReplace() const;
|
||||||
int count() const;
|
int count() const;
|
||||||
void setSearchAgainSupported(bool supported);
|
void setSearchAgainSupported(bool supported);
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/projectnodes.h>
|
#include <projectexplorer/projectnodes.h>
|
||||||
#include <projectexplorer/projecttree.h>
|
#include <projectexplorer/projecttree.h>
|
||||||
|
#include <projectexplorer/session.h>
|
||||||
#include <texteditor/basefilefind.h>
|
#include <texteditor/basefilefind.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
@@ -637,6 +638,8 @@ static void displayResults(SearchResult *search, QFutureWatcher<CPlusPlus::Usage
|
|||||||
item.setUserData(int(result.type));
|
item.setUserData(int(result.type));
|
||||||
item.setStyle(colorStyleForUsageType(result.type));
|
item.setStyle(colorStyleForUsageType(result.type));
|
||||||
item.setUseTextEditorFont(true);
|
item.setUseTextEditorFont(true);
|
||||||
|
if (search->supportsReplace())
|
||||||
|
item.setSelectForReplacement(SessionManager::projectForFile(result.path));
|
||||||
search->addResult(item);
|
search->addResult(item);
|
||||||
|
|
||||||
if (parameters.prettySymbolName.isEmpty())
|
if (parameters.prettySymbolName.isEmpty())
|
||||||
@@ -829,10 +832,13 @@ void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o, const QStri
|
|||||||
const QString line = FindMacroUsesInFile::matchingLine(macro.bytesOffset(), source,
|
const QString line = FindMacroUsesInFile::matchingLine(macro.bytesOffset(), source,
|
||||||
&column);
|
&column);
|
||||||
SearchResultItem item;
|
SearchResultItem item;
|
||||||
item.setFilePath(Utils::FilePath::fromString(macro.fileName()));
|
const Utils::FilePath filePath = Utils::FilePath::fromString(macro.fileName());
|
||||||
|
item.setFilePath(filePath);
|
||||||
item.setLineText(line);
|
item.setLineText(line);
|
||||||
item.setMainRange(macro.line(), column, macro.nameToQString().length());
|
item.setMainRange(macro.line(), column, macro.nameToQString().length());
|
||||||
item.setUseTextEditorFont(true);
|
item.setUseTextEditorFont(true);
|
||||||
|
if (search->supportsReplace())
|
||||||
|
item.setSelectForReplacement(SessionManager::projectForFile(filePath));
|
||||||
search->addResult(item);
|
search->addResult(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user