aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Adam <cristian.adam@qt.io>2025-08-11 17:27:39 +0200
committerCristian Adam <cristian.adam@qt.io>2025-08-14 09:10:42 +0000
commit893a86a51ca2fe119ce86e1c3195d282e5b9e1f5 (patch)
tree406b3f47145138e82983694a6fca5b2be3dfc1bf
parent95e389c53e76b4cfbf140fc18cdaf798c819e2ce (diff)
QmlJSEditor: Fix refactoring component to separate file17.0
`ParentFolderNode` is returning the `<build-dir>/<URI>` folder, which is not what the user is expecting when providing the `<source-dir>` as target directory. For CMake projects the expectation is that the new qml file is added to the project that was using the parent qml file. Fixes: QTCREATORBUG-33298 Change-Id: I22d026f4952444b21092500bdb1d965ead077727 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
index 60fc563295a..f2b2f82bca6 100644
--- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
+++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
@@ -19,6 +19,7 @@
#include <qmljs/qmljsrewriter.h>
#include <qmljstools/qmljsrefactoringchanges.h>
#include <projectexplorer/project.h>
+#include <projectexplorer/projectmanager.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/projecttree.h>
@@ -171,12 +172,22 @@ public:
if (path.toUrlishString() == currentFileName.toFileInfo().path()) {
// hack for the common case, next version should use the wizard
- ProjectExplorer::Node *oldFileNode = ProjectExplorer::ProjectTree::nodeForFile(
- currentFileName);
- if (oldFileNode) {
- ProjectExplorer::FolderNode *containingFolder = oldFileNode->parentFolderNode();
- if (containingFolder)
- containingFolder->addFiles({newFileName});
+ using namespace ProjectExplorer;
+ bool fileAdded = false;
+ if (Project *const project = ProjectManager::projectForFile(currentFileName)) {
+ if (ProjectNode *const product = project->productNodeForFilePath(currentFileName)) {
+ if (product->addFiles({newFileName}))
+ fileAdded = true;
+ }
+ }
+ if (!fileAdded) {
+ ProjectExplorer::Node *oldFileNode = ProjectExplorer::ProjectTree::nodeForFile(
+ currentFileName);
+ if (oldFileNode) {
+ ProjectExplorer::FolderNode *containingFolder = oldFileNode->parentFolderNode();
+ if (containingFolder)
+ containingFolder->addFiles({newFileName});
+ }
}
}