Project code style setting migration notification

This commit is contained in:
Rustam Vishnyakov
2017-08-29 13:49:54 +03:00
parent d3e36561f4
commit 7fdbcb0f64
2 changed files with 37 additions and 0 deletions
@@ -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<String,CodeStyleSettings> 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<rv>: 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);
@@ -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.