From 7fdbcb0f6405ad430cb3ddd6bf488fa9120ded5e Mon Sep 17 00:00:00 2001 From: Rustam Vishnyakov Date: Mon, 28 Aug 2017 19:04:35 +0300 Subject: [PATCH] Project code style setting migration notification --- .../ProjectCodeStyleSettingsManager.java | 32 +++++++++++++++++++ .../src/messages/ApplicationBundle.properties | 5 +++ 2 files changed, 37 insertions(+) diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/ProjectCodeStyleSettingsManager.java b/platform/lang-api/src/com/intellij/psi/codeStyle/ProjectCodeStyleSettingsManager.java index 39ba9326b90f..e03119bce010 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/ProjectCodeStyleSettingsManager.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/ProjectCodeStyleSettingsManager.java @@ -16,6 +16,13 @@ package com.intellij.psi.codeStyle; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationDisplayType; +import com.intellij.notification.NotificationGroup; +import com.intellij.notification.NotificationType; +import com.intellij.openapi.application.ApplicationBundle; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.TransactionGuard; import com.intellij.openapi.components.MainConfigurationStateSplitter; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.State; @@ -47,6 +54,9 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager { private final static Object LEGACY_SETTINGS_IMPORT_LOCK = new Object(); private final Map mySettingsMap = ContainerUtil.newHashMap(); + private final static NotificationGroup NOTIFICATION_GROUP = + new NotificationGroup("Code style settings migration", NotificationDisplayType.STICKY_BALLOON, true); + @SuppressWarnings("unused") public ProjectCodeStyleSettingsManager(Project project) { this(); @@ -63,6 +73,11 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager { LegacyCodeStyleSettingsManager legacySettingsManager = ServiceManager.getService(project, LegacyCodeStyleSettingsManager.class); if (legacySettingsManager != null && legacySettingsManager.getState() != null) { loadState(legacySettingsManager.getState()); + if (!project.isDefault() && + !ApplicationManager.getApplication().isUnitTestMode() && + !ApplicationManager.getApplication().isHeadlessEnvironment()) { + saveProjectAndNotify(project); + } LOG.info("Imported old project code style settings."); } else { @@ -74,6 +89,14 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager { } } + private static void saveProjectAndNotify(@NotNull Project project) { + TransactionGuard.submitTransaction(project, () -> { + project.save(); + Notification notification = new CodeStyleMigrationNotification(project.getName()); + notification.notify(project); + }); + } + @Override public void setMainProjectCodeStyle(@Nullable CodeStyleSettings settings) { // TODO: Remove the assignment below when there are no direct usages of PER_PROJECT_SETTINGS. @@ -141,6 +164,15 @@ public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager { return e; } + private static class CodeStyleMigrationNotification extends Notification { + public CodeStyleMigrationNotification(@NotNull String projectName) { + super(NOTIFICATION_GROUP.getDisplayId(), + ApplicationBundle.message("project.code.style.migration.title"), + ApplicationBundle.message("project.code.style.migration.message", projectName), + NotificationType.INFORMATION); + } + } + @Override protected boolean isIgnoredOnSave(@NotNull String fieldName) { return "PER_PROJECT_SETTINGS".equals(fieldName); diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index 1c54254fd9b5..0478c6c67ca8 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -807,3 +807,8 @@ settings.editor.scheme.import.success={0} was imported to {1} scheme. settings.editor.scheme.import.failure=Import failed: {0} is not a valid scheme. title.save.code.style.scheme.as=Duplicate Code Style Scheme As title.save.color.scheme.as=Duplicate Color Scheme As + +project.code.style.migration.title=Project code style settings migration +project.code.style.migration.message={0} code style settings were migrated from .idea/codeStyleSettings.xml to \ + new configuration files codeStyleConfig.xml and Project.xml under .idea/codeStyles directory.\ + \nIf project configuration directory .idea is under version control, the files can be added to VCS too. \ No newline at end of file