| 657 | } |
| 658 | |
| 659 | void SourceFormatterSelectionEditPrivate::updatePreview() |
| 660 | { |
| 661 | if (languages.empty() || !currentStyle()) { |
| 662 | ui.descriptionLabel->hide(); |
| 663 | ui.previewArea->hide(); |
| 664 | return; |
| 665 | } |
| 666 | |
| 667 | const auto& currentStyle = validCurrentStyle(); |
| 668 | |
| 669 | updateLabel(*ui.descriptionLabel, currentStyle.description()); |
| 670 | |
| 671 | if (!currentStyle.usePreview()) { |
| 672 | ui.previewArea->hide(); |
| 673 | return; |
| 674 | } |
| 675 | |
| 676 | document->setReadWrite(true); |
| 677 | |
| 678 | const auto& mimeType = currentLanguage().defaultMimeType(); |
| 679 | document->setHighlightingMode(currentStyle.modeForMimetype(mimeType)); |
| 680 | |
| 681 | //NOTE: this is ugly, but otherwise kate might remove tabs again :-/ |
| 682 | // see also: https://bugs.kde.org/show_bug.cgi?id=291074 |
| 683 | const QString replaceTabsConfigKey = QStringLiteral("replace-tabs"); |
| 684 | const auto oldReplaceTabsConfigValue = document->configValue(replaceTabsConfigKey); |
| 685 | document->setConfigValue(replaceTabsConfigKey, false); |
| 686 | |
| 687 | const auto& formatter = currentFormatter().formatter(); |
| 688 | document->setText( |
| 689 | formatter.formatSourceWithStyle(currentStyle, formatter.previewText(currentStyle, mimeType), QUrl(), mimeType)); |
| 690 | |
| 691 | document->setConfigValue(replaceTabsConfigKey, oldReplaceTabsConfigValue); |
| 692 | |
| 693 | ui.previewArea->show(); |
| 694 | view->setCursorPosition(KTextEditor::Cursor(0, 0)); |
| 695 | |
| 696 | document->setReadWrite(false); |
| 697 | } |
| 698 | |
| 699 | QListWidgetItem& SourceFormatterSelectionEditPrivate::addStyleItem(SourceFormatterStyle& style, StyleCategory category, |
| 700 | NewItemPosition position) |
no test coverage detected