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

Method newStyle

kdevplatform/shell/sourceformatterselectionedit.cpp:1132–1165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1130}
1131
1132void SourceFormatterSelectionEdit::newStyle()
1133{
1134 Q_D(SourceFormatterSelectionEdit);
1135
1136 const auto& currentStyle = d->validCurrentStyle();
1137 auto& newStyle = d->currentFormatter().addNewStyle();
1138 newStyle.copyDataFrom(currentStyle);
1139 newStyle.setCaption(i18n("New %1", currentStyle.caption()));
1140
1141 d->currentLanguage().setSelectedStyle(&newStyle);
1142
1143 {
1144 const QSignalBlocker blocker(d->ui.styleList);
1145
1146 // Don't insert the new item into the correct ordered position, because the user will probably enter a
1147 // different caption (which affects ordering) right away. Note that when the user renames a style, it is
1148 // not immediately moved into its new ordered position to avoid the "jumping" of the renamed style.
1149 // Always keeping style items in their correct UI order positions is not trivial to implement, which is
1150 // another reason not to do it.
1151 // User-defined styles are displayed on top of predefined styles, so the eventual ordered position of
1152 // the new item is most likely closer to the top than to the bottom => place it at the top of the list.
1153 auto& newStyleItem = d->addStyleItem(newStyle, StyleCategory::UserDefined, NewItemPosition::Top);
1154
1155 // An edited item is not automatically selected, which results in weird UI behavior:
1156 // the source style (currentStyle) remains selected after the editing finishes.
1157 // Select the new style here to prevent this confusion.
1158 d->ui.styleList->setCurrentItem(&newStyleItem);
1159
1160 d->ui.styleList->editItem(&newStyleItem);
1161 }
1162
1163 d->updateUiForCurrentStyle();
1164 emit changed();
1165}
1166
1167void SourceFormatterSelectionEdit::styleNameChanged(QListWidgetItem* item)
1168{

Callers

nothing calls this directly

Calls 5

copyDataFromMethod · 0.80
setCaptionMethod · 0.80
setSelectedStyleMethod · 0.80
captionMethod · 0.45

Tested by

no test coverage detected