| 838 | SourceFormatterSelectionEdit::~SourceFormatterSelectionEdit() = default; |
| 839 | |
| 840 | void 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 | |
| 877 | void SourceFormatterSelectionEdit::addSourceFormatter(ISourceFormatter* ifmt) |
| 878 | { |
nothing calls this directly
no test coverage detected