mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Separate storage for new project code style settings (for compatibility with versions before 11.x)
This commit is contained in:
@@ -33,9 +33,19 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
|
||||
public CodeStyleSettings PER_PROJECT_SETTINGS = null;
|
||||
public boolean USE_PER_PROJECT_SETTINGS = false;
|
||||
private CodeStyleSettings myTemporarySettings;
|
||||
private boolean myIsLoaded = false;
|
||||
|
||||
public static CodeStyleSettingsManager getInstance(Project project) {
|
||||
return ServiceManager.getService(project, ProjectCodeStyleSettingsManager.class);
|
||||
ProjectCodeStyleSettingsManager projectSettingsManager = ServiceManager.getService(project, ProjectCodeStyleSettingsManager.class);
|
||||
if (!projectSettingsManager.isLoaded()) {
|
||||
LegacyCodeStyleSettingsManager legacySettingsManager = ServiceManager.getService(project, LegacyCodeStyleSettingsManager.class);
|
||||
if (legacySettingsManager != null && legacySettingsManager.getState() != null) {
|
||||
projectSettingsManager.loadState(legacySettingsManager.getState());
|
||||
projectSettingsManager.USE_PER_PROJECT_SETTINGS = true;
|
||||
LOG.info("Imported old project code style settings.");
|
||||
}
|
||||
}
|
||||
return projectSettingsManager;
|
||||
}
|
||||
|
||||
public static CodeStyleSettingsManager getInstance() {
|
||||
@@ -80,6 +90,7 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
|
||||
public void loadState(Element state) {
|
||||
try {
|
||||
readExternal(state);
|
||||
myIsLoaded = true;
|
||||
}
|
||||
catch (InvalidDataException e) {
|
||||
LOG.error(e);
|
||||
@@ -103,4 +114,8 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
|
||||
public void dropTemporarySettings() {
|
||||
myTemporarySettings = null;
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return myIsLoaded;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi.codeStyle;
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.components.StorageScheme;
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
* Supports old code style settings (before version 11.x). The settings are returned as is without any
|
||||
* changes.
|
||||
* @author Rustam Vishnyakov
|
||||
*/
|
||||
@State(
|
||||
name = "CodeStyleSettingsManager",
|
||||
storages = {
|
||||
@Storage( file = "$PROJECT_FILE$")
|
||||
,@Storage( file = "$PROJECT_CONFIG_DIR$/projectCodeStyle.xml", scheme = StorageScheme.DIRECTORY_BASED)
|
||||
}
|
||||
)
|
||||
public class LegacyCodeStyleSettingsManager implements PersistentStateComponent<Element> {
|
||||
|
||||
private Element myState;
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
return myState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
myState = state;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -22,10 +22,10 @@ import com.intellij.openapi.components.StorageScheme;
|
||||
|
||||
|
||||
@State(
|
||||
name = "CodeStyleSettingsManager",
|
||||
name = "ProjectCodeStyleSettingsManager",
|
||||
storages = {
|
||||
@Storage( file = "$PROJECT_FILE$")
|
||||
,@Storage( file = "$PROJECT_CONFIG_DIR$/projectCodeStyle.xml", scheme = StorageScheme.DIRECTORY_BASED)
|
||||
,@Storage( file = "$PROJECT_CONFIG_DIR$/codeStyleSettings.xml", scheme = StorageScheme.DIRECTORY_BASED)
|
||||
}
|
||||
)
|
||||
public class ProjectCodeStyleSettingsManager extends CodeStyleSettingsManager{
|
||||
|
||||
@@ -156,6 +156,9 @@
|
||||
<projectService serviceInterface="com.intellij.psi.codeStyle.ProjectCodeStyleSettingsManager"
|
||||
serviceImplementation="com.intellij.psi.codeStyle.ProjectCodeStyleSettingsManager"/>
|
||||
|
||||
<projectService serviceInterface="com.intellij.psi.codeStyle.LegacyCodeStyleSettingsManager"
|
||||
serviceImplementation="com.intellij.psi.codeStyle.LegacyCodeStyleSettingsManager"/>
|
||||
|
||||
<projectService serviceInterface="com.intellij.codeInsight.daemon.impl.analysis.HighlightingSettingsPerFile"
|
||||
serviceImplementation="com.intellij.codeInsight.daemon.impl.analysis.HighlightingSettingsPerFile"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user