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

Method updatePreview

kdevplatform/shell/sourceformatterselectionedit.cpp:659–697  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

657}
658
659void 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
699QListWidgetItem& SourceFormatterSelectionEditPrivate::addStyleItem(SourceFormatterStyle& style, StyleCategory category,
700 NewItemPosition position)

Callers 1

editStyleMethod · 0.80

Calls 12

updateLabelFunction · 0.85
emptyMethod · 0.80
modeForMimetypeMethod · 0.80
showMethod · 0.80
QUrlClass · 0.70
CursorClass · 0.50
descriptionMethod · 0.45
usePreviewMethod · 0.45
setTextMethod · 0.45
formatSourceWithStyleMethod · 0.45
previewTextMethod · 0.45
setCursorPositionMethod · 0.45

Tested by

no test coverage detected