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

Method addSourceFormatterNoUi

kdevplatform/shell/sourceformatterselectionedit.cpp:840–875  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

838SourceFormatterSelectionEdit::~SourceFormatterSelectionEdit() = default;
839
840void SourceFormatterSelectionEdit::addSourceFormatterNoUi(ISourceFormatter* ifmt)
841{
842 Q_D(SourceFormatterSelectionEdit);
843
844 const QString formatterName = ifmt->name();
845 qCDebug(SHELL) << "Adding source formatter:" << formatterName;
846
847 if (std::any_of(d->formatters.cbegin(), d->formatters.cend(), [&formatterName](const auto& f) {
848 return formatterName == f->name();
849 })) {
850 qCWarning(SHELL) << "formatter plugin" << formatterName
851 << "loading which was already seen before by SourceFormatterSelectionEdit";
852 return;
853 }
854
855 d->formatters.push_back(std::make_unique<FormatterData>(
856 *ifmt, Core::self()->sourceFormatterControllerInternal()->stylesForFormatter(*ifmt)));
857 auto& formatter = *d->formatters.back();
858
859 // The loop below can invalidate currentLanguagePtr; resetUi() selects the first language anyway.
860 d->currentLanguagePtr = nullptr;
861
862 // Built-in styles share the same MIME list object. User-defined styles usually have MIME lists equal to the
863 // shared built-in list. addedMimeLists allows to quickly skip duplicate lists as an optimization.
864 // Note that a single addedMimeLists object cannot be shared by consecutive calls to this function, because
865 // formatter is different in each call, and formatter is added to language settings in the loop below.
866 std::vector<SourceFormatterStyle::MimeList> addedMimeLists;
867 formatter.forEachStyle([d, &formatter, &addedMimeLists](const SourceFormatterStyle& style) {
868 auto mimeTypes = style.mimeTypes();
869 if (std::find(addedMimeLists.cbegin(), addedMimeLists.cend(), mimeTypes) != addedMimeLists.cend()) {
870 return; // this is a duplicate list
871 }
872 addedMimeLists.push_back(std::move(mimeTypes));
873 d->addMimeTypes(addedMimeLists.back(), formatter);
874 });
875}
876
877void SourceFormatterSelectionEdit::addSourceFormatter(ISourceFormatter* ifmt)
878{

Callers

nothing calls this directly

Calls 8

stylesForFormatterMethod · 0.80
forEachStyleMethod · 0.80
mimeTypesMethod · 0.80
addMimeTypesMethod · 0.80
nameMethod · 0.45
push_backMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected