From 9c1af1a39edc604ed9549ac94c76687ca310e9d9 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 17 Oct 2014 17:08:02 +0200 Subject: [PATCH] =?UTF-8?q?IDEA-130605=20Import=20Settings:=20"Select=20Co?= =?UTF-8?q?mponents=20to=20Import"=20dialog=20has=20some=20unreadable=20it?= =?UTF-8?q?ems=20=E2=80=94=20fix=20Live=20Templates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ExportableTemplateSettings.java | 22 +++---- .../template/impl/TemplateSettings.java | 60 +++---------------- .../impl/ExportableFileTemplateSettings.java | 2 +- .../src/messages/CodeInsightBundle.properties | 1 - .../src/messages/OptionsBundle.properties | 3 +- .../src/META-INF/LangExtensions.xml | 28 +++------ 6 files changed, 27 insertions(+), 89 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ExportableTemplateSettings.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ExportableTemplateSettings.java index 3beafeb3efe9..e082b90d47c3 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ExportableTemplateSettings.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/ExportableTemplateSettings.java @@ -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 { - - public final static String EXPORTABLE_SETTINGS_FILE = "template.settings.xml"; - - private Collection deletedKeys = new ArrayList(); + private Collection deletedKeys = new SmartList(); private boolean isLoaded = false; private TemplateSettings parentSettings; @@ -50,8 +43,8 @@ public class ExportableTemplateSettings implements PersistentStateComponent deletedKeys) { this.deletedKeys = deletedKeys; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java index 060521016991..02fe604990f0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java @@ -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, ExportableComponent { - - private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.template.impl.TemplateSettings"); +public class TemplateSettings implements PersistentStateComponent { + 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, 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 myTemplates = MultiMap.createLinked(); private final Map myTemplatesById = new LinkedHashMap(); @@ -173,8 +162,7 @@ public class TemplateSettings implements PersistentStateComponent, Expo SchemeProcessor processor = new BaseSchemeProcessor() { @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, 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, 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, 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 loaded = mySchemesManager.loadSchemes(); for (TemplateGroup group : loaded) { @@ -539,7 +495,7 @@ public class TemplateSettings implements PersistentStateComponent, 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(); } diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/ExportableFileTemplateSettings.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/ExportableFileTemplateSettings.java index 29cf1b18644a..8d136a28a749 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/ExportableFileTemplateSettings.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/impl/ExportableFileTemplateSettings.java @@ -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() { diff --git a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties index e7a7b43bf223..b826fd201230 100644 --- a/platform/platform-resources-en/src/messages/CodeInsightBundle.properties +++ b/platform/platform-resources-en/src/messages/CodeInsightBundle.properties @@ -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 diff --git a/platform/platform-resources-en/src/messages/OptionsBundle.properties b/platform/platform-resources-en/src/messages/OptionsBundle.properties index 592a49029c6a..f68444569820 100644 --- a/platform/platform-resources-en/src/messages/OptionsBundle.properties +++ b/platform/platform-resources-en/src/messages/OptionsBundle.properties @@ -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 \ No newline at end of file +exportable.GeneralSettings.presentable.name=General +exportable.ExportableTemplateSettings.presentable.name=Live templates \ No newline at end of file diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 56ed09c9de65..b4df75cd547b 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -23,8 +23,7 @@ - + @@ -35,10 +34,8 @@ - - + + @@ -50,26 +47,19 @@ - + - + - - - - - + + + +