This commit is contained in:
Vladimir Krivosheev
2014-11-18 17:56:48 +01:00
parent cb1ddf5d98
commit c9b8426533
2 changed files with 11 additions and 32 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -15,7 +15,6 @@
*/
package com.intellij.openapi.options;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.impl.ApplicationImpl;
import com.intellij.openapi.components.RoamingType;
@@ -40,12 +39,7 @@ public class SchemesManagerFactoryImpl extends SchemesManagerFactory implements
public <T extends Scheme, E extends ExternalizableScheme> SchemesManager<T, E> createSchemesManager(@NotNull String fileSpec,
@NotNull SchemeProcessor<E> processor,
@NotNull RoamingType roamingType) {
Application application = ApplicationManager.getApplication();
if (!(application instanceof ApplicationImpl)) {
return null;
}
IApplicationStore applicationStore = ((ApplicationImpl)application).getStateStore();
IApplicationStore applicationStore = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore();
String baseDirPath = applicationStore.getStateStorageManager().expandMacros(fileSpec);
StreamProvider provider = applicationStore.getStateStorageManager().getStreamProvider();
SchemesManagerImpl<T, E> manager = new SchemesManagerImpl<T, E>(fileSpec, processor, roamingType, provider, new File(baseDirPath));
@@ -18,7 +18,6 @@ package com.intellij.openapi.options;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.impl.ApplicationImpl;
import com.intellij.openapi.components.RoamingType;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.StateStorageException;
@@ -379,7 +378,7 @@ public class SchemesManagerImpl<T extends Scheme, E extends ExternalizableScheme
String schemePath = element.getAttributeValue(ORIGINAL_SCHEME_PATH);
Element sharedElement = loadGlobalScheme(schemePath);
Element sharedElement = myProvider != null && myProvider.isEnabled() ? StorageUtil.loadElement(myProvider.loadContent(schemePath, myRoamingType)) : null;
if (sharedElement != null) {
E result = readScheme(sharedElement, Collections.<String, E>emptyMap());
if (result != null) {
@@ -425,12 +424,6 @@ public class SchemesManagerImpl<T extends Scheme, E extends ExternalizableScheme
}
}
@Nullable
private Element loadGlobalScheme(@NotNull String schemePath) throws IOException {
StreamProvider provider = getProvider();
return provider != null && provider.isEnabled() ? StorageUtil.loadElement(provider.loadContent(schemePath, myRoamingType)) : null;
}
@NotNull
private String createFileName(@NotNull CharSequence fileName) {
if (StringUtilRt.endsWithIgnoreCase(fileName, mySchemeExtension)) {
@@ -489,16 +482,15 @@ public class SchemesManagerImpl<T extends Scheme, E extends ExternalizableScheme
@Override
@NotNull
public Collection<SharedScheme<E>> loadSharedSchemes(Collection<T> currentSchemeList) {
StreamProvider provider = getProvider();
if (provider == null || !provider.isEnabled()) {
if (myProvider == null || !myProvider.isEnabled()) {
return Collections.emptyList();
}
Collection<String> names = new THashSet<String>(getAllSchemeNames(currentSchemeList));
Collection<String> names = getAllSchemeNames(currentSchemeList);
Map<String, SharedScheme<E>> result = new THashMap<String, SharedScheme<E>>();
for (String subPath : provider.listSubFiles(myFileSpec, myRoamingType)) {
for (String subPath : myProvider.listSubFiles(myFileSpec, myRoamingType)) {
try {
Element element = StorageUtil.loadElement(provider.loadContent(getFileFullPath(subPath), myRoamingType));
Element element = StorageUtil.loadElement(myProvider.loadContent(getFileFullPath(subPath), myRoamingType));
if (element != null) {
SharedSchemeData original = unwrap(element);
E scheme = doReadScheme(original.original);
@@ -557,19 +549,18 @@ public class SchemesManagerImpl<T extends Scheme, E extends ExternalizableScheme
@SuppressWarnings("deprecation")
@Override
public void exportScheme(@NotNull final E scheme, final String name, final String description) throws WriteExternalException, IOException {
StreamProvider provider = getProvider();
if (provider == null) {
if (myProvider == null) {
return;
}
Parent document = myProcessor.writeScheme(scheme);
if (document != null) {
String fileSpec = getFileFullPath(FileUtil.sanitizeName(scheme.getName())) + mySchemeExtension;
if (!provider.isApplicable(fileSpec, myRoamingType)) {
if (!myProvider.isApplicable(fileSpec, myRoamingType)) {
return;
}
StorageUtil.sendContent(provider, fileSpec, wrap(document, name, description), myRoamingType, false);
StorageUtil.sendContent(myProvider, fileSpec, wrap(document, name, description), myRoamingType, false);
}
}
@@ -584,13 +575,7 @@ public class SchemesManagerImpl<T extends Scheme, E extends ExternalizableScheme
@Override
public boolean isImportAvailable() {
return getProvider() != null;
}
@Nullable
private static StreamProvider getProvider() {
StreamProvider provider = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager().getStreamProvider();
return provider == null || !provider.isEnabled() ? null : provider;
return myProvider != null;
}
@Override