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

Method projectOpened

kdevplatform/shell/sourceformattercontroller.cpp:290–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288}
289
290void SourceFormatterController::FileFormatter::projectOpened(const IProject& project,
291 const QVector<ISourceFormatter*>& formatters)
292{
293 // Adapt the indentation mode if a project was just opened. Otherwise if a document
294 // is loaded before its project, it might not have the correct indentation mode set.
295
296 if (formatters.empty()) {
297 return;
298 }
299
300 const auto config = Config::projectConfig(project);
301 if (!Config::projectOverridesSession(config)) {
302 return; // The opened project does not specify indentation => nothing to do.
303 }
304
305 OwningRawPointerContainer<QHash<QString, FileFormatter*>> fileFormatterCache;
306 const auto fileFormatterForUrl = [&fileFormatterCache, &config, &formatters](QUrl&& url, QMimeType&& mimeType) {
307 const auto mimeTypeName = mimeType.name();
308
309 auto ff = fileFormatterCache->value(mimeTypeName);
310 if (ff) {
311 ff->m_url = std::move(url);
312 Q_ASSERT_X(ff->m_mimeType == mimeType, Q_FUNC_INFO,
313 "When MIME type names are equal, the MIME types must also compare equal.");
314 // All other ff's data members already have correct values:
315 // * m_sourceFormatterConfig equals config for all elements of fileFormatterCache;
316 // * m_formatter and m_style are determined by config and m_mimeType.
317 } else {
318 const auto data = Config::readFormatterData(config, mimeTypeName, formatters);
319 if (data.isValid()) {
320 ff = new FileFormatter(std::move(url), std::move(mimeType), config, data.formatter, data.style());
321 }
322 fileFormatterCache->insert(mimeTypeName, ff);
323 }
324 return std::as_const(ff);
325 };
326
327 const auto documents = ICore::self()->documentController()->openDocuments();
328 for (const IDocument* doc : documents) {
329 auto url = doc->url();
330 if (!project.inProject(IndexedString{url})) {
331 continue;
332 }
333 if (const auto* const ff = fileFormatterForUrl(std::move(url), doc->mimeType())) {
334 ff->adaptEditorIndentationMode(doc->textDocument());
335 }
336 }
337}
338
339void SourceFormatterController::pluginLoaded(IPlugin* plugin)
340{

Callers

nothing calls this directly

Calls 15

projectConfigFunction · 0.85
projectOverridesSessionFunction · 0.85
readFormatterDataFunction · 0.85
emptyMethod · 0.80
styleMethod · 0.80
openDocumentsMethod · 0.80
documentControllerMethod · 0.80
nameMethod · 0.45
valueMethod · 0.45
isValidMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected