forked from qt-creator/qt-creator
ProjectExplorer: Support bulk renamings in project tree
If a user changes the name of a file abc.cpp to def.cpp, and there is a file abc.h in the same directory, it's likely that the user wants to rename that file to def.h. Detect such circumstances and offer the user to automatically rename the sibling files. Fixes: QTCREATORBUG-21738 Change-Id: Ib3ece08698a3341ef4087066d2289048f6b0fa61 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -335,18 +335,20 @@ int ProjectTreeWidget::expandedCount(Node *node)
|
||||
|
||||
void ProjectTreeWidget::rowsInserted(const QModelIndex &parent, int start, int end)
|
||||
{
|
||||
if (m_delayedRename.isEmpty())
|
||||
return;
|
||||
Node *node = m_model->nodeForIndex(parent);
|
||||
QTC_ASSERT(node, return);
|
||||
int i = start;
|
||||
while (i <= end) {
|
||||
for (int i = start; i <= end && !m_delayedRename.isEmpty(); ++i) {
|
||||
QModelIndex idx = m_model->index(i, 0, parent);
|
||||
Node *n = m_model->nodeForIndex(idx);
|
||||
if (n && n->filePath() == m_delayedRename) {
|
||||
if (!n)
|
||||
continue;
|
||||
const int renameIdx = m_delayedRename.indexOf(n->filePath());
|
||||
if (renameIdx != -1) {
|
||||
m_view->setCurrentIndex(idx);
|
||||
m_delayedRename.clear();
|
||||
break;
|
||||
m_delayedRename.removeAt(renameIdx);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,7 +469,7 @@ void ProjectTreeWidget::renamed(const FilePath &oldPath, const FilePath &newPath
|
||||
if (node)
|
||||
m_view->setCurrentIndex(m_model->indexForNode(node));
|
||||
else
|
||||
m_delayedRename = newPath;
|
||||
m_delayedRename << newPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user