MCPcopy Create free account
hub / github.com/KDE/kdevelop / addFilesToTarget

Method addFilesToTarget

plugins/filetemplates/templateclassassistant.cpp:120–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120void TemplateClassAssistantPrivate::addFilesToTarget (const QHash< QString, QUrl >& fileUrls)
121{
122 // Add the generated files to a target, if one is found
123 QUrl url = baseUrl;
124 if (!url.isValid())
125 {
126 // This was probably not launched from the project manager view
127 // Still, we try to find the common URL where the generated files are located
128
129 if (!fileUrls.isEmpty())
130 {
131 url = fileUrls.constBegin().value().adjusted(QUrl::RemoveFilename);
132 }
133 }
134 qCDebug(PLUGIN_FILETEMPLATES) << "Searching for targets with URL" << url;
135 IProject* project = ICore::self()->projectController()->findProjectForUrl(url);
136 if (!project || !project->buildSystemManager())
137 {
138 qCDebug(PLUGIN_FILETEMPLATES) << "No suitable project found";
139 return;
140 }
141
142 const QList<ProjectBaseItem*> items = project->itemsForPath(IndexedString(url));
143 if (items.isEmpty())
144 {
145 qCDebug(PLUGIN_FILETEMPLATES) << "No suitable project items found";
146 return;
147 }
148
149 QList<ProjectTargetItem*> targets;
150 ProjectTargetItem* target = nullptr;
151
152 for (ProjectBaseItem* item : items) {
153 if (ProjectTargetItem* target = item->target())
154 {
155 targets << target;
156 }
157 }
158
159 if (targets.isEmpty())
160 {
161 // If no target was explicitly found yet, try all the targets in the current folder
162 targets.reserve(items.size());
163 for (ProjectBaseItem* item : items) {
164 targets << item->targetList();
165 }
166 }
167
168 if (targets.isEmpty())
169 {
170 // If still no targets, we traverse the tree up to the first directory with targets
171 ProjectBaseItem* item = items.first()->parent();
172 while (targets.isEmpty() && item)
173 {
174 targets = item->targetList();
175 item = item->parent();
176 }
177 }

Callers 1

acceptMethod · 0.45

Calls 15

constBeginMethod · 0.80
findProjectForUrlMethod · 0.80
projectControllerMethod · 0.80
buildSystemManagerMethod · 0.80
targetListMethod · 0.80
buttonMethod · 0.80
execMethod · 0.80
selectedItemsMethod · 0.80
folderMethod · 0.80
projectFileManagerMethod · 0.80
IndexedStringClass · 0.50
PathClass · 0.50

Tested by

no test coverage detected