inspection settings: copy to new profile: get actual ( un-applied ) information about...
authorDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Tue, 19 Jul 2016 09:02:18 +0000 (12:02 +0300)
committerDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Tue, 19 Jul 2016 09:02:18 +0000 (12:02 +0300)
platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java

index d0eaa6ebb79ef4e5b6a8fec499fb7747bbde502d..8d94af0995b37a1e0af97e52fb4943919b5de20c 100644 (file)
@@ -116,7 +116,9 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
                                                  boolean modifyName,
                                                  boolean modifyLevel) {
     LOG.assertTrue(modifyLevel || modifyName);
-    String profileDefaultName = selectedProfile.getName();
+    String profileDefaultName = getProfilePanel(selectedProfile).getCurrentProfileName();
+
+    final boolean isProjectLevel = getProfilePanel(selectedProfile).isProjectLevel() ^ modifyLevel;
     if (modifyName) {
       final Matcher matcher = COPIED_PROFILE_SUFFIX_PATTERN.matcher(profileDefaultName);
       int nextIdx;
@@ -128,25 +130,18 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
         profileDefaultName += " copy";
         nextIdx = 1;
       }
-      if (hasName(profileDefaultName, modifyLevel != myPanels.get(selectedProfile).isProjectLevel())) {
+      if (hasName(profileDefaultName, isProjectLevel)) {
         String currentProfileDefaultName;
         do {
           currentProfileDefaultName = profileDefaultName + " " + String.valueOf(nextIdx);
           nextIdx++;
         }
-        while (hasName(currentProfileDefaultName, modifyLevel != myPanels.get(selectedProfile).isProjectLevel()));
+        while (hasName(currentProfileDefaultName, isProjectLevel));
         profileDefaultName = currentProfileDefaultName;
       }
     }
 
-    ProfileManager profileManager = selectedProfile.getProfileManager();
-    if (modifyLevel) {
-      if (profileManager == myApplicationProfileManager) {
-        profileManager = myProjectProfileManager;
-      } else {
-        profileManager = myApplicationProfileManager;
-      }
-    }
+    ProfileManager profileManager = isProjectLevel ? myProjectProfileManager : myApplicationProfileManager;
     InspectionProfileImpl inspectionProfile =
       new InspectionProfileImpl(profileDefaultName, InspectionToolRegistrar.getInstance(), profileManager);
 
@@ -154,6 +149,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable
     inspectionProfile.setName(profileDefaultName);
     inspectionProfile.initInspectionTools(project);
     inspectionProfile.setModified(true);
+    inspectionProfile.setProjectLevel(profileManager == myProjectProfileManager);
 
     final InspectionProfileImpl modifiableModel = (InspectionProfileImpl)inspectionProfile.getModifiableModel();
     modifiableModel.setModified(true);