| 958 | } |
| 959 | |
| 960 | void SourceFormatterSelectionEdit::saveSettings(KConfigGroup& config) const |
| 961 | { |
| 962 | Q_D(const SourceFormatterSelectionEdit); |
| 963 | |
| 964 | // Store possibly modified user-defined styles. Store globally to allow reusing styles across sessions. |
| 965 | KConfigGroup globalConfig = Core::self()->sourceFormatterControllerInternal()->globalConfig(); |
| 966 | for (const auto& formatter : d->formatters) { |
| 967 | KConfigGroup fmtgrp = globalConfig.group(formatter->name()); |
| 968 | |
| 969 | // Delete all user-defined styles so we don't leave behind styles deleted in the UI. |
| 970 | const auto oldStyleGroups = fmtgrp.groupList(); |
| 971 | for (const QString& subgrp : oldStyleGroups) { |
| 972 | if (subgrp.startsWith(userStyleNamePrefix)) { |
| 973 | fmtgrp.deleteGroup( subgrp ); |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | formatter->forEachUserDefinedStyle([&fmtgrp](const SourceFormatterStyle& style) { |
| 978 | KConfigGroup styleGroup = fmtgrp.group(style.name()); |
| 979 | styleGroup.writeEntry(SourceFormatterController::styleCaptionKey(), style.caption()); |
| 980 | styleGroup.writeEntry(SourceFormatterController::styleShowPreviewKey(), style.usePreview()); |
| 981 | styleGroup.writeEntry(SourceFormatterController::styleContentKey(), style.content()); |
| 982 | styleGroup.writeEntry(SourceFormatterController::styleMimeTypesKey(), style.mimeTypesVariant()); |
| 983 | styleGroup.writeEntry(SourceFormatterController::styleSampleKey(), style.overrideSample()); |
| 984 | }); |
| 985 | } |
| 986 | globalConfig.sync(); |
| 987 | |
| 988 | // Store formatter and style selection for each language. |
| 989 | for (const auto& lang : d->languages) { |
| 990 | lang.saveSettings(config); |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | void SourceFormatterSelectionEdit::selectLanguage(int index) |
| 995 | { |
nothing calls this directly
no test coverage detected