diff --git a/platform/lang-impl/src/com/intellij/formatting/contextConfiguration/ConfigureCodeStyleOnSelectedFragment.java b/platform/lang-impl/src/com/intellij/formatting/contextConfiguration/ConfigureCodeStyleOnSelectedFragment.java index 8346ae47a3d5..fc98d2bec630 100644 --- a/platform/lang-impl/src/com/intellij/formatting/contextConfiguration/ConfigureCodeStyleOnSelectedFragment.java +++ b/platform/lang-impl/src/com/intellij/formatting/contextConfiguration/ConfigureCodeStyleOnSelectedFragment.java @@ -15,6 +15,7 @@ */ package com.intellij.formatting.contextConfiguration; +import com.intellij.application.options.codeStyle.CodeStyleSchemesModel; import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.lang.Language; @@ -93,7 +94,7 @@ public class ConfigureCodeStyleOnSelectedFragment implements IntentionAction { private final Editor myEditor; private final Document myDocument; private SelectedTextFormatter mySelectedTextFormatter; - private final CodeStyleSettings mySettings; + private CodeStyleSettings mySettings; public FragmentCodeStyleSettingsDialog(@NotNull final Editor editor, @@ -159,6 +160,7 @@ public class ConfigureCodeStyleOnSelectedFragment implements IntentionAction { private void applyFromUiToSettings() { try { + createNewCodeStyleSchemeIfDefault(); myTabbedLanguagePanel.apply(mySettings); } catch (ConfigurationException e) { @@ -166,6 +168,17 @@ public class ConfigureCodeStyleOnSelectedFragment implements IntentionAction { } } + private void createNewCodeStyleSchemeIfDefault() { + CodeStyleSchemes schemes = CodeStyleSchemes.getInstance(); + CodeStyleScheme current = schemes.getCurrentScheme(); + if (current != null && CodeStyleSchemesModel.cannotBeModified(current)) { + CodeStyleScheme newScheme = schemes.createNewScheme(null, current); + schemes.addScheme(newScheme); + CodeStyleSettingsManager.getInstance(myEditor.getProject()).PREFERRED_PROJECT_CODE_STYLE = newScheme.getName(); + mySettings = newScheme.getCodeStyleSettings(); + } + } + @Override public void doCancelAction() { mySelectedTextFormatter.restoreSelectedText();