forked from qt-creator/qt-creator
ProjectExplorer: Factor out code for finding file nodes
... with the same base file name. We want to re-use this functionality in a follow-up patch. Change-Id: Ia9b5b3f003406c7451d59801c49679d9575d1222 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -214,18 +214,7 @@ bool FlatModel::setData(const QModelIndex &index, const QVariant &value, int rol
|
|||||||
// The base name of the file was changed. Go look for other files with the same base name
|
// The base name of the file was changed. Go look for other files with the same base name
|
||||||
// and offer to rename them as well.
|
// and offer to rename them as well.
|
||||||
if (orgFilePath != newFilePath && orgFileInfo.suffix() == newFilePath.toFileInfo().suffix()) {
|
if (orgFilePath != newFilePath && orgFileInfo.suffix() == newFilePath.toFileInfo().suffix()) {
|
||||||
ProjectNode *productNode = node->parentProjectNode();
|
const QList<Node *> candidateNodes = ProjectTree::siblingsWithSameBaseName(node);
|
||||||
while (productNode && !productNode->isProduct())
|
|
||||||
productNode = productNode->parentProjectNode();
|
|
||||||
if (productNode) {
|
|
||||||
const auto filter = [&orgFilePath, &orgFileInfo](const Node *n) {
|
|
||||||
return n->asFileNode()
|
|
||||||
&& n->filePath().toFileInfo().dir() == orgFileInfo.dir()
|
|
||||||
&& n->filePath().toFileInfo().completeBaseName()
|
|
||||||
== orgFileInfo.completeBaseName()
|
|
||||||
&& n->filePath() != orgFilePath;
|
|
||||||
};
|
|
||||||
const QList<Node *> candidateNodes = productNode->findNodes(filter);
|
|
||||||
if (!candidateNodes.isEmpty()) {
|
if (!candidateNodes.isEmpty()) {
|
||||||
const QMessageBox::StandardButton reply = QMessageBox::question(
|
const QMessageBox::StandardButton reply = QMessageBox::question(
|
||||||
Core::ICore::mainWindow(), tr("Rename More Files?"),
|
Core::ICore::mainWindow(), tr("Rename More Files?"),
|
||||||
@@ -246,7 +235,6 @@ bool FlatModel::setData(const QModelIndex &index, const QVariant &value, int rol
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &f : toRename) {
|
for (const auto &f : toRename) {
|
||||||
ProjectExplorerPlugin::renameFile(std::get<0>(f), std::get<2>(f).toString());
|
ProjectExplorerPlugin::renameFile(std::get<0>(f), std::get<2>(f).toString());
|
||||||
|
@@ -48,6 +48,7 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
@@ -470,6 +471,23 @@ Node *ProjectTree::nodeForFile(const FilePath &fileName)
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QList<Node *> ProjectTree::siblingsWithSameBaseName(const Node *fileNode)
|
||||||
|
{
|
||||||
|
ProjectNode *productNode = fileNode->parentProjectNode();
|
||||||
|
while (productNode && !productNode->isProduct())
|
||||||
|
productNode = productNode->parentProjectNode();
|
||||||
|
if (!productNode)
|
||||||
|
return {};
|
||||||
|
const QFileInfo fi = fileNode->filePath().toFileInfo();
|
||||||
|
const auto filter = [&fi](const Node *n) {
|
||||||
|
return n->asFileNode()
|
||||||
|
&& n->filePath().toFileInfo().dir() == fi.dir()
|
||||||
|
&& n->filePath().toFileInfo().completeBaseName() == fi.completeBaseName()
|
||||||
|
&& n->filePath().toString() != fi.filePath();
|
||||||
|
};
|
||||||
|
return productNode->findNodes(filter);
|
||||||
|
}
|
||||||
|
|
||||||
void ProjectTree::hideContextMenu()
|
void ProjectTree::hideContextMenu()
|
||||||
{
|
{
|
||||||
m_focusForContextMenu = nullptr;
|
m_focusForContextMenu = nullptr;
|
||||||
|
@@ -82,6 +82,8 @@ public:
|
|||||||
static Project *projectForNode(const Node *node);
|
static Project *projectForNode(const Node *node);
|
||||||
static Node *nodeForFile(const Utils::FilePath &fileName);
|
static Node *nodeForFile(const Utils::FilePath &fileName);
|
||||||
|
|
||||||
|
static const QList<Node *> siblingsWithSameBaseName(const Node *fileNode);
|
||||||
|
|
||||||
void expandCurrentNodeRecursively();
|
void expandCurrentNodeRecursively();
|
||||||
|
|
||||||
void collapseAll();
|
void collapseAll();
|
||||||
|
Reference in New Issue
Block a user