mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ability to specify additionalExportFile in State annotation — we can export component state without instantiation
This commit is contained in:
@@ -48,7 +48,8 @@ import java.util.*;
|
||||
@Storage(file = StoragePathMacros.APP_CONFIG + "/other.xml"),
|
||||
@Storage(file = StoragePathMacros.APP_CONFIG + "/templates.xml")
|
||||
},
|
||||
storageChooser = LastStorageChooserForWrite.class
|
||||
storageChooser = LastStorageChooserForWrite.class,
|
||||
additionalExportFile = TemplateSettings.TEMPLATES_DIR_PATH
|
||||
)
|
||||
public class TemplateSettings implements PersistentStateComponent<TemplateSettings.State> {
|
||||
private static final Logger LOG = Logger.getInstance(TemplateSettings.class);
|
||||
@@ -90,6 +91,8 @@ public class TemplateSettings implements PersistentStateComponent<TemplateSettin
|
||||
@NonNls private static final String KEY = "key";
|
||||
@NonNls private static final String ID = "id";
|
||||
|
||||
static final String TEMPLATES_DIR_PATH = StoragePathMacros.ROOT_CONFIG + "/templates";
|
||||
|
||||
private final MultiMap<String, TemplateImpl> myTemplates = MultiMap.createLinked();
|
||||
|
||||
private final Map<String, Template> myTemplatesById = new LinkedHashMap<String, Template>();
|
||||
@@ -183,7 +186,7 @@ public class TemplateSettings implements PersistentStateComponent<TemplateSettin
|
||||
private TemplateKey myLastSelectedTemplate;
|
||||
|
||||
public TemplateSettings(SchemesManagerFactory schemesManagerFactory) {
|
||||
mySchemesManager = schemesManagerFactory.createSchemesManager(StoragePathMacros.ROOT_CONFIG + "/templates", new BaseSchemeProcessor<TemplateGroup>() {
|
||||
mySchemesManager = schemesManagerFactory.createSchemesManager(TEMPLATES_DIR_PATH, new BaseSchemeProcessor<TemplateGroup>() {
|
||||
@Override
|
||||
@Nullable
|
||||
public TemplateGroup readScheme(@NotNull final Document schemeContent) throws InvalidDataException {
|
||||
|
||||
@@ -59,8 +59,7 @@ public class ExportSettingsAction extends AnAction implements DumbAware {
|
||||
public void actionPerformed(@Nullable AnActionEvent e) {
|
||||
ApplicationManager.getApplication().saveSettings();
|
||||
|
||||
MultiMap<File, ExportableComponent> fileToComponents = getExportableComponentsMap(true);
|
||||
ChooseComponentsToExportDialog dialog = new ChooseComponentsToExportDialog(fileToComponents, true,
|
||||
ChooseComponentsToExportDialog dialog = new ChooseComponentsToExportDialog(getExportableComponentsMap(true), true,
|
||||
IdeBundle.message("title.select.components.to.export"),
|
||||
IdeBundle.message(
|
||||
"prompt.please.check.all.components.to.export"));
|
||||
@@ -183,8 +182,25 @@ public class ExportSettingsAction extends AnAction implements DumbAware {
|
||||
!StringUtil.isEmpty(storage.file()) &&
|
||||
storage.file().startsWith(StoragePathMacros.APP_CONFIG)) {
|
||||
File file = new File(storageManager.expandMacros(storage.file()));
|
||||
if (!onlyExisting || file.exists()) {
|
||||
result.putValue(file, new MyExportableComponent(file, getExportableComponentPresentableName(stateAnnotation.name(), aClass, pluginDescriptor)));
|
||||
|
||||
File additionalExportFile = null;
|
||||
if (!StringUtil.isEmpty(stateAnnotation.additionalExportFile())) {
|
||||
additionalExportFile = new File(storageManager.expandMacros(stateAnnotation.additionalExportFile()));
|
||||
if (onlyExisting && !additionalExportFile.exists()) {
|
||||
additionalExportFile = null;
|
||||
}
|
||||
}
|
||||
|
||||
boolean fileExists = !onlyExisting || file.exists();
|
||||
if (fileExists || additionalExportFile != null) {
|
||||
File[] files;
|
||||
if (additionalExportFile == null) {
|
||||
files = new File[]{file};
|
||||
}
|
||||
else {
|
||||
files = fileExists ? new File[]{file, additionalExportFile} : new File[]{additionalExportFile};
|
||||
}
|
||||
result.putValue(file, new MyExportableComponent(files, getExportableComponentPresentableName(stateAnnotation.name(), aClass, pluginDescriptor)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,18 +236,18 @@ public class ExportSettingsAction extends AnAction implements DumbAware {
|
||||
}
|
||||
|
||||
private static final class MyExportableComponent implements ExportableComponent {
|
||||
private final File file;
|
||||
private final File[] files;
|
||||
private final String name;
|
||||
|
||||
public MyExportableComponent(@NotNull File file, @NotNull String name) {
|
||||
this.file = file;
|
||||
public MyExportableComponent(@NotNull File[] files, @NotNull String name) {
|
||||
this.files = files;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public File[] getExportFiles() {
|
||||
return new File[]{file};
|
||||
return files;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -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.
|
||||
@@ -36,24 +36,22 @@ import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.updateSettings.impl.UpdateSettings;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.util.io.ZipUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipException;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public class ImportSettingsAction extends AnAction implements DumbAware {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
final Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
|
||||
ChooseComponentsToExportDialog.chooseSettingsFile(PathManager.getConfigPath(), component, IdeBundle.message("title.import.file.location"), IdeBundle.message("prompt.choose.import.file.path")).doWhenDone(new Consumer<String>() {
|
||||
@@ -73,6 +71,7 @@ public class ImportSettingsAction extends AnAction implements DumbAware {
|
||||
return;
|
||||
}
|
||||
|
||||
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
|
||||
final ZipEntry magicEntry = new ZipFile(saveFile).getEntry(ImportSettingsFilenameFilter.SETTINGS_JAR_MARKER);
|
||||
if (magicEntry == null) {
|
||||
Messages.showErrorDialog(
|
||||
@@ -82,13 +81,15 @@ public class ImportSettingsAction extends AnAction implements DumbAware {
|
||||
}
|
||||
|
||||
MultiMap<File, ExportableComponent> filesToComponents = ExportSettingsAction.getExportableComponentsMap(false);
|
||||
List<ExportableComponent> components = getComponentsStored(saveFile, ContainerUtil.newArrayList(filesToComponents.values()));
|
||||
List<ExportableComponent> components = getComponentsStored(saveFile, filesToComponents.values());
|
||||
filesToComponents.values().retainAll(components);
|
||||
final ChooseComponentsToExportDialog dialog = new ChooseComponentsToExportDialog(filesToComponents, false,
|
||||
IdeBundle.message("title.select.components.to.import"),
|
||||
IdeBundle.message("prompt.check.components.to.import"));
|
||||
dialog.show();
|
||||
if (!dialog.isOK()) return;
|
||||
if (!dialog.showAndGet()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Set<ExportableComponent> chosenComponents = dialog.getExportableComponents();
|
||||
Set<String> relativeNamesToExtract = new HashSet<String>();
|
||||
for (final ExportableComponent chosenComponent : chosenComponents) {
|
||||
@@ -146,19 +147,19 @@ public class ImportSettingsAction extends AnAction implements DumbAware {
|
||||
return IdeBundle.message("message.please.ensure.correct.settings");
|
||||
}
|
||||
|
||||
private static List<ExportableComponent> getComponentsStored(File zipFile,
|
||||
ArrayList<ExportableComponent> registeredComponents)
|
||||
throws IOException {
|
||||
@NotNull
|
||||
private static List<ExportableComponent> getComponentsStored(@NotNull File zipFile,
|
||||
@NotNull Collection<? extends ExportableComponent> registeredComponents) throws IOException {
|
||||
final File configPath = new File(PathManager.getConfigPath());
|
||||
|
||||
final ArrayList<ExportableComponent> components = new ArrayList<ExportableComponent>();
|
||||
for (ExportableComponent component : registeredComponents) {
|
||||
final File[] exportFiles = component.getExportFiles();
|
||||
for (File exportFile : exportFiles) {
|
||||
for (File exportFile : component.getExportFiles()) {
|
||||
final String rPath = FileUtil.getRelativePath(configPath, exportFile);
|
||||
assert rPath != null;
|
||||
String relativePath = FileUtil.toSystemIndependentName(rPath);
|
||||
if (exportFile.isDirectory()) relativePath += "/";
|
||||
if (exportFile.isDirectory()) {
|
||||
relativePath += '/';
|
||||
}
|
||||
if (ZipUtil.isZipContainsEntry(zipFile, relativePath)) {
|
||||
components.add(component);
|
||||
break;
|
||||
@@ -167,5 +168,4 @@ public class ImportSettingsAction extends AnAction implements DumbAware {
|
||||
}
|
||||
return components;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
package com.intellij.openapi.keymap.impl;
|
||||
|
||||
import com.intellij.openapi.actionSystem.IdeActions;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.keymap.KeyMapBundle;
|
||||
import com.intellij.openapi.keymap.Keymap;
|
||||
import com.intellij.openapi.keymap.KeymapManagerListener;
|
||||
import com.intellij.openapi.keymap.ex.KeymapManagerEx;
|
||||
@@ -35,14 +33,16 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
@State(
|
||||
name = "KeymapManager",
|
||||
storages = @Storage(file = StoragePathMacros.APP_CONFIG + "/keymap.xml", roamingType = RoamingType.PER_PLATFORM)
|
||||
storages = @Storage(file = StoragePathMacros.APP_CONFIG + "/keymap.xml", roamingType = RoamingType.PER_PLATFORM),
|
||||
additionalExportFile = KeymapManagerImpl.KEYMAPS_DIR_PATH
|
||||
)
|
||||
public class KeymapManagerImpl extends KeymapManagerEx implements PersistentStateComponent<Element>, ExportableApplicationComponent {
|
||||
public class KeymapManagerImpl extends KeymapManagerEx implements PersistentStateComponent<Element>, ApplicationComponent {
|
||||
static final String KEYMAPS_DIR_PATH = StoragePathMacros.ROOT_CONFIG + "/keymaps";
|
||||
|
||||
private final List<KeymapManagerListener> myListeners = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
private String myActiveKeymapName;
|
||||
private final Map<String, String> myBoundShortcuts = new HashMap<String, String>();
|
||||
@@ -55,7 +55,7 @@ public class KeymapManagerImpl extends KeymapManagerEx implements PersistentStat
|
||||
public static boolean ourKeymapManagerInitialized = false;
|
||||
|
||||
KeymapManagerImpl(DefaultKeymap defaultKeymap, SchemesManagerFactory factory) {
|
||||
mySchemesManager = factory.createSchemesManager(StoragePathMacros.ROOT_CONFIG + "/keymaps",
|
||||
mySchemesManager = factory.createSchemesManager(KEYMAPS_DIR_PATH,
|
||||
new BaseSchemeProcessor<KeymapImpl>() {
|
||||
@Override
|
||||
public KeymapImpl readScheme(@NotNull final Document schemeContent) throws InvalidDataException {
|
||||
@@ -95,18 +95,6 @@ public class KeymapManagerImpl extends KeymapManagerEx implements PersistentStat
|
||||
ourKeymapManagerInitialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public File[] getExportFiles() {
|
||||
return new File[]{new File(PathManager.getOptionsPath() + File.separatorChar + "keymap.xml"), mySchemesManager.getRootDirectory()};
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getPresentableName() {
|
||||
return KeyMapBundle.message("key.maps.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Keymap[] getAllKeymaps() {
|
||||
List<Keymap> answer = new ArrayList<Keymap>();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
mouse.shortcut.label=Click here to enter mouse shortcut
|
||||
prefix.key.pressed.message=Prefix Key Pressed.
|
||||
key.maps.name=Key maps
|
||||
action.column.name=Action
|
||||
shortcuts.column.name=Shortcuts
|
||||
|
||||
|
||||
@@ -302,3 +302,4 @@ exportable.libraryTable.presentable.name=Global libraries
|
||||
exportable.NotificationConfiguration.presentable.name=Notifications
|
||||
exportable.CodeInsightSettings.presentable.name=CodeInsight
|
||||
exportable.HttpConfigurable.presentable.name=HTTP Proxy
|
||||
exportable.KeymapManager.presentable.name=Key maps
|
||||
|
||||
@@ -34,4 +34,6 @@ public @interface State {
|
||||
Class<? extends StateStorageChooser> storageChooser() default StateStorageChooser.class;
|
||||
|
||||
boolean reloadable() default true;
|
||||
|
||||
String additionalExportFile() default "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user