Do not modify CodeStyleSettings of "Default" Code Style Scheme, create copy and modify it instead (IDEA-144408)

This commit is contained in:
Yaroslav Lepenkin
2015-09-09 19:20:30 +03:00
parent 60195b3c5f
commit 43890f1144
@@ -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();