BundledKeymapProvider should be able to override default load logic

This commit is contained in:
Vladimir Krivosheev
2017-02-01 15:07:44 +01:00
parent e1766bf61e
commit ca0bd80263
2 changed files with 12 additions and 4 deletions
@@ -16,9 +16,14 @@
package com.intellij.openapi.keymap.impl;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.util.io.URLUtil;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.function.Function;
/**
* Name file as "Your scheme name.xml" and put it to keymaps.
@@ -29,4 +34,10 @@ public interface BundledKeymapProvider {
@NotNull
List<String> getKeymapFileNames();
default <R> R load(@NotNull String key, @NotNull Function<InputStream, R> consumer) throws IOException {
try (InputStream stream = URLUtil.openResourceStream(new URL("file:///keymaps/" + key))) {
return consumer.apply(stream);
}
}
}
@@ -27,7 +27,6 @@ import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.io.FileUtilRt
import gnu.trove.THashMap
import org.jdom.Element
import java.net.URL
import java.util.*
private val LOG = Logger.getInstance("#com.intellij.openapi.keymap.impl.DefaultKeymap")
@@ -65,9 +64,7 @@ open class DefaultKeymap {
LOG.catchAndLog {
loadKeymapsFromElement(object: SchemeDataHolder<KeymapImpl> {
override fun read(): Element {
return JDOMUtil.loadResourceDocument(URL("file:///keymaps/$key")).rootElement
}
override fun read() = provider.load(key) { JDOMUtil.load(it) }
override fun updateDigest(scheme: KeymapImpl) {
}