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..4f9a846d5763 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,13 @@ 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.xmlb.XmlSerializer; -import org.jdom.Element; +import com.intellij.util.SmartList; +import com.intellij.util.xmlb.XmlSerializerUtil; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.Collection; /** @@ -32,33 +30,27 @@ 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(); +public class ExportableTemplateSettings implements PersistentStateComponent { + private Collection deletedKeys = new SmartList(); private boolean isLoaded = false; private TemplateSettings parentSettings; @Nullable @Override - public Element getState() { + public ExportableTemplateSettings getState() { if (parentSettings != null) { - this.deletedKeys.clear(); - this.deletedKeys.addAll(parentSettings.getDeletedTemplates()); + deletedKeys.clear(); + deletedKeys.addAll(parentSettings.getDeletedTemplates()); } - return XmlSerializer.serialize(this); + return this; } @Override - public void loadState(Element state) { - XmlSerializer.deserializeInto(this, state); + public void loadState(ExportableTemplateSettings state) { + XmlSerializerUtil.copyBean(state, this); isLoaded = true; } @@ -71,7 +63,6 @@ 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-impl/src/com/intellij/ide/SaveAndSyncHandlerImpl.java b/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandlerImpl.java index 1f96a3fa2559..e42c796ab8bb 100644 --- a/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandlerImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/SaveAndSyncHandlerImpl.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. @@ -33,7 +33,7 @@ import com.intellij.openapi.vfs.newvfs.ManagingFS; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; import com.intellij.openapi.vfs.newvfs.RefreshQueue; import com.intellij.openapi.vfs.newvfs.RefreshSession; -import com.intellij.util.Alarm; +import com.intellij.util.SingleAlarm; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -47,7 +47,7 @@ import java.util.concurrent.atomic.AtomicInteger; * @author Vladimir Kondratyev */ public class SaveAndSyncHandlerImpl implements ApplicationComponent, SaveAndSyncHandler { - private static final Logger LOG = Logger.getInstance("#com.intellij.ide.SaveAndSyncHandler"); + private static final Logger LOG = Logger.getInstance(SaveAndSyncHandler.class); private final Runnable myIdleListener; private final PropertyChangeListener myGeneralSettingsListener; @@ -55,18 +55,26 @@ public class SaveAndSyncHandlerImpl implements ApplicationComponent, SaveAndSync private final AtomicInteger myBlockSaveOnFrameDeactivationCount = new AtomicInteger(); private final AtomicInteger myBlockSyncOnFrameActivationCount = new AtomicInteger(); - private final Alarm myRefreshDelayAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD); + private final SingleAlarm myRefreshDelayAlarm = new SingleAlarm(new Runnable() { + @Override + public void run() { + if (canSyncOrSave()) { + refreshOpenFiles(); + } + maybeRefresh(ModalityState.NON_MODAL); + } + }, 300); private long myRefreshSessionId = 0; - public static SaveAndSyncHandlerImpl getInstance(){ - return (SaveAndSyncHandlerImpl) ApplicationManager.getApplication().getComponent(SaveAndSyncHandler.class); + public static SaveAndSyncHandlerImpl getInstance() { + return (SaveAndSyncHandlerImpl)ApplicationManager.getApplication().getComponent(SaveAndSyncHandler.class); } - public SaveAndSyncHandlerImpl(final FrameStateManager frameStateManager, - final FileDocumentManager fileDocumentManager, - final GeneralSettings generalSettings, - final ProgressManager progressManager) { + public SaveAndSyncHandlerImpl(@NotNull FrameStateManager frameStateManager, + @NotNull final FileDocumentManager fileDocumentManager, + @NotNull final GeneralSettings generalSettings, + @NotNull ProgressManager progressManager) { myProgressManager = progressManager; myIdleListener = new Runnable() { @@ -78,14 +86,11 @@ public class SaveAndSyncHandlerImpl implements ApplicationComponent, SaveAndSync } }; - IdeEventQueue.getInstance().addIdleListener( - myIdleListener, - generalSettings.getInactiveTimeout() * 1000 - ); + IdeEventQueue.getInstance().addIdleListener(myIdleListener, generalSettings.getInactiveTimeout() * 1000); myGeneralSettingsListener = new PropertyChangeListener() { @Override - public void propertyChange(PropertyChangeEvent e) { + public void propertyChange(@NotNull PropertyChangeEvent e) { if (GeneralSettings.PROP_INACTIVE_TIMEOUT.equals(e.getPropertyName())) { IdeEventQueue eventQueue = IdeEventQueue.getInstance(); eventQueue.removeIdleListener(myIdleListener); @@ -94,6 +99,7 @@ public class SaveAndSyncHandlerImpl implements ApplicationComponent, SaveAndSync } } }; + generalSettings.addPropertyChangeListener(myGeneralSettingsListener); frameStateManager.addListener(new FrameStateListener() { @@ -106,7 +112,13 @@ public class SaveAndSyncHandlerImpl implements ApplicationComponent, SaveAndSync @Override public void onFrameActivated() { - refreshFiles(); + if (ApplicationManager.getApplication().isDisposed() || !generalSettings.isSyncOnFrameActivation()) { + return; + } + + LOG.debug("enter: refreshFiles()"); + myRefreshDelayAlarm.cancelAndRequest(); + LOG.debug("exit: refreshFiles()"); } }); } @@ -158,25 +170,6 @@ public class SaveAndSyncHandlerImpl implements ApplicationComponent, SaveAndSync } } - private void refreshFiles() { - if (ApplicationManager.getApplication().isDisposed() || !GeneralSettings.getInstance().isSyncOnFrameActivation()) { - return; - } - - LOG.debug("enter: refreshFiles()"); - myRefreshDelayAlarm.cancelAllRequests(); - myRefreshDelayAlarm.addRequest(new Runnable() { - @Override - public void run() { - if (canSyncOrSave()) { - refreshOpenFiles(); - } - maybeRefresh(ModalityState.NON_MODAL); - } - }, 300, ModalityState.NON_MODAL); - LOG.debug("exit: refreshFiles()"); - } - public void maybeRefresh(@NotNull ModalityState modalityState) { if (myBlockSyncOnFrameActivationCount.get() == 0 && GeneralSettings.getInstance().isSyncOnFrameActivation()) { LOG.debug("VFS refresh started"); 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 @@ - + - + - - - - - + + + +