mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+13
-22
@@ -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<Element> {
|
||||
|
||||
public final static String EXPORTABLE_SETTINGS_FILE = "template.settings.xml";
|
||||
|
||||
private Collection<TemplateSettings.TemplateKey> deletedKeys = new ArrayList<TemplateSettings.TemplateKey>();
|
||||
public class ExportableTemplateSettings implements PersistentStateComponent<ExportableTemplateSettings> {
|
||||
private Collection<TemplateSettings.TemplateKey> deletedKeys = new SmartList<TemplateSettings.TemplateKey>();
|
||||
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<Elem
|
||||
return deletedKeys;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration") // Property via reflection
|
||||
public void setDeletedKeys(Collection<TemplateSettings.TemplateKey> deletedKeys) {
|
||||
this.deletedKeys = deletedKeys;
|
||||
|
||||
+8
-52
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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() {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user