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

Method applyAllChanges

kdevplatform/language/codegen/documentchangeset.cpp:199–326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197}
198
199DocumentChangeSet::ChangeResult DocumentChangeSet::applyAllChanges()
200{
201 Q_D(DocumentChangeSet);
202
203 QUrl oldActiveDoc;
204 if (IDocument* activeDoc = ICore::self()->documentController()->activeDocument()) {
205 oldActiveDoc = activeDoc->url();
206 }
207
208 QList<QUrl> allFiles;
209 const auto changedFiles = QSet<KDevelop::IndexedString>(d->documentsRename.keyBegin(), d->documentsRename.keyEnd())
210 + QSet<KDevelop::IndexedString>(d->changes.keyBegin(), d->changes.keyEnd());
211 allFiles.reserve(changedFiles.size());
212 for (const IndexedString& file : changedFiles) {
213 allFiles << file.toUrl();
214 }
215
216 if (!KDevelop::ensureWritable(allFiles)) {
217 return ChangeResult(QStringLiteral("some affected files are not writable"));
218 }
219
220 // rename files
221 QHash<IndexedString, IndexedString>::const_iterator it = d->documentsRename.constBegin();
222 for (; it != d->documentsRename.constEnd(); ++it) {
223 QUrl url = it.key().toUrl();
224 IProject* p = ICore::self()->projectController()->findProjectForUrl(url);
225 if (p) {
226 QList<ProjectFileItem*> files = p->filesForPath(it.key());
227 if (!files.isEmpty()) {
228 ProjectBaseItem::RenameStatus renamed = files.first()->rename(it.value().str());
229 if (renamed == ProjectBaseItem::RenameOk) {
230 const QUrl newUrl = Path(Path(url).parent(), it.value().str()).toUrl();
231 if (url == oldActiveDoc) {
232 oldActiveDoc = newUrl;
233 }
234 IndexedString idxNewDoc(newUrl);
235
236 // ensure changes operate on new file name
237 ChangesHash::iterator iter = d->changes.find(it.key());
238 if (iter != d->changes.end()) {
239 // copy changes
240 ChangesList value = iter.value();
241 // remove old entry
242 d->changes.erase(iter);
243 // adapt to new url
244 for (auto& change : value) {
245 change->m_document = idxNewDoc;
246 }
247
248 d->changes[idxNewDoc] = value;
249 }
250 } else {
251 ///FIXME: share code with project manager for the error code string representation
252 return ChangeResult(i18n("Could not rename '%1' to '%2'",
253 url.toDisplayString(QUrl::PreferLocalFile), it.value().str()));
254 }
255 } else {
256 //TODO: do it outside the project management?

Callers 15

testReplaceSameLineMethod · 0.80
generateMethod · 0.80
cppOutputMethod · 0.80
yamlOutputMethod · 0.80
executeMethod · 0.80
executeMethod · 0.80
executeMethod · 0.80
executeMethod · 0.80
executeMethod · 0.80
moveIntoSourceMethod · 0.80
executeMethod · 0.80

Calls 15

ensureWritableFunction · 0.85
ChangeResultClass · 0.85
createCodeRepresentationFunction · 0.85
activeDocumentMethod · 0.80
documentControllerMethod · 0.80
constBeginMethod · 0.80
constEndMethod · 0.80
findProjectForUrlMethod · 0.80
projectControllerMethod · 0.80
strMethod · 0.80
removeDuplicatesMethod · 0.80
generateNewTextMethod · 0.80

Tested by 6

testReplaceSameLineMethod · 0.64
generateMethod · 0.64
cppOutputMethod · 0.64
yamlOutputMethod · 0.64
yamlTemplateMethod · 0.64
cppTemplateMethod · 0.64