IDEA-130605 Import Settings: "Select Components to Import" dialog has some unreadable items — fix Live Templates

This commit is contained in:
Vladimir Krivosheev
2014-10-17 17:17:46 +02:00
parent 155f0fdaab
commit 9c1af1a39e
6 changed files with 27 additions and 89 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 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.
@@ -16,15 +16,14 @@
package com.intellij.codeInsight.template.impl;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.components.StoragePathMacros;
import com.intellij.util.SmartList;
import com.intellij.util.xmlb.XmlSerializer;
import org.jdom.Element;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
/**
@@ -32,17 +31,11 @@ import java.util.Collection;
* @author Rustam Vishnyakov
*/
@State(
name="ExportableTemplateSettings",
storages= {
@Storage(
file = StoragePathMacros.APP_CONFIG + "/" + ExportableTemplateSettings.EXPORTABLE_SETTINGS_FILE
)}
name = "ExportableTemplateSettings",
storages = @Storage(file = StoragePathMacros.APP_CONFIG + "/template.settings.xml")
)
public class ExportableTemplateSettings implements PersistentStateComponent<Element> {
public final static String EXPORTABLE_SETTINGS_FILE = "template.settings.xml";
private Collection<TemplateSettings.TemplateKey> deletedKeys = new ArrayList<TemplateSettings.TemplateKey>();
private Collection<TemplateSettings.TemplateKey> deletedKeys = new SmartList<TemplateSettings.TemplateKey>();
private boolean isLoaded = false;
private TemplateSettings parentSettings;
@@ -50,8 +43,8 @@ public class ExportableTemplateSettings implements PersistentStateComponent<Elem
@Override
public Element getState() {
if (parentSettings != null) {
this.deletedKeys.clear();
this.deletedKeys.addAll(parentSettings.getDeletedTemplates());
deletedKeys.clear();
deletedKeys.addAll(parentSettings.getDeletedTemplates());
}
return XmlSerializer.serialize(this);
}
@@ -71,7 +64,6 @@ public class ExportableTemplateSettings implements PersistentStateComponent<Elem
return deletedKeys;
}
@SuppressWarnings("UnusedDeclaration") // Property via reflection
public void setDeletedKeys(Collection<TemplateSettings.TemplateKey> deletedKeys) {
this.deletedKeys = deletedKeys;
@@ -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.
@@ -13,13 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.codeInsight.template.impl;
import com.intellij.AbstractBundle;
import com.intellij.codeInsight.CodeInsightBundle;
import com.intellij.codeInsight.template.Template;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ex.DecodeDefaultsUtil;
import com.intellij.openapi.components.*;
import com.intellij.openapi.diagnostic.Logger;
@@ -39,22 +36,16 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
@State(
name="TemplateSettings",
storages= {
@Storage(
file = StoragePathMacros.APP_CONFIG + "/other.xml"
)}
name = "TemplateSettings",
storages = @Storage(file = StoragePathMacros.APP_CONFIG + "/other.xml")
)
public class TemplateSettings implements PersistentStateComponent<Element>, ExportableComponent {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.template.impl.TemplateSettings");
public class TemplateSettings implements PersistentStateComponent<Element> {
private static final Logger LOG = Logger.getInstance(TemplateSettings.class);
@NonNls public static final String USER_GROUP_NAME = "user";
@NonNls private static final String TEMPLATE_SET = "templateSet";
@@ -97,8 +88,6 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
@NonNls private static final String KEY = "key";
@NonNls private static final String ID = "id";
@NonNls private static final String TEMPLATES_CONFIG_FOLDER = "templates";
private final MultiMap<String,TemplateImpl> myTemplates = MultiMap.createLinked();
private final Map<String,Template> myTemplatesById = new LinkedHashMap<String,Template>();
@@ -173,8 +162,7 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
SchemeProcessor<TemplateGroup> processor = new BaseSchemeProcessor<TemplateGroup>() {
@Override
@Nullable
public TemplateGroup readScheme(@NotNull final Document schemeContent)
throws InvalidDataException, IOException, JDOMException {
public TemplateGroup readScheme(@NotNull final Document schemeContent) throws InvalidDataException {
return readTemplateFile(schemeContent, schemeContent.getRootElement().getAttributeValue("group"), false, false,
getClass().getClassLoader());
}
@@ -191,7 +179,7 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
}
@Override
public Element writeScheme(@NotNull final TemplateGroup template) throws WriteExternalException {
public Element writeScheme(@NotNull final TemplateGroup template) {
Element templateSetElement = new Element(TEMPLATE_SET);
templateSetElement.setAttribute(GROUP, template.getName());
@@ -244,20 +232,6 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
return myDefaultTemplates.get(TemplateKey.keyOf(t));
}
@Override
@NotNull
public File[] getExportFiles() {
File exportableSettingsFile =
new File(PathManager.getOptionsPath() + File.separator + ExportableTemplateSettings.EXPORTABLE_SETTINGS_FILE);
return new File[]{getTemplateDirectory(true), exportableSettingsFile };
}
@Override
@NotNull
public String getPresentableName() {
return CodeInsightBundle.message("templates.export.display.name");
}
public static TemplateSettings getInstance() {
return ServiceManager.getService(TemplateSettings.class);
}
@@ -460,24 +434,6 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
return template;
}
@Nullable
private static File getTemplateDirectory(boolean toCreate) {
String directoryPath = PathManager.getConfigPath() + File.separator + TEMPLATES_CONFIG_FOLDER;
File directory = new File(directoryPath);
if (!directory.exists()) {
if (!toCreate) {
return null;
}
if (!directory.mkdir()) {
if (LOG.isDebugEnabled()) {
LOG.debug("cannot create directory: " + directory.getAbsolutePath());
}
return null;
}
}
return directory;
}
private void loadTemplates() {
Collection<TemplateGroup> loaded = mySchemesManager.loadSchemes();
for (TemplateGroup group : loaded) {
@@ -539,7 +495,7 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
throw new InvalidDataException();
}
Element root = document.getRootElement();
if (root == null || !TEMPLATE_SET.equals(root.getName())) {
if (!TEMPLATE_SET.equals(root.getName())) {
throw new InvalidDataException();
}
@@ -138,7 +138,7 @@ public class ExportableFileTemplateSettings extends FileTemplatesLoader implemen
}
private static String getXmlElementGroupName(FTManager manager) {
return manager.getName().toLowerCase(Locale.US) + "_" + "templates";
return manager.getName().toLowerCase(Locale.US) + "_templates";
}
public boolean isLoaded() {
@@ -299,7 +299,6 @@ templates.no.defined=No templates defined in this context
templates.surround.no.defined=No surround templates defined in this context
templates.settings.page.title=Live Templates
templates.select.template.chooser.title=Select Template
templates.export.display.name=Live templates
templates.dialog.edit.variables.title=Edit Template Variables
templates.dialog.edit.variables.border.title=Variables
templates.dialog.edit.variables.action.move.up=Move &Up
@@ -285,4 +285,5 @@ exportable.AbbreviationManager.presentable.name=Actions
exportable.FindSettings.presentable.name=Find
exportable.DaemonCodeAnalyzerSettings.presentable.name=Error highlighting
exportable.PrintSettings.presentable.name=Print
exportable.GeneralSettings.presentable.name=General
exportable.GeneralSettings.presentable.name=General
exportable.ExportableTemplateSettings.presentable.name=Live templates
@@ -23,8 +23,7 @@
<applicationService serviceInterface="com.intellij.openapi.project.ProjectLocator"
serviceImplementation="com.intellij.openapi.project.ProjectLocatorImpl"/>
<applicationService serviceInterface="com.intellij.packageDependencies.DependencyUISettings"
serviceImplementation="com.intellij.packageDependencies.DependencyUISettings"/>
<applicationService serviceImplementation="com.intellij.packageDependencies.DependencyUISettings"/>
<applicationService serviceInterface="com.intellij.ide.fileTemplates.FileTemplateManager"
serviceImplementation="com.intellij.ide.fileTemplates.impl.FileTemplateManagerImpl"/>
@@ -35,10 +34,8 @@
<applicationService serviceInterface="com.intellij.ide.PsiCopyPasteManager"
serviceImplementation="com.intellij.ide.PsiCopyPasteManager"/>
<applicationService serviceInterface="com.intellij.usages.UsageViewSettings"
serviceImplementation="com.intellij.usages.UsageViewSettings"/>
<applicationService serviceInterface="com.intellij.refactoring.RefactoringSettings"
serviceImplementation="com.intellij.refactoring.RefactoringSettings"/>
<applicationService serviceImplementation="com.intellij.usages.UsageViewSettings"/>
<applicationService serviceImplementation="com.intellij.refactoring.RefactoringSettings"/>
<applicationService serviceInterface="com.intellij.refactoring.RefactoringActionHandlerFactory"
serviceImplementation="com.intellij.refactoring.openapi.impl.RefactoringActionHandlerFactoryImpl"/>
@@ -50,26 +47,19 @@
<applicationService serviceInterface="com.intellij.lang.PsiBuilderFactory"
serviceImplementation="com.intellij.lang.impl.PsiBuilderFactoryImpl"/>
<applicationService serviceInterface="com.intellij.codeInsight.documentation.DocumentationManagerUtil"
serviceImplementation="com.intellij.codeInsight.documentation.DocumentationManagerUtil"/>
<applicationService serviceImplementation="com.intellij.codeInsight.documentation.DocumentationManagerUtil"/>
<applicationService serviceInterface="com.intellij.navigation.ChooseByNameRegistry"
serviceImplementation="com.intellij.navigation.ChooseByNameRegistry"/>
<applicationService serviceImplementation="com.intellij.navigation.ChooseByNameRegistry"/>
<applicationService serviceInterface="com.intellij.application.options.CodeStyleSettingsUtil"
serviceImplementation="com.intellij.application.options.CodeStyleSettingsUtilImpl"/>
<applicationService serviceInterface="com.intellij.ide.PsiActionSupportFactory"
serviceImplementation="com.intellij.ide.PsiActionSupportFactoryImpl"/>
<applicationService serviceInterface="com.intellij.codeInspection.ex.InspectionToolRegistrar"
serviceImplementation="com.intellij.codeInspection.ex.InspectionToolRegistrar"/>
<applicationService serviceInterface="com.intellij.codeInsight.template.impl.TemplateSettings"
serviceImplementation="com.intellij.codeInsight.template.impl.TemplateSettings"/>
<applicationService serviceInterface="com.intellij.codeInsight.template.impl.ExportableTemplateSettings"
serviceImplementation="com.intellij.codeInsight.template.impl.ExportableTemplateSettings"/>
<applicationService serviceInterface="com.intellij.execution.ui.layout.impl.RunnerLayoutSettings"
serviceImplementation="com.intellij.execution.ui.layout.impl.RunnerLayoutSettings"/>
<exportable serviceInterface="com.intellij.codeInsight.template.impl.TemplateSettings"/>
<applicationService serviceImplementation="com.intellij.codeInspection.ex.InspectionToolRegistrar"/>
<applicationService serviceImplementation="com.intellij.codeInsight.template.impl.TemplateSettings"/>
<applicationService serviceImplementation="com.intellij.codeInsight.template.impl.ExportableTemplateSettings"/>
<applicationService serviceImplementation="com.intellij.execution.ui.layout.impl.RunnerLayoutSettings"/>
<applicationService serviceImplementation="com.intellij.codeEditor.printing.PrintSettings"/>
<applicationService serviceInterface="com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings"