mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-89379 Export Settings Includes other.xml When Only Code Style Selected
This commit is contained in:
+136
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.ide.fileTemplates.impl;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.components.*;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author Rustam Vishnyakov
|
||||
*/
|
||||
@State(
|
||||
name="ExportableFileTemplateSettings",
|
||||
storages= {
|
||||
@Storage(
|
||||
file = StoragePathMacros.APP_CONFIG + "/" + ExportableFileTemplateSettings.EXPORTABLE_SETTINGS_FILE
|
||||
)}
|
||||
)
|
||||
public class ExportableFileTemplateSettings implements PersistentStateComponent<Element>, ExportableComponent {
|
||||
|
||||
public final static String EXPORTABLE_SETTINGS_FILE = "file.template.settings.xml";
|
||||
|
||||
static final String ELEMENT_TEMPLATE = "template";
|
||||
static final String ATTRIBUTE_NAME = "name";
|
||||
static final String ATTRIBUTE_REFORMAT = "reformat";
|
||||
static final String ATTRIBUTE_ENABLED = "enabled";
|
||||
|
||||
private FileTemplateManagerImpl myFileTemplateManager;
|
||||
private boolean myLoaded = false;
|
||||
|
||||
|
||||
public ExportableFileTemplateSettings() {
|
||||
myFileTemplateManager = FileTemplateManagerImpl.getInstanceImpl();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public File[] getExportFiles() {
|
||||
File exportableSettingsFile =
|
||||
new File(PathManager.getOptionsPath() + File.separator + EXPORTABLE_SETTINGS_FILE);
|
||||
return new File[] {myFileTemplateManager.getDefaultTemplatesManager().getConfigRoot(false), exportableSettingsFile};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableName() {
|
||||
return IdeBundle.message("item.file.templates");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Element getState() {
|
||||
Element element = new Element("fileTemplateSettings");
|
||||
for (FTManager manager : myFileTemplateManager.getAllManagers()) {
|
||||
final Element templatesGroup = new Element(getXmlElementGroupName(manager));
|
||||
element.addContent(templatesGroup);
|
||||
for (FileTemplateBase template : manager.getAllTemplates(true)) {
|
||||
// save only those settings that differ from defaults
|
||||
boolean shouldSave = template.isReformatCode() != FileTemplateBase.DEFAULT_REFORMAT_CODE_VALUE;
|
||||
if (template instanceof BundledFileTemplate) {
|
||||
shouldSave |= ((BundledFileTemplate)template).isEnabled() != FileTemplateBase.DEFAULT_ENABLED_VALUE;
|
||||
}
|
||||
if (!shouldSave) {
|
||||
continue;
|
||||
}
|
||||
final Element templateElement = new Element(ELEMENT_TEMPLATE);
|
||||
templateElement.setAttribute(ATTRIBUTE_NAME, template.getQualifiedName());
|
||||
templateElement.setAttribute(ATTRIBUTE_REFORMAT, Boolean.toString(template.isReformatCode()));
|
||||
if (template instanceof BundledFileTemplate) {
|
||||
templateElement.setAttribute(ATTRIBUTE_ENABLED, Boolean.toString(((BundledFileTemplate)template).isEnabled()));
|
||||
}
|
||||
templatesGroup.addContent(templateElement);
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
doLoad(myFileTemplateManager, state);
|
||||
myLoaded = true;
|
||||
}
|
||||
|
||||
static void doLoad(FileTemplateManagerImpl fileTemplateManager, Element element) {
|
||||
for (final FTManager manager : fileTemplateManager.getAllManagers()) {
|
||||
final Element templatesGroup = element.getChild(getXmlElementGroupName(manager));
|
||||
if (templatesGroup == null) {
|
||||
continue;
|
||||
}
|
||||
final List children = templatesGroup.getChildren(ELEMENT_TEMPLATE);
|
||||
|
||||
for (final Object elem : children) {
|
||||
final Element child = (Element)elem;
|
||||
final String qName = child.getAttributeValue(ATTRIBUTE_NAME);
|
||||
final FileTemplateBase template = manager.getTemplate(qName);
|
||||
if (template == null) {
|
||||
continue;
|
||||
}
|
||||
final boolean reformat = Boolean.TRUE.toString().equals(child.getAttributeValue(ATTRIBUTE_REFORMAT));
|
||||
template.setReformatCode(reformat);
|
||||
if (template instanceof BundledFileTemplate) {
|
||||
final boolean enabled = Boolean.parseBoolean(child.getAttributeValue(ATTRIBUTE_ENABLED, "true"));
|
||||
((BundledFileTemplate)template).setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getXmlElementGroupName(FTManager manager) {
|
||||
return manager.getName().toLowerCase(Locale.US) + "_" + "templates";
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return myLoaded;
|
||||
}
|
||||
}
|
||||
+19
-68
@@ -25,8 +25,6 @@ import com.intellij.ide.plugins.PluginManager;
|
||||
import com.intellij.ide.plugins.cl.PluginClassLoader;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.components.ExportableComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
@@ -59,7 +57,7 @@ import java.util.*;
|
||||
* locking policy: if the class needs to take a read or write action, the LOCK lock must be taken
|
||||
* _inside_, not outside of the read action
|
||||
*/
|
||||
public class FileTemplateManagerImpl extends FileTemplateManager implements ExportableComponent, JDOMExternalizable {
|
||||
public class FileTemplateManagerImpl extends FileTemplateManager implements JDOMExternalizable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.fileTemplates.impl.FileTemplateManagerImpl");
|
||||
|
||||
private static final String TEMPLATES_DIR = "fileTemplates";
|
||||
@@ -87,11 +85,6 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo
|
||||
private static final String ELEMENT_DELETED_INCLUDES = "deleted_includes";
|
||||
private static final String ELEMENT_RECENT_TEMPLATES = "recent_templates";
|
||||
private static final String ELEMENT_TEMPLATES = "templates";
|
||||
private static final String ELEMENT_INTERNAL_TEMPLATE = "internal_template";
|
||||
private static final String ELEMENT_TEMPLATE = "template";
|
||||
private static final String ATTRIBUTE_NAME = "name";
|
||||
private static final String ATTRIBUTE_REFORMAT = "reformat";
|
||||
private static final String ATTRIBUTE_ENABLED = "enabled";
|
||||
|
||||
private final FTManager[] myAllManagers;
|
||||
private final FileTypeManagerEx myTypeManager;
|
||||
@@ -113,7 +106,7 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo
|
||||
myDirToManagerMap.put(INCLUDES_DIR + "/", myPatternsManager);
|
||||
myDirToManagerMap.put(CODETEMPLATES_DIR + "/", myCodeTemplatesManager);
|
||||
myDirToManagerMap.put(J2EE_TEMPLATES_DIR + "/", myJ2eeTemplatesManager);
|
||||
|
||||
|
||||
myAllManagers = new FTManager[]{myDefaultTemplatesManager, myInternalTemplatesManager, myPatternsManager, myCodeTemplatesManager, myJ2eeTemplatesManager};
|
||||
|
||||
loadDefaultTemplates();
|
||||
@@ -278,16 +271,6 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo
|
||||
return FileUtil.startsWith(path, prefix) && !path.substring(prefix.length()).contains("/");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public File[] getExportFiles() {
|
||||
return new File[]{myDefaultTemplatesManager.getConfigRoot(false), PathManager.getDefaultOptionsFile()};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPresentableName() {
|
||||
return IdeBundle.message("item.file.templates");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FileTemplate[] getAllTemplates() {
|
||||
final Collection<FileTemplateBase> templates = myDefaultTemplatesManager.getAllTemplates(false);
|
||||
@@ -362,6 +345,7 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo
|
||||
}
|
||||
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
|
||||
final Element recentElement = element.getChild(ELEMENT_RECENT_TEMPLATES);
|
||||
if (recentElement != null) {
|
||||
myRecentList.readExternal(recentElement);
|
||||
@@ -386,35 +370,18 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo
|
||||
final List children = templatesElement.getChildren();
|
||||
for (final Object child : children) {
|
||||
final Element childElement = (Element)child;
|
||||
boolean reformat = Boolean.TRUE.toString().equals(childElement.getAttributeValue(ATTRIBUTE_REFORMAT));
|
||||
boolean reformat =
|
||||
Boolean.TRUE.toString().equals(childElement.getAttributeValue(ExportableFileTemplateSettings.ATTRIBUTE_REFORMAT));
|
||||
if (!reformat) {
|
||||
final String name = childElement.getAttributeValue(ATTRIBUTE_NAME);
|
||||
final String name = childElement.getAttributeValue(ExportableFileTemplateSettings.ATTRIBUTE_NAME);
|
||||
templateNamesWithReformatOff.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (final FTManager manager : myAllManagers) {
|
||||
final Element templatesGroup = element.getChild(getXmlElementGroupName(manager));
|
||||
if (templatesGroup == null) {
|
||||
continue;
|
||||
}
|
||||
final List children = templatesGroup.getChildren(ELEMENT_TEMPLATE);
|
||||
|
||||
for (final Object elem : children) {
|
||||
final Element child = (Element)elem;
|
||||
final String qName = child.getAttributeValue(ATTRIBUTE_NAME);
|
||||
final FileTemplateBase template = manager.getTemplate(qName);
|
||||
if (template == null) {
|
||||
continue;
|
||||
}
|
||||
final boolean reformat = Boolean.TRUE.toString().equals(child.getAttributeValue(ATTRIBUTE_REFORMAT));
|
||||
template.setReformatCode(reformat);
|
||||
if (template instanceof BundledFileTemplate) {
|
||||
final boolean enabled = Boolean.parseBoolean(child.getAttributeValue(ATTRIBUTE_ENABLED, "true"));
|
||||
((BundledFileTemplate)template).setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
ExportableFileTemplateSettings exportableFileTemplateSettings = ServiceManager.getService(ExportableFileTemplateSettings.class);
|
||||
if (!exportableFileTemplateSettings.isLoaded()) {
|
||||
ExportableFileTemplateSettings.doLoad(this, element);
|
||||
}
|
||||
|
||||
// apply data loaded from older format
|
||||
@@ -466,27 +433,6 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo
|
||||
element.addContent(recentElement);
|
||||
myRecentList.writeExternal(recentElement);
|
||||
|
||||
for (FTManager manager : myAllManagers) {
|
||||
final Element templatesGroup = new Element(getXmlElementGroupName(manager));
|
||||
element.addContent(templatesGroup);
|
||||
for (FileTemplateBase template : manager.getAllTemplates(true)) {
|
||||
// save only those settings that differ from defaults
|
||||
boolean shouldSave = template.isReformatCode() != FileTemplateBase.DEFAULT_REFORMAT_CODE_VALUE;
|
||||
if (template instanceof BundledFileTemplate) {
|
||||
shouldSave |= ((BundledFileTemplate)template).isEnabled() != FileTemplateBase.DEFAULT_ENABLED_VALUE;
|
||||
}
|
||||
if (!shouldSave) {
|
||||
continue;
|
||||
}
|
||||
final Element templateElement = new Element(ELEMENT_TEMPLATE);
|
||||
templateElement.setAttribute(ATTRIBUTE_NAME, template.getQualifiedName());
|
||||
templateElement.setAttribute(ATTRIBUTE_REFORMAT, Boolean.toString(template.isReformatCode()));
|
||||
if (template instanceof BundledFileTemplate) {
|
||||
templateElement.setAttribute(ATTRIBUTE_ENABLED, Boolean.toString(((BundledFileTemplate)template).isEnabled()));
|
||||
}
|
||||
templatesGroup.addContent(templateElement);
|
||||
}
|
||||
}
|
||||
//Element deletedTemplatesElement = new Element(ELEMENT_DELETED_TEMPLATES);
|
||||
//element.addContent(deletedTemplatesElement);
|
||||
//myDefaultTemplatesManager.getDeletedTemplates().writeExternal(deletedTemplatesElement);
|
||||
@@ -519,10 +465,6 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo
|
||||
// return templateElement;
|
||||
//}
|
||||
|
||||
private static String getXmlElementGroupName(FTManager manager) {
|
||||
return manager.getName().toLowerCase(Locale.US) + "_" + "templates";
|
||||
}
|
||||
|
||||
private void validateRecentNames() {
|
||||
final Collection<FileTemplateBase> allTemplates = myDefaultTemplatesManager.getAllTemplates(false);
|
||||
final List<String> allNames = new ArrayList<String>(allTemplates.size());
|
||||
@@ -714,4 +656,13 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FTManager[] getAllManagers() {
|
||||
return myAllManagers;
|
||||
}
|
||||
|
||||
FTManager getDefaultTemplatesManager() {
|
||||
return myDefaultTemplatesManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@
|
||||
|
||||
<applicationService serviceInterface="com.intellij.ide.fileTemplates.FileTemplateManager"
|
||||
serviceImplementation="com.intellij.ide.fileTemplates.impl.FileTemplateManagerImpl"/>
|
||||
<exportable serviceInterface="com.intellij.ide.fileTemplates.FileTemplateManager"/>
|
||||
<applicationService serviceInterface="com.intellij.ide.fileTemplates.impl.ExportableFileTemplateSettings"
|
||||
serviceImplementation="com.intellij.ide.fileTemplates.impl.ExportableFileTemplateSettings"/>
|
||||
<exportable serviceInterface="com.intellij.ide.fileTemplates.impl.ExportableFileTemplateSettings"/>
|
||||
|
||||
<applicationService serviceInterface="com.intellij.ide.PsiCopyPasteManager"
|
||||
serviceImplementation="com.intellij.ide.PsiCopyPasteManager"/>
|
||||
|
||||
Reference in New Issue
Block a user