mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
more synchronisation
This commit is contained in:
@@ -28,21 +28,24 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CodeStyleSettingsManager implements PersistentStateComponent<Element> {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#" + CodeStyleSettingsManager.class.getName());
|
||||
|
||||
public CodeStyleSettings PER_PROJECT_SETTINGS = null;
|
||||
public boolean USE_PER_PROJECT_SETTINGS = false;
|
||||
private CodeStyleSettings myTemporarySettings;
|
||||
private boolean myIsLoaded = false;
|
||||
public volatile CodeStyleSettings PER_PROJECT_SETTINGS = null;
|
||||
public volatile boolean USE_PER_PROJECT_SETTINGS = false;
|
||||
private volatile CodeStyleSettings myTemporarySettings;
|
||||
private volatile boolean myIsLoaded = false;
|
||||
|
||||
public static CodeStyleSettingsManager getInstance(Project project) {
|
||||
public static CodeStyleSettingsManager getInstance(@NotNull Project project) {
|
||||
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());
|
||||
LOG.info("Imported old project code style settings.");
|
||||
synchronized (projectSettingsManager) {
|
||||
if (!projectSettingsManager.isLoaded()) {
|
||||
LegacyCodeStyleSettingsManager legacySettingsManager = ServiceManager.getService(project, LegacyCodeStyleSettingsManager.class);
|
||||
if (legacySettingsManager != null && legacySettingsManager.getState() != null) {
|
||||
projectSettingsManager.loadState(legacySettingsManager.getState());
|
||||
LOG.info("Imported old project code style settings.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return projectSettingsManager;
|
||||
@@ -58,26 +61,29 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
|
||||
public CodeStyleSettingsManager() {}
|
||||
|
||||
@NotNull
|
||||
public static CodeStyleSettings getSettings(final @Nullable Project project) {
|
||||
public static CodeStyleSettings getSettings(@Nullable final Project project) {
|
||||
final CodeStyleSettingsManager instance = project == null || project.isDefault() ? getInstance() : getInstance(project);
|
||||
return instance.getCurrentSettings();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CodeStyleSettings getCurrentSettings() {
|
||||
if (myTemporarySettings != null) return myTemporarySettings;
|
||||
if (USE_PER_PROJECT_SETTINGS && PER_PROJECT_SETTINGS != null) return PER_PROJECT_SETTINGS;
|
||||
CodeStyleSettings temporarySettings = myTemporarySettings;
|
||||
if (temporarySettings != null) return temporarySettings;
|
||||
CodeStyleSettings projectSettings = PER_PROJECT_SETTINGS;
|
||||
if (USE_PER_PROJECT_SETTINGS && projectSettings != null) return projectSettings;
|
||||
return CodeStyleSchemes.getInstance().getCurrentScheme().getCodeStyleSettings();
|
||||
}
|
||||
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
private void readExternal(Element element) throws InvalidDataException {
|
||||
DefaultJDOMExternalizer.readExternal(this, element);
|
||||
}
|
||||
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
private void writeExternal(Element element) throws WriteExternalException {
|
||||
DefaultJDOMExternalizer.writeExternal(this, element, new DifferenceFilter<CodeStyleSettingsManager>(this, new CodeStyleSettingsManager()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
Element result = new Element("state");
|
||||
try {
|
||||
@@ -89,6 +95,7 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
try {
|
||||
readExternal(state);
|
||||
@@ -99,17 +106,7 @@ public class CodeStyleSettingsManager implements PersistentStateComponent<Elemen
|
||||
}
|
||||
}
|
||||
|
||||
public void disposeComponent() {}
|
||||
public void initComponent() {}
|
||||
public void projectOpened() {}
|
||||
public void projectClosed() {}
|
||||
|
||||
@NotNull
|
||||
public String getComponentName() {
|
||||
return "CodeStyleSettingsManager";
|
||||
}
|
||||
|
||||
public void setTemporarySettings(CodeStyleSettings settings) {
|
||||
public void setTemporarySettings(@NotNull CodeStyleSettings settings) {
|
||||
myTemporarySettings = settings;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ public class CodeStyleSchemeImpl implements JDOMExternalizable, CodeStyleScheme,
|
||||
private Element myRootElement;
|
||||
private String myParentSchemeName;
|
||||
private final boolean myIsDefault;
|
||||
private CodeStyleSettings myCodeStyleSettings;
|
||||
private volatile CodeStyleSettings myCodeStyleSettings;
|
||||
private final ExternalInfo myExternalInfo = new ExternalInfo();
|
||||
|
||||
public CodeStyleSchemeImpl(String name, String parentSchemeName, Element rootElement) {
|
||||
|
||||
+5
-5
@@ -25,6 +25,7 @@ import com.intellij.util.xmlb.Accessor;
|
||||
import com.intellij.util.xmlb.SerializationFilter;
|
||||
import com.intellij.util.xmlb.XmlSerializer;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -40,8 +41,7 @@ import java.io.File;
|
||||
)}
|
||||
)
|
||||
public class PersistableCodeStyleSchemes extends CodeStyleSchemesImpl implements PersistentStateComponent<Element>, NamedComponent {
|
||||
|
||||
public final static String CODE_STYLE_SCHEMES_FILE = "code.style.schemes.xml";
|
||||
@NonNls static final String CODE_STYLE_SCHEMES_FILE = "code.style.schemes.xml";
|
||||
|
||||
private boolean isLoaded;
|
||||
|
||||
@@ -64,7 +64,7 @@ public class PersistableCodeStyleSchemes extends CodeStyleSchemesImpl implements
|
||||
public void loadState(Element state) {
|
||||
init();
|
||||
XmlSerializer.deserializeInto(this, state);
|
||||
this.isLoaded = true;
|
||||
isLoaded = true;
|
||||
updateCurrentScheme();
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class PersistableCodeStyleSchemes extends CodeStyleSchemesImpl implements
|
||||
|
||||
@Override
|
||||
public boolean isLoaded() {
|
||||
return this.isLoaded;
|
||||
return isLoaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,7 +86,7 @@ public class PersistableCodeStyleSchemes extends CodeStyleSchemesImpl implements
|
||||
if (legacySettings != null) {
|
||||
CURRENT_SCHEME_NAME = legacySettings.CURRENT_SCHEME_NAME;
|
||||
}
|
||||
this.isLoaded = true;
|
||||
isLoaded = true;
|
||||
updateCurrentScheme();
|
||||
}
|
||||
|
||||
|
||||
+15
-17
@@ -32,9 +32,10 @@ public abstract class AbstractSchemesManager<T extends Scheme, E extends Externa
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.options.AbstractSchemesManager");
|
||||
|
||||
protected final List<T> mySchemes = new ArrayList<T>();
|
||||
private T myCurrentScheme;
|
||||
private volatile T myCurrentScheme;
|
||||
private String myCurrentSchemeName;
|
||||
|
||||
@Override
|
||||
public void addNewScheme(@NotNull final T scheme, final boolean replaceExisting) {
|
||||
int toReplace = -1;
|
||||
boolean newSchemeIsShared = isShared(scheme);
|
||||
@@ -80,17 +81,20 @@ public abstract class AbstractSchemesManager<T extends Scheme, E extends Externa
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllSchemes() {
|
||||
for (T t : getAllSchemes()) {
|
||||
removeScheme(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<T> getAllSchemes() {
|
||||
return Collections.unmodifiableList(new ArrayList<T>(mySchemes));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T findSchemeByName(final String schemeName) {
|
||||
for (T scheme : mySchemes) {
|
||||
@@ -102,34 +106,26 @@ public abstract class AbstractSchemesManager<T extends Scheme, E extends Externa
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void save() throws WriteExternalException;
|
||||
|
||||
@Override
|
||||
public void setCurrentSchemeName(final String schemeName) {
|
||||
myCurrentSchemeName = schemeName;
|
||||
if (schemeName != null) {
|
||||
T found = findSchemeByName(schemeName);
|
||||
if (found != null) {
|
||||
myCurrentScheme = found;
|
||||
}
|
||||
else {
|
||||
myCurrentScheme = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
myCurrentScheme = null;
|
||||
}
|
||||
myCurrentScheme = schemeName == null ? null : findSchemeByName(schemeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T getCurrentScheme() {
|
||||
if (myCurrentScheme == null) {
|
||||
T currentScheme = myCurrentScheme;
|
||||
if (currentScheme == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return findSchemeByName(myCurrentScheme.getName());
|
||||
}
|
||||
return findSchemeByName(currentScheme.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeScheme(final T scheme) {
|
||||
String schemeName = scheme.getName();
|
||||
Scheme toDelete = findSchemeToDelete(schemeName);
|
||||
@@ -153,6 +149,7 @@ public abstract class AbstractSchemesManager<T extends Scheme, E extends Externa
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<String> getAllSchemeNames() {
|
||||
return getAllSchemeNames(mySchemes);
|
||||
@@ -175,6 +172,7 @@ public abstract class AbstractSchemesManager<T extends Scheme, E extends Externa
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<SharedScheme<E>> loadSharedSchemes() {
|
||||
return loadSharedSchemes(getAllSchemes());
|
||||
|
||||
Reference in New Issue
Block a user